FileDocCategorySizeDatePackage
DOMEntityResolverWrapper.javaAPI DocJava SE 5 API8196Fri Aug 26 14:55:56 BST 2005com.sun.org.apache.xerces.internal.util

DOMEntityResolverWrapper

public class DOMEntityResolverWrapper extends Object implements XMLEntityResolver
This class wraps DOM entity resolver to XNI entity resolver.
see
LSResourceResolver
author
Gopal Sharma, SUN MicroSystems Inc.
author
Elena Litani, IBM
author
Ramesh Mandava, Sun Microsystems
version
$Id: DOMEntityResolverWrapper.java,v 1.12 2004/02/25 19:46:15 kohsuke Exp $

Fields Summary
private static final String
XML_TYPE
XML 1.0 type constant according to DOM L3 LS CR spec "http://www.w3.org/TR/2003/CR-DOM-Level-3-LS-20031107"
private static final String
XSD_TYPE
XML Schema constant according to DOM L3 LS CR spec "http://www.w3.org/TR/2003/CR-DOM-Level-3-LS-20031107"
protected LSResourceResolver
fEntityResolver
The DOM entity resolver.
Constructors Summary
public DOMEntityResolverWrapper()
Default constructor.


    //
    // Constructors
    //

       
      
public DOMEntityResolverWrapper(LSResourceResolver entityResolver)
Wraps the specified DOM entity resolver.

        setEntityResolver(entityResolver);
    
Methods Summary
public org.w3c.dom.ls.LSResourceResolvergetEntityResolver()
Returns the DOM entity resolver.

        return fEntityResolver;
    
private java.lang.StringgetType(com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier resourceIdentifier)
Determines the type of resource being resolved

        if (resourceIdentifier instanceof XMLGrammarDescription) {
            XMLGrammarDescription desc = (XMLGrammarDescription) resourceIdentifier;
            if (XMLGrammarDescription.XML_SCHEMA.equals(desc.getGrammarType())) {
                return XSD_TYPE;
            }
        }
        return XML_TYPE;
    
public com.sun.org.apache.xerces.internal.xni.parser.XMLInputSourceresolveEntity(com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier resourceIdentifier)
Resolves an external parsed entity. If the entity cannot be resolved, this method should return null.

param
resourceIdentifier description of the resource to be revsoved
throws
XNIException Thrown on general error.
throws
IOException Thrown if resolved entity stream cannot be opened or some other i/o error occurs.

        // resolve entity using DOM entity resolver
        if (fEntityResolver != null) {
            // For entity resolution the type of the resource would be  XML TYPE
            // DOM L3 LS spec mention only the XML 1.0 recommendation right now
            LSInput inputSource =
                resourceIdentifier == null
                    ? fEntityResolver.resolveResource(
                        null,
                        null,
                        null,
                        null,
                        null)
                    : fEntityResolver.resolveResource(
                        getType(resourceIdentifier),
                        resourceIdentifier.getNamespace(),
                        resourceIdentifier.getPublicId(),
                        resourceIdentifier.getLiteralSystemId(),
                        resourceIdentifier.getBaseSystemId());
            if (inputSource != null) {
                String publicId = inputSource.getPublicId();
                String systemId = inputSource.getSystemId();
                String baseSystemId = inputSource.getBaseURI();
                InputStream byteStream = inputSource.getByteStream();
                Reader charStream = inputSource.getCharacterStream();
                String encoding = inputSource.getEncoding();
                String data = inputSource.getStringData();
                XMLInputSource xmlInputSource =
                    new XMLInputSource(publicId, systemId, baseSystemId);

                if (charStream != null) {
                    xmlInputSource.setCharacterStream(charStream);
                }
                if (byteStream != null) {
                    xmlInputSource.setByteStream((InputStream) byteStream);
                }
                if (data != null && data.length() != 0) {
                    xmlInputSource.setCharacterStream(
                        new StringReader(data));
                }
                xmlInputSource.setEncoding(encoding);
                return xmlInputSource;
            }
        }

        // unable to resolve entity
        return null;

    
public voidsetEntityResolver(org.w3c.dom.ls.LSResourceResolver entityResolver)
Sets the DOM entity resolver.

        fEntityResolver = entityResolver;