Search in sources :

Example 81 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project languagetool by languagetool-org.

the class AfterTheDeadlineChecker method getDocument.

private Document getDocument(String xml) {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource inputSource = new InputSource(new StringReader(xml));
        return builder.parse(inputSource);
    } catch (Exception e) {
        throw new RuntimeException("Could not parse XML: " + xml);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException)

Example 82 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project jop by jop-devel.

the class XmlBuilder method createDom.

/**
	 * Create a DOM object.
	 * (guideline: http://totheriver.com/learn/xml/xmltutorial.html)
	 * 
	 * @return An XML Document (DOM)
	 * @throws XmlSerializationException 
	 */
public static Document createDom() throws XmlSerializationException {
    Document dom;
    //get an instance of factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        //get an instance of builder
        DocumentBuilder db = dbf.newDocumentBuilder();
        //create an instance of DOM
        dom = db.newDocument();
    } catch (ParserConfigurationException pce) {
        throw new XmlSerializationException("Error while trying to instantiate DocumentBuilder", pce);
    }
    return dom;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 83 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project head by mifos.

the class XMLParser method parser.

public ColumnPropertyMapping parser() throws SystemException {
    Document document = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream("org/mifos/framework/util/resources/audit/ColumnMapping.xml"));
        getColumnPropertyMapping(document);
    } catch (ParserConfigurationException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } catch (SAXParseException e) {
        throw new SystemException(e);
    } catch (SAXException e) {
        throw new SystemException(e);
    }
    return columnPropertyMapping;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) SystemException(org.mifos.framework.exceptions.SystemException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 84 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project head by mifos.

the class TableTagParser method parser.

public Table parser(String filename) throws TableTagParseException {
    Table table = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "tabletag.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsURIString(filename));
        /*
             * NodeList tableNodeList =
             * document.getElementsByTagName(TableTagConstants.TABLE); table =
             * new Table[tableNodeList.getLength()];
             *
             * for (int i = 0; i < table.length; i++) { table[i] = new Table();
             * table[i].setRow(createRow(tableNodeList.item(i))); }
             */
        Node tableNode = document.getFirstChild();
        table = new Table();
        table.setPath(createPath(tableNode));
        table.setPageRequirements(createPageRequirements(tableNode));
        table.setRow(createRow(tableNode));
    } catch (Exception e) {
        throw new TableTagParseException(e);
    }
    return table;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) TableTagParseException(org.mifos.framework.exceptions.TableTagParseException)

Example 85 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project head by mifos.

the class TypeParser method parser.

public Files parser(String filename) throws TableTagTypeParserException {
    Files file = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "type.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
        Node fileNode = document.getFirstChild();
        file = new Files();
        file.setFileName(createFileName(fileNode));
    } catch (ParserConfigurationException pce) {
        throw new TableTagTypeParserException(pce);
    } catch (IOException ioe) {
        throw new TableTagTypeParserException(ioe);
    } catch (SAXParseException saxpe) {
        throw new TableTagTypeParserException(saxpe);
    } catch (SAXException saxe) {
        throw new TableTagTypeParserException(saxe);
    } catch (MifosRuntimeException saxe) {
        throw new TableTagTypeParserException(saxe);
    }
    return file;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) Node(org.w3c.dom.Node) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) TableTagTypeParserException(org.mifos.framework.exceptions.TableTagTypeParserException) SAXException(org.xml.sax.SAXException) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Aggregations

DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)759 DocumentBuilder (javax.xml.parsers.DocumentBuilder)622 Document (org.w3c.dom.Document)526 Element (org.w3c.dom.Element)244 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)232 NodeList (org.w3c.dom.NodeList)209 IOException (java.io.IOException)197 InputSource (org.xml.sax.InputSource)193 SAXException (org.xml.sax.SAXException)173 Node (org.w3c.dom.Node)145 StringReader (java.io.StringReader)142 Test (org.junit.Test)117 File (java.io.File)86 DOMSource (javax.xml.transform.dom.DOMSource)77 ByteArrayInputStream (java.io.ByteArrayInputStream)72 InputStream (java.io.InputStream)63 StreamResult (javax.xml.transform.stream.StreamResult)50 ArrayList (java.util.ArrayList)47 SAXParseException (org.xml.sax.SAXParseException)46 Transformer (javax.xml.transform.Transformer)44