com.xml_project.morganaxproc.filesystem
Class XProcFilesystem

java.lang.Object
  extended by com.xml_project.morganaxproc.filesystem.XProcFilesystem
All Implemented Interfaces:
CollectionURIResolver, ModuleURIResolver, org.xml.sax.EntityResolver
Direct Known Subclasses:
AlternateFilesystem

public abstract class XProcFilesystem
extends java.lang.Object
implements CollectionURIResolver, ModuleURIResolver, org.xml.sax.EntityResolver

This class is the core of file-/stream access in MorganaXProc although it does not provide any file-/stream access itself. This task is left to extending classes.

The basic methods for access files and streams via uri are implemented. The core implementation is left over to classes extending XProcFilesystem.

Practically you will probably never extend XProcFilesystem but extend one of the classes already implementing the abstract methods in XProcFilesystem. Typically you will extends DefaultFilesystem or AlternativeFilesystem to add support for additional uri schemes or enhance the implemented methods for http-request.


Nested Class Summary
 class XProcFilesystem.DefectiveURIException
           
static class XProcFilesystem.LoadResult
          A class wrapping the results from loading a resource from an uri.
static class XProcFilesystem.ParseMode
          The parsing modes used when building XOM documents.
static class XProcFilesystem.ProtectedResourceException
          An Exception thrown if the request resource needs authentication.
 class XProcFilesystem.StreamResult
          A class wrapping an InputStream and the uri from which the input stream was obtained.
static class XProcFilesystem.UnknownSchemeException
          An Exception thrown if the scheme in an uri is not known or not supported.
 class XProcFilesystem.UnsupportedMethodException
          An Exception thrown if a XProcHttpRequest which an unsupported method is found.
static class XProcFilesystem.UnsupportedXMLVersionException
           
 
Field Summary
static java.lang.String DIRECTORY_MARKER
          A prefix to mark directory entries in the result of getDirectoryList.
protected  XProcConfiguration theConfig
           
 
Constructor Summary
protected XProcFilesystem(XProcConfiguration config)
           
 
Method Summary
 nu.xom.Document build(java.lang.String textDoc, java.lang.String uri, XProcFilesystem.ParseMode parseMode)
          Builds a XOM document from the given String using the given parseMode and with uri as base uri for the document.
protected abstract  void clearCookieStore()
          Makes sure the cookie store used for httpRequest is empty.
 XProcFilesystem copy(XProcConfiguration newConfig)
           Creates a new instance of the XProcFilesystem.
protected abstract  java.net.URI copyResource(java.net.URI source, java.net.URI target)
          Copies resource source to target.
 java.net.URI copyResourceChecked(java.net.URI source, java.net.URI target)
          Implementation for pxf:copy
protected abstract  java.net.URI createDirectory(java.net.URI uri)
          Create the directory names by the uri.
 java.net.URI createDirectoryChecked(java.net.URI uri)
          Implementation for pxf:mkdir
protected abstract  java.net.URI createTemp(java.net.URI uri, boolean createFolder, java.lang.String prefix, java.lang.String suffix, boolean deleteOnExit)
          Create Create a temp file in the directory named by uri.
 java.net.URI createTempChecked(java.net.URI folderURI, boolean createFolder, java.lang.String prefix, java.lang.String suffix, boolean deleteOnExit)
           
protected abstract  void deleteResource(java.net.URI uri, boolean recursive)
          Delete the resource designated by uri.
 void deleteResourceChecked(java.net.URI uri, boolean recursive)
          Implementation for pxf:delete
 XProcHttpResponse doHttpRequest(XProcHttpRequest request, com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space)
          This method performs a http request by calling abstract method httpRequest(XProcHttpRequest) or (if this fails) by getting the uri via getInputStream for method 'get'.
 javax.xml.transform.stream.StreamSource getAsStreamSource(java.net.URI uri)
           
protected abstract  java.lang.String getContentType(java.net.URI uri)
          Return the content type of the resource designated by uri.
