Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 39477 invoked from network); 15 Apr 2010 19:45:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Apr 2010 19:45:13 -0000 Received: (qmail 82891 invoked by uid 500); 15 Apr 2010 19:45:13 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 82828 invoked by uid 500); 15 Apr 2010 19:45:12 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 82821 invoked by uid 99); 15 Apr 2010 19:45:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 19:45:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Apr 2010 19:45:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 957FA238890B; Thu, 15 Apr 2010 19:44:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cvs@cocoon.apache.org From: simonetripodi@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100415194451.957FA238890B@eris.apache.org> 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> elements = new HashMap>(); + 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 attributes; if (this.elements.containsKey(key)) { attributes = this.elements.get(key); @@ -45,6 +58,10 @@ public final class ToRewrite { attributes = new HashSet(); 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,