com.sun.org.apache.xerces.internal.xni.grammars.Grammar Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.xni.grammars.Grammar. 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: XMLGrammarCachingConfiguration.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
DTDGrammar parseDTD(XMLInputSource is)
            throws IOException {
    XMLEntityResolver resolver = getEntityResolver();
    if(resolver != null) {
        fDTDLoader.setEntityResolver(resolver);
    }
    fDTDLoader.setProperty(ERROR_REPORTER, fErrorReporter);

    // Should check whether the grammar with this namespace is already in
    // the grammar resolver. But since we don't know the target namespace
    // of the document here, we leave such check to the application...
    DTDGrammar grammar = (DTDGrammar)fDTDLoader.loadGrammar(is);
    // by default, hand it off to the grammar pool
    if (grammar != null) {
        fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_DTD,
                                  new Grammar[]{grammar});
    }

    return grammar;

}
 
Example #2
Source File: XMLGrammarPreparser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse a grammar from a location identified by an
 * XMLInputSource.
 * This method also adds this grammar to the XMLGrammarPool
 *
 * @param type The type of the grammar to be constructed
 * @param is The XMLInputSource containing this grammar's
 * information
 * <strong>If a URI is included in the systemId field, the parser will not expand this URI or make it
 * available to the EntityResolver</strong>
 * @return The newly created <code>Grammar</code>.
 * @exception XNIException thrown on an error in grammar
 * construction
 * @exception IOException thrown if an error is encountered
 * in reading the file
 */
public Grammar preparseGrammar(String type, XMLInputSource
            is) throws XNIException, IOException {
    if(fLoaders.containsKey(type)) {
        XMLGrammarLoader gl = (XMLGrammarLoader)fLoaders.get(type);
        // make sure gl's been set up with all the "basic" properties:
        gl.setProperty(SYMBOL_TABLE, fSymbolTable);
        gl.setProperty(ENTITY_RESOLVER, fEntityResolver);
        gl.setProperty(ERROR_REPORTER, fErrorReporter);
        // potentially, not all will support this one...
        if(fGrammarPool != null) {
            try {
                gl.setProperty(GRAMMAR_POOL, fGrammarPool);
            } catch(Exception e) {
                // too bad...
            }
        }
        return gl.loadGrammar(is);
    }
    return null;
}
 
Example #3
Source File: XMLSchemaLoader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void initGrammarBucket(){
    if(fGrammarPool != null) {
        Grammar [] initialGrammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_SCHEMA);
        for (int i = 0; i < initialGrammars.length; i++) {
            // put this grammar into the bucket, along with grammars
            // imported by it (directly or indirectly)
            if (!fGrammarBucket.putGrammar((SchemaGrammar)(initialGrammars[i]), true)) {
                // REVISIT: a conflict between new grammar(s) and grammars
                // in the bucket. What to do? A warning? An exception?
                fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
                        "GrammarConflict", null,
                        XMLErrorReporter.SEVERITY_WARNING);
            }
        }
    }
}
 
Example #4
Source File: XMLGrammarPoolImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public Grammar [] retrieveInitialGrammarSet (String grammarType) {
    synchronized (fGrammars) {
        int grammarSize = fGrammars.length ;
        Grammar [] tempGrammars = new Grammar[fGrammarCount];
        int pos = 0;
        for (int i = 0; i < grammarSize; i++) {
            for (Entry e = fGrammars[i]; e != null; e = e.next) {
                if (e.desc.getGrammarType().equals(grammarType)) {
                    tempGrammars[pos++] = e.grammar;
                }
            }
        }
        Grammar[] toReturn = new Grammar[pos];
        System.arraycopy(tempGrammars, 0, toReturn, 0, pos);
        return toReturn;
    }
}
 
Example #5
Source File: SoftReferenceGrammarPool.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the grammar associated to the specified grammar description.
 * Currently, the root element name is used as the key for DTD grammars
 * and the target namespace  is used as the key for Schema grammars.
 *
 * @param desc The Grammar Description.
 */