protected abstract  java.lang.String[] getDirectoryList(java.net.URI uri)
          Returns a list of the resource names found in the directory found on the given uri.
 java.lang.String[] getDirectoryList(XProcSecurityManager.Operations operation, java.net.URI uri)
          Gets a list of resource names in the directory named by the uri after a security check for the given operation is performed.
protected  nu.xom.Document getDocument(java.net.URI uri, XProcFilesystem.ParseMode parseMode)
           Creates a new XOM document by getting an InputStream via getInputStream for the given uri and then building it, using the given parseMode.
protected abstract  java.lang.String getEncoding(java.net.URI uri)
          Return the encoding of the resource designated by uri.
protected abstract  XProcFilesystem.StreamResult getInputStream(java.net.URI uri)
          Returns a StreamResult from the given uri.
 XProcFilesystem.LoadResult getLoadResult(XProcSecurityManager.Operations operation, java.lang.String href, java.net.URI primaryBase, java.lang.String secondaryBase, java.lang.String contentType, java.lang.String dataWrapper)
          Returns a LoadResult obtained from href made absolute by using primaryBase or (if this fails) by secondaryBase after performing a security check for the given operation.
protected abstract  java.io.OutputStream getOutputStream(java.net.URI uri)
          Returns an OutputStream associated with the given uri.
protected abstract  nu.xom.Document getResourceInfo(java.net.URI uri, boolean writeAllowed)
          Returns a document as specified for pxf:info or null, if the resource does not exist.
 nu.xom.Document getResourceInfoChecked(java.net.URI uri)
          Implementation for pxf:info
protected abstract  XProcHttpResponse httpRequest(XProcHttpRequest request)
          Returns a XProcHttpResponse answering the given XProcHttpRequest.
 nu.xom.Document loadDocument(XProcSecurityManager.Operations operation, java.lang.String href, java.net.URI primaryBase, java.lang.String secondaryBase, XProcFilesystem.ParseMode parseMode)
          Returns a XOM document from the URI given by href either made absolute by using primaryBase or, if this fails, by using secondaryBase.
 nu.xom.Document loadDocument(XProcSecurityManager.Operations operation, java.net.URI uri, XProcFilesystem.ParseMode parseMode)
          Returns a XOM document from the given uri build with the given parseMode after a security check is performed for the given operation.
 nu.xom.Document loadDocumentFromPackage(XProcSecurityManager.Operations op, java.lang.String href, com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space, XProcFilesystem.ParseMode mode)
          Tries to load a component as document from an EXPath packaging system, if one is installed.
protected abstract  java.net.URI moveResource(java.net.URI source, java.net.URI target)
          Moves file source to target.
 java.net.URI moveResourceChecked(java.net.URI source, java.net.URI target)
          Implementation for pxf:move
 javax.xml.transform.stream.StreamSource resolveAsStreamSource(java.lang.String href, java.lang.String base, com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space)
           
 java.util.List<java.net.URI> resolveCollection(java.net.URI theURI)
          Represents the default implementation for fn:collection used in XPath, p:xquery and p:xslt.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
           
 java.util.List<javax.xml.transform.stream.StreamSource> resolveModule(java.lang.String targetNamespace, java.util.List<java.lang.String> locationHints, java.lang.String baseURI)
          Called to resolve module import in XQuery and p:xquery
 java.lang.String resolveText(java.net.URI absoluteURI, java.lang.String encoding)
           
 java.net.URI resolveURI(java.lang.String href, java.net.URI baseURI)
          Generates an absolute URI from href and baseURI.
protected abstract  java.net.URI touchResource(java.net.URI uri, long timeStamp)
           
 java.net.URI touchResourceChecked(java.net.URI uri, long timestamp)
          Implementation for pxf:touch
protected  void writeData(byte[] data, java.net.URI uri)
          Writes data to the uri.
 java.lang.String writeData(XProcSecurityManager.Operations operation, byte[] data, java.net.URI uri)
          Writes data to the uri after a security check for the given operation is performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIRECTORY_MARKER

public static final java.lang.String DIRECTORY_MARKER
A prefix to mark directory entries in the result of getDirectoryList.

See Also:
Constant Field Values

