Class XMLResourceResolver
java.lang.Object
org.jboss.metadata.parser.util.XMLResourceResolver
- All Implemented Interfaces:
XMLResolver, LSResourceResolver, EntityResolver
public class XMLResourceResolver
extends Object
implements XMLResolver, EntityResolver, LSResourceResolver
Local entity resolver to handle standard J2EE DTDs and Schemas as well as JBoss
specific DTDs.
- Author:
- Scott.Stark@jboss.org, Thomas.Diesler@jboss.org, Dimitris.Andreadis@jboss.org, Eduardo Martins
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MapObtain a read-only view of the current entity map.booleanReturns the boolean value to inform id DTD was found in the XML file or notstatic booleanprotected InputStreamloadResource(ClassLoader loader, String resource, boolean trace) Look for the resource on the given class loader.protected InputStreamloadResource(String resource, boolean trace) Look for the resource on the class loader that loaded this resolver.static voidregisterEntity(String id, String dtdFileName) Register the mapping from the public id/system id to the dtd/xsd file name.voidregisterLocalEntity(String id, String dtdOrSchema) Register the mapping from the public id/system id to the dtd/xsd file name.protected InputSourceresolveClasspathName(String systemId, boolean trace) Resolve the systemId as a classpath resource.resolveEntity(String publicId, String systemId) Returns DTD/Schema inputSource.resolveEntity(String publicID, String systemID, String baseURI, String namespace) protected InputSourceresolvePublicID(String publicId, boolean trace) Load the schema from the class entity to schema file mapping.protected InputSourceresolveSystemID(String systemId, boolean trace) Attempt to use the systemId as a URL from which the schema can be read.protected InputSourceresolveSystemIDasURL(String systemId, boolean trace) Attempt to use the systemId as a URL from which the schema can be read.static voidsetWarnOnNonFileURLs(boolean warnOnNonFileURLs)
-
Constructor Details
-
XMLResourceResolver
public XMLResourceResolver()
-
-
Method Details
-
getEntityMap
Obtain a read-only view of the current entity map.- Returns:
- Mapinvalid input: '<'String, String> of the publicID/systemID to dtd/schema file name
-
isWarnOnNonFileURLs
public static boolean isWarnOnNonFileURLs() -
setWarnOnNonFileURLs
public static void setWarnOnNonFileURLs(boolean warnOnNonFileURLs) -
registerEntity
Register the mapping from the public id/system id to the dtd/xsd file name. This overwrites any existing mapping.- Parameters:
id- the DOCTYPE public id or system id such as "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"dtdFileName- the simple dtd/xsd file name, "ejb-jar.dtd"
-
registerLocalEntity
Register the mapping from the public id/system id to the dtd/xsd file name. This overwrites any existing mapping.- Parameters:
id- the DOCTYPE public id or system id such as "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN"dtdOrSchema- the simple dtd/xsd file name, "ejb-jar.dtd"
-
resolveEntity
Returns DTD/Schema inputSource. The resolution logic is: 1. Check the publicId against the current registered values in the class mapping of entity name to dtd/schema file name. If found, the resulting file name is passed to the loadResource to locate the file as a classpath resource. 2. Check the systemId against the current registered values in the class mapping of entity name to dtd/schema file name. If found, the resulting file name is passed to the loadResource to locate the file as a classpath resource. 3. Strip the systemId name down to the simple file name by removing an URL style path elements (myschemas/x.dtd becomes x.dtd), and call loadResource to locate the simple file name as a classpath resource. 4. Attempt to resolve the systemId as a URL from which the schema can be read. If the URL input stream can be opened this returned as the resolved input.- Specified by:
resolveEntityin interfaceEntityResolver- Parameters:
publicId- - Public ID of DTD, or null if it is a schemasystemId- - the system ID of DTD or Schema- Returns:
- InputSource of entity
- Throws:
SAXExceptionIOException
-
isEntityResolved
public boolean isEntityResolved()Returns the boolean value to inform id DTD was found in the XML file or not This is here to avoid validation errors in descriptors that do not have a DOCTYPE declaration.- Returns:
- boolean - true if DTD was found in XML
-
resolvePublicID
Load the schema from the class entity to schema file mapping.- Parameters:
publicId- - the public entity name of the schematrace- - trace level logging flag- Returns:
- the InputSource for the schema file found on the classpath, null if the publicId is not registered or found.
- See Also:
-
resolveSystemID
Attempt to use the systemId as a URL from which the schema can be read. This checks to see whether the systemId is a key to an entry in the class entity map.- Parameters:
systemId- - the systemIdtrace- - trace level logging flag- Returns:
- the URL InputSource if the URL input stream can be opened, null if the systemId is not a URL or could not be opened.
-
resolveSystemIDasURL
Attempt to use the systemId as a URL from which the schema can be read. This uses the systemID as a URL.- Parameters:
systemId- - the systemIdtrace- - trace level logging flag- Returns:
- the URL InputSource if the URL input stream can be opened, null if the systemId is not a URL or could not be opened.
-
resolveClasspathName
Resolve the systemId as a classpath resource. If not found, the systemId is simply used as a classpath resource name.- Parameters:
systemId- - the system ID of DTD or Schematrace- - trace level logging flag- Returns:
- the InputSource for the schema file found on the classpath, null if the systemId is not registered or found.
-
loadResource
Look for the resource on the class loader that loaded this resolver. If not found try the thread context class loader. This first simply tries the resource name as is, and if not found, the resource is prepended with either "dtd/" or "schema/" depending on whether the resource ends in ".dtd" or ".xsd".- Parameters:
resource- - the classpath resource name of the schematrace- - trace level logging flag- Returns:
- the resource InputStream if found, null if not found.
-
loadResource
Look for the resource on the given class loader. This first simply tries the resource name as is, and if not found, the resource is prepended with either "dtd/" or "schema/" depending on whether the resource ends in ".dtd" or ".xsd".- Parameters:
resource- - the classpath resource name of the schematrace- - trace level logging flag- Returns:
- the resource InputStream if found, null if not found.
-
resolveEntity
public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException - Specified by:
resolveEntityin interfaceXMLResolver- Throws:
XMLStreamException
-
resolveResource
public LSInput resolveResource(String type, String namespaceURI, String publicID, String systemID, String baseURI) - Specified by:
resolveResourcein interfaceLSResourceResolver
-