use of javax.xml.parsers.DocumentBuilderFactory in project Openfire by igniterealtime.
the class UserSchemaValidator method validateAndParse.
/**
* Perform a validate and a parse of the specified source document.
* Validating is done with the specified schemafiles.
*
* @return A Document when the validation s successful.
*/
Document validateAndParse() {
ValidatorErrorHandler handler = new ValidatorErrorHandler();
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setXIncludeAware(true);
documentBuilderFactory.setValidating(false);
// We don't want xml:base and xml:lang attributes in the output.
documentBuilderFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
documentBuilderFactory.setFeature("http://apache.org/xml/features/xinclude/fixup-language", false);
if (schemaSources.length > 0) {
Log.info("Checking Schema's");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(handler);
Schema schema = schemaFactory.newSchema(schemaSources);
documentBuilderFactory.setSchema(schema);
Log.info("Start validating document");
} else {
Log.info("Loading document");
}
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
handler.reset();
// Communicate some info about the Xincludes in the imported file. These imports should be resolvable by the server.
documentBuilder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
Log.info(String.format("resolved Entity:%s %s", (publicId != null ? publicId : ""), systemId));
return null;
}
});
documentBuilder.setErrorHandler(handler);
Document result = documentBuilder.parse(source);
if (result != null && handler.isValid()) {
return result;
} else {
Log.warn(String.format("document is invalid. %1$d errors found.", handler.getNrOfErrors()));
return null;
}
} catch (Exception e) {
Log.warn(String.format("document validation failed. %1$d errors found.", handler.getNrOfErrors()));
Log.debug("", e);
return null;
}
}
use of javax.xml.parsers.DocumentBuilderFactory in project Openfire by igniterealtime.
the class Launcher method launchBrowser.
private synchronized void launchBrowser() {
try {
// Note, we use standard DOM to read in the XML. This is necessary so that
// Launcher has fewer dependencies.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document = factory.newDocumentBuilder().parse(configFile);
Element rootElement = document.getDocumentElement();
Element adminElement = (Element) rootElement.getElementsByTagName("adminConsole").item(0);
String port = "-1";
String securePort = "-1";
Element portElement = (Element) adminElement.getElementsByTagName("port").item(0);
if (portElement != null) {
port = portElement.getTextContent();
}
Element securePortElement = (Element) adminElement.getElementsByTagName("securePort").item(0);
if (securePortElement != null) {
securePort = securePortElement.getTextContent();
}
if ("-1".equals(port)) {
Desktop.getDesktop().browse(URI.create("https://127.0.0.1:" + securePort + "/index.html"));
} else {
Desktop.getDesktop().browse(URI.create("http://127.0.0.1:" + port + "/index.html"));
}
} catch (Exception e) {
// Make sure to print the exception
e.printStackTrace(System.out);
JOptionPane.showMessageDialog(new JFrame(), configFile + " " + e.getMessage());
}
}
use of javax.xml.parsers.DocumentBuilderFactory in project Openfire by igniterealtime.
the class GatewayDWR 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");
allowElement.appendChild(buildCreator("ConfigManager", "net.sf.kraken.web.ConfigManager"));
allowElement.appendChild(buildCreator("ConnectionTester", "net.sf.kraken.web.ConnectionTester"));
root.appendChild(allowElement);
} catch (ParserConfigurationException e) {
Log.error("Error configuring DWR for gateway plugin: ", e);
}
configuration.addConfig(document);
// Specify the path for the js files
Object bean = container.getBean("interface");
if (bean instanceof DefaultInterfaceProcessor) {
DefaultInterfaceProcessor processor = (DefaultInterfaceProcessor) bean;
processor.setOverridePath("/plugins/kraken/dwr");
}
}
use of javax.xml.parsers.DocumentBuilderFactory 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.DocumentBuilderFactory 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);
}
}
Aggregations