com.sun.org.apache.xerces.internal.impl.XMLEntityManager Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.impl.XMLEntityManager. 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: XMLSchemaValidator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setLocationHints(XSDDescription desc, String[] locations, StringList docLocations) {
    int length = locations.length;
    String[] hints = new String[length];
    int counter = 0;

    for (int i=0; i<length; i++) {
        try {
            String id = XMLEntityManager.expandSystemId(locations[i], desc.getBaseSystemId(), false);
            if (!docLocations.contains(id)) {
                hints[counter++] = locations[i];
            }
        }
        catch (MalformedURIException e) {
        }
    }

    if (counter > 0) {
        if (counter == length) {
            fXSDDescription.fLocationHints = hints;
        }
        else {
            fXSDDescription.fLocationHints = new String[counter];
            System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
        }
    }
}
 
Example #2
Source File: XIncludeHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Search for a xml:base attribute, and if one is found, put the new base URI into
 * effect.
 */
protected void processXMLBaseAttributes(XMLAttributes attributes) {
    String baseURIValue =
        attributes.getValue(NamespaceContext.XML_URI, "base");
    if (baseURIValue != null) {
        try {
            String expandedValue =
                XMLEntityManager.expandSystemId(
                    baseURIValue,
                    fCurrentBaseURI.getExpandedSystemId(),
                    false);
            fCurrentBaseURI.setLiteralSystemId(baseURIValue);
            fCurrentBaseURI.setBaseSystemId(
                fCurrentBaseURI.getExpandedSystemId());
            fCurrentBaseURI.setExpandedSystemId(expandedValue);

            // push the new values on the stack
            saveBaseURI();
        }
        catch (MalformedURIException e) {
            // REVISIT: throw error here
        }
    }
}
 
Example #3
Source File: XIncludeHandler.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Search for a xml:base attribute, and if one is found, put the new base URI into
 * effect.
 */
protected void processXMLBaseAttributes(XMLAttributes attributes) {
    String baseURIValue =
        attributes.getValue(NamespaceContext.XML_URI, "base");
    if (baseURIValue != null) {
        try {
            String expandedValue =
                XMLEntityManager.expandSystemId(
                    baseURIValue,
                    fCurrentBaseURI.getExpandedSystemId(),
                    false);
            fCurrentBaseURI.setLiteralSystemId(baseURIValue);
            fCurrentBaseURI.setBaseSystemId(
                fCurrentBaseURI.getExpandedSystemId());
            fCurrentBaseURI.setExpandedSystemId(expandedValue);

            // push the new values on the stack
            saveBaseURI();
        }
        catch (MalformedURIException e) {
            // REVISIT: throw error here
        }
    }
}
 
Example #4
Source File: XMLSchemaValidator.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private void setLocationHints(XSDDescription desc, String[] locations, StringList docLocations) {
    int length = locations.length;
    String[] hints = new String[length];
    int counter = 0;

    for (int i=0; i<length; i++) {
        try {
            String id = XMLEntityManager.expandSystemId(locations[i], desc.getBaseSystemId(), false);
            if (!docLocations.contains(id)) {
                hints[counter++] = locations[i];
            }
        }
        catch (MalformedURIException e) {
        }
    }

    if (counter > 0) {
        if (counter == length) {
            fXSDDescription.fLocationHints = hints;
        }
        else {
            fXSDDescription.fLocationHints = new String[counter];
            System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
        }
    }
}
 
Example #5
Source File: XIncludeHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Search for a xml:base attribute, and if one is found, put the new base URI into
 * effect.
 */
protected void processXMLBaseAttributes(XMLAttributes attributes) {
    String baseURIValue =
        attributes.getValue(NamespaceContext.XML_URI, "base");
    if (baseURIValue != null) {
        try {
            String expandedValue =
                XMLEntityManager.expandSystemId(
                    baseURIValue,
                    fCurrentBaseURI.getExpandedSystemId(),
                    false);
            fCurrentBaseURI.setLiteralSystemId(baseURIValue);
            fCurrentBaseURI.setBaseSystemId(
                fCurrentBaseURI.getExpandedSystemId());
            fCurrentBaseURI.setExpandedSystemId(expandedValue);

            // push the new values on the stack
            saveBaseURI();
        }
        catch (MalformedURIException e) {
            // REVISIT: throw error here
        }
    }
}
 