theConfig

protected final XProcConfiguration theConfig
Constructor Detail

XProcFilesystem

protected XProcFilesystem(XProcConfiguration config)
Method Detail

copy

public XProcFilesystem copy(XProcConfiguration newConfig)
                     throws java.lang.Exception

Creates a new instance of the XProcFilesystem. This method is used in XProcConfiguration to create a new instance while creating a copy of an XProcConfiguration.
Implementers should overwrite this method, if the implementation does not support constructor with (XProcConfiguration config).

Parameters:
newConfig - the newConfiguration for the XProcFilesystem.
Returns:
a new instance of the filesystem.
Throws:
java.lang.Exception - thrown, when unable to create a new instance.

getInputStream

protected abstract XProcFilesystem.StreamResult getInputStream(java.net.URI uri)
                                                        throws java.io.IOException,
                                                               XProcFilesystem.UnknownSchemeException,
                                                               XProcFilesystem.ProtectedResourceException
Returns a StreamResult from the given uri.

Parameters:
uri - the uri from which the StreamResult should be taken.
Returns:
the StreamResult an the given uri.
Throws:
java.io.IOException - if an error occurred reading the uri.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).

getOutputStream

protected abstract java.io.OutputStream getOutputStream(java.net.URI uri)
                                                 throws java.io.IOException,
                                                        XProcFilesystem.UnknownSchemeException,
                                                        XProcFilesystem.ProtectedResourceException
Returns an OutputStream associated with the given uri.

Parameters:
uri - the uri for which the OutputStream is requested.
Returns:
the requested output stream.
Throws:
java.io.IOException - if an error occurred making the OutputStream for the uri.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).

getContentType

protected abstract java.lang.String getContentType(java.net.URI uri)
                                            throws java.io.IOException,
                                                   XProcFilesystem.UnknownSchemeException,
                                                   XProcFilesystem.ProtectedResourceException
Return the content type of the resource designated by uri.

Parameters:
uri - the uri for which the content type is requested.
Returns:
the requested content type.
Throws:
java.io.IOException - if any error occurred while requesting the content type.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).

getEncoding

protected abstract java.lang.String getEncoding(java.net.URI uri)
                                         throws java.io.IOException,
                                                XProcFilesystem.UnknownSchemeException,
                                                XProcFilesystem.ProtectedResourceException
Return the encoding of the resource designated by uri.

Parameters:
uri - the uri for which the encoding is requested.
Returns:
the requested encoding.
Throws:
java.io.IOException - if any error occurred while requesting the encoding.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).

httpRequest

protected abstract XProcHttpResponse httpRequest(XProcHttpRequest request)
                                          throws java.io.IOException,
                                                 XProcFilesystem.UnknownSchemeException
Returns a XProcHttpResponse answering the given XProcHttpRequest.

Parameters:
request - the request to answer.
Returns:
the XProcHttpResponse for this request.
Throws:
java.io.IOException - if an IOException occurred.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.

clearCookieStore

protected abstract void clearCookieStore()
Makes sure the cookie store used for httpRequest is empty.


getDirectoryList

protected abstract java.lang.String[] getDirectoryList(java.net.URI uri)
                                                throws java.io.IOException,
                                                       XProcFilesystem.ProtectedResourceException,
                                                       XProcFilesystem.UnknownSchemeException
Returns a list of the resource names found in the directory found on the given uri. If the uri does not name a directory, an IOException is thrown. The names appearing in the result are just the file names, i.e. the last segment of the path. If the directory at uri contains directories, the names of this directories must be returned prefix with DIRECTORY_MARKER.

Parameters:
uri - the uri for which the directory listing is requested.
Returns:
a string array which the content of the requested directory.
Throws:
java.io.IOException - if an error occurred reading the resource at uri or if the resource is no directory.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.

getResourceInfo

protected abstract nu.xom.Document getResourceInfo(java.net.URI uri,
                                                   boolean writeAllowed)
                                            throws XProcFilesystem.UnknownSchemeException,
                                                   java.io.IOException,
                                                   java.io.FileNotFoundException
