use of javax.xml.parsers.ParserConfigurationException 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.ParserConfigurationException in project jphp by jphp-compiler.
the class UIReader method read.
public Component read(InputStream inputStream) {
try {
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document document = builder.parse(inputStream);
Element root = document.getDocumentElement();
return readElement(root);
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of javax.xml.parsers.ParserConfigurationException in project midpoint by Evolveum.
the class DOMUtil method parseFile.
public static Document parseFile(File file) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder loader = factory.newDocumentBuilder();
return loader.parse(file);
} catch (SAXException | IOException | ParserConfigurationException ex) {
throw new IllegalStateException("Error parsing XML document " + ex.getMessage(), ex);
}
}
use of javax.xml.parsers.ParserConfigurationException in project midpoint by Evolveum.
the class DOMUtil method createDocumentBuilder.
public static DocumentBuilder createDocumentBuilder() {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
try {
return factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new IllegalStateException("Error creating document builder " + e.getMessage(), e);
}
}
use of javax.xml.parsers.ParserConfigurationException in project XobotOS by xamarin.
the class Properties method loadFromXML.
/**
* Loads the properties from an {@code InputStream} containing the
* properties in XML form. The XML document must begin with (and conform to)
* following DOCTYPE:
*
* <pre>
* <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
* </pre>
*
* Also the content of the XML data must satisfy the DTD but the xml is not
* validated against it. The DTD is not loaded from the SYSTEM ID. After
* this method returns the InputStream is not closed.
*
* @param in the InputStream containing the XML document.
* @throws IOException in case an error occurs during a read operation.
* @throws InvalidPropertiesFormatException if the XML data is not a valid
* properties file.
*/
public synchronized void loadFromXML(InputStream in) throws IOException, InvalidPropertiesFormatException {
if (in == null) {
throw new NullPointerException();
}
if (builder == null) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new Error(e);
}
builder.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException e) throws SAXException {
throw e;
}
public void error(SAXParseException e) throws SAXException {
throw e;
}
public void fatalError(SAXParseException e) throws SAXException {
throw e;
}
});
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (systemId.equals(PROP_DTD_NAME)) {
InputSource result = new InputSource(new StringReader(PROP_DTD));
result.setSystemId(PROP_DTD_NAME);
return result;
}
throw new SAXException("Invalid DOCTYPE declaration: " + systemId);
}
});
}
try {
Document doc = builder.parse(in);
NodeList entries = doc.getElementsByTagName("entry");
if (entries == null) {
return;
}
int entriesListLength = entries.getLength();
for (int i = 0; i < entriesListLength; i++) {
Element entry = (Element) entries.item(i);
String key = entry.getAttribute("key");
String value = entry.getTextContent();
/*
* key != null & value != null but key or(and) value can be
* empty String
*/
put(key, value);
}
} catch (IOException e) {
throw e;
} catch (SAXException e) {
throw new InvalidPropertiesFormatException(e);
}
}
Aggregations