Example #6
Source File: XSDHandler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) {
    SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
    if (sg == null) {
        return findGrammar(desc, ignoreConflict) != null;
    }
    else if (sg.isImmutable()) {
        return true;
    }
    else {
        try {
            return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false));
        }
        catch (MalformedURIException e) {
            return false;
        }
    }
}
 
Example #7
Source File: XMLSchemaValidator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void setLocationHints(XSDDescription desc, String[] locations, StringList docLocations) {
    int length = locations.length;
    String[] hints = new String[length];
    int counter = 0;

    for (int i=0; i<length; i++) {
        try {
            String id = XMLEntityManager.expandSystemId(locations[i], desc.getBaseSystemId(), false);
            if (!docLocations.contains(id)) {
                hints[counter++] = locations[i];
            }
        }
        catch (MalformedURIException e) {
        }
    }

    if (counter > 0) {
        if (counter == length) {
            fXSDDescription.fLocationHints = hints;
        }
        else {
            fXSDDescription.fLocationHints = new String[counter];
            System.arraycopy(hints, 0, fXSDDescription.fLocationHints, 0, counter);
        }
    }
}
 
Example #8
Source File: XIncludeHandler.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Search for a xml:base attribute, and if one is found, put the new base URI into
 * effect.
 */
protected void processXMLBaseAttributes(XMLAttributes attributes) {
    String baseURIValue =
        attributes.getValue(NamespaceContext.XML_URI, "base");
    if (baseURIValue != null) {
        try {
            String expandedValue =
                XMLEntityManager.expandSystemId(
                    baseURIValue,
                    fCurrentBaseURI.getExpandedSystemId(),
                    false);
            fCurrentBaseURI.setLiteralSystemId(baseURIValue);
            fCurrentBaseURI.setBaseSystemId(
                fCurrentBaseURI.getExpandedSystemId());
            fCurrentBaseURI.setExpandedSystemId(expandedValue);

            // push the new values on the stack
            saveBaseURI();
        }
        catch (MalformedURIException e) {
            // REVISIT: throw error here
        }
    }
}
 
Example #9
Source File: XSDHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) {
    SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
    if (sg == null) {
        return findGrammar(desc, ignoreConflict) != null;
    }
    else if (sg.isImmutable()) {
        return true;
    }
    else {
        try {
            return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false));
        }
        catch (MalformedURIException e) {
            return false;
        }
    }
}
 
Example #10
Source File: XSDHandler.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) {
    SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
    if (sg == null) {
        return findGrammar(desc, ignoreConflict) != null;
    }
    else if (sg.isImmutable()) {
        return true;
    }
    else {
        try {
            return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false));
        }
        catch (MalformedURIException e) {
            return false;
        }
    }
}
 
Example #11
Source File: XSDHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean isExistingGrammar(XSDDescription desc, boolean ignoreConflict) {
    SchemaGrammar sg = fGrammarBucket.getGrammar(desc.getTargetNamespace());
    if (sg == null) {
        return findGrammar(desc, ignoreConflict) != null;
    }
    else if (sg.isImmutable()) {
        return true;
    }
    else {
        try {
            return sg.getDocumentLocations().contains(XMLEntityManager.expandSystemId(desc.getLiteralSystemId(), desc.getBaseSystemId(), false));
        }
        catch (MalformedURIException e) {
            return false;
        }
    }
}
 
Example #12
Source File: XIncludeHandler.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Search for a xml:base attribute, and if one is found, put the new base URI into
 * effect.
 */
