com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource. 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: XMLDTDScannerImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets the input source.
 *
 * @param inputSource The input source or null.
 *
 * @throws IOException Thrown on i/o error.
 */
public void setInputSource(XMLInputSource inputSource) throws IOException {
    if (inputSource == null) {
        // no system id was available
        if (fDTDHandler != null) {
            fDTDHandler.startDTD(null, null);
            fDTDHandler.endDTD(null);
        }
        if (nonValidatingMode){
            nvGrammarInfo.startDTD(null,null);
            nvGrammarInfo.endDTD(null);
        }
        return;
    }
    fEntityManager.setEntityHandler(this);
    fEntityManager.startDTDEntity(inputSource);
}
 
Example #2
Source File: XMLSchemaLoader.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private static XMLInputSource saxToXMLInputSource(InputSource sis) {
    String publicId = sis.getPublicId();
    String systemId = sis.getSystemId();

    Reader charStream = sis.getCharacterStream();
    if (charStream != null) {
        return new XMLInputSource(publicId, systemId, null, charStream,
                null);
    }

    InputStream byteStream = sis.getByteStream();
    if (byteStream != null) {
        return new XMLInputSource(publicId, systemId, null, byteStream,
                sis.getEncoding());
    }

    return new XMLInputSource(publicId, systemId, null, false);
}
 
Example #3
Source File: XSDHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void validateAnnotations(ArrayList annotationInfo) {
    if (fAnnotationValidator == null) {
        createAnnotationValidator();
    }
    final int size = annotationInfo.size();
    final XMLInputSource src = new XMLInputSource(null, null, null);
    fGrammarBucketAdapter.refreshGrammars(fGrammarBucket);
    for (int i = 0; i < size; i += 2) {
        src.setSystemId((String) annotationInfo.get(i));
        XSAnnotationInfo annotation = (XSAnnotationInfo) annotationInfo.get(i+1);
        while (annotation != null) {
            src.setCharacterStream(new StringReader(annotation.fAnnotation));
            try {
                fAnnotationValidator.parse(src);
            }
            catch (IOException exc) {}
            annotation = annotation.next;
        }
    }
}
 
Example #4
Source File: XMLGrammarPreparser.java    From hottub 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 = 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 #5
Source File: XSDHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Error handling code shared between the various getSchemaDocument() methods.
 */
private Element getSchemaDocument1(boolean mustResolve, boolean hasInput,
        XMLInputSource schemaSource, Element referElement, IOException ioe) {
    // either an error occured (exception), or empty input source was
    // returned, we need to report an error or a warning
    if (mustResolve) {
        if (hasInput) {
            reportSchemaError("schema_reference.4",
                    new Object[]{schemaSource.getSystemId()},
                    referElement, ioe);
        }
        else {
            reportSchemaError("schema_reference.4",
                    new Object[]{schemaSource == null ? "" : schemaSource.getSystemId()},
                    referElement, ioe);
        }
    }
    else if (hasInput) {
        reportSchemaWarning("schema_reference.4",
                new Object[]{schemaSource.getSystemId()},
                referElement, ioe);
    }

    fLastSchemaWasDuplicate = false;
    return null;
}
 
Example #6
Source File: XSDHandler.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private XMLInputSource resolveSchemaSource(XSDDescription desc, boolean mustResolve,
        Element referElement, boolean usePairs) {

    XMLInputSource schemaSource = null;
    try {
        Map pairs = usePairs ? fLocationPairs : EMPTY_TABLE;
        schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityResolver);
    }
    catch (IOException ex) {
        if (mustResolve) {
            reportSchemaError("schema_reference.4",
                    new Object[]{desc.getLocationHints()[0]},
                    referElement);
        }
        else {
            reportSchemaWarning("schema_reference.4",
                    new Object[]{desc.getLocationHints()[0]},
                    referElement);
        }
    }

    return schemaSource;
}
 
Example #7
Source File: XMLGrammarPreparser.java    From openjdk-jdk9 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 = 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 #8
Source File: XMLSchemaLoader.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
private static XMLInputSource saxToXMLInputSource(InputSource sis) {
    String publicId = sis.getPublicId();
    String systemId = sis.getSystemId();

    Reader charStream = sis.getCharacterStream();
    if (charStream != null) {
        return new XMLInputSource(publicId, systemId, null, charStream,
                null);
    }

    InputStream byteStream = sis.getByteStream();
    if (byteStream != null) {
        return new XMLInputSource(publicId, systemId, null, byteStream,
                sis.getEncoding());
    }

    return new XMLInputSource(publicId, systemId, null);
}
 
