GUACAMOLE-497: Fall back to qualified name of XML element if SAX parser does 
not provide local name.


Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/37f7df80
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/37f7df80
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/37f7df80

Branch: refs/heads/master
Commit: 37f7df804dd8db676fcb6a5fbda3c187a5cdd89c
Parents: c6aa790
Author: Michael Jumper <mjum...@apache.org>
Authored: Thu Feb 1 19:01:29 2018 -0800
Committer: Michael Jumper <mjum...@apache.org>
Committed: Thu Feb 1 21:21:05 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/guacamole/xml/DocumentHandler.java    | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/37f7df80/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java
----------------------------------------------------------------------
diff --git 
a/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java 
b/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java
index eb9bf5d..ed55290 100644
--- a/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java
+++ b/guacamole-ext/src/main/java/org/apache/guacamole/xml/DocumentHandler.java
@@ -84,6 +84,10 @@ public class DocumentHandler extends DefaultHandler {
     public void startElement(String uri, String localName, String qName,
         Attributes attributes) throws SAXException {
 
+        // If the SAX implementation does not provide the local name, the
+        // qualified name should be used instead
+        String name = localName.isEmpty() ? qName : localName;
+
         // Get current state
         DocumentHandlerState current = getCurrentState();
 
@@ -94,7 +98,7 @@ public class DocumentHandler extends DefaultHandler {
         if (current == null) {
 
             // Validate element name
-            if (!localName.equals(rootElementName))
+            if (!name.equals(rootElementName))
                 throw new SAXException("Root element must be '" + 
rootElementName + "'");
 
             handler = root;
@@ -103,12 +107,12 @@ public class DocumentHandler extends DefaultHandler {
         // Otherwise, get handler from parent
         else {
             TagHandler parent_handler = current.getTagHandler();
-            handler = parent_handler.childElement(localName);
+            handler = parent_handler.childElement(name);
         }
 
         // If no handler returned, the element was not expected
         if (handler == null)
-            throw new SAXException("Unexpected element: '" + localName + "'");
+            throw new SAXException("Unexpected element: '" + name + "'");
 
         // Initialize handler
         handler.init(attributes);

Reply via email to