hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

CreateInterface chokes on DTD declaration #2

Closed wlbaker closed 7 years ago

wlbaker commented 7 years ago

The command to build a java interface throws a fatal error.

prompt$ CreateInterface --system org.freedesktop.NetworkManager /org/freedesktop/NetworkManager
[Fatal Error] introspect.dtd:1:3: The markup declarations contained or pointed to by the document type declaration must be well-formed.

One solution, turn off DTD checking. Easily done with a few lines of code. See below.

/bbaker

-------CUT HERE-------------CUT HERE-------------CUT HERE----------

diff --git a/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java b/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
index c1ca549..7ea5191 100644
--- a/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
+++ b/src/main/java/org/freedesktop/dbus/bin/CreateInterface.java
@@ -734,6 +734,14 @@
     */
     public void createInterface(Reader introspectdata) throws ParserConfigurationException, SAXException, IOException, DBusException {
         DocumentBuilderFactory lfactory = DocumentBuilderFactory.newInstance();
+        // FIXME: Option to remove validation and external DTD check
+        // http://stackoverflow.com/questions/155101/make-documentbuilder-parse-ignore-dtd-references
+        lfactory.setValidating(false);
+        lfactory.setNamespaceAware(true);
+        lfactory.setFeature("http://xml.org/sax/features/namespaces", false);
+        lfactory.setFeature("http://xml.org/sax/features/validation", false);
+        lfactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
+        lfactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
         DocumentBuilder builder = lfactory.newDocumentBuilder();
         Document document = builder.parse(new InputSource(introspectdata));
hypfvieh commented 7 years ago

Thanks for the hint. I didn't use the CreateInterface tool - it is still the original version provided by freedesktop.org.

Anyway, I added your suggestion and made it the default (ignore dtd). I also added a new commandline option to re-enable dtd validation (--enable-dtd-validation).