[Yanel-commits] rev 32472 - public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/yanel/gwt/accesspolicyeditor/client

michi at wyona.com michi at wyona.com
Mon Feb 25 22:45:19 CET 2008


Author: michi
Date: 2008-02-25 22:45:18 +0100 (Mon, 25 Feb 2008)
New Revision: 32472

Modified:
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/yanel/gwt/accesspolicyeditor/client/AsynchronousIdentitiesAndRightsGetter.java
Log:
parse XML response

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/yanel/gwt/accesspolicyeditor/client/AsynchronousIdentitiesAndRightsGetter.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/yanel/gwt/accesspolicyeditor/client/AsynchronousIdentitiesAndRightsGetter.java	2008-02-25 21:22:06 UTC (rev 32471)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/yanel/gwt/accesspolicyeditor/client/AsynchronousIdentitiesAndRightsGetter.java	2008-02-25 21:45:18 UTC (rev 32472)
@@ -20,6 +20,7 @@
 import com.google.gwt.http.client.Request;
 import com.google.gwt.http.client.Response;
 import com.google.gwt.xml.client.Element;
+import com.google.gwt.xml.client.NodeList;
 import com.google.gwt.xml.client.XMLParser;
 import com.google.gwt.user.client.Window;
 
@@ -49,16 +50,22 @@
         // http://code.google.com/p/bunsenandbeaker/wiki/DevGuideXML
         Element rootElement = XMLParser.parse(response.getText()).getDocumentElement();
         Window.alert("Root element: " + rootElement.getTagName());
-        users.add("dz");
+        Element usersElement = getFirstChildElement(rootElement, "users");
+        NodeList userElements = usersElement.getElementsByTagName("user");
+        for (int i = 0; i < userElements.getLength(); i++) {
+            users.add(((Element) userElements.item(i)).getAttribute("id"));
+        }
     }
 
     /**
      * Get users
      */
     public String[] getUsers() {
-        String[] u = new String[2];
-        u[0] = "dz";
-        u[1] = "ep";
+        String[] u = new String[users.size()];
+        for (int i = 0; i < users.size(); i++) {
+            u[i] = (String) users.elementAt(i);
+            Window.alert("User: " + u[i]);
+        }
         return u;
     }
 
@@ -82,4 +89,12 @@
         r[2] = "Toolbar";
         return r;
     }
+
+    /**
+     * Get first child with a specific tag name
+     */
+    private Element getFirstChildElement(Element parent, String name) {
+        NodeList nl = parent.getElementsByTagName(name);
+        return (Element) nl.item(0);
+    }
 }



More information about the Yanel-commits mailing list