com.ddtek.xmlconverter
Class ConverterResolver

java.lang.Object
  extended by com.ddtek.xmlconverter.ConverterResolver
All Implemented Interfaces:
com.ddtek.xmlconverter.interfaces.StAXResolver, URIResolver

public class ConverterResolver
extends Object
implements URIResolver, com.ddtek.xmlconverter.interfaces.StAXResolver

An implementation of URIResolver which can resolve Converter URIs and many others. This class resolves URIs which start with converter: or file: or can be recognized as file URIs (e.g. C:\abc.txt or \\server\path). Any other URI will be handed to the URL class for further processing. Instances of this class are created from the ConverterFactory class.


Method Summary
 InputStream createInputStream(String uri, String URIBase)
          A convenience method to resolve a Stylus Studio URI and return an InputStream.
 OutputStream createOutputStream(String uri, String URIBase)
          A convenience method to resolve a Stylus Studio URI and return an OutputStream.
 Configuration getConfiguration()
          Get the Configuration associated with this ConverterResolver.
 ConverterFactory getFactory()
          Get the ConverterFactory which created this ConverterResolver.
 SAXSource getSAXSource(String uri, String URIBase)
          Resolve a url and return a SAXSource which can be used to read the data.
 javax.xml.stream.XMLStreamReader getXMLStreamReader(String uri, String URIBase)
          Resolve a url and return a XMLStreamReader to read the data.
 Result outputStreamResolver(String uri, String URIBase)
          Resolve a URI and return a Result which can be used to write data to the URI.
 Source resolve(String uri, String URIBase)
          Resolve a URI and return a Source which can be used to read data from the URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConfiguration

public Configuration getConfiguration()
Get the Configuration associated with this ConverterResolver.

Returns:
A reference to the Configuration object.

getFactory

public ConverterFactory getFactory()
Get the ConverterFactory which created this ConverterResolver.

Returns:
A reference to the ConverterFactory.

resolve

public Source resolve(String uri,
                      String URIBase)
               throws TransformerException
Resolve a URI and return a 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().

Specified by:
resolve in interface URIResolver
Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
A Source object which can be used to read the URI data, or null if the scheme: is not registered.
Throws:
TransformerException - If the URI is malformed or some other error occurs.

outputStreamResolver

public Result outputStreamResolver(String uri,
                                   String URIBase)
                            throws TransformerException,
                                   IOException
Resolve a URI and return a Result which can be used to write data to the URI.

Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
A Result which can be used to write data to the URI, or null if the scheme: is not registered. The Result returned is always a StreamResult. To write data to it, cast it as a StreamResult, and use getOutputStream to get the output stream. It is VERY important to close() the OutputStream, whether you actually write any data to it or not.
Throws:
TransformerException - If the URI is malformed or some other error occurs.
IOException

createInputStream

public InputStream createInputStream(String uri,
                                     String URIBase)
                              throws IOException
A convenience method to resolve a Stylus Studio URI and return an InputStream. This method will attempt to use the Stylus resolver to create an InputStream.

Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
An InputStream which can be used to read the URI data, or null if the URI could not be resolved
Throws:
IOException - If an error occurs.

createOutputStream

public OutputStream createOutputStream(String uri,
                                       String URIBase)
                                throws IOException
A convenience method to resolve a Stylus Studio URI and return an OutputStream. This method will attempt to use the Stylus resolver to create an OutputStream.

Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
An OutputStream
Throws:
IOException - If an error occurs.

getXMLStreamReader

public javax.xml.stream.XMLStreamReader getXMLStreamReader(String uri,
                                                           String URIBase)
                                                    throws javax.xml.stream.XMLStreamException
Resolve a url and return a XMLStreamReader to read the data. The url must represent an xml data source. This method will return a XMLStreamReader to read the contents of the data source.

Specified by:
getXMLStreamReader in interface com.ddtek.xmlconverter.interfaces.StAXResolver
Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
An XMLStreamReader or null if the uri scheme was not recognized.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

getSAXSource

public SAXSource getSAXSource(String uri,
                              String URIBase)
                       throws ConverterException
Resolve a url and return a SAXSource which can be used to read the data. The url must represent an xml data source. This method will return a SAXSource to read the contents of the data source. The caller should register a ContentHandler by calling SAXSource.getXMLReader().setContentHandler() an then start the data flow by calling SAXSource.getXMLReader().parse(null);

Specified by:
getSAXSource in interface com.ddtek.xmlconverter.interfaces.StAXResolver
Parameters:
uri - The URI to be resolved.
URIBase - The base URI in effect when the URI was encountered.
Returns:
A SAXSource containing an XMLReader or null if the uri scheme was not recognized.
Throws:
ConverterException - if an error occurs