You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by at...@apache.org on 2008/10/26 22:07:28 UTC

svn commit: r708039 - /portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java

Author: ate
Date: Sun Oct 26 14:07:28 2008
New Revision: 708039

URL: http://svn.apache.org/viewvc?rev=708039&view=rev
Log:
Replacing jdom with Java standard w3c dom

Modified:
    portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java

Modified: portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java?rev=708039&r1=708038&r2=708039&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java (original)
+++ portals/jetspeed-2/portal/branches/JS2-871-pluto-2.0-upgrade/components/jetspeed-portal/src/main/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java Sun Oct 26 14:07:28 2008
@@ -16,12 +16,15 @@
  */
 package org.apache.jetspeed.layout.impl;
 
-import java.io.StringReader;
+import java.io.ByteArrayInputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.JetspeedActions;
@@ -34,9 +37,9 @@
 import org.apache.jetspeed.om.page.SecurityConstraintsDef;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.request.RequestContext;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 
 /**
  * Security Permission action
@@ -170,11 +173,12 @@
             throw new AJAXException("Missing 'xml' parameter");
         try
         {
-            SAXBuilder saxBuilder = new SAXBuilder();
-            StringReader reader = new StringReader(xml);
-            Document document = saxBuilder.build(reader);
-            Element root = document.getRootElement();
-            String name = root.getAttribute("name").getValue();
+            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+            DocumentBuilder builder = domFactory.newDocumentBuilder();
+            Document document = builder.parse(new ByteArrayInputStream(xml.getBytes(requestContext.getCharacterEncoding())));
+            
+            Element root = document.getDocumentElement();
+            String name = root.getAttribute("name");
             PageSecurity pageSecurity = pageManager.getPageSecurity();
             SecurityConstraintsDef def = pageSecurity.getSecurityConstraintsDef(name);
             int defsSize = 0;
@@ -184,21 +188,21 @@
                 def.setName(name);
                 added = true;
             }
-            int xmlSize = root.getChildren("security-constraint").size();
+            NodeList xmlConstraints = root.getElementsByTagName("security-contraint");
+            int xmlSize = xmlConstraints.getLength();
             if (added == false)
             {
                 defsSize = def.getSecurityConstraints().size();
             }
             int min = (xmlSize < defsSize) ? xmlSize : defsSize;
-            List xmlConstraints = root.getChildren("security-constraint");
             List constraints = def.getSecurityConstraints();
-            Element owner = root.getChild("owner");
-            if (owner != null)
+            NodeList owners = root.getElementsByTagName("owner");
+            if (owners.getLength() == 1)
             {
             }
             for (int ix = 0; ix < min; ix++)
             {
-                Element xmlConstraint = (Element)xmlConstraints.get(ix);
+                Element xmlConstraint = (Element)xmlConstraints.item(ix);
                 SecurityConstraint constraint =  (SecurityConstraint)constraints.get(ix);                
                 updateConstraintValues(xmlConstraint, constraint);
                 count++;                
@@ -222,7 +226,7 @@
                 // add new constraints
                 for (int ix = min; ix < xmlSize; ix++)
                 {
-                    Element xmlConstraint = (Element)xmlConstraints.get(ix);
+                    Element xmlConstraint = (Element)xmlConstraints.item(ix);
                     SecurityConstraint constraint =  pageManager.newPageSecuritySecurityConstraint();                    
                     updateConstraintValues(xmlConstraint, constraint);
                     constraints.add(constraint);                    
@@ -248,10 +252,20 @@
     
     protected void updateConstraintValues(Element xmlConstraint, SecurityConstraint constraint)
     {
-        constraint.setRoles(parseCSVList(xmlConstraint.getChildText("roles")));
-        constraint.setGroups(parseCSVList(xmlConstraint.getChildText("groups")));
-        constraint.setPermissions(parseCSVList(xmlConstraint.getChildText("permissions")));
-        constraint.setUsers(parseCSVList(xmlConstraint.getChildText("users")));        
+        constraint.setRoles(parseCSVList(getChildText(xmlConstraint, "roles")));
+        constraint.setGroups(parseCSVList(getChildText(xmlConstraint, "groups")));
+        constraint.setPermissions(parseCSVList(getChildText(xmlConstraint, "permissions")));
+        constraint.setUsers(parseCSVList(getChildText(xmlConstraint, "users")));        
+    }
+    
+    protected String getChildText(Element parent, String childName)
+    {
+        NodeList children = parent.getElementsByTagName(childName);
+        if (children.getLength() > 0)
+        {
+            return ((Element)children.item(0)).getTextContent();
+        }
+        return null;
     }
     
     protected List parseCSVList(String csv)



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org