public Grammar getGrammar(XMLGrammarDescription desc) {
    synchronized (fGrammars) {
        clean();
        int hash = hashCode(desc);
        int index = (hash & 0x7FFFFFFF) % fGrammars.length;
        for (Entry entry = fGrammars[index]; entry != null; entry = entry.next) {
            Grammar tempGrammar = (Grammar) entry.grammar.get();
            /** If the soft reference has been cleared, remove this entry from the pool. */
            if (tempGrammar == null) {
                removeEntry(entry);
            }
            else if ((entry.hash == hash) && equals(entry.desc, desc)) {
                return tempGrammar;
            }
        }
        return null;
    }
}
 
Example #6
Source File: XMLGrammarPoolImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public Grammar [] retrieveInitialGrammarSet (String grammarType) {
    synchronized (fGrammars) {
        int grammarSize = fGrammars.length ;
        Grammar [] tempGrammars = new Grammar[fGrammarCount];
        int pos = 0;
        for (int i = 0; i < grammarSize; i++) {
            for (Entry e = fGrammars[i]; e != null; e = e.next) {
                if (e.desc.getGrammarType().equals(grammarType)) {
                    tempGrammars[pos++] = e.grammar;
                }
            }
        }
        Grammar[] toReturn = new Grammar[pos];
        System.arraycopy(tempGrammars, 0, toReturn, 0, pos);
        return toReturn;
    }
}
 
Example #7
Source File: SoftReferenceGrammarPool.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the grammar associated to the specified grammar description.
 * Currently, the root element name is used as the key for DTD grammars
 * and the target namespace  is used as the key for Schema grammars.
 *
 * @param desc The Grammar Description.
 */
public Grammar getGrammar(XMLGrammarDescription desc) {
    synchronized (fGrammars) {
        clean();
        int hash = hashCode(desc);
        int index = (hash & 0x7FFFFFFF) % fGrammars.length;
        for (Entry entry = fGrammars[index]; entry != null; entry = entry.next) {
            Grammar tempGrammar = (Grammar) entry.grammar.get();
            /** If the soft reference has been cleared, remove this entry from the pool. */
            if (tempGrammar == null) {
                removeEntry(entry);
            }
            else if ((entry.hash == hash) && equals(entry.desc, desc)) {
                return tempGrammar;
            }
        }
        return null;
    }
}
 
Example #8
Source File: XMLGrammarPoolImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Removes the grammar associated to the specified grammar description from the
 * grammar pool and returns the removed grammar. Currently, the root element name
 * is used as the key for DTD grammars and the target namespace  is used
 * as the key for Schema grammars.
 *
 * @param desc The Grammar Description.
 * @return     The removed grammar.
 */
public Grammar removeGrammar(XMLGrammarDescription desc) {
    synchronized (fGrammars) {
        int hash = hashCode(desc);
    int index = (hash & 0x7FFFFFFF) % fGrammars.length;
    for (Entry entry = fGrammars[index], prev = null ; entry != null ; prev = entry, entry = entry.next) {
        if ((entry.hash == hash) && equals(entry.desc, desc)) {
            if (prev != null) {
                    prev.next = entry.next;
        }
        else {
            fGrammars[index] = entry.next;
        }
            Grammar tempGrammar = entry.grammar;
            entry.grammar = null;
            fGrammarCount--;
            return tempGrammar;
        }
    }
    return null;
    }
}
 
Example #9
Source File: XMLSchemaLoader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public XSModel load(LSInput is) {
    try {
        Grammar g = loadGrammar(dom2xmlInputSource(is));
        return ((XSGrammar) g).toXSModel();
    } catch (Exception e) {
        reportDOMFatalError(e);
        return null;
    }
}
 
Example #10
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 #11
Source File: SoftReferenceGrammarPool.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the grammar associated to the specified grammar description from the
 * grammar pool and returns the removed grammar. Currently, the root element name
 * is used as the key for DTD grammars and the target namespace  is used
 * as the key for Schema grammars.
 *
 * @param desc The Grammar Description.
 * @return     The removed grammar.
 */
