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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
}
Aggregations