Returns a document as specified for pxf:info or null, if the resource does not exist.

Parameters:
uri - the uri to get the information for.
Returns:
the document or null.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.IOException
java.io.FileNotFoundException

copyResource

protected abstract java.net.URI copyResource(java.net.URI source,
                                             java.net.URI target)
                                      throws XProcFilesystem.UnknownSchemeException,
                                             java.io.FileNotFoundException,
                                             java.io.IOException
Copies resource source to target. If target names a folder, the copy is put into this folder. If a file with target already exists, it is overwritten.

Parameters:
source - a uri designating a file
target - a uri designating a file or a folder
Returns:
the target uri where source was copied to.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

moveResource

protected abstract java.net.URI moveResource(java.net.URI source,
                                             java.net.URI target)
                                      throws XProcFilesystem.UnknownSchemeException,
                                             java.io.FileNotFoundException,
                                             java.io.IOException
Moves file source to target. If target names a folder, the copy is put into this folder. If a file with target already exists, it is overwritten.

Parameters:
source -
target -
Returns:
the absolute uri of the target.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

deleteResource

protected abstract void deleteResource(java.net.URI uri,
                                       boolean recursive)
                                throws XProcFilesystem.UnknownSchemeException,
                                       java.io.FileNotFoundException,
                                       java.io.IOException
Delete the resource designated by uri. If uri designated an non empty folder, recursive must be true, otherwise an IOException is thrown.

Parameters:
uri -
recursive -
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

touchResource

protected abstract java.net.URI touchResource(java.net.URI uri,
                                              long timeStamp)
                                       throws XProcFilesystem.UnknownSchemeException,
                                              java.io.FileNotFoundException,
                                              java.io.IOException
Parameters:
uri -
timeStamp - value.
Returns:
the absolute uri of the touched resource.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

createDirectory

protected abstract java.net.URI createDirectory(java.net.URI uri)
                                         throws XProcFilesystem.UnknownSchemeException,
                                                java.io.IOException
Create the directory names by the uri.

Parameters:
uri -
Returns:
the absolute uri of the created directory.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.IOException

createTemp

protected abstract java.net.URI createTemp(java.net.URI uri,
                                           boolean createFolder,
                                           java.lang.String prefix,
                                           java.lang.String suffix,
                                           boolean deleteOnExit)
                                    throws XProcFilesystem.UnknownSchemeException,
                                           java.io.FileNotFoundException,
                                           java.io.IOException
Create Create a temp file in the directory named by uri.

Parameters:
uri - the directory in which the temp file should be created.
prefix - the file names prefix or null.
suffix - the file names suffix or null.
deleteOnExit - true, if the created file should be deleted when the processor terminates.
Returns:
the absolute uri of the created temp file
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

createDirectoryChecked

public final java.net.URI createDirectoryChecked(java.net.URI uri)
                                          throws XProcFilesystem.UnknownSchemeException,
                                                 java.io.IOException,
                                                 XProcSecurityException
Implementation for pxf:mkdir

Parameters:
uri -
Returns:
the absolute uri of the created resource.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.IOException
XProcSecurityException

createTempChecked

public final java.net.URI createTempChecked(java.net.URI folderURI,
                                            boolean createFolder,
                                            java.lang.String prefix,
                                            java.lang.String suffix,
                                            boolean deleteOnExit)
                                     throws XProcSecurityException,
                                            XProcFilesystem.UnknownSchemeException,
                                            java.io.FileNotFoundException,
                                            java.io.IOException
Parameters:
folderURI -
createFolder -
prefix -
suffix -
deleteOnExit -
Returns:
the absolute uri of the created resource.
Throws:
XProcSecurityException
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
java.io.IOException

touchResourceChecked

public final java.net.URI touchResourceChecked(java.net.URI uri,
                                               long timestamp)
                                        throws XProcFilesystem.UnknownSchemeException,
                                               java.io.FileNotFoundException,
                                               XProcSecurityException,
                                               java.io.IOException
Implementation for pxf:touch