public Grammar removeGrammar(XMLGrammarDescription desc) {
    synchronized (fGrammars) {
        clean();
        int hash = hashCode(desc);
        int index = (hash & 0x7FFFFFFF) % fGrammars.length;
        for (Entry entry = fGrammars[index]; entry != null; entry = entry.next) {
            if ((entry.hash == hash) && equals(entry.desc, desc)) {
                return removeEntry(entry);
            }
        }
        return null;
    }
}
 
Example #12
Source File: XMLGrammarPoolImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the grammar associated to the specified grammar description.
 * Currently, the root element name is used as the key for DTD grammars
 * and the target namespace  is used as the key for Schema grammars.
 *
 * @param desc The Grammar Description.
 */
public Grammar getGrammar(XMLGrammarDescription desc) {
    synchronized (fGrammars) {
        int hash = hashCode(desc);
    int index = (hash & 0x7FFFFFFF) % fGrammars.length;
    for (Entry entry = fGrammars[index] ; entry != null ; entry = entry.next) {
        if ((entry.hash == hash) && equals(entry.desc, desc)) {
            return entry.grammar;
        }
    }
    return null;
}
}
 
Example #13
Source File: XSDHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public Grammar[] retrieveInitialGrammarSet(String grammarType) {
    if (grammarType == XMLGrammarDescription.XML_SCHEMA) {
        if (fInitialGrammarSet == null) {
            if (fGrammarBucket == null) {
                fInitialGrammarSet = new Grammar [] {SchemaGrammar.Schema4Annotations.INSTANCE};
            }
            else {
                SchemaGrammar [] schemaGrammars = fGrammarBucket.getGrammars();
                /**
                 * If the grammar bucket already contains the schema for schemas
                 * then we already have the definitions for the parts relevant
                 * to annotations.
                 */
                for (int i = 0; i < schemaGrammars.length; ++i) {
                    if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(schemaGrammars[i].getTargetNamespace())) {
                        fInitialGrammarSet = schemaGrammars;
                        return fInitialGrammarSet;
                    }
                }
                Grammar [] grammars = new Grammar[schemaGrammars.length + 1];
                System.arraycopy(schemaGrammars, 0, grammars, 0, schemaGrammars.length);
                grammars[grammars.length - 1] = SchemaGrammar.Schema4Annotations.INSTANCE;
                fInitialGrammarSet = grammars;
            }
        }
        return fInitialGrammarSet;
    }
    return new Grammar[0];
}
 
Example #14
Source File: XSLoaderImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void putGrammar(Grammar grammar) {
    SchemaGrammar cachedGrammar =
        toSchemaGrammar(super.getGrammar(grammar.getGrammarDescription()));
    if (cachedGrammar != null) {
        SchemaGrammar newGrammar = toSchemaGrammar(grammar);
        if (newGrammar != null) {
            mergeSchemaGrammars(cachedGrammar, newGrammar);
        }
    }
    else {
        super.putGrammar(grammar);
    }
}
 
Example #15
Source File: XSDHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Grammar[] retrieveInitialGrammarSet(String grammarType) {
    if (grammarType == XMLGrammarDescription.XML_SCHEMA) {
        if (fInitialGrammarSet == null) {
            if (fGrammarBucket == null) {
                fInitialGrammarSet = new Grammar [] {SchemaGrammar.Schema4Annotations.INSTANCE};
            }
            else {
                SchemaGrammar [] schemaGrammars = fGrammarBucket.getGrammars();
                /**
                 * If the grammar bucket already contains the schema for schemas
                 * then we already have the definitions for the parts relevant
                 * to annotations.
                 */
                for (int i = 0; i < schemaGrammars.length; ++i) {
                    if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(schemaGrammars[i].getTargetNamespace())) {
                        fInitialGrammarSet = schemaGrammars;
                        return fInitialGrammarSet;
                    }
                }
                Grammar [] grammars = new Grammar[schemaGrammars.length + 1];
                System.arraycopy(schemaGrammars, 0, grammars, 0, schemaGrammars.length);
                grammars[grammars.length - 1] = SchemaGrammar.Schema4Annotations.INSTANCE;
                fInitialGrammarSet = grammars;
            }
        }
        return fInitialGrammarSet;
    }
    return new Grammar[0];
}
 
