use of javax.xml.parsers.DocumentBuilder in project Openfire by igniterealtime.
the class MonitoringDWR method configure.
@Override
public void configure(ServletConfig servletConfig, Configuration configuration) throws ServletException {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = dbf.newDocumentBuilder();
document = builder.newDocument();
Element root = document.createElement("dwr");
document.appendChild(root);
Element allowElement = document.createElement("allow");
// Build stats bean
Element createElement = buildCreator("Stats", org.jivesoftware.openfire.reporting.stats.StatsAction.class.getName());
Element convertConversationElement = document.createElement("convert");
convertConversationElement.setAttribute("converter", "bean");
convertConversationElement.setAttribute("match", org.jivesoftware.openfire.archive.ConversationInfo.class.getName());
// Build conversation Element.
Element conversationElement = buildCreator("conversations", org.jivesoftware.openfire.archive.ConversationUtils.class.getName());
allowElement.appendChild(createElement);
allowElement.appendChild(convertConversationElement);
allowElement.appendChild(conversationElement);
root.appendChild(allowElement);
} catch (ParserConfigurationException e) {
Log.error("error creating DWR configuration: " + e);
}
configuration.addConfig(document);
// Specify the path for the Stat.js file
Object bean = container.getBean("interface");
if (bean instanceof DefaultInterfaceProcessor) {
DefaultInterfaceProcessor processor = (DefaultInterfaceProcessor) bean;
processor.setOverridePath("/plugins/" + MonitoringConstants.NAME + "/dwr");
}
}
use of javax.xml.parsers.DocumentBuilder in project jOOQ by jOOQ.
the class XMLasDOMBinding method builder.
/**
* Get a namespace-aware document builder
*/
public static DocumentBuilder builder() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// [#4592] FIX START: Prevent OWASP attack vectors
try {
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
} catch (ParserConfigurationException ignore) {
}
try {
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
} catch (ParserConfigurationException ignore) {
}
try {
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (ParserConfigurationException ignore) {
}
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);
// [#4592] FIX END
// -----------------------------------------------------------------
// [#9] [#107] In order to take advantage of namespace-related DOM
// features, the internal builder should be namespace-aware
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.xml.parsers.DocumentBuilder in project jersey by jersey.
the class ExtendedWadlWebappOsgiTest method checkWadl.
private void checkWadl(String wadl, URI baseUri) throws Exception {
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
DocumentBuilder b = bf.newDocumentBuilder();
Document document = b.parse(new ByteArrayInputStream(wadl.getBytes(Charset.forName("UTF-8"))));
XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("/wadl:application/wadl:resources/@base", document, XPathConstants.STRING);
assertEquals(baseUri.toString(), val.endsWith("/") ? val.substring(0, val.length() - 1) : val);
val = (String) xp.evaluate("count(//wadl:resource)", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements.", val, "4");
val = (String) xp.evaluate("count(//wadl:resource[@path='items'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'items' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with '{id}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with '{id}' path.", "2", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Typically returns the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at '{id}' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Tries hard to return the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at 'try-hard' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='items']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'items' path.", "4", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:application/wadl:doc)", document, XPathConstants.STRING);
assertEquals("Unexpected number of doc elements in application element.", "3", val);
}
use of javax.xml.parsers.DocumentBuilder in project jersey by jersey.
the class ExtendedWadlWebappTest method checkWadl.
private void checkWadl(String wadl, URI baseUri) throws Exception {
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
// if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
// bf.setXIncludeAware(false);
// }
DocumentBuilder b = bf.newDocumentBuilder();
Document document = b.parse(new ByteArrayInputStream(wadl.getBytes(Charset.forName("UTF-8"))));
XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("/wadl:application/wadl:resources/@base", document, XPathConstants.STRING);
assertEquals(baseUri.toString(), val.endsWith("/") ? val.substring(0, val.length() - 1) : val);
val = (String) xp.evaluate("count(//wadl:resource)", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements.", val, "4");
val = (String) xp.evaluate("count(//wadl:resource[@path='items'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'items' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with '{id}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}'])", document, XPathConstants.STRING);
assertEquals("Unexpected number of resource elements with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with '{id}' path.", "2", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='{id}']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Typically returns the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at '{id}' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'try-hard' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='try-hard']/wadl:method[@id='getItem']" + "/wadl:doc[contains(., 'Tries hard to return the item if it exists.')])", document, XPathConstants.STRING);
assertEquals("Unexpected documentation of getItem resource method at 'try-hard' path", "1", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='items']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'items' path.", "4", val);
val = (String) xp.evaluate("count(//wadl:resource[@path='value/{value}']/wadl:method)", document, XPathConstants.STRING);
assertEquals("Unexpected number of methods in resource element with 'value/{value}' path.", "1", val);
val = (String) xp.evaluate("count(//wadl:application/wadl:doc)", document, XPathConstants.STRING);
assertEquals("Unexpected number of doc elements in application element.", "3", val);
}
use of javax.xml.parsers.DocumentBuilder in project quickstarts by jboss-switchyard.
the class TypeTransformationTest method loadXML.
private Document loadXML(String path) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(getClass().getClassLoader().getResourceAsStream(path));
}
Aggregations