org.n52.security.common.xml
Class ClasspathEntityResolver

java.lang.Object
  extended by org.n52.security.common.xml.ClasspathEntityResolver
All Implemented Interfaces:
org.xml.sax.EntityResolver
Direct Known Subclasses:
ClasspathLSResourceResolver

public class ClasspathEntityResolver
extends java.lang.Object
implements org.xml.sax.EntityResolver

Class ClasspathEntityResolver tries to load external entities from the classpath.

To find the entities in the classpath a mapping file must be specified. The mapping file is located at "META-INF/xml/entity-mapping.properties".

The file contains entries structured like this:

[publicId|systemId]=path in classpath

e.g.:

http://tempuri.org/test.dtd=META-INF/xml/dtds/test.dtd

Version:
$Revision: $
Author:
Marko Reiprecht Created on 22.03.2008

Constructor Summary
ClasspathEntityResolver()
          Constructor creates a new instance in quite mode.
ClasspathEntityResolver(boolean quite)
          Constructor creates a new instance.
ClasspathEntityResolver(boolean quite, java.lang.ClassLoader loader)
          Constructor creates a new instance.
 
Method Summary
protected  org.xml.sax.InputSource createInputSource(java.lang.String resourcefile)
          Method creates an input source for the given resource file.
protected  org.xml.sax.InputSource emptyInputSource()
          Method creates an InputSource which points to an empty resource.
protected  java.lang.String getMappedResourceFileName(java.lang.String identifier)
          Method gets the mapped resource file name for the given identifier.
 boolean isQuite()
          Method gets the quite state.
protected  void loadMapping(java.lang.ClassLoader classloader)
          Method loads all entries from the mapping files located at META-INF/xml/entity-mapping.properties.
 org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId)
          Method resolves an entity by looking in a special mapping file located at "META-INF/xml/entity-mapping.properties".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathEntityResolver

public ClasspathEntityResolver()
Constructor creates a new instance in quite mode.


ClasspathEntityResolver

public ClasspathEntityResolver(boolean quite)
Constructor creates a new instance.

Parameters:
quite - the quite mode.

ClasspathEntityResolver

public ClasspathEntityResolver(boolean quite,
                               java.lang.ClassLoader loader)
Constructor creates a new instance.

Parameters:
quite - the quite mode.
loader - the classloader to use, if null this.getClass().getClassLoader() is used.
Method Detail

loadMapping

protected void loadMapping(java.lang.ClassLoader classloader)
Method loads all entries from the mapping files located at META-INF/xml/entity-mapping.properties. A typical entity mapping looks like this:

[publicId|systemId]=path in classpath

e.g.:

http://tempuri.org/test.dtd=META-INF/xml/dtds/test.dtd

Parameters:
classloader - the classloader if null this.getClass().getClassLoader() is used.

isQuite

public boolean isQuite()
Method gets the quite state. If the EnityReslover is in quite mode, all non resolved entities are simply ignored (not loaded), otherwise the parsers default mode is used.

Returns:
boolean.

resolveEntity

public org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
                                             java.lang.String systemId)
Method resolves an entity by looking in a special mapping file located at "META-INF/xml/entity-mapping.properties".

First it looks for a publicId mapping and then for a systemId mapping. If none mapping is found it returns a "emtpy" inputsource in quite mode or null in nonquite mode.

Specified by:
resolveEntity in interface org.xml.sax.EntityResolver
Parameters:
publicId - the publicId.
systemId - the systemId.
Returns:
InputSource.

createInputSource

protected org.xml.sax.InputSource createInputSource(java.lang.String resourcefile)
Method creates an input source for the given resource file.

It tries to load the resourcefile from the classpath. If it fails it simple ignores the entity.

Parameters:
resourcefile - the resourcefile.
Returns:
InputSource.

emptyInputSource

protected org.xml.sax.InputSource emptyInputSource()
Method creates an InputSource which points to an empty resource.

Returns:
InputSource.

getMappedResourceFileName

protected java.lang.String getMappedResourceFileName(java.lang.String identifier)
Method gets the mapped resource file name for the given identifier.

Parameters:
identifier - the identifier (e.g. publicId or systemId).
Returns:
String if mapping is found, otherwise null.


Copyright © 2004-2009 52north.org. All Rights Reserved.