Example #9
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 #10
Source File: XMLGrammarPreparser.java    From jdk1.8-source-analysis with Apache License 2.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 = 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 #11
Source File: XMLDocumentScannerImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
protected void resolveExternalSubsetAndRead()
throws IOException, XNIException {

    fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);
    fDTDDescription.setRootName(fElementQName.rawname);
    XMLInputSource src = fExternalSubsetResolver.getExternalSubset(fDTDDescription);

    if (src != null) {
        fDoctypeName = fElementQName.rawname;
        fDoctypePublicId = src.getPublicId();
        fDoctypeSystemId = src.getSystemId();
        // call document handler
        if (fDocumentHandler != null) {
            // This inserts a doctypeDecl event into the stream though no
            // DOCTYPE existed in the instance document.
            fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);
        }
        try {
            fDTDScanner.setInputSource(src);
            while (fDTDScanner.scanDTDExternalSubset(true));
        } finally {
            fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);
        }
    }
}
 
Example #12
Source File: XMLDTDLoader.java    From hottub 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 #13
Source File: XMLStreamReaderImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * @param inputStream
 * @param encoding
 * @param props
 * @throws XMLStreamException
 */
public XMLStreamReaderImpl(InputStream inputStream, String encoding, PropertyManager props ) throws  XMLStreamException {
    init(props);
    //publicId, systemid, baseSystemId, inputStream, enocding
    XMLInputSource inputSource = new XMLInputSource(null,null,null, new BufferedInputStream(inputStream),encoding );
    //pass the input source to document scanner impl.
    setInputSource(inputSource);
}
 
Example #14
Source File: XSLoaderImpl.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an XML Schema document from a location identified by a URI
 * reference. If the URI contains a fragment identifier, the behavior is
 * not defined by this specification.
 * @param uri The location of the XML Schema document to be read.
 * @return An XSModel representing this schema.
 */
public XSModel loadURI(String uri) {
    try {
        fGrammarPool.clear();
        return ((XSGrammar) fSchemaLoader.loadGrammar(new XMLInputSource(null, uri, null))).toXSModel();
    }
    catch (Exception e){
        fSchemaLoader.reportDOMFatalError(e);
        return null;
    }
}
 
Example #15
Source File: XSDHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * resolveSchema method is responsible for resolving location of the schema (using XMLEntityResolver),
 * and if it was succefully resolved getting the schema Document.
 * @param desc
 * @param mustResolve
 * @param referElement
 * @return A schema Element or null.
 */
private Element resolveSchema(XSDDescription desc, boolean mustResolve,
                              Element referElement, boolean usePairs) {
    XMLInputSource schemaSource = null;
    try {
        Map<String, XMLSchemaLoader.LocationArray> pairs = usePairs ? fLocationPairs : Collections.emptyMap();
        schemaSource = XMLSchemaLoader.resolveDocument(desc, pairs, fEntityManager);
    }
    catch (IOException ex) {
        if (mustResolve) {
            reportSchemaError("schema_reference.4",
                    new Object[]{desc.getLocationHints()[0]},
                    referElement);
        }
        else {
            reportSchemaWarning("schema_reference.4",
                    new Object[]{desc.getLocationHints()[0]},
                    referElement);
        }
    }
    if (schemaSource instanceof DOMInputSource) {
        return getSchemaDocument(desc.getTargetNamespace(), (DOMInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
    } // DOMInputSource
    else if (schemaSource instanceof SAXInputSource) {
        return getSchemaDocument(desc.getTargetNamespace(), (SAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
    } // SAXInputSource
    else if (schemaSource instanceof StAXInputSource) {
        return getSchemaDocument(desc.getTargetNamespace(), (StAXInputSource) schemaSource, mustResolve, desc.getContextType(), referElement);
    } // StAXInputSource
    else if (schemaSource instanceof XSInputSource) {
        return getSchemaDocument((XSInputSource) schemaSource, desc);
    } // XSInputSource
    return getSchemaDocument(desc.getTargetNamespace(), schemaSource, mustResolve, desc.getContextType(), referElement);
}
 
Example #16
Source File: XMLSchemaLoader.java    From jdk1.8-source-analysis with Apache License 2.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 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 #17
Source File: XMLSchemaLoader.java    From hottub 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;
}
 
Example #18
Source File: XMLSchemaLoader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public XSModel loadURI(String uri) {
    try {
        Grammar g = loadGrammar(new XMLInputSource(null, uri, null));
        return ((XSGrammar)g).toXSModel();
    }
    catch (Exception e){
        reportDOMFatalError(e);
        return null;
    }
}
 
Example #19
Source File: XMLStreamReaderImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param reader
 * @param props
 * @throws XMLStreamException
 */
public XMLStreamReaderImpl(Reader reader, PropertyManager props) throws  XMLStreamException {
    init(props);
    //publicId, systemid, baseSystemId, inputStream, enocding
    //xxx: Using buffered reader
    XMLInputSource inputSource = new XMLInputSource(null,null,null,new BufferedReader(reader),null);
    //pass the input source to document scanner impl.
    setInputSource(inputSource);
}
 
Example #20
Source File: XMLDocumentScannerImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the input source.
 *
 * @param inputSource The input source.
 *
 * @throws IOException Thrown on i/o error.
 */
public void setInputSource(XMLInputSource inputSource) throws IOException {
    fEntityManager.setEntityHandler(this);
    //this starts a new entity and sets the current entity to the document entity.
    fEntityManager.startDocumentEntity(inputSource);
    // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
    setScannerState(XMLEvent.START_DOCUMENT);
}
 
Example #21
Source File: XMLDocumentScannerImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Sets the input source.
 *
 * @param inputSource The input source.
 *
 * @throws IOException Thrown on i/o error.
 */
public void setInputSource(XMLInputSource inputSource) throws IOException {
    fEntityManager.setEntityHandler(this);
    //this starts a new entity and sets the current entity to the document entity.
    fEntityManager.startDocumentEntity(inputSource);
    // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
    setScannerState(XMLEvent.START_DOCUMENT);
}
 
Example #22
Source File: Util.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
Example #23
Source File: XMLGrammarCachingConfiguration.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
SchemaGrammar parseXMLSchema(XMLInputSource is)
            throws IOException {
    XMLEntityResolver resolver = getEntityResolver();
    if(resolver != null) {
        fSchemaLoader.setEntityResolver(resolver);
    }
    if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) {
        fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, new XSMessageFormatter());
    }
    fSchemaLoader.setProperty(ERROR_REPORTER, fErrorReporter);

    String propPrefix = Constants.XERCES_PROPERTY_PREFIX;
    String propName = propPrefix + Constants.SCHEMA_LOCATION;
    fSchemaLoader.setProperty(propName, getProperty(propName));
    propName = propPrefix + Constants.SCHEMA_NONS_LOCATION;
    fSchemaLoader.setProperty(propName, getProperty(propName));
    propName = Constants.JAXP_PROPERTY_PREFIX+Constants.SCHEMA_SOURCE;
    fSchemaLoader.setProperty(propName, getProperty(propName));
    fSchemaLoader.setFeature(SCHEMA_FULL_CHECKING, getFeature(SCHEMA_FULL_CHECKING));

    // 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 XSDHandler
    SchemaGrammar grammar = (SchemaGrammar)fSchemaLoader.loadGrammar(is);
    // by default, hand it off to the grammar pool
    if (grammar != null) {
        fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_SCHEMA,
                                  new Grammar[]{grammar});
    }

    return grammar;

}
 