Parameters:
uri -
timestamp -
Returns:
the absolute uri of the touched resource.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
XProcSecurityException
java.io.IOException

moveResourceChecked

public final java.net.URI moveResourceChecked(java.net.URI source,
                                              java.net.URI target)
                                       throws XProcFilesystem.UnknownSchemeException,
                                              java.io.FileNotFoundException,
                                              XProcSecurityException,
                                              java.io.IOException
Implementation for pxf:move

Parameters:
source -
target -
Returns:
the absolute uri of the target.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
XProcSecurityException
java.io.IOException

copyResourceChecked

public final java.net.URI copyResourceChecked(java.net.URI source,
                                              java.net.URI target)
                                       throws XProcFilesystem.UnknownSchemeException,
                                              java.io.FileNotFoundException,
                                              XProcSecurityException,
                                              java.io.IOException
Implementation for pxf:copy

Parameters:
source -
target -
Returns:
the absolute uri of the target.
Throws:
XProcFilesystem.UnknownSchemeException
java.io.FileNotFoundException
XProcSecurityException
java.io.IOException

deleteResourceChecked

public final void deleteResourceChecked(java.net.URI uri,
                                        boolean recursive)
                                 throws XProcSecurityException,
                                        java.io.FileNotFoundException,
                                        XProcFilesystem.UnknownSchemeException,
                                        java.io.IOException
Implementation for pxf:delete

Parameters:
uri -
recursive -
Throws:
XProcSecurityException
java.io.FileNotFoundException
XProcFilesystem.UnknownSchemeException
java.io.IOException

getResourceInfoChecked

public final nu.xom.Document getResourceInfoChecked(java.net.URI uri)
                                             throws XProcSecurityException,
                                                    java.io.IOException,
                                                    java.io.FileNotFoundException,
                                                    XProcFilesystem.UnknownSchemeException
Implementation for pxf:info

Parameters:
uri -
Returns:
a document representing the read infos.
Throws:
XProcSecurityException
java.io.IOException
java.io.FileNotFoundException
XProcFilesystem.UnknownSchemeException

resolveCollection

public java.util.List<java.net.URI> resolveCollection(java.net.URI theURI)
                                               throws javax.xml.xpath.XPathException
Represents the default implementation for fn:collection used in XPath, p:xquery and p:xslt.

The default behavior is this:

Specified by:
resolveCollection in interface CollectionURIResolver
Parameters:
theURI - which designates the collection
Returns:
a list of uris associated with the given uri.
Throws:
javax.xml.xpath.XPathException - raised, if any Exception occured.

getAsStreamSource

public final javax.xml.transform.stream.StreamSource getAsStreamSource(java.net.URI uri)
                                                                throws javax.xml.transform.TransformerException
Throws:
javax.xml.transform.TransformerException

resolveURI

public final java.net.URI resolveURI(java.lang.String href,
                                     java.net.URI baseURI)
                              throws java.io.IOException
Generates an absolute URI from href and baseURI. If href is relative, baseURI is used to make it absolute.

Parameters:
href - an uri (fragment).
baseURI - an absolute uri.
Returns:
the absolute uri resulting from href and baseURI.
Throws:
java.io.IOException - if href is null or href is relative and baseURI is null or there is a syntax error in href.

loadDocument

public final nu.xom.Document loadDocument(XProcSecurityManager.Operations operation,
                                          java.lang.String href,
                                          java.net.URI primaryBase,
                                          java.lang.String secondaryBase,
                                          XProcFilesystem.ParseMode parseMode)
                                   throws java.io.IOException,
                                          nu.xom.ValidityException,
                                          nu.xom.ParsingException,
                                          XProcFilesystem.UnknownSchemeException,
                                          XProcSecurityException,
                                          XProcFilesystem.ProtectedResourceException,
                                          XProcFilesystem.UnsupportedXMLVersionException,
                                          XProcFilesystem.DefectiveURIException

Returns a XOM document from the URI given by href either made absolute by using primaryBase or, if this fails, by using secondaryBase. The document is build with the given parseMode after a security check is performed for the given operation. After making href absolute in the specified way, loadDocument(Operations,URI,ParseMode) is called.