protected void processXMLBaseAttributes(XMLAttributes attributes) {
    String baseURIValue =
        attributes.getValue(NamespaceContext.XML_URI, "base");
    if (baseURIValue != null) {
        try {
            String expandedValue =
                XMLEntityManager.expandSystemId(
                    baseURIValue,
                    fCurrentBaseURI.getExpandedSystemId(),
                    false);
            fCurrentBaseURI.setLiteralSystemId(baseURIValue);
            fCurrentBaseURI.setBaseSystemId(
                fCurrentBaseURI.getExpandedSystemId());
            fCurrentBaseURI.setExpandedSystemId(expandedValue);

            // push the new values on the stack
            saveBaseURI();
        }
        catch (MalformedURIException e) {
            // REVISIT: throw error here
        }
    }
}
 
Example #13
Source File: XIncludeHandler.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the file indicated by the given XMLLocator has already been included
 * in the current stack.
 * @param includedSource the source to check for inclusion
 * @return true if the source has already been included
 */
protected boolean searchForRecursiveIncludes(XMLLocator includedSource) {
    String includedSystemId = includedSource.getExpandedSystemId();

    if (includedSystemId == null) {
        try {
            includedSystemId =
                XMLEntityManager.expandSystemId(
                    includedSource.getLiteralSystemId(),
                    includedSource.getBaseSystemId(),
                    false);
        }
        catch (MalformedURIException e) {
            reportFatalError("ExpandedSystemId");
        }
    }

    if (includedSystemId.equals(fCurrentBaseURI.getExpandedSystemId())) {
        return true;
    }

    if (fParentXIncludeHandler == null) {
        return false;
    }
    return fParentXIncludeHandler.searchForRecursiveIncludes(
        includedSource);
}
 
Example #14
Source File: XMLSchemaLoader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** This method tries to resolve location of the given schema.
 * The loader stores the namespace/location pairs in a hashtable (use "" as the
 * namespace of absent namespace). When resolving an entity, loader first tries
 * to find in the hashtable whether there is a value for that namespace,
 * if so, pass that location value to the user-defined entity resolver.
 *
 * @param desc
 * @param locationPairs
 * @param entityResolver
 * @return
 * @throws IOException
 */
public static XMLInputSource resolveDocument(XSDDescription desc, Map locationPairs,
        XMLEntityResolver entityResolver) throws IOException {
    String loc = null;
    // we consider the schema location properties for import
    if (desc.getContextType() == XSDDescription.CONTEXT_IMPORT ||
            desc.fromInstance()) {
        // use empty string as the key for absent namespace
        String namespace = desc.getTargetNamespace();
        String ns = namespace == null ? XMLSymbols.EMPTY_STRING : namespace;
        // get the location hint for that namespace
        LocationArray tempLA = (LocationArray)locationPairs.get(ns);
        if(tempLA != null)
            loc = tempLA.getFirstLocation();
    }

    // if it's not import, or if the target namespace is not set
    // in the schema location properties, use location hint
    if (loc == null) {
        String[] hints = desc.getLocationHints();
        if (hints != null && hints.length > 0)
            loc = hints[0];
    }

    String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false);
    desc.setLiteralSystemId(loc);
    desc.setExpandedSystemId(expandedLoc);
    return entityResolver.resolveEntity(desc);
}
 
Example #15
Source File: XMLInputSourceAdaptor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public String getSystemId() {
    try {
        return XMLEntityManager.expandSystemId(
                fSource.getSystemId(), fSource.getBaseSystemId(), false);
    } catch (MalformedURIException e) {
        return fSource.getSystemId();
    }
}
 
Example #16
Source File: XIncludeHandler.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if the file indicated by the given XMLLocator has already been included
 * in the current stack.
 * @param includedSource the source to check for inclusion
 * @return true if the source has already been included
 */
protected boolean searchForRecursiveIncludes(XMLLocator includedSource) {
    String includedSystemId = includedSource.getExpandedSystemId();

    if (includedSystemId == null) {
        try {
            includedSystemId =
                XMLEntityManager.expandSystemId(
                    includedSource.getLiteralSystemId(),
                    includedSource.getBaseSystemId(),
                    false);
        }
        catch (MalformedURIException e) {
            reportFatalError("ExpandedSystemId");
        }
    }

    if (includedSystemId.equals(fCurrentBaseURI.getExpandedSystemId())) {
        return true;
    }

    if (fParentXIncludeHandler == null) {
        return false;
    }
    return fParentXIncludeHandler.searchForRecursiveIncludes(
        includedSource);
}
 
