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