jdk.internal.org.xml.sax.InputSource Java Examples

The following examples show how to use jdk.internal.org.xml.sax.InputSource. 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: ParserSAX.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #2
Source File: SAXParser.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #3
Source File: SAXParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #4
Source File: SAXParser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #5
Source File: SAXParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #6
Source File: ParserSAX.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #7
Source File: SAXParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #8
Source File: ParserSAX.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #9
Source File: ParserSAX.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #10
Source File: SAXParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #11
Source File: ParserSAX.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #12
Source File: SAXParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #13
Source File: ParserSAX.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource} as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the InputSource or handler is
 * null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputSource is, DefaultHandler handler)
    throws SAXException, IOException
{
    if ((is == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    //              Set up the handler
    mHandCont = handler;
    mHandDtd = handler;
    mHandErr = handler;
    mHandEnt = handler;
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException | IOException | RuntimeException saxe) {
        throw saxe;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #14
Source File: SAXParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Parse the content given {@link org.xml.sax.InputSource}
 * as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param is The InputSource containing the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the <code>InputSource</code> object
 *   is <code>null</code>.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(InputSource is, DefaultHandler dh)
    throws SAXException, IOException
{
    if (is == null) {
        throw new IllegalArgumentException("InputSource cannot be null");
    }

    XMLReader reader = this.getXMLReader();
    if (dh != null) {
        reader.setContentHandler(dh);
        reader.setEntityResolver(dh);
        reader.setErrorHandler(dh);
        reader.setDTDHandler(dh);
    }
    reader.parse(is);
}
 
Example #15
Source File: SAXParser.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse the content of the file specified as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param f The file containing the XML to parse
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the File object is null.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(File f, DefaultHandler dh)
    throws SAXException, IOException
{
    if (f == null) {
        throw new IllegalArgumentException("File cannot be null");
    }

    //convert file to appropriate URI, f.toURI().toASCIIString()
    //converts the URI to string as per rule specified in
    //RFC 2396,
    InputSource input = new InputSource(f.toURI().toASCIIString());
    this.parse(input, dh);
}
 
Example #16
Source File: SAXParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse the content of the file specified as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param f The file containing the XML to parse
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the File object is null.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(File f, DefaultHandler dh)
    throws SAXException, IOException
{
    if (f == null) {
        throw new IllegalArgumentException("File cannot be null");
    }

    //convert file to appropriate URI, f.toURI().toASCIIString()
    //converts the URI to string as per rule specified in
    //RFC 2396,
    InputSource input = new InputSource(f.toURI().toASCIIString());
    this.parse(input, dh);
}
 
Example #17
Source File: SAXParser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parse the content of the file specified as XML using the
 * specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param f The file containing the XML to parse
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the File object is null.
 * @throws IOException If any IO errors occur.
 * @throws SAXException If any SAX errors occur during processing.
 *
 * @see org.xml.sax.DocumentHandler
 */
public void parse(File f, DefaultHandler dh)
    throws SAXException, IOException
{
    if (f == null) {
        throw new IllegalArgumentException("File cannot be null");
    }

    //convert file to appropriate URI, f.toURI().toASCIIString()
    //converts the URI to string as per rule specified in
    //RFC 2396,
    InputSource input = new InputSource(f.toURI().toASCIIString());
    this.parse(input, dh);
}
 
Example #18
Source File: ParserSAX.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #19
Source File: Parser.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up a new input source on the top of the input stack. Note, the first
 * byte returned by the entity's byte stream has to be the first byte in the
 * entity. However, the parser does not expect the byte order mask in both
 * cases when encoding is provided by the input source.
 *
 * @param is A new input source to set up.
 * @exception IOException If any IO errors occur.
 * @exception Exception is parser specific exception form panic method.
 */
protected void setinp(InputSource is)
        throws Exception {
    Reader reader = null;
    mChIdx = 0;
    mChLen = 0;
    mChars = mInp.chars;
    mInp.src = null;
    if (mPh < PH_DOC_START) {
        mIsSAlone = false;  // default [#2.9]
    }
    mIsSAloneSet = false;
    if (is.getCharacterStream() != null) {
        //          Ignore encoding in the xml text decl.
        reader = is.getCharacterStream();
        xml(reader);
    } else if (is.getByteStream() != null) {
        String expenc;
        if (is.getEncoding() != null) {
            //              Ignore encoding in the xml text decl.
            expenc = is.getEncoding().toUpperCase();
            if (expenc.equals("UTF-16")) {
                reader = bom(is.getByteStream(), 'U');  // UTF-16 [#4.3.3]
            } else {
                reader = enc(expenc, is.getByteStream());
            }
            xml(reader);
        } else {
            //              Get encoding from BOM or the xml text decl.
            reader = bom(is.getByteStream(), ' ');
            if (reader == null) {
                //          Encoding is defined by the xml text decl.
                reader = enc("UTF-8", is.getByteStream());
                expenc = xml(reader);
                if (expenc.startsWith("UTF-16")) {
                    panic(FAULT);  // UTF-16 must have BOM [#4.3.3]
                }
                reader = enc(expenc, is.getByteStream());
            } else {
                //          Encoding is defined by the BOM.
                xml(reader);
            }
        }
    } else {
        //          There is no support for public/system identifiers.
        panic(FAULT);
    }
    mInp.src = reader;
    mInp.pubid = is.getPublicId();
    mInp.sysid = is.getSystemId();
}
 
Example #20
Source File: Parser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resoves a parameter entity.
 *
 * This method resolves a parameter entity references. It is also reports
 * external entities to the application.
 *
 * @param flag The '-' instruct the method to do not set up surrounding
 * spaces [#4.4.8].
 * @exception Exception is parser specific exception form panic method.
 * @exception IOException
 */
@SuppressWarnings("fallthrough")
private void pent(char flag) throws Exception {
    char ch;
    int idx = mBuffIdx + 1;
    Input inp = null;
    String str = null;
    bappend('%');
    if (mPh != PH_DTD) // the DTD internal subset
    {
        return;         // Not Recognized [#4.4.1]
    }               //              Read entity name
    bname(false);
    str = new String(mBuff, idx + 2, mBuffIdx - idx - 1);
    if (getch() != ';') {
        panic(FAULT);
    }
    inp = mPEnt.get(str);
    //              Restore the buffer offset
    mBuffIdx = idx - 1;
    if (inp != null) {
        if (inp.chars == null) {
            //              External parameter entity
            InputSource is = resolveEnt(str, inp.pubid, inp.sysid);
            if (is != null) {
                if (flag != '-') {
                    bappend(' ');  // tail space
                }
                push(new Input(BUFFSIZE_READER));
                // BUG: there is no leading space! [#4.4.8]
                setinp(is);
                mInp.pubid = inp.pubid;
                mInp.sysid = inp.sysid;
            } else {
                //          Unresolved external parameter entity
                skippedEnt("%" + str);
            }
        } else {
            //              Internal parameter entity
            if (flag == '-') {
                //          No surrounding spaces
                inp.chIdx = 1;
            } else {
                //          Insert surrounding spaces
                bappend(' ');  // tail space
                inp.chIdx = 0;
            }
            push(inp);
        }
    } else {
        //          Unknown parameter entity
        skippedEnt("%" + str);
    }
}
 
Example #21
Source File: Parser.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up a new input source on the top of the input stack. Note, the first
 * byte returned by the entity's byte stream has to be the first byte in the
 * entity. However, the parser does not expect the byte order mask in both
 * cases when encoding is provided by the input source.
 *
 * @param is A new input source to set up.
 * @exception IOException If any IO errors occur.
 * @exception Exception is parser specific exception form panic method.
 */
protected void setinp(InputSource is)
        throws Exception {
    Reader reader = null;
    mChIdx = 0;
    mChLen = 0;
    mChars = mInp.chars;
    mInp.src = null;
    if (mPh < PH_DOC_START) {
        mIsSAlone = false;  // default [#2.9]
    }
    mIsSAloneSet = false;
    if (is.getCharacterStream() != null) {
        //          Ignore encoding in the xml text decl.
        reader = is.getCharacterStream();
        xml(reader);
    } else if (is.getByteStream() != null) {
        String expenc;
        if (is.getEncoding() != null) {
            //              Ignore encoding in the xml text decl.
            expenc = is.getEncoding().toUpperCase();
            if (expenc.equals("UTF-16")) {
                reader = bom(is.getByteStream(), 'U');  // UTF-16 [#4.3.3]
            } else {
                reader = enc(expenc, is.getByteStream());
            }
            xml(reader);
        } else {
            //              Get encoding from BOM or the xml text decl.
            reader = bom(is.getByteStream(), ' ');
            if (reader == null) {
                //          Encoding is defined by the xml text decl.
                reader = enc("UTF-8", is.getByteStream());
                expenc = xml(reader);
                if (expenc.startsWith("UTF-16")) {
                    panic(FAULT);  // UTF-16 must have BOM [#4.3.3]
                }
                reader = enc(expenc, is.getByteStream());
            } else {
                //          Encoding is defined by the BOM.
                xml(reader);
            }
        }
    } else {
        //          There is no support for public/system identifiers.
        panic(FAULT);
    }
    mInp.src = reader;
    mInp.pubid = is.getPublicId();
    mInp.sysid = is.getSystemId();
}
 
Example #22
Source File: ParserSAX.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #23
Source File: Parser.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Resoves a parameter entity.
 *
 * This method resolves a parameter entity references. It is also reports
 * external entities to the application.
 *
 * @param flag The '-' instruct the method to do not set up surrounding
 * spaces [#4.4.8].
 * @exception Exception is parser specific exception form panic method.
 * @exception IOException
 */
@SuppressWarnings("fallthrough")
private void pent(char flag) throws Exception {
    char ch;
    int idx = mBuffIdx + 1;
    Input inp = null;
    String str = null;
    bappend('%');
    if (mPh != PH_DTD) // the DTD internal subset
    {
        return;         // Not Recognized [#4.4.1]
    }               //              Read entity name
    bname(false);
    str = new String(mBuff, idx + 2, mBuffIdx - idx - 1);
    if (getch() != ';') {
        panic(FAULT);
    }
    inp = mPEnt.get(str);
    //              Restore the buffer offset
    mBuffIdx = idx - 1;
    if (inp != null) {
        if (inp.chars == null) {
            //              External parameter entity
            InputSource is = resolveEnt(str, inp.pubid, inp.sysid);
            if (is != null) {
                if (flag != '-') {
                    bappend(' ');  // tail space
                }
                push(new Input(BUFFSIZE_READER));
                // BUG: there is no leading space! [#4.4.8]
                setinp(is);
                mInp.pubid = inp.pubid;
                mInp.sysid = inp.sysid;
            } else {
                //          Unresolved external parameter entity
                skippedEnt("%" + str);
            }
        } else {
            //              Internal parameter entity
            if (flag == '-') {
                //          No surrounding spaces
                inp.chIdx = 1;
            } else {
                //          Insert surrounding spaces
                bappend(' ');  // tail space
                inp.chIdx = 0;
            }
            push(inp);
        }
    } else {
        //          Unknown parameter entity
        skippedEnt("%" + str);
    }
}
 
Example #24
Source File: ParserSAX.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #25
Source File: Parser.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resoves a parameter entity.
 *
 * This method resolves a parameter entity references. It is also reports
 * external entities to the application.
 *
 * @param flag The '-' instruct the method to do not set up surrounding
 * spaces [#4.4.8].
 * @exception Exception is parser specific exception form panic method.
 * @exception IOException
 */
@SuppressWarnings("fallthrough")
private void pent(char flag) throws Exception {
    char ch;
    int idx = mBuffIdx + 1;
    Input inp = null;
    String str = null;
    bappend('%');
    if (mPh != PH_DTD) // the DTD internal subset
    {
        return;         // Not Recognized [#4.4.1]
    }               //              Read entity name
    bname(false);
    str = new String(mBuff, idx + 2, mBuffIdx - idx - 1);
    if (getch() != ';') {
        panic(FAULT);
    }
    inp = mPEnt.get(str);
    //              Restore the buffer offset
    mBuffIdx = idx - 1;
    if (inp != null) {
        if (inp.chars == null) {
            //              External parameter entity
            InputSource is = resolveEnt(str, inp.pubid, inp.sysid);
            if (is != null) {
                if (flag != '-') {
                    bappend(' ');  // tail space
                }
                push(new Input(BUFFSIZE_READER));
                // BUG: there is no leading space! [#4.4.8]
                setinp(is);
                mInp.pubid = inp.pubid;
                mInp.sysid = inp.sysid;
            } else {
                //          Unresolved external parameter entity
                skippedEnt("%" + str);
            }
        } else {
            //              Internal parameter entity
            if (flag == '-') {
                //          No surrounding spaces
                inp.chIdx = 1;
            } else {
                //          Insert surrounding spaces
                bappend(' ');  // tail space
                inp.chIdx = 0;
            }
            push(inp);
        }
    } else {
        //          Unknown parameter entity
        skippedEnt("%" + str);
    }
}
 
Example #26
Source File: ParserSAX.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #27
Source File: ParserSAX.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #28
Source File: ParserSAX.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse an XML document.
 *
 * <p>The application can use this method to instruct the XML reader to
 * begin parsing an XML document from any valid input source (a character
 * stream, a byte stream, or a URI).</p>
 *
 * <p>Applications may not invoke this method while a parse is in progress
 * (they should create a new XMLReader instead for each nested XML
 * document). Once a parse is complete, an application may reuse the same
 * XMLReader object, possibly with a different input source.</p>
 *
 * <p>During the parse, the XMLReader will provide information about the XML
 * document through the registered event handlers.</p>
 *
 * <p>This method is synchronous: it will not return until parsing has
 * ended. If a client application wants to terminate parsing early, it
 * should throw an exception.</p>
 *
 * @param is The input source for the top-level of the XML document.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly wrapping
 * another exception.
 * @exception java.io.IOException An IO exception from the parser, possibly
 * from a byte stream or character stream supplied by the application.
 * @see org.xml.sax.InputSource
 * @see #parse(java.lang.String)
 * @see #setEntityResolver
 * @see #setDTDHandler
 * @see #setContentHandler
 * @see #setErrorHandler
 */
public void parse(InputSource is) throws IOException, SAXException {
    if (is == null) {
        throw new IllegalArgumentException("");
    }
    //              Set up the document
    mInp = new Input(BUFFSIZE_READER);
    mPh = PH_BEFORE_DOC;  // before parsing
    try {
        setinp(is);
    } catch (SAXException saxe) {
        throw saxe;
    } catch (IOException ioe) {
        throw ioe;
    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception e) {
        panic(e.toString());
    }
    parse();
}
 
Example #29
Source File: Parser.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up a new input source on the top of the input stack. Note, the first
 * byte returned by the entity's byte stream has to be the first byte in the
 * entity. However, the parser does not expect the byte order mask in both
 * cases when encoding is provided by the input source.
 *
 * @param is A new input source to set up.
 * @exception IOException If any IO errors occur.
 * @exception Exception is parser specific exception form panic method.
 */
protected void setinp(InputSource is)
        throws Exception {
    Reader reader = null;
    mChIdx = 0;
    mChLen = 0;
    mChars = mInp.chars;
    mInp.src = null;
    if (mPh < PH_DOC_START) {
        mIsSAlone = false;  // default [#2.9]
    }
    mIsSAloneSet = false;
    if (is.getCharacterStream() != null) {
        //          Ignore encoding in the xml text decl.
        reader = is.getCharacterStream();
        xml(reader);
    } else if (is.getByteStream() != null) {
        String expenc;
        if (is.getEncoding() != null) {
            //              Ignore encoding in the xml text decl.
            expenc = is.getEncoding().toUpperCase();
            if (expenc.equals("UTF-16")) {
                reader = bom(is.getByteStream(), 'U');  // UTF-16 [#4.3.3]
            } else {
                reader = enc(expenc, is.getByteStream());
            }
            xml(reader);
        } else {
            //              Get encoding from BOM or the xml text decl.
            reader = bom(is.getByteStream(), ' ');
            if (reader == null) {
                //          Encoding is defined by the xml text decl.
                reader = enc("UTF-8", is.getByteStream());
                expenc = xml(reader);
                if (expenc.startsWith("UTF-16")) {
                    panic(FAULT);  // UTF-16 must have BOM [#4.3.3]
                }
                reader = enc(expenc, is.getByteStream());
            } else {
                //          Encoding is defined by the BOM.
                xml(reader);
            }
        }
    } else {
        //          There is no support for public/system identifiers.
        panic(FAULT);
    }
    mInp.src = reader;
    mInp.pubid = is.getPublicId();
    mInp.sysid = is.getSystemId();
}
 
Example #30
Source File: Parser.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sets up a new input source on the top of the input stack. Note, the first
 * byte returned by the entity's byte stream has to be the first byte in the
 * entity. However, the parser does not expect the byte order mask in both
 * cases when encoding is provided by the input source.
 *
 * @param is A new input source to set up.
 * @exception IOException If any IO errors occur.
 * @exception Exception is parser specific exception form panic method.
 */
protected void setinp(InputSource is)
        throws Exception {
    Reader reader = null;
    mChIdx = 0;
    mChLen = 0;
    mChars = mInp.chars;
    mInp.src = null;
    if (mPh < PH_DOC_START) {
        mIsSAlone = false;  // default [#2.9]
    }
    mIsSAloneSet = false;
    if (is.getCharacterStream() != null) {
        //          Ignore encoding in the xml text decl.
        reader = is.getCharacterStream();
        xml(reader);
    } else if (is.getByteStream() != null) {
        String expenc;
        if (is.getEncoding() != null) {
            //              Ignore encoding in the xml text decl.
            expenc = is.getEncoding().toUpperCase();
            if (expenc.equals("UTF-16")) {
                reader = bom(is.getByteStream(), 'U');  // UTF-16 [#4.3.3]
            } else {
                reader = enc(expenc, is.getByteStream());
            }
            xml(reader);
        } else {
            //              Get encoding from BOM or the xml text decl.
            reader = bom(is.getByteStream(), ' ');
            if (reader == null) {
                //          Encoding is defined by the xml text decl.
                reader = enc("UTF-8", is.getByteStream());
                expenc = xml(reader);
                if (expenc.startsWith("UTF-16")) {
                    panic(FAULT);  // UTF-16 must have BOM [#4.3.3]
                }
                reader = enc(expenc, is.getByteStream());
            } else {
                //          Encoding is defined by the BOM.
                xml(reader);
            }
        }
    } else {
        //          There is no support for public/system identifiers.
        panic(FAULT);
    }
    mInp.src = reader;
    mInp.pubid = is.getPublicId();
    mInp.sysid = is.getSystemId();
}