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

The following examples show how to use jdk.internal.org.xml.sax.SAXException. 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: PropertiesDefaultHandler.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public void load(Properties props, InputStream in)
    throws IOException, InvalidPropertiesFormatException, UnsupportedEncodingException
{
    this.properties = props;

    try {
        SAXParser parser = new SAXParserImpl();
        parser.parse(in, this);
    } catch (SAXException saxe) {
        throw new InvalidPropertiesFormatException(saxe);
    }

    /**
     * String xmlVersion = propertiesElement.getAttribute("version"); if
     * (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0) throw new
     * InvalidPropertiesFormatException( "Exported Properties file format
     * version " + xmlVersion + " is not supported. This java installation
     * can read" + " versions " + EXTERNAL_XML_VERSION + " or older. You" +
     * " may need to install a newer version of JDK.");
     */
}
 
Example #2
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 #3
Source File: JFCParserHandler.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    switch (qName.toLowerCase()) {
    case ELEMENT_CONFIGURATION:
        String version = attributes.getValue(ATTRIBUTE_VERSION);
        if (version == null || !version.startsWith("2.")) {
           throw new SAXException("This version of Flight Recorder can only read JFC file format version 2.x");
        }
        label = attributes.getValue(ATTRIBUTE_LABEL);
        description = getOptional(attributes, ATTRIBUTE_DESCRIPTION, "");
        provider = getOptional(attributes, ATTRIBUTE_PROVIDER, "");
        break;
    case ELEMENT_EVENT_TYPE:
        currentEventPath = attributes.getValue(ATTRIBUTE_NAME);
        break;
    case ELEMENT_SETTING:
        currentSettingsName = attributes.getValue(ATTRIBUTE_NAME);
        break;
    }
    currentCharacters = null;
}
 
Example #4
Source File: PropertiesDefaultHandler.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element: " + qName + " is invalid, must match  \"(comment?,entry*)\".", null));
    }

    if (validEntry) {
        properties.setProperty(key, buf.toString());
        buf.delete(0, buf.length());
        validEntry = false;
    }
}
 
Example #5
Source File: ParserSAX.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reports white space characters and empties the parser's buffer. This
 * method is called only if parser is going to return control to the main
 * loop. This means that this method may use parser buffer to report white
 * space without copeing characters to temporary buffer.
 */
protected void bflash_ws() throws SAXException {
    if (mBuffIdx >= 0) {
        // BUG: With additional info from DTD and xml:space attr [#2.10]
        // the following call can be supported:
        // mHandCont.ignorableWhitespace(mBuff, 0, (mBuffIdx + 1));

        //          Textual data has been read
        mHandCont.characters(mBuff, 0, (mBuffIdx + 1));
        mBuffIdx = -1;
    }
}
 
Example #6
Source File: PropertiesDefaultHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #7
Source File: SAXParser.java    From dragonwell8_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 #8
Source File: ParserSAX.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reports white space characters and empties the parser's buffer. This
 * method is called only if parser is going to return control to the main
 * loop. This means that this method may use parser buffer to report white
 * space without copying characters to temporary buffer.
 */
protected void bflash_ws() throws SAXException {
    if (mBuffIdx >= 0) {
        // BUG: With additional info from DTD and xml:space attr [#2.10]
        // the following call can be supported:
        // mHandCont.ignorableWhitespace(mBuff, 0, (mBuffIdx + 1));

        //          Textual data has been read
        mHandCont.characters(mBuff, 0, (mBuffIdx + 1));
        mBuffIdx = -1;
    }
}
 
Example #9
Source File: ParserSAX.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reports white space characters and empties the parser's buffer. This
 * method is called only if parser is going to return control to the main
 * loop. This means that this method may use parser buffer to report white
 * space without copeing characters to temporary buffer.
 */
protected void bflash_ws() throws SAXException {
    if (mBuffIdx >= 0) {
        // BUG: With additional info from DTD and xml:space attr [#2.10]
        // the following call can be supported:
        // mHandCont.ignorableWhitespace(mBuff, 0, (mBuffIdx + 1));

        //          Textual data has been read
        mHandCont.characters(mBuff, 0, (mBuffIdx + 1));
        mBuffIdx = -1;
    }
}
 
Example #10
Source File: PropertiesDefaultHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
    throws SAXException
{
    if (rootElem < 2) {
        rootElem++;
    }

    if (rootElm == null) {
        fatalError(new SAXParseException("An XML properties document must contain"
                + " the DOCTYPE declaration as defined by java.util.Properties.", null));
    }

    if (rootElem == 1 && !rootElm.equals(qName)) {
        fatalError(new SAXParseException("Document root element \"" + qName
                + "\", must match DOCTYPE root \"" + rootElm + "\"", null));
    }
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element type \"" + qName + "\" must be declared.", null));
    }
    if (qName.equals(ELEMENT_ENTRY)) {
        validEntry = true;
        key = attributes.getValue(ATTR_KEY);
        if (key == null) {
            fatalError(new SAXParseException("Attribute \"key\" is required and must be specified for element type \"entry\"", null));
        }
    } else if (qName.equals(ALLOWED_COMMENT)) {
        if (sawComment) {
            fatalError(new SAXParseException("Only one comment element may be allowed. "
                    + "The content of element type \"properties\" must match \"(comment?,entry*)\"", null));
        }
        sawComment = true;
    }
}
 
Example #11
Source File: JFCParserHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
    if (currentCharacters == null) {
        currentCharacters = new StringBuilder(length);
    }
    currentCharacters.append(ch, start, length);
}
 
Example #12
Source File: PropertiesDefaultHandler.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (!ALLOWED_ELEMENTS.contains(qName)) {
        fatalError(new SAXParseException("Element: " + qName + " is invalid, must match  \"(comment?,entry*)\".", null));
    }

    if (validEntry) {
        properties.setProperty(key, buf.toString());
        buf.delete(0, buf.length());
        validEntry = false;
    }
}
 
Example #13
Source File: PropertiesDefaultHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void fatalError(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #14
Source File: JFCParser.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void parseXML(String content, JFCParserHandler ch) throws SAXException, IOException {
    CharArrayReader r = new CharArrayReader(content.toCharArray());
    SAXParser parser = new SAXParserImpl();
    parser.parse(new InputSource(r), ch);
}
 
Example #15
Source File: ParserSAX.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Notifies the handler about fatal parsing error.
 *
 * @param msg The problem description message.
 */
protected void panic(String msg) throws SAXException {
    SAXParseException spe = new SAXParseException(msg, this);
    mHandErr.fatalError(spe);
    throw spe;  // [#1.2] fatal error definition
}
 
Example #16
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 #17
Source File: PropertiesDefaultHandler.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void notationDecl(String name, String publicId, String systemId) throws SAXException {
    rootElm = name;
}
 
Example #18
Source File: PropertiesDefaultHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void warning(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #19
Source File: PropertiesDefaultHandler.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void notationDecl(String name, String publicId, String systemId) throws SAXException {
    rootElm = name;
}
 
Example #20
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 #21
Source File: ParserSAX.java    From dragonwell8_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 #22
Source File: PropertiesDefaultHandler.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void error(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #23
Source File: PropertiesDefaultHandler.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void error(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #24
Source File: PropertiesDefaultHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void fatalError(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #25
Source File: ParserSAX.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Notifies the handler about fatal parsing error.
 *
 * @param msg The problem description message.
 */
protected void panic(String msg) throws SAXException {
    SAXParseException spe = new SAXParseException(msg, this);
    mHandErr.fatalError(spe);
    throw spe;  // [#1.2] fatal error definition
}
 
Example #26
Source File: PropertiesDefaultHandler.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
    if (validEntry) {
        buf.append(ch, start, length);
    }
}
 
Example #27
Source File: PropertiesDefaultHandler.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void error(SAXParseException x) throws SAXException {
    throw x;
}
 
Example #28
Source File: DefaultHandler.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Receive notification of an unparsed entity declaration.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to keep track of the unparsed entities
 * declared in a document.</p>
 *
 * @param name The entity name.
 * @param publicId The entity public identifier, or null if not
 *                 available.
 * @param systemId The entity system identifier.
 * @param notationName The name of the associated notation.
 * @exception org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.DTDHandler#unparsedEntityDecl
 */
public void unparsedEntityDecl (String name, String publicId,
                                String systemId, String notationName)
    throws SAXException
{
    // no op
}
 
Example #29
Source File: SAXParser.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Parse the content described by the giving Uniform Resource
 * Identifier (URI) as XML using the specified
 * {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param uri The location of the content to be parsed.
 * @param dh The SAX DefaultHandler to use.
 *
 * @throws IllegalArgumentException If the uri 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(String uri, DefaultHandler dh)
    throws SAXException, IOException
{
    if (uri == null) {
        throw new IllegalArgumentException("uri cannot be null");
    }

    InputSource input = new InputSource(uri);
    this.parse(input, dh);
}
 
Example #30
Source File: ParserSAX.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Parse the content of the given {@link java.io.InputStream} instance as
 * XML using the specified {@link org.xml.sax.helpers.DefaultHandler}.
 *
 * @param src InputStream containing the content to be parsed.
 * @param handler The SAX DefaultHandler to use.
 * @exception IOException If any IO errors occur.
 * @exception IllegalArgumentException If the given InputStream or handler
 * is null.
 * @exception SAXException If the underlying parser throws a SAXException
 * while parsing.
 * @see org.xml.sax.helpers.DefaultHandler
 */
public void parse(InputStream src, DefaultHandler handler)
        throws SAXException, IOException {
    if ((src == null) || (handler == null)) {
        throw new IllegalArgumentException("");
    }
    parse(new InputSource(src), handler);
}