Example #17
Source File: ValidatorHandlerImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Resolves a system identifier against a base URI. */
private String resolveSystemId(String systemId, String baseURI) {
    try {
        return XMLEntityManager.expandSystemId(systemId, baseURI, false);
    }
    // In the event that resolution failed against the
    // base URI, just return the system id as is. There's not
    // much else we can do.
    catch (URI.MalformedURIException ex) {
        return systemId;
    }
}
 
Example #18
Source File: XMLDTDLoader.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a Grammar object by parsing the contents of the
 * entity pointed to by source.
 *
 * @param source        the location of the entity which forms
 *                          the starting point of the grammar to be constructed.
 * @throws IOException      When a problem is encountered reading the entity
 *          XNIException    When a condition arises (such as a FatalError) that requires parsing
 *                              of the entity be terminated.
 */
public Grammar loadGrammar(XMLInputSource source)
        throws IOException, XNIException {
    reset();
    // First chance checking strict URI
    String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
    XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null);
    if (!fBalanceSyntaxTrees) {
        fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
    }
    else {
        fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
    }
    fGrammarBucket = new DTDGrammarBucket();
    fGrammarBucket.setStandalone(false);
    fGrammarBucket.setActiveGrammar(fDTDGrammar);
    // no reason to use grammar bucket's "put" method--we
    // know which grammar it is, and we don't know the root name anyway...

    // actually start the parsing!
    try {
        fDTDScanner.setInputSource(source);
        fDTDScanner.scanDTDExternalSubset(true);
    } catch (EOFException e) {
        // expected behaviour...
    }
    finally {
        // Close all streams opened by the parser.
        fEntityManager.closeReaders();
    }
    if(fDTDGrammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLDTDDescription.XML_DTD, new Grammar[] {fDTDGrammar});
    }
    return fDTDGrammar;
}
 
Example #19
Source File: ValidatorHandlerImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Resolves a system identifier against a base URI. */
private String resolveSystemId(String systemId, String baseURI) {
    try {
        return XMLEntityManager.expandSystemId(systemId, baseURI, false);
    }
    // In the event that resolution failed against the
    // base URI, just return the system id as is. There's not
    // much else we can do.
    catch (URI.MalformedURIException ex) {
        return systemId;
    }
}
 
Example #20
Source File: XMLGrammarPreparser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a preparser using the specified symbol table.
 *
 * @param symbolTable The symbol table to use.
 */
public XMLGrammarPreparser (SymbolTable symbolTable) {
    fSymbolTable = symbolTable;

    fLoaders = new HashMap<>();
    fErrorReporter = new XMLErrorReporter();
    setLocale(Locale.getDefault());
    fEntityResolver = new XMLEntityManager();
    // those are all the basic properties...
}
 
Example #21
Source File: XMLDTDLoader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Grammar object by parsing the contents of the
 * entity pointed to by source.
 *
 * @param source        the location of the entity which forms
 *                          the starting point of the grammar to be constructed.
 * @throws IOException      When a problem is encountered reading the entity
 *          XNIException    When a condition arises (such as a FatalError) that requires parsing
 *                              of the entity be terminated.
 */
public Grammar loadGrammar(XMLInputSource source)
        throws IOException, XNIException {
    reset();
    // First chance checking strict URI
    String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
    XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null);
    if (!fBalanceSyntaxTrees) {
        fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
    }
    else {
        fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
    }
    fGrammarBucket = new DTDGrammarBucket();
    fGrammarBucket.setStandalone(false);
    fGrammarBucket.setActiveGrammar(fDTDGrammar);
    // no reason to use grammar bucket's "put" method--we
    // know which grammar it is, and we don't know the root name anyway...

    // actually start the parsing!
    try {
        fDTDScanner.setInputSource(source);
        fDTDScanner.scanDTDExternalSubset(true);
    } catch (EOFException e) {
        // expected behaviour...
    }
    finally {
        // Close all streams opened by the parser.
        fEntityManager.closeReaders();
    }
    if(fDTDGrammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLDTDDescription.XML_DTD, new Grammar[] {fDTDGrammar});
    }
    return fDTDGrammar;
}
 