Example #16
Source File: SoftReferenceGrammarPool.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
protected Entry(int hash, int bucket, XMLGrammarDescription desc, Grammar grammar,
        Entry next, ReferenceQueue<Grammar> queue) {
    this.hash = hash;
    this.bucket = bucket;
    this.prev = null;
    this.next = next;
    if (next != null) {
        next.prev = this;
    }
    this.desc = desc;
    this.grammar = new SoftGrammarReference(this, grammar, queue);
}
 
Example #17
Source File: PreParseGrammarTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws FileNotFoundException, XNIException, IOException {
    File xsdf = new File(System.getProperty("test.src", ".") + "/test.xsd");
    InputStream is = new BufferedInputStream(new FileInputStream(xsdf));
    XMLInputSource xis = new XMLInputSource(null, null, null, is, null);
    XMLGrammarPreparser gp = new XMLGrammarPreparser();
    gp.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);
    //The NullPointerException is observed on next call during ant task
    // execution
    Grammar res = gp.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, xis);
    System.out.println("Grammar preparsed successfully:" + res);
    return;
}
 
Example #18
Source File: CachingParserPool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the grammar associated to the specified description.
 *
 * @param desc The description of the grammar.
 */
public Grammar getGrammar(XMLGrammarDescription desc) {

    if (super.containsGrammar(desc)) {
        return super.getGrammar(desc);
    }
    return null;

}
 
Example #19
Source File: XMLSchemaLoader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public XSModel load(LSInput is) {
    try {
        Grammar g = loadGrammar(dom2xmlInputSource(is));
        return ((XSGrammar) g).toXSModel();
    } catch (Exception e) {
        reportDOMFatalError(e);
        return null;
    }
}
 
Example #20
Source File: SoftReferenceGrammarPool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Removes the given entry from the pool
 *
 * @param entry the entry to remove
 * @return The grammar attached to this entry
 */
private Grammar removeEntry(Entry entry) {
    if (entry.prev != null) {
        entry.prev.next = entry.next;
    }
    else {
        fGrammars[entry.bucket] = entry.next;
    }
    if (entry.next != null) {
        entry.next.prev = entry.prev;
    }
    --fGrammarCount;
    entry.grammar.entry = null;
    return (Grammar) entry.grammar.get();
}
 
Example #21
Source File: XMLDTDLoader.java    From openjdk-jdk9 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: XSDHandler.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Grammar retrieveGrammar(XMLGrammarDescription desc) {
    if (desc.getGrammarType() == XMLGrammarDescription.XML_SCHEMA) {
        final String tns = ((XMLSchemaDescription) desc).getTargetNamespace();
        if (fGrammarBucket != null) {
            Grammar grammar = fGrammarBucket.getGrammar(tns);
            if (grammar != null) {
                return grammar;
            }
        }
        if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(tns)) {
            return SchemaGrammar.Schema4Annotations.INSTANCE;
        }
    }
    return null;
}
 
Example #23
Source File: XSDHandler.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public Grammar[] retrieveInitialGrammarSet(String grammarType) {
    if (grammarType == XMLGrammarDescription.XML_SCHEMA) {
        if (fInitialGrammarSet == null) {
            if (fGrammarBucket == null) {
                fInitialGrammarSet = new Grammar [] {SchemaGrammar.Schema4Annotations.INSTANCE};
            }
            else {
                SchemaGrammar [] schemaGrammars = fGrammarBucket.getGrammars();
                /**
                 * If the grammar bucket already contains the schema for schemas
                 * then we already have the definitions for the parts relevant
                 * to annotations.
                 */
                for (int i = 0; i < schemaGrammars.length; ++i) {
                    if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(schemaGrammars[i].getTargetNamespace())) {
                        fInitialGrammarSet = schemaGrammars;
                        return fInitialGrammarSet;
                    }
                }
                Grammar [] grammars = new Grammar[schemaGrammars.length + 1];
                System.arraycopy(schemaGrammars, 0, grammars, 0, schemaGrammars.length);
                grammars[grammars.length - 1] = SchemaGrammar.Schema4Annotations.INSTANCE;
                fInitialGrammarSet = grammars;
            }
        }
        return fInitialGrammarSet;
    }
    return new Grammar[0];
}
 