Parameters:
operation - the Operation for which the docuement should be loaded.
href - the uri (fragment) form which the document should be loaded.
primaryBase - the first uri to use to make hrefabsolute.
secondaryBase - the second uri to use to make hrefabsolute.
Returns:
the document on the uri given by href and either primaryBase or secondary base.
Throws:
java.io.IOException - if an IOException occurred obtaining the input stream.
nu.xom.ParsingException - if the input stream is not a valid document.
nu.xom.ValidityException - if the input stream is not a valid document.
XProcFilesystem.UnknownSchemeException - if the scheme in uri is unknown or not supported.
XProcSecurityException - if accessing this resource for this operation is forbidden by the current setting of XProcSecurityManager.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).
XProcFilesystem.UnsupportedXMLVersionException - if the document is in an xml version not supported.
XProcFilesystem.DefectiveURIException

loadDocument

public final nu.xom.Document loadDocument(XProcSecurityManager.Operations operation,
                                          java.net.URI uri,
                                          XProcFilesystem.ParseMode parseMode)
                                   throws java.io.IOException,
                                          nu.xom.ParsingException,
                                          nu.xom.ValidityException,
                                          XProcFilesystem.UnknownSchemeException,
                                          XProcSecurityException,
                                          XProcFilesystem.ProtectedResourceException,
                                          XProcFilesystem.UnsupportedXMLVersionException,
                                          XProcFilesystem.DefectiveURIException

Returns a XOM document from the given uri build with the given parseMode after a security check is performed for the given operation. To build the document from the uri getDocument is called.

Parameters:
operation - the Operations for which the document should be loaded.
uri - the uri from which the document should be loaded.
parseMode - the ParseMode to use for building the document.
Returns:
the document on the given uri.
Throws:
java.io.IOException - if an IOException occurred obtaining the input stream.
nu.xom.ParsingException - if the input stream is not a valid document.
nu.xom.ValidityException - if the input stream is not a valid document.
XProcFilesystem.UnknownSchemeException - if the scheme in uri is unknown or not supported.
XProcSecurityException - if accessing this resource for this operation is forbidden by the current setting of XProcSecurityManager.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).
XProcFilesystem.UnsupportedXMLVersionException - if the document is in an xml version not supported.
XProcFilesystem.DefectiveURIException

build

public nu.xom.Document build(java.lang.String textDoc,
                             java.lang.String uri,
                             XProcFilesystem.ParseMode parseMode)
                      throws java.io.IOException,
                             nu.xom.ParsingException,
                             nu.xom.ValidityException,
                             XProcFilesystem.DefectiveURIException

Builds a XOM document from the given String using the given parseMode and with uri as base uri for the document.

This method should only be used with sources already checked by XProcSecuritySystem because no security checking is performed here.

Parameters:
textDoc - the String with the serialized document.
uri - the base uri for the newly build document.
parseMode - the ParseMode to use while building the document.
Returns:
the newly build document
Throws:
java.io.IOException - if an error occurred reading the reader or if no builder for the parseMode was found.
nu.xom.ParsingException - if the reader does not contain a valid document.
nu.xom.ValidityException - if the reader does not contain a valid document.
XProcFilesystem.DefectiveURIException

getLoadResult

public final XProcFilesystem.LoadResult getLoadResult(XProcSecurityManager.Operations operation,
                                                      java.lang.String href,
                                                      java.net.URI primaryBase,
                                                      java.lang.String secondaryBase,
                                                      java.lang.String contentType,
                                                      java.lang.String dataWrapper)
                                               throws java.io.IOException,
                                                      XProcFilesystem.UnknownSchemeException,
                                                      XProcSecurityException,
                                                      XProcFilesystem.ProtectedResourceException

Returns a LoadResult obtained from href made absolute by using primaryBase or (if this fails) by secondaryBase after performing a security check for the given operation.