Example #22
Source File: XMLDTDLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a Grammar object by parsing the contents of the
 * entity pointed to by source.
 *
 * @param source        the location of the entity which forms
 *                          the starting point of the grammar to be constructed.
 * @throws IOException      When a problem is encountered reading the entity
 *          XNIException    When a condition arises (such as a FatalError) that requires parsing
 *                              of the entity be terminated.
 */
public Grammar loadGrammar(XMLInputSource source)
        throws IOException, XNIException {
    reset();
    // First chance checking strict URI
    String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
    XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null);
    if (!fBalanceSyntaxTrees) {
        fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
    }
    else {
        fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
    }
    fGrammarBucket = new DTDGrammarBucket();
    fGrammarBucket.setStandalone(false);
    fGrammarBucket.setActiveGrammar(fDTDGrammar);
    // no reason to use grammar bucket's "put" method--we
    // know which grammar it is, and we don't know the root name anyway...

    // actually start the parsing!
    try {
        fDTDScanner.setInputSource(source);
        fDTDScanner.scanDTDExternalSubset(true);
    } catch (EOFException e) {
        // expected behaviour...
    }
    finally {
        // Close all streams opened by the parser.
        fEntityManager.closeReaders();
    }
    if(fDTDGrammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLDTDDescription.XML_DTD, new Grammar[] {fDTDGrammar});
    }
    return fDTDGrammar;
}
 
Example #23
Source File: XIncludeHandler.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if the file indicated by the given XMLLocator has already been included
 * in the current stack.
 * @param includedSource the source to check for inclusion
 * @return true if the source has already been included
 */
protected boolean searchForRecursiveIncludes(XMLLocator includedSource) {
    String includedSystemId = includedSource.getExpandedSystemId();

    if (includedSystemId == null) {
        try {
            includedSystemId =
                XMLEntityManager.expandSystemId(
                    includedSource.getLiteralSystemId(),
                    includedSource.getBaseSystemId(),
                    false);
        }
        catch (MalformedURIException e) {
            reportFatalError("ExpandedSystemId");
        }
    }

    if (includedSystemId.equals(fCurrentBaseURI.getExpandedSystemId())) {
        return true;
    }

    if (fParentXIncludeHandler == null) {
        return false;
    }
    return fParentXIncludeHandler.searchForRecursiveIncludes(
        includedSource);
}
 
Example #24
Source File: XMLGrammarPreparser.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Constructs a preparser using the specified symbol table.
 *
 * @param symbolTable The symbol table to use.
 */
public XMLGrammarPreparser (SymbolTable symbolTable) {
    fSymbolTable = symbolTable;

    fLoaders = new HashMap<>();
    fErrorReporter = new XMLErrorReporter();
    setLocale(Locale.getDefault());
    fEntityResolver = new XMLEntityManager();
    // those are all the basic properties...
}
 
Example #25
Source File: ValidatorHandlerImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** Resolves a system identifier against a base URI. */
private String resolveSystemId(String systemId, String baseURI) {
    try {
        return XMLEntityManager.expandSystemId(systemId, baseURI, false);
    }
    // In the event that resolution failed against the
    // base URI, just return the system id as is. There's not
    // much else we can do.
    catch (URI.MalformedURIException ex) {
        return systemId;
    }
}
 
Example #26
Source File: XMLInputSourceAdaptor.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public String getSystemId() {
    try {
        return XMLEntityManager.expandSystemId(
                fSource.getSystemId(), fSource.getBaseSystemId(), false);
    } catch (MalformedURIException e) {
        return fSource.getSystemId();
    }
}
 
