public class Resolver
extends java.lang.Object
implements org.xml.sax.EntityResolver
Features include:
java.io.Reader
available as the "character
stream" property.
Subclasses can perform tasks such as supporting new URI schemes for URIs which are not URLs, such as URNs (see RFC 2396) or for accessing MIME entities which are part of a multipart/related group (see RFC 2387). They may also be used to support particular catalog syntaxes, such as the SGML/Open Catalog (SOCAT) which supports the SGML notion of "Formal Public Identifiers (FPIs).
Modifier and Type | Field and Description |
---|---|
private java.util.Hashtable |
id2loader |
private java.util.Hashtable |
id2resource |
private java.util.Hashtable |
id2uri |
private boolean |
ignoringMIME |
private static java.lang.String[] |
types |
Constructor and Description |
---|
Resolver()
Constructs a resolver.
|
Modifier and Type | Method and Description |
---|---|
static org.xml.sax.InputSource |
createInputSource(java.io.File file)
Creates an input source from a given file, autodetecting
the character encoding.
|
static org.xml.sax.InputSource |
createInputSource(java.lang.String contentType,
java.io.InputStream stream,
boolean checkType,
java.lang.String scheme)
Returns an input source, using the MIME type information and URL
scheme to statically determine the correct character encoding if
possible and otherwise autodetecting it.
|
static org.xml.sax.InputSource |
createInputSource(java.net.URL uri,
boolean checkType)
Creates an input source from a given URI.
|
boolean |
isIgnoringMIME()
Returns true if this resolver is ignoring MIME types in the documents
it returns, to work around bugs in how servers have reported the
documents' MIME types.
|
private java.io.InputStream |
mapResource(java.lang.String publicId) |
private java.lang.String |
name2uri(java.lang.String publicId) |
void |
registerCatalogEntry(java.lang.String publicId,
java.lang.String uri)
Registers the given public ID as corresponding to a particular
URI, typically a local copy.
|
void |
registerCatalogEntry(java.lang.String publicId,
java.lang.String resourceName,
java.lang.ClassLoader loader)
Registers a given public ID as corresponding to a particular Java
resource in a given class loader, typically distributed with a
software package.
|
org.xml.sax.InputSource |
resolveEntity(java.lang.String name,
java.lang.String uri)
SAX:
Resolve the given entity into an input source.
|
void |
setIgnoringMIME(boolean value)
Tells the resolver whether to ignore MIME types in the documents it
retrieves.
|
private boolean ignoringMIME
private java.util.Hashtable id2uri
private java.util.Hashtable id2resource
private java.util.Hashtable id2loader
private static final java.lang.String[] types
public static org.xml.sax.InputSource createInputSource(java.lang.String contentType, java.io.InputStream stream, boolean checkType, java.lang.String scheme) throws java.io.IOException
This method can be used to access XML documents which do not have URIs (such as servlet input streams, or most JavaMail message entities) and to support access methods such as HTTP POST or PUT. (URLs normally return content using the GET method.)
The caller should set the system ID in order for relative URIs found in this document to be interpreted correctly. In some cases, a custom resolver will need to be used; for example, documents may be grouped in a single MIME "multipart/related" bundle, and relative URLs would refer to other documents in that bundle.
contentType
- The MIME content type for the source for which
an InputSource is desired, such as text/xml;charset=utf-8.stream
- The input byte stream for the input source.checkType
- If true, this verifies that the content type is known
to support XML documents, such as application/xml.scheme
- Unless this is "file", unspecified MIME types
default to US-ASCII. Files are always autodetected since most
file systems discard character encoding information.java.io.IOException
public static org.xml.sax.InputSource createInputSource(java.net.URL uri, boolean checkType) throws java.io.IOException
uri
- the URI (system ID) for the entitycheckType
- if true, the MIME content type for the entity
is checked for document type and character set encoding.java.io.IOException
public static org.xml.sax.InputSource createInputSource(java.io.File file) throws java.io.IOException
java.io.IOException
public org.xml.sax.InputSource resolveEntity(java.lang.String name, java.lang.String uri) throws java.io.IOException
When a URI is used, createInputSource is used to correctly deduce the character encoding used by this entity. No MIME type checking is done.
resolveEntity
in interface org.xml.sax.EntityResolver
name
- Used to find alternate copies of the entity, when
this value is non-null; this is the XML "public ID".uri
- Used when no alternate copy of the entity is found;
this is the XML "system ID", normally a URI.java.io.IOException
public boolean isIgnoringMIME()
public void setIgnoringMIME(boolean value)
private java.lang.String name2uri(java.lang.String publicId)
public void registerCatalogEntry(java.lang.String publicId, java.lang.String uri)
publicId
- The managed public ID being mappeduri
- The URI of the preferred copy of that entityprivate java.io.InputStream mapResource(java.lang.String publicId)
public void registerCatalogEntry(java.lang.String publicId, java.lang.String resourceName, java.lang.ClassLoader loader)
If a mapping to a URI has been provided, that mapping takes precedence over this one.
publicId
- The managed public ID being mappedresourceName
- The name of the Java resourceloader
- The class loader holding the resource, or null if
it is a system resource.