Parameters:
operation - the Operations for which the LoadResult is requested.
href - a uri (fragment) to the resource.
primaryBase - the base uri used to make href absolute.
secondaryBase - the base uri used to make href absolute if loading of (href/baseURI) fails.
contentType - may be used to overwrite the content type of the obtained resource if it is empty, "application/octet-stream" or "content/unknown". If contentType is null, the original content type of the resource is used.
dataWrapper - the java class name of the DataWrapper to use or null. If dataWrapper is null, a possible wrapper for the data is determined using either the extension of the uri or the content type found and the settings in XProcConfiguration.
Returns:
the LoadResult found.
Throws:
java.io.IOException - if there is a problem with reading the data on the uri.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcSecurityException - if accessing this resource for this operation is forbidden by the current setting of XProcSecurityManager.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).

writeData

public final java.lang.String writeData(XProcSecurityManager.Operations operation,
                                        byte[] data,
                                        java.net.URI uri)
                                 throws java.io.IOException,
                                        XProcFilesystem.UnknownSchemeException,
                                        XProcSecurityException,
                                        XProcFilesystem.ProtectedResourceException

Writes data to the uri after a security check for the given operation is performed.

Parameters:
operation - the Operations for which the data should be written.
data - the data to be written.
uri - the uri to which the data should be written.
Returns:
the uri to which the data was actually written.
Throws:
java.io.IOException - if any problem occurs writing the data.
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcSecurityException - if accessing this resource for this operation is forbidden by the current setting of XProcSecurityManager.
XProcFilesystem.ProtectedResourceException - if the resource with the made uri cannot be accessed without authentication (HTPP status code 401).

writeData

protected void writeData(byte[] data,
                         java.net.URI uri)
                  throws XProcFilesystem.UnknownSchemeException,
                         XProcFilesystem.ProtectedResourceException,
                         java.io.IOException

Writes data to the uri.

This is a low level method called by writeData(Operations, byte[], URI)

.

You should never call it directly, because there is no security checking in this method. The method is declared protected so you can overwrite it in extending classes to store data to uris where no output stream is available or which need special treatment.

Parameters:
data - data the data to be written.
uri - the uri to which the data should be written.
Throws:
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the made uri cannot be accessed without authentication (HTPP status code 401).
java.io.IOException - if any problem occurs writing the data.

getDirectoryList

public final java.lang.String[] getDirectoryList(XProcSecurityManager.Operations operation,
                                                 java.net.URI uri)
                                          throws XProcSecurityException,
                                                 XProcFilesystem.ProtectedResourceException,
                                                 XProcFilesystem.UnknownSchemeException,
                                                 java.io.IOException

Gets a list of resource names in the directory named by the uri after a security check for the given operation is performed.

Parameters:
operation - the Operations for which the data should be written.
uri - the uri to which the data should be written.
Returns:
a list with the ressource names found on the given uri.
Throws:
XProcSecurityException - if accessing this resource for this operation is forbidden by the current setting of XProcSecurityManager.
XProcFilesystem.ProtectedResourceException - if the resource with the made uri cannot be accessed without authentication (HTPP status code 401).
XProcFilesystem.UnknownSchemeException - if the uri's scheme is unknown or not supported.
java.io.IOException - if any problem occurs reading the directory.

doHttpRequest

public final XProcHttpResponse doHttpRequest(XProcHttpRequest request,
                                             com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space)
                                      throws java.io.IOException,
                                             XProcFilesystem.UnknownSchemeException,
                                             XProcFilesystem.ProtectedResourceException,
                                             com.xml_project.morganaxproc.core.XProcRuntimeException,
                                             XProcFilesystem.UnsupportedMethodException,
                                             XProcSecurityException

This method performs a http request by calling abstract method httpRequest(XProcHttpRequest) or (if this fails) by getting the uri via getInputStream for method 'get'.

This method work as a bridge between implementations of XProcFilesystem supporting httpRequest and those not supporting it. A not supporting implementation is required to throw an UnknownSchemaException. If this occurs and the method in request is get, doHttpRequest will try to make a XProcHttpResponse with a response body obtained by calling abstract method getInputStream with the uri from request.

