Search in sources :

Example 96 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project openhab1-addons by openhab.

the class IhcProjectFile method parseProject.

static HashMap<Integer, ArrayList<IhcEnumValue>> parseProject(String filePath, String dumpResourcesToFile) throws IhcExecption {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new File(filePath));
        return parseProject(doc, dumpResourcesToFile);
    } catch (ParserConfigurationException e) {
        throw new IhcExecption(e);
    } catch (SAXException e) {
        throw new IhcExecption(e);
    } catch (IOException e) {
        throw new IhcExecption(e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) File(java.io.File) SAXException(org.xml.sax.SAXException)

Example 97 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project openhab1-addons by openhab.

the class IhcClient method LoadProjectFileFromController.

private Document LoadProjectFileFromController() throws IhcExecption {
    try {
        WSProjectInfo projectInfo = getProjectInfo();
        int numberOfSegments = controllerService.getProjectNumberOfSegments();
        int segmentationSize = controllerService.getProjectSegmentationSize();
        logger.debug("Number of segments: {}", numberOfSegments);
        logger.debug("Segmentation size: {}", segmentationSize);
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        for (int i = 0; i < numberOfSegments; i++) {
            logger.debug("Downloading segment {}", i);
            WSFile data = controllerService.getProjectSegment(i, projectInfo.getProjectMajorRevision(), projectInfo.getProjectMinorRevision());
            byteStream.write(data.getData());
        }
        logger.debug("File size before base64 encoding: {} bytes", byteStream.size());
        byte[] decodedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(byteStream.toString());
        logger.debug("File size after base64 encoding: {} bytes", decodedBytes.length);
        GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
        InputStreamReader in = new InputStreamReader(gzis, "ISO-8859-1");
        InputSource reader = new InputSource(in);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        return db.parse(reader);
    } catch (Exception e) {
        throw new IhcExecption(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStreamReader(java.io.InputStreamReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SocketTimeoutException(java.net.SocketTimeoutException) WSFile(org.openhab.binding.ihc.ws.datatypes.WSFile) GZIPInputStream(java.util.zip.GZIPInputStream) WSProjectInfo(org.openhab.binding.ihc.ws.datatypes.WSProjectInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 98 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project openhab1-addons by openhab.

the class DeviceTypeLoader method loadDeviceTypesXML.

/**
     * Reads the device types from input stream and stores them in memory for
     * later access.
     * 
     * @param is the input stream from which to read
     */
public void loadDeviceTypesXML(InputStream in) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(in);
    doc.getDocumentElement().normalize();
    Node root = doc.getDocumentElement();
    NodeList nodes = root.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals("device")) {
            processDevice((Element) node);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 99 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project orientdb by orientechnologies.

the class OXmlExtractor method extract.

@Override
public void extract(final Reader iReader) {
    super.extract(iReader);
    try {
        final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder dBuilder;
        dBuilder = dbFactory.newDocumentBuilder();
        final InputSource is = new InputSource(iReader);
        final Document xmlDocument = dBuilder.parse(is);
        xmlDocument.getDocumentElement().normalize();
        final Object res = xml2doc(xmlDocument);
        if (res instanceof Collection)
            items.addAll((Collection) res);
        else
            items.add(res);
    } catch (ParserConfigurationException e) {
        throw new OExtractorException("[XML extractor] error on creating XML parser", e);
    } catch (Exception e) {
        throw new OExtractorException("[XML extractor] error on parsing XML", e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Collection(java.util.Collection) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NoSuchElementException(java.util.NoSuchElementException)

Example 100 with DocumentBuilderFactory

use of javax.xml.parsers.DocumentBuilderFactory in project randomizedtesting by randomizedtesting.

the class TestAntXmlReport method antxml.

@Test
public void antxml() throws Exception {
    super.executeTarget("antxml");
    // Simple check for existence.
    Assert.assertTrue(new File(getProject().getBaseDir(), "ant-xmls/TEST-com.carrotsearch.ant.tasks.junit4.tests.TestBeforeClassError.xml").length() > 0);
    Assert.assertTrue(new File(getProject().getBaseDir(), "ant-xmls/TEST-com.carrotsearch.ant.tasks.junit4.tests.replication.TestSuiteReplicated-2.xml").length() > 0);
    // Check for warning messages about duplicate suites.
    assertLogContains("Duplicate suite name used with XML reports");
    // Attempt to read and parse.
    File basedir = new File(getProject().getBaseDir(), "ant-xmls");
    for (File f : basedir.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".xml")) {
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            docBuilder.parse(f);
        }
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) Test(org.junit.Test)

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