Example #24
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 #25
Source File: XSLoaderImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse an XML Schema document from a location identified by a URI
 * reference. If the URI contains a fragment identifier, the behavior is
 * not defined by this specification.
 * @param uri The location of the XML Schema document to be read.
 * @return An XSModel representing this schema.
 */
public XSModel loadURI(String uri) {
    try {
        fGrammarPool.clear();
        return ((XSGrammar) fSchemaLoader.loadGrammar(new XMLInputSource(null, uri, null))).toXSModel();
    }
    catch (Exception e){
        fSchemaLoader.reportDOMFatalError(e);
        return null;
    }
}
 
Example #26
Source File: XMLSchemaLoader.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 {

    // 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;
}
 
Example #27
Source File: XSLoaderImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses the content of XML Schema documents specified as the list of URI
 * references. If the URI contains a fragment identifier, the behavior
 * is not defined by this specification.
 * @param uriList The list of URI locations.
 * @return An XSModel representing the schema documents.
 */
public XSModel loadURIList(StringList uriList) {
    int length = uriList.getLength();
    try {
        fGrammarPool.clear();
        for (int i = 0; i < length; ++i) {
            fSchemaLoader.loadGrammar(new XMLInputSource(null, uriList.item(i), null, false));
        }
        return fGrammarPool.toXSModel();
    }
    catch (Exception e) {
        fSchemaLoader.reportDOMFatalError(e);
        return null;
    }
}
 
Example #28
Source File: XMLDocumentScannerImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the input source.
 *
 * @param inputSource The input source.
 *
 * @throws IOException Thrown on i/o error.
 */
public void setInputSource(XMLInputSource inputSource) throws IOException {
    fEntityManager.setEntityHandler(this);
    //this starts a new entity and sets the current entity to the document entity.
    fEntityManager.startDocumentEntity(inputSource);
    // fDocumentSystemId = fEntityManager.expandSystemId(inputSource.getSystemId());
    setScannerState(XMLEvent.START_DOCUMENT);
}
 
Example #29
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 #30
Source File: XMLSchemaLoader.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
public XSModel loadURIList(StringList uriList) {
    int length = uriList.getLength();
    SchemaGrammar[] gs = new SchemaGrammar[length];
    for (int i = 0; i < length; i++) {
        try {
            gs[i] =
                (SchemaGrammar) loadGrammar(new XMLInputSource(null, uriList.item(i), null));
        } catch (Exception e) {
            reportDOMFatalError(e);
            return null;
        }
    }
    return new XSModelImpl(gs);
}