Parameters:
request - the XProcHttpRequest to perform.
Returns:
an XProcHttpResponse to the request.
Throws:
java.io.IOException - if an IOException occurred.
XProcFilesystem.UnknownSchemeException - if the scheme in the uri is not known or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).
com.xml_project.morganaxproc.core.XProcRuntimeException - if an XProcRuntimeException occured while calling httpRequest.
XProcFilesystem.UnsupportedMethodException - if the xml version is not supported.
XProcSecurityException

getDocument

protected nu.xom.Document getDocument(java.net.URI uri,
                                      XProcFilesystem.ParseMode parseMode)
                               throws java.io.IOException,
                                      nu.xom.ParsingException,
                                      nu.xom.ValidityException,
                                      XProcFilesystem.UnknownSchemeException,
                                      XProcFilesystem.ProtectedResourceException,
                                      XProcFilesystem.DefectiveURIException

Creates a new XOM document by getting an InputStream via getInputStream for the given uri and then building it, using the given parseMode.

This is a low level method called by loadDocument. You should never call it directly, because there is no security checking in this method. (This is done by loadDocument). The method is declared protected so you can overwrite it in extending classes to return XOM documents which are not available via getInputStream or come from a special source (like a document buffer for instance).

Parameters:
uri - the uri for the document to create.
parseMode - the ParseMode that must be used to create the document.
Returns:
the newly created document
Throws:
java.io.IOException - if an IOException occurred obtaining the input stream.
nu.xom.ParsingException - if the input stream is not a valid document.
nu.xom.ValidityException - if the input stream is not a valid document.
XProcFilesystem.UnknownSchemeException - if the scheme in uri is unknown or not supported.
XProcFilesystem.ProtectedResourceException - if the resource with the given uri cannot be obtained without authentication (HTPP status code 401).
XProcFilesystem.DefectiveURIException

resolveText

public java.lang.String resolveText(java.net.URI absoluteURI,
                                    java.lang.String encoding)
                             throws XPathException
Parameters:
absoluteURI -
encoding - may be null
Returns:
a string
Throws:
javax.xml.xpath.XPathException
XPathException

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
                                      throws org.xml.sax.SAXException,
                                             java.io.IOException
Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Throws:
org.xml.sax.SAXException
java.io.IOException

resolveAsStreamSource

public final javax.xml.transform.stream.StreamSource resolveAsStreamSource(java.lang.String href,
                                                                           java.lang.String base,
                                                                           com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space)
                                                                    throws javax.xml.transform.TransformerException
Parameters:
href -
base -
Returns:
the resolved resource
Throws:
javax.xml.transform.TransformerException

resolveModule

public final java.util.List<javax.xml.transform.stream.StreamSource> resolveModule(java.lang.String targetNamespace,
                                                                                   java.util.List<java.lang.String> locationHints,
                                                                                   java.lang.String baseURI)
Description copied from interface: ModuleURIResolver
Called to resolve module import in XQuery and p:xquery

Specified by:
resolveModule in interface ModuleURIResolver
Parameters:
targetNamespace - the target namespace of the module
locationHints - the location hints (if any)
baseURI - the base uri of the importing module
Returns:
a list of StreamSource's. May be null, if no modules are found.

loadDocumentFromPackage

public final nu.xom.Document loadDocumentFromPackage(XProcSecurityManager.Operations op,
                                                     java.lang.String href,
                                                     com.xml_project.morganaxproc.morganapkg.MorganaPKG.UriSpaces space,
                                                     XProcFilesystem.ParseMode mode)
                                              throws nu.xom.ParsingException,
                                                     XProcFilesystem.DefectiveURIException
Tries to load a component as document from an EXPath packaging system, if one is installed. In case of an ParsingException for spaces UriSpaces.XQuery or RelaxNG a document with the root element or is created and the resource found at href is inserted as text child to this root.

Parameters:
op - - the operation for security check
href - - the uri of the component
space - - the uri space to look for
mode - - the parseMode
Returns:
the document or null, if an error occurred, no packaging system is found or no component with this uri is found.
Throws:
nu.xom.ParsingException
XProcFilesystem.DefectiveURIException