|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.exln.stylus.io.StylusFileFactory
Defines a factory API that enables applications to read and write
data streams using any custom file system which implements the
StylusFile
interface. This class also implements the interfaces
URIResolver
and EntityResolver
.
If you register an instance of this class as the URIResolver and/or EntityResolver
for your parser or transformer, it will use StylusFileFactory to resolve references
as needed.
To use this class:
registerScheme(String scheme, String className, String classPath)
).unlockAPI(String installID)
.registerScheme(String scheme, String className, String classPath)
method. Except as
described above, the class paths
are determined automatically from the location of CustomFileSystem.jar.
The simplest way to use this class is:
StylusFile sf =
StylusFileFactory.getFactory().createStylusFile(String url);
The resulting StylusFile
object can be used to access the specified url using one of
the built-in protocols listed above. See StylusFile
and createStylusFile
.
If you have implemented a custom file system and wish to use this class to access it,
you must register your custom file system as follows, before calling createStylusFile
:
StylusFileFactory.getFactory().registerScheme(String scheme, String className);
For more details, see registerScheme
.
Nested Class Summary | |
static class |
StylusFileFactory.ResolverWrapper
Wraps the singleton StylusFileFactory object in a class which can be instantiated with a constructor. |
Method Summary | |
static InputStream |
createInputStream(String uri,
String URIBase)
A convenience method to resolve a Stylus Studio URI and return an InputStream. |
static Result |
createOutputResult(String uri,
String URIBase)
A convenience method to resolve a Stylus Studio URI and return a StreamResult. |
static OutputStream |
createOutputStream(String uri,
String URIBase)
A convenience method to resolve a Stylus Studio URI and return an OutputStream. |
static StreamSource |
createSource(String uri,
String URIBase,
boolean useResolver)
A convenience method to resolve a Stylus Studio uri and return a StreamSource. |
StylusFile |
createStylusFile(String url)
Create a StylusFile object for file access through a custom file system. |
StylusFile |
createStylusFile(String url,
InputStream is)
Create a StylusFile object for file access through a custom file system. |
StylusFile |
createStylusFile(String url,
OutputStream os)
Create a StylusFile object for file access through a custom file system. |
static StylusFileFactory |
getFactory()
Get the singleton StylusFileFactory . |
static String |
getUnlockAPIError()
Get the error message generated from the last call to unlockAPI. |
Result |
outputStreamResolver(String uri,
String URIBase)
Resolve a URI and return a Result which can be used to write data to the URI. |
void |
registerScheme(String scheme,
String className)
Register a scheme name and its associated StylusFile class name. |
void |
registerScheme(String scheme,
String className,
String classPath)
Register a scheme name and its associated StylusFile class name and classpath. |
Source |
resolve(String uri,
String URIBase)
Resolve a URI and return a Source which can
be used to read data from the URI. |
InputSource |
resolveEntity(String publicId,
String systemId)
Implementation of EntityResolver. |
static boolean |
unlockAPI(String installID)
Unlock the StylusFileFactory API. |
static void |
unlockObject(Object obj)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static StylusFileFactory getFactory()
StylusFileFactory
. If the factory does not yet exist,
it will be created and initialized.
public static boolean unlockAPI(String installID)
installID
- - The Installation ID provided with your license.
public static String getUnlockAPIError()
public static void unlockObject(Object obj)
public StylusFile createStylusFile(String url) throws IOException
StylusFile
object for file access through a custom file system.
The parameter String url is parsed to get the scheme prefix. The scheme is
used to select a custom file system which can access files via that protocol.
The scheme should either be a built-in scheme or should have been registered
with registerScheme
.
The scheme:// prefix is then removed from the url and the rest is passed as
the String parameter to the constructor for that
StylusFile
class for the selected custom file system.
The StylusFile
object returned by createStylusFile
can be used to:
StylusFile.getInputStream()
or StylusFile.copyToFile(String)
StylusFile.getOutputStream()
or StylusFile.copyFromFile(String)
StylusFile
.
StylusFile
object for the class which was registered to the scheme.
IOException
- in any of the following conditions:
registerScheme
StylusFile
public StylusFile createStylusFile(String url, InputStream is) throws IOException
StylusFile
object for file access through a custom file system.
This method differs from createStylusFile(String)
in that it invokes a
2 argument constructor (String, InputStream) of the StylusFile
class.
This is useful if the
StylusFile
object being created is an adapter or converter which
will read input from the InputStream. The application will normally get the
result of the conversion by calling getInputStream() and using it to read the converted
data.
The parameter String url is parsed to get the scheme prefix. The scheme is
used to select a custom file system which can access files via that protocol.
The scheme should either be a built-in scheme or should have been registered
with registerScheme
.
The scheme:// prefix is then removed from the url and the rest is passed as
the String parameter to the constructor for that
StylusFile
class for the selected custom file system.
The StylusFile
object returned by createStylusFile
can be used to:
StylusFile.getInputStream()
or StylusFile.copyToFile(String)
StylusFile
.
StylusFile
object for the class which was registered to the scheme.
IOException
- in any of the following conditions:
registerScheme
StylusFile
public StylusFile createStylusFile(String url, OutputStream os) throws IOException
StylusFile
object for file access through a custom file system.
This method differs from createStylusFile(String)
in that it invokes a
2 argument constructor (String, OutputStream) of the StylusFile
class.
This is useful if the
StylusFile
object being created is an adapter or converter which
will write output to the OutputStream. The application will normally call
the object's getOutputStream method and use that stream to send data to the
adapter.
The parameter String url is parsed to get the scheme prefix. The scheme is
used to select a custom file system which can access files via that protocol.
The scheme should either be a built-in scheme or should have been registered
with one of the registerScheme
methods.
The scheme:// prefix is then removed from the url and the rest is passed as
the String parameter to the constructor for that
StylusFile
class for the selected custom file system.
The application can then send data to the
StylusFile
object returned by createStylusFile
by calling either:
For more details, see StylusFile
.
StylusFile
object for the class which was registered to the scheme.
IOException
- in any of the following conditions:
registerScheme
StylusFile
public void registerScheme(String scheme, String className) throws IllegalArgumentException
StylusFile
class name.
The method StylusFileFactory.createStylusFile
examines the scheme: part of its URL
parameter to know which class to instantiate.
StylusFileFactory
has
a built-in association from the
scheme: to the class name to be instantiated. This built-in list is:
registerScheme
method.
StylusFile
) and wish to use that class through the StylusFileFactory
API, you must register
the association between a scheme: and your class name.
You do this by calling the registerScheme
method. You must call it exactly once for each
scheme you wish to register. When your class is needed, StylusFileFactory will create a class loader
whose class path will be taken from the system property className.classpath
scheme
- The scheme you wish to register.className
- The name of the class which implements StylusFile
and which
should be instantiated when a URL with the registered scheme is passed to the
createStylusFile
method.
IllegalArgumentException
- if
public void registerScheme(String scheme, String className, String classPath) throws IllegalArgumentException
StylusFile
class name and classpath.
This method differs from registerScheme(String scheme, String className)
by allowing
the caller to specify additional classpath elements to use when loading classes for the
specified scheme.
scheme
- The scheme you wish to register.className
- The name of the class which implements StylusFile
and which
should be instantiated when a URL with the registered scheme is passed to the
createStylusFile
method.classPath
- Additional ';' separated elements of the classpath which will be used to load
className. These pathnames will be appended after the pathnames in the system property:
className.classpath
IllegalArgumentException
- if
public Source resolve(String uri, String URIBase) throws TransformerException
Source
which can
be used to read data from the URI. The Source returned by this method
is a StreamSource. To get the data, cast it as a StreamSource and call
getInputStream().
resolve
in interface URIResolver
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.
TransformerException
- If the URI is malformed.public Result outputStreamResolver(String uri, String URIBase) throws TransformerException, IOException
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.
TransformerException
- If the URI is malformed.
IOException
public static StreamSource createSource(String uri, String URIBase, boolean useResolver) throws TransformerException
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.useResolver
- Use the Stylus resolver if this is true.
TransformerException
- If an error occurs.public static InputStream createInputStream(String uri, String URIBase) throws IOException
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.
IOException
- If an error occurs.public static OutputStream createOutputStream(String uri, String URIBase) throws IOException
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.
IOException
- If an error occurs.public static Result createOutputResult(String uri, String URIBase) throws IOException
uri
- The URI to be resolved.URIBase
- The base URI in effect when the URI was encountered.
IOException
- If an error occurs.public InputSource resolveEntity(String publicId, String systemId) throws IOException
resolveEntity
in interface EntityResolver
publicId
- The public identifier of the external entity being referenced,
or null if none was supplied.systemId
- The system identifier of the external entity being referenced.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |