Search in sources :

Example 6 with SAXException

use of org.xml.sax.SAXException in project hadoop by apache.

the class FSEditLogOp method appendXAttrsToXml.

private static void appendXAttrsToXml(ContentHandler contentHandler, List<XAttr> xAttrs) throws SAXException {
    for (XAttr xAttr : xAttrs) {
        contentHandler.startElement("", "", "XATTR", new AttributesImpl());
        XMLUtils.addSaxString(contentHandler, "NAMESPACE", xAttr.getNameSpace().toString());
        XMLUtils.addSaxString(contentHandler, "NAME", xAttr.getName());
        if (xAttr.getValue() != null) {
            try {
                XMLUtils.addSaxString(contentHandler, "VALUE", XAttrCodec.encodeValue(xAttr.getValue(), XAttrCodec.HEX));
            } catch (IOException e) {
                throw new SAXException(e);
            }
        }
        contentHandler.endElement("", "", "XATTR");
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) IOException(java.io.IOException) XAttr(org.apache.hadoop.fs.XAttr) SAXException(org.xml.sax.SAXException)

Example 7 with SAXException

use of org.xml.sax.SAXException in project hadoop by apache.

the class OfflineEditsXmlLoader method loadEdits.

/**
   * Loads edits file, uses visitor to process all elements
   */
@Override
public void loadEdits() throws IOException {
    try {
        XMLReader xr = XMLReaderFactory.createXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        xr.setDTDHandler(null);
        xr.parse(new InputSource(fileReader));
        visitor.close(null);
    } catch (SAXParseException e) {
        System.out.println("XML parsing error: " + "\n" + "Line:    " + e.getLineNumber() + "\n" + "URI:     " + e.getSystemId() + "\n" + "Message: " + e.getMessage());
        visitor.close(e);
        throw new IOException(e.toString());
    } catch (SAXException e) {
        visitor.close(e);
        throw new IOException(e.toString());
    } catch (RuntimeException e) {
        visitor.close(e);
        throw e;
    } finally {
        fileReader.close();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Example 8 with SAXException

use of org.xml.sax.SAXException in project hadoop by apache.

the class XmlEditsVisitor method start.

/**
   * Start visitor (initialization)
   */
@Override
public void start(int version) throws IOException {
    try {
        contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl());
        StringBuilder bld = new StringBuilder();
        bld.append(version);
        addString(bld.toString());
        contentHandler.endElement("", "", "EDITS_VERSION");
    } catch (SAXException e) {
        throw new IOException("SAX error: " + e.getMessage());
    }
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 9 with SAXException

use of org.xml.sax.SAXException in project hadoop by apache.

the class XmlEditsVisitor method close.

/**
   * Finish visitor
   */
@Override
public void close(Throwable error) throws IOException {
    try {
        contentHandler.endElement("", "", "EDITS");
        if (error != null) {
            String msg = error.getMessage();
            XMLUtils.addSaxString(contentHandler, "ERROR", (msg == null) ? "null" : msg);
        }
        contentHandler.endDocument();
    } catch (SAXException e) {
        throw new IOException("SAX error: " + e.getMessage());
    }
    out.close();
}
Also used : IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 10 with SAXException

use of org.xml.sax.SAXException in project tomcat by apache.

the class DefaultServlet method secureXslt.

private Source secureXslt(InputStream is) {
    // Need to filter out any external entities
    Source result = null;
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(secureEntityResolver);
        Document document = builder.parse(is);
        result = new DOMSource(document);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        if (debug > 0) {
            log(e.getMessage(), e);
        }
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
    return result;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) InputSource(org.xml.sax.InputSource) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)1084 IOException (java.io.IOException)653 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)387 Document (org.w3c.dom.Document)258 DocumentBuilder (javax.xml.parsers.DocumentBuilder)213 InputSource (org.xml.sax.InputSource)205 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)158 InputStream (java.io.InputStream)141 Element (org.w3c.dom.Element)115 File (java.io.File)109 NodeList (org.w3c.dom.NodeList)106 SAXParseException (org.xml.sax.SAXParseException)104 Node (org.w3c.dom.Node)91 StringReader (java.io.StringReader)83 TransformerException (javax.xml.transform.TransformerException)82 ByteArrayInputStream (java.io.ByteArrayInputStream)81 SAXParser (javax.xml.parsers.SAXParser)76 ArrayList (java.util.ArrayList)71 FileInputStream (java.io.FileInputStream)64 XMLReader (org.xml.sax.XMLReader)56