cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r934567 - in /cocoon/cocoon3/trunk/cocoon-sax/src: main/java/org/apache/cocoon/sax/component/ToRewrite.java test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java
Date Thu, 15 Apr 2010 19:44:51 GMT
Author: simonetripodi
Date: Thu Apr 15 19:44:51 2010
New Revision: 934567

URL: http://svn.apache.org/viewvc?rev=934567&view=rev
Log:
added support for "match all namespaces"

Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ToRewrite.java
    cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ToRewrite.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ToRewrite.java?rev=934567&r1=934566&r2=934567&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ToRewrite.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ToRewrite.java
Thu Apr 15 19:44:51 2010
@@ -25,8 +25,16 @@ import java.util.Set;
 
 public final class ToRewrite {
 
+    public static final String ALL_NAMESPACES = "*";
+
+    private static final String EMPY_NAMESPACE = "";
+
     private final Map<Element, Set<Element>> elements = new HashMap<Element,
Set<Element>>();
 
+    public void addElement(String elementName, String attributeName) {
+        this.addElement(ALL_NAMESPACES, elementName, ALL_NAMESPACES, attributeName);
+    }
+
     public void addElement(String elementNamespace,
             String elementName,
             String attributeNamespace,
@@ -37,7 +45,12 @@ public final class ToRewrite {
         if (attributeName == null) {
             throw new IllegalArgumentException("Parameter 'attributeName' must not be null");
         }
+
+        if (elementNamespace == null) {
+            elementNamespace = EMPY_NAMESPACE;
+        }
         Element key = new Element(elementNamespace, elementName);
+
         Set<Element> attributes;
         if (this.elements.containsKey(key)) {
             attributes = this.elements.get(key);
@@ -45,6 +58,10 @@ public final class ToRewrite {
             attributes = new HashSet<Element>();
             this.elements.put(key, attributes);
         }
+
+        if (attributeNamespace == null) {
+            attributeNamespace = EMPY_NAMESPACE;
+        }
         attributes.add(new Element(attributeNamespace, attributeName));
     }
 
@@ -59,36 +76,28 @@ public final class ToRewrite {
 
     private final class Element {
 
-        private static final String EMPTY = "";
-
         private final String namespace;
 
         private final String name;
 
         public Element(String namespace, String name) {
-            if (namespace != null) {
-                this.namespace = namespace;
-            } else {
-                this.namespace = EMPTY;
-            }
+            this.namespace = namespace;
             this.name = name;
         }
 
         public String getNamespace() {
-            return namespace;
+            return this.namespace;
         }
 
         public String getName() {
-            return name;
+            return this.name;
         }
 
         @Override
         public int hashCode() {
-            final int prime = 97;
-            int result = 7;
-            result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
-            result = prime * result + ((name == null) ? 0 : name.hashCode());
-            return result;
+            final int initialNonZeroOddNumber = 97;
+            final int multiplierNonZeroOddNumber = 7;
+            return initialNonZeroOddNumber * multiplierNonZeroOddNumber + this.name.hashCode();
         }
 
         @Override
@@ -97,35 +106,34 @@ public final class ToRewrite {
                 return true;
             }
 
-            if (obj == null) {
-                return false;
-            }
-
-            if (this.getClass() != obj.getClass()) {
+            if (obj == null || this.getClass() != obj.getClass()) {
                 return false;
             }
 
             Element other = (Element) obj;
 
-            if (this.namespace == null) {
-                if (other.getNamespace() != null) {
-                    return false;
-                }
-            } else if (!this.namespace.equals(other.getNamespace())) {
+            if (!(ALL_NAMESPACES.equals(this.namespace)
+                    || ALL_NAMESPACES.equals(other.getNamespace()))
+                    && !this.namespace.equals(other.getNamespace())) {
                 return false;
             }
 
-            if (this.name == null) {
-                if (other.getName() != null) {
-                    return false;
-                }
-            } else if (!this.name.equals(other.getName())) {
+            if (!this.name.equals(other.getName())) {
                 return false;
             }
 
             return true;
         }
 
+        @Override
+        public String toString() {
+            return "{ namespace='"
+                    + this.namespace
+                    + "', name='"
+                    + this.name
+                    + "' }";
+        }
+
     }
 
 }

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java?rev=934567&r1=934566&r2=934567&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java
Thu Apr 15 19:44:51 2010
@@ -76,10 +76,7 @@ public final class LinkRewriterTransform
         URL source = this.getClass().getResource("/apache_home.html");
 
         ToRewrite toRewrite = new ToRewrite();
-        toRewrite.addElement("http://www.w3.org/1999/xhtml",
-                "a",
-                "",
-                "href");
+        toRewrite.addElement("a", "href");
         toRewrite.addElement("http://www.w3.org/1999/xhtml",
                 "link",
                 null,



Mime
View raw message