org.mycore.common.xml
Class MCRURIResolver

java.lang.Object
  extended by org.mycore.common.xml.MCRURIResolver
All Implemented Interfaces:
URIResolver, EntityResolver

public final class MCRURIResolver
extends Object
implements URIResolver, EntityResolver

Reads XML documents from various URI types. This resolver is used to read DTDs, XML Schema files, XSL document() usages, xsl:include usages and MyCoRe Editor include declarations. DTDs and Schema files are read from the CLASSPATH of the application when XML is parsed. XML document() calls and xsl:include calls within XSL stylesheets can be read from URIs of type resource, webapp, file, session, query or mcrobject. MyCoRe editor include declarations can read XML files from resource, webapp, file, session, http or https, query, or mcrobject URIs.

Author:
Frank Luetzenkirchen, Thomas Scheffler (yagee)

Nested Class Summary
static interface MCRURIResolver.MCRResolver
          Resolver interface.
static interface MCRURIResolver.MCRResolverProvider
          provides a URI -- Resolver Mapping One can implement this interface to provide additional URI schemes this MCRURIResolver should handle, too.
 
Field Summary
(package private) static String SESSION_OBJECT_NAME
           
 
Method Summary
(package private)  MCRURIResolver.MCRResolver getResolver(String scheme)
           
 String getScheme(String uri)
          Returns the protocol or scheme for the given URI.
static void init(ServletContext ctx, String webAppBase)
          Initializes the MCRURIResolver for servlet applications.
static MCRURIResolver instance()
          Returns the MCRURIResolver singleton
protected  Element parseStream(InputStream in)
          Reads xml from an InputStream and returns the parsed root element.
 Element resolve(String uri)
          Reads XML from URIs of various type.
 Source resolve(String href, String base)
          URI Resolver that resolves XSL document() or xsl:include calls.
 InputSource resolveEntity(String publicId, String systemId)
          Implements the SAX EntityResolver interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_OBJECT_NAME

static final String SESSION_OBJECT_NAME
See Also:
Constant Field Values
Method Detail

instance

public static MCRURIResolver instance()
Returns the MCRURIResolver singleton


init

public static void init(ServletContext ctx,
                        String webAppBase)
Initializes the MCRURIResolver for servlet applications.

Parameters:
ctx - the servlet context of this web application
webAppBase - the base URL of this web application

resolve

public Source resolve(String href,
                      String base)
               throws TransformerException
URI Resolver that resolves XSL document() or xsl:include calls.

Specified by:
resolve in interface URIResolver
Throws:
TransformerException
See Also:
URIResolver

resolveEntity

public InputSource resolveEntity(String publicId,
                                 String systemId)
                          throws IOException
Implements the SAX EntityResolver interface. This resolver type is used to read DTDs and XML Schema files when parsing XML documents. This resolver searches such files in the CLASSPATH of the current application.

Specified by:
resolveEntity in interface EntityResolver
Throws:
IOException
See Also:
EntityResolver

resolve

public Element resolve(String uri)
Reads XML from URIs of various type.

Parameters:
uri - the URI where to read the XML from
Returns:
the root element of the XML document

getScheme

public String getScheme(String uri)
Returns the protocol or scheme for the given URI.

Parameters:
uri - the URI to parse
Returns:
the protocol/scheme part before the ":"

getResolver

MCRURIResolver.MCRResolver getResolver(String scheme)

parseStream

protected Element parseStream(InputStream in)
                       throws JDOMException,
                              IOException
Reads xml from an InputStream and returns the parsed root element.

Parameters:
in - the InputStream that contains the XML document
Returns:
the root element of the parsed input stream
Throws:
IOException
JDOMException