Search in sources :

Example 36 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project OpenAM by OpenRock.

the class LogMessageProviderBase method getXMLDoc.

private Document getXMLDoc() throws IOException {
    Document xmlDoc = null;
    try {
        DocumentBuilder builder = XMLUtils.getSafeDocumentBuilder(true);
        builder.setErrorHandler(new ValidationErrorHandler());
        InputStream is = getClass().getClassLoader().getResourceAsStream(xmlDefinitionFilename);
        if (is != null) {
            xmlDoc = builder.parse(is);
        } else {
            throw new IOException(xmlDefinitionFilename + " cannot be found.");
        }
    } catch (SAXParseException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    } catch (SAXException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    } catch (ParserConfigurationException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    }
    return xmlDoc;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 37 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project OpenAM by OpenRock.

the class ValidationErrorHandler method getXMLDocument.

public static Document getXMLDocument(InputStream in) throws Exception {
    try {
        DocumentBuilder builder = getSafeDocumentBuilder(validating);
        Document doc = builder.parse(in);
        return doc;
    } catch (SAXParseException pe) {
        String msg = "\n" + pe.getMessage() + "\n";
        Object[] params = { new Integer(pe.getLineNumber()) };
        throw new Exception(msg + "XMLUtils.parser_error" + params);
    } catch (SAXException sax) {
        Object[] params = { sax.getMessage() };
        throw new Exception("XMLUtils.exception_message" + params);
    } catch (ParserConfigurationException pc) {
        Object[] params = { pc.getMessage() };
        throw new Exception("XMLUtils.invalid_xml_document" + params);
    } catch (IOException ioe) {
        Object[] params = { ioe.getMessage() };
        throw new Exception("XMLUtils.invalid_input_stream" + params);
    }
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SAXException(org.xml.sax.SAXException)

Example 38 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project pcgen by PCGen.

the class ReadXML method readxmlFile.

/**
	 * Reads through the file and parses the XML.
	 * @param table the file that is the table.
	 */
private void readxmlFile(File table) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Logging.debugPrint("readxmlFile called.");
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        /* The document used for XML parsing. */
        final Document document = db.parse(table);
        tableName = document.getElementsByTagName("lookuptable").item(0).getAttributes().getNamedItem("name").getNodeValue();
        /* The rows of the table. */
        final int rows = document.getElementsByTagName("row").getLength();
        int items = document.getElementsByTagName("item").getLength();
        /* The columns of a tabke. */
        final int cols = items / rows;
        vt.setName(table.getPath());
        int pos = 0;
        for (int x = 0; x < rows; x++) {
            Collection<String> row = new ArrayList<>();
            for (int y = 0; y < cols; y++) {
                row.add(document.getElementsByTagName("item").item(pos).getChildNodes().item(0).getNodeValue());
                pos++;
            }
            vt.add(row);
        }
    } catch (ParserConfigurationException | IllegalArgumentException | IOException | SAXException e) {
        Logging.errorPrint(e.getLocalizedMessage());
        Logging.errorPrint("Could not parse xml file " + table.getPath());
        Logging.errorPrint("IO", e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 39 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project android_frameworks_base by ResurrectionRemix.

the class OMAParser method parse.

public MOTree parse(String text, String urn) throws IOException, SAXException {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(new StringReader(text)), this);
        return new MOTree(mRoot, urn);
    } catch (ParserConfigurationException pce) {
        throw new SAXException(pce);
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 40 with ParserConfigurationException

use of javax.xml.parsers.ParserConfigurationException in project OpenAM by OpenRock.

the class XMLResourceExceptionHandler method asXMLDOM.

/**
     * Convert a Map to XML DOM. The root node is an {@code error} element. Collections are
     * represented as child {@code entry} elements.
     * @param map The map to convert.
     * @return The DOM document.
     */
public static Document asXMLDOM(Map<String, Object> map) {
    try {
        Document document = XMLUtils.newDocument();
        Element root = write(document, "error", map);
        document.appendChild(root);
        return document;
    } catch (ParserConfigurationException e1) {
        throw new IllegalStateException("Cannot construct DOM Document", e1);
    }
}
Also used : Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Aggregations

ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1435 SAXException (org.xml.sax.SAXException)1039 IOException (java.io.IOException)951 Document (org.w3c.dom.Document)751 DocumentBuilder (javax.xml.parsers.DocumentBuilder)687 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)622 Element (org.w3c.dom.Element)389 InputSource (org.xml.sax.InputSource)260 NodeList (org.w3c.dom.NodeList)248 Node (org.w3c.dom.Node)225 SAXParser (javax.xml.parsers.SAXParser)185 File (java.io.File)171 InputStream (java.io.InputStream)170 TransformerException (javax.xml.transform.TransformerException)167 SAXParserFactory (javax.xml.parsers.SAXParserFactory)144 ByteArrayInputStream (java.io.ByteArrayInputStream)141 StringReader (java.io.StringReader)127 ArrayList (java.util.ArrayList)122 DOMSource (javax.xml.transform.dom.DOMSource)114 StreamResult (javax.xml.transform.stream.StreamResult)98