Example #24
Source File: SoftReferenceGrammarPool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void cacheGrammars(String grammarType, Grammar[] grammars) {
    if (!fPoolIsLocked) {
        for (int i = 0; i < grammars.length; ++i) {
            putGrammar(grammars[i]);
        }
    }
}
 
Example #25
Source File: SoftReferenceGrammarPool.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void cacheGrammars(String grammarType, Grammar[] grammars) {
    if (!fPoolIsLocked) {
        for (int i = 0; i < grammars.length; ++i) {
            putGrammar(grammars[i]);
        }
    }
}
 
Example #26
Source File: XMLDTDLoader.java    From openjdk-jdk8u-backup 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 #27
Source File: XMLDTDLoader.java    From openjdk-8 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 #28
Source File: XMLSchemaLoader.java    From openjdk-jdk9 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 {

    // REVISIT: this method should have a namespace parameter specified by
    // user. In this case we can easily detect if a schema asked to be loaded
    // is already in the local cache.

    reset(fLoaderConfig);
    fSettingsChanged = false;
    XSDDescription desc = new XSDDescription();
    desc.fContextType = XSDDescription.CONTEXT_PREPARSE;
    desc.setBaseSystemId(source.getBaseSystemId());
    desc.setLiteralSystemId( source.getSystemId());
    // none of the other fields make sense for preparsing
    Map<String, LocationArray> locationPairs = new HashMap<>();
    // Process external schema location properties.
    // We don't call tokenizeSchemaLocationStr here, because we also want
    // to check whether the values are valid URI.
    processExternalHints(fExternalSchemas, fExternalNoNSSchema,
            locationPairs, fErrorReporter);
    SchemaGrammar grammar = loadSchema(desc, source, locationPairs);

    if(grammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, fGrammarBucket.getGrammars());
        // NOTE: we only need to verify full checking in case the schema was not provided via JAXP
        // since full checking already verified for all JAXP schemas
        if(fIsCheckedFully && fJAXPCache.get(grammar) != grammar) {
            XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
        }
    }
    return grammar;
}
 
Example #29
Source File: XMLGrammarPoolImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public void cacheGrammars(String grammarType, Grammar[] grammars) {
    if(!fPoolIsLocked) {
        for (int i = 0; i < grammars.length; i++) {
            if(DEBUG) {
                System.out.println("CACHED GRAMMAR " + (i+1) ) ;
                Grammar temp = grammars[i] ;
                //print(temp.getGrammarDescription());
            }
            putGrammar(grammars[i]);
        }
    }
}
 
Example #30
Source File: XMLSchemaLoader.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 {

    // REVISIT: this method should have a namespace parameter specified by
    // user. In this case we can easily detect if a schema asked to be loaded
    // is already in the local cache.

    reset(fLoaderConfig);
    fSettingsChanged = false;
    XSDDescription desc = new XSDDescription();
    desc.fContextType = XSDDescription.CONTEXT_PREPARSE;
    desc.setBaseSystemId(source.getBaseSystemId());
    desc.setLiteralSystemId( source.getSystemId());
    // none of the other fields make sense for preparsing
    Map locationPairs = new HashMap();
    // Process external schema location properties.
    // We don't call tokenizeSchemaLocationStr here, because we also want
    // to check whether the values are valid URI.
    processExternalHints(fExternalSchemas, fExternalNoNSSchema,
            locationPairs, fErrorReporter);
    SchemaGrammar grammar = loadSchema(desc, source, locationPairs);

    if(grammar != null && fGrammarPool != null) {
        fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA, fGrammarBucket.getGrammars());
        // NOTE: we only need to verify full checking in case the schema was not provided via JAXP
        // since full checking already verified for all JAXP schemas
        if(fIsCheckedFully && fJAXPCache.get(grammar) != grammar) {
            XSConstraints.fullSchemaChecking(fGrammarBucket, fSubGroupHandler, fCMBuilder, fErrorReporter);
        }
    }
    return grammar;
}