com.hp.hpl.jena.util
Class FileManager

java.lang.Object
  extended by com.hp.hpl.jena.util.FileManager

public class FileManager
extends Object

FileManager A FileManager provides access to named file-like resources by opening InputStreams to things in the filing system, by URL (http: and file:) amd found by the classloader. It can also load RDF data from such a system resource into an existing model or create a new (Memory-based) model. There is a global FileManager which provide uniform access to system resources: applications may also create specialised FileManagers. A FileManager contains a list of location functions to try: the global FileManger has one @link{LocatorFile} and one @link{LocatorClassLoader}. A FileManager works in conjunction with a LocationMapper. A @link{LocationMapper} is a set of alternative locations for system resources and a set of alternative prefix locations. For example, a local copy of a common RDF dataset may be used whenever the usual URL is used by the application. The FileManager also supports the idea of "current directory". This only applies to the LocatorFile and not, for example, items found by a classloader.

Version:
$Id: FileManager.java,v 1.8 2004/12/07 18:51:18 andy_seaborne Exp $
Author:
Andy Seaborne
See Also:
LocationMapper

Field Summary
static String filePathSeparator
           
static String PATH_DELIMITER
          Delimiter between path entries : because URI scheme names use : we only allow ;
 
Constructor Summary
FileManager()
          Create an uninitialized FileManager
FileManager(LocationMapper _mapper)
          Create with the given location mapper
 
Method Summary
 void addLocator(Locator loc)
          Add a locator to the end of the locators list
 void addLocatorClassLoader(ClassLoader cLoad)
          Add a class loader locator
 void addLocatorFile()
          Add a file locator
 void addLocatorFile(String dir)
          Add a file locator which uses dir as its working directory
 void addLocatorSystemClassLoader()
          Add the system class loader
 void addLocatorURL()
          Add a URL locator
 void addLocatorZip(String zfn)
          Add a zip file locator
static FileManager get()
          Get the global file manager.
 Model loadModel(String filenameOrURI)
          Load a model from a file (local or remote).
 Model loadModel(String filenameOrURI, String rdfSyntax)
          Load a model from a file (local or remote).
 Model loadModel(String filenameOrURI, String baseURI, String rdfSyntax)
          Load a model from a file (local or remote).
 Iterator locators()
          Return an iterator over all the handlers
 InputStream open(String filenameOrURI)
          Open a file using the locators of this FileManager
 InputStream openNoMap(String filenameOrURI)
          Open a file using the locators of this FileManager but without location mapping
 Model readModel(Model model, String filenameOrURI)
          Read a file of RDF into a model.
 Model readModel(Model model, String filenameOrURI, String rdfSyntax)
          Read a file of RDF into a model.
 Model readModel(Model model, String filenameOrURI, String baseURI, String syntax)
          Read a file of RDF into a model.
 String readWholeFileAsUTF8(InputStream in)
          Slurp up a whole file: map filename as necessary
 String readWholeFileAsUTF8(String filename)
          Slurp up a whole file: map filename as necessary
 String remap(String filenameOrURI)
          Apply the mapping of a filename or URI
 void remove(Locator loc)
          Remove a locator
 void resetCache()
          Reset the model cache
 void setMapper(LocationMapper _mapper)
          Set the location mapping
 void setModelCaching(boolean state)
          Change the state of model cache : does not clear the cache
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_DELIMITER

public static final String PATH_DELIMITER
Delimiter between path entries : because URI scheme names use : we only allow ;

See Also:
Constant Field Values

filePathSeparator

public static final String filePathSeparator
Constructor Detail

FileManager

public FileManager()
Create an uninitialized FileManager


FileManager

public FileManager(LocationMapper _mapper)
Create with the given location mapper

Method Detail

get

public static FileManager get()
Get the global file manager.

Returns:
the global file manager

setMapper

public void setMapper(LocationMapper _mapper)
Set the location mapping


locators

public Iterator locators()
Return an iterator over all the handlers


addLocator

public void addLocator(Locator loc)
Add a locator to the end of the locators list


addLocatorFile

public void addLocatorFile()
Add a file locator


addLocatorFile

public void addLocatorFile(String dir)
Add a file locator which uses dir as its working directory


addLocatorSystemClassLoader

public void addLocatorSystemClassLoader()
Add the system class loader


addLocatorClassLoader

public void addLocatorClassLoader(ClassLoader cLoad)
Add a class loader locator


addLocatorURL

public void addLocatorURL()
Add a URL locator


addLocatorZip

public void addLocatorZip(String zfn)
Add a zip file locator


remove

public void remove(Locator loc)
Remove a locator


resetCache

public void resetCache()
Reset the model cache


setModelCaching

public void setModelCaching(boolean state)
Change the state of model cache : does not clear the cache


loadModel

public Model loadModel(String filenameOrURI)
Load a model from a file (local or remote). Guesses the syntax of the file based on filename extension, defaulting to RDF/XML.

Parameters:
filenameOrURI - The filename or a URI (file:, http:)
Returns:
a new model

loadModel

public Model loadModel(String filenameOrURI,
                       String rdfSyntax)
Load a model from a file (local or remote). Guesses the syntax of the file based on filename extension, defaulting to RDF/XML.

Parameters:
filenameOrURI - The filename or a URI (file:, http:)
rdfSyntax - RDF Serialization syntax.
Returns:
a new model

loadModel

public Model loadModel(String filenameOrURI,
                       String baseURI,
                       String rdfSyntax)
Load a model from a file (local or remote). Guesses the syntax of the file based on filename extension, defaulting to RDF/XML.

Parameters:
filenameOrURI - The filename or a URI (file:, http:)
baseURI - Base URI for loading the RDF model.
rdfSyntax - RDF Serialization syntax.
Returns:
a new model

readModel

public Model readModel(Model model,
                       String filenameOrURI)
Read a file of RDF into a model.

Parameters:
model -
filenameOrURI -
Returns:
The model or null, if there was an error.

readModel

public Model readModel(Model model,
                       String filenameOrURI,
                       String rdfSyntax)
Read a file of RDF into a model.

Parameters:
model -
filenameOrURI -
rdfSyntax - RDF Serialization syntax.
Returns:
The model or null, if there was an error.

readModel

public Model readModel(Model model,
                       String filenameOrURI,
                       String baseURI,
                       String syntax)
Read a file of RDF into a model.

Parameters:
model -
filenameOrURI -
baseURI -
syntax -
Returns:
The model
Throws:
If - syntax error in file.

open

public InputStream open(String filenameOrURI)
Open a file using the locators of this FileManager


remap

public String remap(String filenameOrURI)
Apply the mapping of a filename or URI


readWholeFileAsUTF8

public String readWholeFileAsUTF8(InputStream in)
Slurp up a whole file: map filename as necessary


readWholeFileAsUTF8

public String readWholeFileAsUTF8(String filename)
Slurp up a whole file: map filename as necessary


openNoMap

public InputStream openNoMap(String filenameOrURI)
Open a file using the locators of this FileManager but without location mapping



Copyright © 2000, 2001, 2002, 2003, 2004 Hewlett-Packard Development Company, LP