Class DefaultEntityResolver
- java.lang.Object
-
- org.apache.commons.configuration.resolver.DefaultEntityResolver
-
- All Implemented Interfaces:
EntityRegistry
,org.xml.sax.EntityResolver
public class DefaultEntityResolver extends java.lang.Object implements org.xml.sax.EntityResolver, EntityRegistry
The DefaultEntityResolver used by XML Configurations.- Since:
- 1.7
- Version:
- $Id: DefaultEntityResolver.java 1301991 2012-03-17 20:18:02Z sebb $
- Author:
- Commons Configuration team
-
-
Constructor Summary
Constructors Constructor Description DefaultEntityResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.net.URL>
getRegisteredEntities()
Returns a map with the entity IDs that have been registered using theregisterEntityId()
method.void
registerEntityId(java.lang.String publicId, java.net.URL entityURL)
Registers the specified URL for the specified public identifier.org.xml.sax.InputSource
resolveEntity(java.lang.String publicId, java.lang.String systemId)
Resolves the requested external entity.
-
-
-
Constructor Detail
-
DefaultEntityResolver
public DefaultEntityResolver()
-
-
Method Detail
-
registerEntityId
public void registerEntityId(java.lang.String publicId, java.net.URL entityURL)
Registers the specified URL for the specified public identifier.
This implementation maps
PUBLICID
's to URLs (from which the resource will be loaded). A common use case for this method is to register local URLs (possibly computed at runtime by a class loader) for DTDs and Schemas. This allows the performance advantage of using a local version without having to ensure everySYSTEM
URI on every processed XML document is local. This implementation provides only basic functionality. If more sophisticated features are required, either callingXMLConfiguration.setDocumentBuilder(DocumentBuilder)
to set a customDocumentBuilder
(which also can be initialized with a customEntityResolver
) or creating a custom entity resolver and registering it with the XMLConfiguration is recommended.- Specified by:
registerEntityId
in interfaceEntityRegistry
- Parameters:
publicId
- Public identifier of the Entity to be resolvedentityURL
- The URL to use for reading this Entity- Throws:
java.lang.IllegalArgumentException
- if the public ID is undefined
-
resolveEntity
public org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
Resolves the requested external entity. This is the default implementation of theEntityResolver
interface. It checks the passed in public ID against the registered entity IDs and uses a local URL if possible.- Specified by:
resolveEntity
in interfaceorg.xml.sax.EntityResolver
- Parameters:
publicId
- the public identifier of the entity being referencedsystemId
- the system identifier of the entity being referenced- Returns:
- an input source for the specified entity
- Throws:
org.xml.sax.SAXException
- if a parsing exception occurs
-
getRegisteredEntities
public java.util.Map<java.lang.String,java.net.URL> getRegisteredEntities()
Returns a map with the entity IDs that have been registered using theregisterEntityId()
method.- Specified by:
getRegisteredEntities
in interfaceEntityRegistry
- Returns:
- a map with the registered entity IDs
-
-