FileDocCategorySizeDatePackage
EntityResolverWrapper.javaAPI DocJava SE 6 API4862Tue Jun 10 00:22:50 BST 2008com.sun.org.apache.xerces.internal.util

EntityResolverWrapper

public class EntityResolverWrapper extends Object implements XMLEntityResolver
This class wraps a SAX entity resolver in an XNI entity resolver.
see
EntityResolver
author
Andy Clark, IBM
version
$Id: EntityResolverWrapper.java,v 1.2.6.1 2005/09/05 07:52:13 neerajbj Exp $

Fields Summary
protected EntityResolver
fEntityResolver
The SAX entity resolver.
Constructors Summary
public EntityResolverWrapper()
Default constructor.

public EntityResolverWrapper(EntityResolver entityResolver)
Wraps the specified SAX entity resolver.

        setEntityResolver(entityResolver);
    
Methods Summary
public org.xml.sax.EntityResolvergetEntityResolver()
Returns the SAX entity resolver.

        return fEntityResolver;
    
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 contains the physical co-ordinates of the resource to be resolved
throws
XNIException Thrown on general error.
throws
IOException Thrown if resolved entity stream cannot be opened or some other i/o error occurs.


        // When both pubId and sysId are null, the user's entity resolver
        // can do nothing about it. We'd better not bother calling it.
        // This happens when the resourceIdentifier is a GrammarDescription,
        // which describes a schema grammar of some namespace, but without
        // any schema location hint. -Sg
        String pubId = resourceIdentifier.getPublicId();
        String sysId = resourceIdentifier.getExpandedSystemId();
        if (pubId == null && sysId == null)
            return null;

        // resolve entity using SAX entity resolver
        if (fEntityResolver != null && resourceIdentifier != null) {
            try {
                InputSource inputSource = fEntityResolver.resolveEntity(pubId, sysId);
                if (inputSource != null) {
                    String publicId = inputSource.getPublicId();
                    String systemId = inputSource.getSystemId();
                    String baseSystemId = resourceIdentifier.getBaseSystemId();
                    InputStream byteStream = inputSource.getByteStream();
                    Reader charStream = inputSource.getCharacterStream();
                    String encoding = inputSource.getEncoding();
                    XMLInputSource xmlInputSource =
                        new XMLInputSource(publicId, systemId, baseSystemId);
                    xmlInputSource.setByteStream(byteStream);
                    xmlInputSource.setCharacterStream(charStream);
                    xmlInputSource.setEncoding(encoding);
                    return xmlInputSource;
                }
            }

            // error resolving entity
            catch (SAXException e) {
                Exception ex = e.getException();
                if (ex == null) {
                    ex = e;
                }
                throw new XNIException(ex);
            }
        }

        // unable to resolve entity
        return null;

    
public voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)
Sets the SAX entity resolver.

        fEntityResolver = entityResolver;