Package org.jboss.util.xml
Class JBossEntityResolver
- java.lang.Object
-
- org.jboss.util.xml.JBossEntityResolver
-
- All Implemented Interfaces:
org.w3c.dom.ls.LSResourceResolver,org.xml.sax.EntityResolver
public class JBossEntityResolver extends java.lang.Object implements org.xml.sax.EntityResolver, org.w3c.dom.ls.LSResourceResolverLocal entity resolver to handle standard J2EE DTDs and Schemas as well as JBoss specific DTDs. Function boolean isEntityResolved() is here to avoid validation errors in descriptors that do not have a DOCTYPE declaration.- Version:
- $Revision$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classJBossEntityResolver.LSInputImpl
-
Field Summary
Fields Modifier and Type Field Description private static java.util.MapentitiesA class wide Mapof publicId/systemId to dtd/xsd file private java.lang.ThreadLocal<java.lang.Boolean>entityResolvedprivate java.util.MaplocalEntitiesA local entities map that overrides the class level entitiesprivate static org.jboss.logging.Loggerlogprivate booleanreplaceSystemPropertiesShould system property refs in system ids be replacedprivate static booleanwarnOnNonFileURLsA class flag indicating whether an attempt to resolve a systemID as a non-file URL should produce a warning rather than a trace level log msg.
-
Constructor Summary
Constructors Constructor Description JBossEntityResolver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.MapgetEntityMap()Obtain a read-only view of the current entity map.booleanisEntityResolved()Returns the boolean value to inform id DTD was found in the XML file or notbooleanisReplaceSystemProperties()static booleanisWarnOnNonFileURLs()protected java.io.InputStreamloadClasspathResource(java.lang.String resource, boolean trace)Look for the resource name on the thread context loader resource path.static voidregisterEntity(java.lang.String id, java.lang.String dtdFileName)Register the mapping from the public id/system id to the dtd/xsd file name.voidregisterLocalEntity(java.lang.String id, java.lang.String dtdOrSchema)Register the mapping from the public id/system id to the dtd/xsd file name.protected org.xml.sax.InputSourceresolveClasspathName(java.lang.String systemId, boolean trace)Resolve the systemId as a classpath resource.org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.String systemId)Returns DTD/Schema inputSource.protected org.xml.sax.InputSourceresolvePublicID(java.lang.String publicId, boolean trace)Load the schema from the class entity to schema file mapping.org.w3c.dom.ls.LSInputresolveResource(java.lang.String type, java.lang.String namespaceURI, java.lang.String publicId, java.lang.String systemId, java.lang.String baseURI)protected org.xml.sax.InputSourceresolveSystemID(java.lang.String systemId, boolean trace)Attempt to use the systemId as a URL from which the schema can be read.protected org.xml.sax.InputSourceresolveSystemIDasURL(java.lang.String systemId, boolean trace)Attempt to use the systemId as a URL from which the schema can be read.voidsetReplaceSystemProperties(boolean replaceSystemProperties)static voidsetWarnOnNonFileURLs(boolean warnOnNonFileURLs)
-
-
-
Field Detail
-
log
private static final org.jboss.logging.Logger log
-
entities
private static java.util.Map entities
A class wide Mapof publicId/systemId to dtd/xsd file
-
warnOnNonFileURLs
private static boolean warnOnNonFileURLs
A class flag indicating whether an attempt to resolve a systemID as a non-file URL should produce a warning rather than a trace level log msg.
-
replaceSystemProperties
private boolean replaceSystemProperties
Should system property refs in system ids be replaced
-
localEntities
private java.util.Map localEntities
A local entities map that overrides the class level entities
-
entityResolved
private java.lang.ThreadLocal<java.lang.Boolean> entityResolved
-
-
Method Detail
-
getEntityMap
public static java.util.Map getEntityMap()
Obtain a read-only view of the current entity map.- Returns:
- Map
of the publicID/systemID to dtd/schema file name
-
isWarnOnNonFileURLs
public static boolean isWarnOnNonFileURLs()
-
setWarnOnNonFileURLs
public static void setWarnOnNonFileURLs(boolean warnOnNonFileURLs)
-
registerEntity
public static void registerEntity(java.lang.String id, java.lang.String dtdFileName)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"
-
isReplaceSystemProperties
public boolean isReplaceSystemProperties()
-
setReplaceSystemProperties
public void setReplaceSystemProperties(boolean replaceSystemProperties)
-
registerLocalEntity
public void registerLocalEntity(java.lang.String id, java.lang.String dtdOrSchema)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
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException, java.io.IOExceptionReturns 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 loadClasspathResource 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 loadClasspathResource 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 loadClasspathResource 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 interfaceorg.xml.sax.EntityResolver- 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:
org.xml.sax.SAXExceptionjava.io.IOException
-
isEntityResolved
public boolean isEntityResolved()
Returns the boolean value to inform id DTD was found in the XML file or not- Returns:
- boolean - true if DTD was found in XML
-
resolvePublicID
protected org.xml.sax.InputSource resolvePublicID(java.lang.String publicId, boolean trace)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:
registerEntity(String, String)
-
resolveSystemID
protected org.xml.sax.InputSource resolveSystemID(java.lang.String systemId, boolean trace)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
protected org.xml.sax.InputSource resolveSystemIDasURL(java.lang.String systemId, boolean trace)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
protected org.xml.sax.InputSource resolveClasspathName(java.lang.String systemId, boolean trace)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.
-
loadClasspathResource
protected java.io.InputStream loadClasspathResource(java.lang.String resource, boolean trace)Look for the resource name on the thread context loader resource path. 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.
-
resolveResource
public org.w3c.dom.ls.LSInput resolveResource(java.lang.String type, java.lang.String namespaceURI, java.lang.String publicId, java.lang.String systemId, java.lang.String baseURI)- Specified by:
resolveResourcein interfaceorg.w3c.dom.ls.LSResourceResolver
-
-