Moved to DOM 2 element interface.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 24 Jan 2003 06:51:07 +0000 (06:51 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 24 Jan 2003 06:51:07 +0000 (06:51 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@415 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/arp/Arp.java
src/edu/internet2/middleware/shibboleth/aa/arp/Rule.java

index 98b2f0c..9beec76 100755 (executable)
@@ -75,6 +75,7 @@ import org.w3c.dom.NodeList;
 
 public class Arp {
 
+       public static final String arpNamespace = "urn:mace:shibboleth:arp:1.0";
        private Principal principal;
        private Set rules = new HashSet();
        private String description;
@@ -137,7 +138,7 @@ public class Arp {
                }
 
                //Grab the description
-               NodeList descriptionNodes = xmlElement.getElementsByTagName("Description");
+               NodeList descriptionNodes = xmlElement.getElementsByTagNameNS(arpNamespace, "Description");
                if (descriptionNodes.getLength() > 0) {
                        Element descriptionNode = (Element) descriptionNodes.item(0);
                        if (descriptionNode.hasChildNodes()
@@ -147,7 +148,7 @@ public class Arp {
                }
 
                //Grab all of the Rule Elements and marshall them
-               NodeList ruleNodes = xmlElement.getElementsByTagName("Rule");
+               NodeList ruleNodes = xmlElement.getElementsByTagNameNS(arpNamespace, "Rule");
                if (ruleNodes.getLength() > 0) {
                        for (int i = 0; i < ruleNodes.getLength(); i++) {
                                Rule rule = new Rule();
@@ -169,10 +170,16 @@ public class Arp {
        Element unmarshall() throws ArpMarshallingException {
 
                try {
-                       Document placeHolder = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                       Element policyNode = placeHolder.createElement("AttributeReleasePolicy");
+                       DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
+                       docFactory.setNamespaceAware(true);
+                       Document placeHolder = docFactory.newDocumentBuilder().newDocument();
+                       
+                       Element policyNode = placeHolder.createElementNS(arpNamespace, "AttributeReleasePolicy");
+                       policyNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", arpNamespace);
+                       policyNode.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+                       policyNode.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:schemaLocation", "urn:mace:shibboleth:arp:1.0 shibboleth-arp-1.0.xsd");
                        if (description != null) {
-                               Element descriptionNode = placeHolder.createElement("Description");
+                               Element descriptionNode = placeHolder.createElementNS(arpNamespace, "Description");
                                descriptionNode.appendChild(placeHolder.createTextNode(description));
                                policyNode.appendChild(descriptionNode);
                        }
index b2a2592..6c255e0 100755 (executable)
@@ -117,10 +117,10 @@ public class Rule {
 
                try {
                        Document placeHolder = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                       Element ruleNode = placeHolder.createElement("Rule");
+                       Element ruleNode = placeHolder.createElementNS(Arp.arpNamespace, "Rule");
 
                        if (description != null) {
-                               Element descriptionNode = placeHolder.createElement("Description");
+                               Element descriptionNode = placeHolder.createElementNS(Arp.arpNamespace, "Description");
                                descriptionNode.appendChild(placeHolder.createTextNode(description));
                                ruleNode.appendChild(descriptionNode);
                        }
@@ -228,16 +228,16 @@ public class Rule {
                        try {
                                Document placeHolder =
                                        DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                               Element targetNode = placeHolder.createElement("Target");
+                               Element targetNode = placeHolder.createElementNS(Arp.arpNamespace, "Target");
 
                                if (matchesAny) {
-                                       Element anyTargetNode = placeHolder.createElement("AnyTarget");
+                                       Element anyTargetNode = placeHolder.createElementNS(Arp.arpNamespace, "AnyTarget");
                                        targetNode.appendChild(anyTargetNode);
                                        return targetNode;
                                }
                                targetNode.appendChild(placeHolder.importNode(requester.unmarshall(), true));
                                if (target.resource.matchesAny()) {
-                                       Element anyResourceNode = placeHolder.createElement("AnyResource");
+                                       Element anyResourceNode = placeHolder.createElementNS(Arp.arpNamespace, "AnyResource");
                                        targetNode.appendChild(anyResourceNode);
                                        return targetNode;
                                }
@@ -334,10 +334,10 @@ public class Rule {
                        try {
                                Document placeHolder =
                                        DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                               Element resourceNode = placeHolder.createElement("Resource");
+                               Element resourceNode = placeHolder.createElementNS(Arp.arpNamespace, "Resource");
                                if (!matchFunctionIdentifier
                                        .equals(new URI("urn:mace:shibboleth:arp:matchFunction:resourceTree"))) {
-                                       resourceNode.setAttribute("matchFunction", matchFunctionIdentifier.toString());
+                                       resourceNode.setAttributeNS(Arp.arpNamespace, "matchFunction", matchFunctionIdentifier.toString());
                                }
                                Text valueNode = placeHolder.createTextNode(value);
                                resourceNode.appendChild(valueNode);
@@ -408,10 +408,10 @@ public class Rule {
                        try {
                                Document placeHolder =
                                        DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                               Element requesterNode = placeHolder.createElement("Requester");
+                               Element requesterNode = placeHolder.createElementNS(Arp.arpNamespace, "Requester");
                                if (!matchFunctionIdentifier
                                        .equals(new URI("urn:mace:shibboleth:arp:matchFunction:exactShar"))) {
-                                       requesterNode.setAttribute("matchFunction", matchFunctionIdentifier.toString());
+                                       requesterNode.setAttributeNS(Arp.arpNamespace, "matchFunction", matchFunctionIdentifier.toString());
                                }
                                Text valueNode = placeHolder.createTextNode(value);
                                requesterNode.appendChild(valueNode);
@@ -574,19 +574,19 @@ public class Rule {
                        try {
                                Document placeHolder =
                                        DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                               Element attributeNode = placeHolder.createElement("Attribute");
+                               Element attributeNode = placeHolder.createElementNS(Arp.arpNamespace, "Attribute");
 
-                               attributeNode.setAttribute("name", name.toString());
+                               attributeNode.setAttributeNS(Arp.arpNamespace, "name", name.toString());
                                if (anyValue) {
-                                       Element anyValueNode = placeHolder.createElement("AnyValue");
-                                       anyValueNode.setAttribute("release", anyValueRelease);
+                                       Element anyValueNode = placeHolder.createElementNS(Arp.arpNamespace, "AnyValue");
+                                       anyValueNode.setAttributeNS(Arp.arpNamespace, "release", anyValueRelease);
                                        attributeNode.appendChild(anyValueNode);
                                }
                                Iterator valueIterator = values.iterator();
                                while (valueIterator.hasNext()) {
                                        AttributeValue value = (AttributeValue) valueIterator.next();
-                                       Element valueNode = placeHolder.createElement("Value");
-                                       valueNode.setAttribute("release", value.getRelease());
+                                       Element valueNode = placeHolder.createElementNS(Arp.arpNamespace, "Value");
+                                       valueNode.setAttributeNS(Arp.arpNamespace, "release", value.getRelease());
                                        Text valueTextNode = placeHolder.createTextNode(value.getValue());
                                        valueNode.appendChild(valueTextNode);
                                        attributeNode.appendChild(valueNode);