Example #27
Source File: XMLDTDLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a Grammar object by parsing the contents of the
 * entity pointed to by source.
 *
 * @param source        the location of the entity which forms
 *                          the starting point of the grammar to be constructed.
 * @throws IOException      When a problem is encountered reading the entity
 *          XNIException    When a condition arises (such as a FatalError) that requires parsing
 *                              of the entity be terminated.
 */
public Grammar loadGrammar(XMLInputSource source)
        throws IOException, XNIException {
    reset();
    // First chance checking strict URI
    String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
    XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null);
    if (!fBalanceSyntaxTrees) {
        fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
    }
    else {
        fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
    }
    fGrammarBucket = new DTDGrammarBucket();
    fGrammarBucket.setStandalone(false);
    fGrammarBucket.setActiveGrammar(fDTDGrammar);
    // no reason to use grammar bucket's "put" method--we
    // know which grammar it is, and we don't know the root name anyway...

    // actually start the parsing!
    try {
        fDTDScanner.setInputSource(source);
        fDTDScanner.scanDTDExternalSubset(true);
    } catch (EOFException e) {
        // expected behaviour...
    }
    finally {
        // Close all streams opened by the parser.
        fEntityManager.closeReaders();
    }
    if(fDTDGrammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLDTDDescription.XML_DTD, new Grammar[] {fDTDGrammar});
    }
    return fDTDGrammar;
}
 
Example #28
Source File: XMLSchemaLoader.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/** This method tries to resolve location of the given schema.
 * The loader stores the namespace/location pairs in a map (use "" as the
 * namespace of absent namespace). When resolving an entity, loader first tries
 * to find in the map whether there is a value for that namespace,
 * if so, pass that location value to the user-defined entity resolver.
 *
 * @param desc
 * @param locationPairs
 * @param entityResolver
 * @return
 * @throws IOException
 */
public static XMLInputSource resolveDocument(XSDDescription desc,
        Map<String, LocationArray> locationPairs,
        XMLEntityResolver entityResolver) throws IOException {
    String loc = null;
    // we consider the schema location properties for import
    if (desc.getContextType() == XSDDescription.CONTEXT_IMPORT ||
            desc.fromInstance()) {
        // use empty string as the key for absent namespace
        String namespace = desc.getTargetNamespace();
        String ns = namespace == null ? XMLSymbols.EMPTY_STRING : namespace;
        // get the location hint for that namespace
        LocationArray tempLA = locationPairs.get(ns);
        if(tempLA != null)
            loc = tempLA.getFirstLocation();
    }

    // if it's not import, or if the target namespace is not set
    // in the schema location properties, use location hint
    if (loc == null) {
        String[] hints = desc.getLocationHints();
        if (hints != null && hints.length > 0)
            loc = hints[0];
    }

    String expandedLoc = XMLEntityManager.expandSystemId(loc, desc.getBaseSystemId(), false);
    desc.setLiteralSystemId(loc);
    desc.setExpandedSystemId(expandedLoc);
    return entityResolver.resolveEntity(desc);
}
 
Example #29
Source File: ValidatorHandlerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Resolves a system identifier against a base URI. */
private String resolveSystemId(String systemId, String baseURI) {
    try {
        return XMLEntityManager.expandSystemId(systemId, baseURI, false);
    }
    // In the event that resolution failed against the
    // base URI, just return the system id as is. There's not
    // much else we can do.
    catch (URI.MalformedURIException ex) {
        return systemId;
    }
}
 
Example #30
Source File: XMLGrammarPreparser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a preparser using the specified symbol table.
 *
 * @param symbolTable The symbol table to use.
 */
public XMLGrammarPreparser (SymbolTable symbolTable) {
    fSymbolTable = symbolTable;

    fLoaders = new HashMap<>();
    fErrorReporter = new XMLErrorReporter();
    setLocale(Locale.getDefault());
    fEntityResolver = new XMLEntityManager();
    // those are all the basic properties...
}