cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r935050 - in /cocoon/cocoon3/trunk/cocoon-sax/src: main/java/org/apache/cocoon/sax/component/ test/java/org/apache/cocoon/sax/component/
Date Fri, 16 Apr 2010 19:28:35 GMT
Author: simonetripodi
Date: Fri Apr 16 19:28:34 2010
New Revision: 935050

URL: http://svn.apache.org/viewvc?rev=935050&view=rev
Log:
simplified LinkRwriter architecture, 1 class is more than enough

Added:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/AbstractLinkRewriterTransformer.java
      - copied, changed from r934977, cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriterTransformer.java
Removed:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriter.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriterTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewritingException.java
Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/component/LinkRewriterTransformerTest.java

Copied: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/AbstractLinkRewriterTransformer.java
(from r934977, cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriterTransformer.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/AbstractLinkRewriterTransformer.java?p2=cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/AbstractLinkRewriterTransformer.java&p1=cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriterTransformer.java&r1=934977&r2=935050&rev=935050&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/LinkRewriterTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/AbstractLinkRewriterTransformer.java
Fri Apr 16 19:28:34 2010
@@ -33,7 +33,7 @@ import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.AttributesImpl;
 
-public final class LinkRewriterTransformer extends AbstractSAXTransformer implements CachingPipelineComponent
{
+public abstract class AbstractLinkRewriterTransformer extends AbstractSAXTransformer implements
CachingPipelineComponent {
 
     public static final String ALL_NAMESPACES = "*";
 
@@ -43,14 +43,8 @@ public final class LinkRewriterTransform
 
     private final Map<Element, Set<Element>> elements = new HashMap<Element,
Set<Element>>();
 
-    private final LinkRewriter linkRewriter;
-
-    public LinkRewriterTransformer(LinkRewriter linkRewriter) {
-        this.linkRewriter = linkRewriter;
-    }
-
     @Override
-    public void startElement(String uri, String localName, String name, Attributes atts)
+    public final void startElement(String uri, String localName, String name, Attributes
atts)
             throws SAXException {
 
         if (this.log.isDebugEnabled()) {
@@ -83,9 +77,9 @@ public final class LinkRewriterTransform
                 attributeValue = atts.getValue(i);
                 atts = new AttributesImpl(atts);
                 try {
-                    ((AttributesImpl) atts).setValue(i,
-                            this.linkRewriter.rewrite(uri, name, attributeNamespace, attributeName,
attributeValue));
-                } catch (LinkRewritingException e) {
+                    String rewrite = this.rewrite(uri, name, attributeNamespace, attributeName,
attributeValue);
+                    ((AttributesImpl) atts).setValue(i, rewrite);
+                } catch (Exception e) {
                     this.log.error("An error occurred while rewriting link '"
                             + attributeValue
                             + "' ("
@@ -142,6 +136,12 @@ public final class LinkRewriterTransform
         attributes.add(new Element(attributeNamespace, attributeName));
     }
 
+    protected abstract String rewrite(String elementNamespace,
+            String elementName,
+            String atributeNamespace,
+            String attributeName,
+            String link) throws Exception;
+
     private boolean contains(String elementNamespace,
             String elementName,
             String atributeNamespace,

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=935050&r1=935049&r2=935050&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
Fri Apr 16 19:28:34 2010
@@ -78,7 +78,7 @@ public final class LinkRewriterTransform
         Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
         pipeline.addComponent(new XMLGenerator(source));
 
-        LinkRewriterTransformer lrt = new LinkRewriterTransformer(new AbsoluteRewriter());
+        AbstractLinkRewriterTransformer lrt = new AbsoluteLinkRewriterTransformer();
         lrt.addElement("a", "href");
         lrt.addElement("http://www.w3.org/1999/xhtml",
                 "link",
@@ -117,22 +117,21 @@ public final class LinkRewriterTransform
                 diff.identical());
     }
 
-    class AbsoluteRewriter implements LinkRewriter {
+    class AbsoluteLinkRewriterTransformer extends AbstractLinkRewriterTransformer {
 
         public String rewrite(String elementNamespace,
                 String elementName,
-                String atributeNamespace,
+                String attributeNamespace,
                 String attributeName,
-                String link) throws LinkRewritingException {
+                String link) throws Exception {
 
-            String rewrittenLink = link;
             if (!link.startsWith("http")) {
-                rewrittenLink = "http://www.apache.org"
+                return "http://www.apache.org"
                         + (link.startsWith(".")
                         ? link.substring(1) : (!link.startsWith("/")
                         ? "/" + link : link));
             }
-            return rewrittenLink;
+            return link;
         }
     }
 



Mime
View raw message