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