Java Code Examples for com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setBaseSystemId()

The following examples show how to use com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setBaseSystemId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLEntityManager.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 2
Source File: XMLEntityManager.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 3
Source File: XMLEntityManager.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();
    String namespace = resourceIdentifier.getNamespace();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 4
Source File: XMLEntityManager.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 5
Source File: XMLEntityManager.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 6
Source File: XMLEntityManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 7
Source File: XMLEntityManager.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 8
Source File: XMLEntityManager.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();
    String namespace = resourceIdentifier.getNamespace();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}
 
Example 9
Source File: XMLEntityManager.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolves the specified public and system identifiers. This
 * method first attempts to resolve the entity based on the
 * EntityResolver registered by the application. If no entity
 * resolver is registered or if the registered entity handler
 * is unable to resolve the entity, then default entity
 * resolution will occur.
 *
 * @param publicId     The public identifier of the entity.
 * @param systemId     The system identifier of the entity.
 * @param baseSystemId The base system identifier of the entity.
 *                     This is the system identifier of the current
 *                     entity and is used to expand the system
 *                     identifier when the system identifier is a
 *                     relative URI.
 *
 * @return Returns an input source that wraps the resolved entity.
 *         This method will never return null.
 *
 * @throws IOException  Thrown on i/o error.
 * @throws XNIException Thrown by entity resolver to signal an error.
 */
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException {
    if(resourceIdentifier == null ) return null;
    String publicId = resourceIdentifier.getPublicId();
    String literalSystemId = resourceIdentifier.getLiteralSystemId();
    String baseSystemId = resourceIdentifier.getBaseSystemId();
    String expandedSystemId = resourceIdentifier.getExpandedSystemId();
    String namespace = resourceIdentifier.getNamespace();

    // if no base systemId given, assume that it's relative
    // to the systemId of the current scanned entity
    // Sometimes the system id is not (properly) expanded.
    // We need to expand the system id if:
    // a. the expanded one was null; or
    // b. the base system id was null, but becomes non-null from the current entity.
    boolean needExpand = (expandedSystemId == null);
    // REVISIT:  why would the baseSystemId ever be null?  if we
    // didn't have to make this check we wouldn't have to reuse the
    // fXMLResourceIdentifier object...
    if (baseSystemId == null && fCurrentEntity != null && fCurrentEntity.entityLocation != null) {
        baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId();
        if (baseSystemId != null)
            needExpand = true;
    }
    if (needExpand)
        expandedSystemId = expandSystemId(literalSystemId, baseSystemId,false);

    // give the entity resolver a chance
    XMLInputSource xmlInputSource = null;

    if (fEntityResolver != null) {
        resourceIdentifier.setBaseSystemId(baseSystemId);
        resourceIdentifier.setExpandedSystemId(expandedSystemId);
        xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
    }

    // do default resolution
    // REVISIT: what's the correct behavior if the user provided an entity
    // resolver (fEntityResolver != null), but resolveEntity doesn't return
    // an input source (xmlInputSource == null)?
    // do we do default resolution, or do we just return null? -SG
    if (xmlInputSource == null) {
        // REVISIT: when systemId is null, I think we should return null.
        //          is this the right solution? -SG
        //if (systemId != null)
        xmlInputSource = new XMLInputSource(publicId, literalSystemId, baseSystemId);
    }

    if (DEBUG_RESOLVER) {
        System.err.println("XMLEntityManager.resolveEntity(" + publicId + ")");
        System.err.println(" = " + xmlInputSource);
    }

    return xmlInputSource;

}