cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 27904] New: - HTMLEventLinkTransformer transforms href links which access a document fragment
Date Wed, 24 Mar 2004 14:25:40 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27904>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27904

HTMLEventLinkTransformer transforms href links which access a document fragment

           Summary: HTMLEventLinkTransformer transforms href links which
                    access a document fragment
           Product: Cocoon 2
           Version: Current CVS 2.1
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: blocks
        AssignedTo: dev@cocoon.apache.org
        ReportedBy: christian.mayrhuber@gmx.net


HTMLEventLinkTransformer transforms links like <a href="#myref"> which makes
the javascript features of cocoon forms such as the calendar non working.

patch to fix:

= SNIP & SNAP ==================================================
---
cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
2004-03-16 14:23:46.000000000 +0100
+++ src/org/apache/cocoon/portal/transformation/HTMLEventLinkTransformer.java
2004-03-24 15:08:02.000000000 +0100
@@ -17,6 +17,7 @@
 
 import java.io.IOException;
 import java.util.Map;
+import java.util.Stack;
 
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.ProcessingException;
@@ -45,6 +46,9 @@
     /** The jxpath for the attribute */
     protected String jxPath;
     
+    /** Remembers if the current element is a remote anchor */
+    protected Stack areRemoteAnchors;
+    
     /* (non-Javadoc)
      * @see
org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
      */
@@ -56,6 +60,7 @@
         super.setup(resolver, objectModel, src, par);
         this.attributeName = par.getParameter("attribute-name", "application-uri");
         this.jxPath = "temporaryAttributes/" + this.attributeName;
+        this.areRemoteAnchors = new Stack();
     }
 
     /* (non-Javadoc)
@@ -63,7 +68,10 @@
      */
     public void startElement(String uri, String name, String raw, Attributes attr)
     throws SAXException {
-        if ("a".equals(name) ) {
+        
+        areRemoteAnchors.push(Boolean.valueOf(isRemoteAnchor(name, attr)));
+      
+        if ( ((Boolean)areRemoteAnchors.peek()).booleanValue() ) {
             this.createAnchorEvent(uri, name, raw, attr);
         } else if ("form".equals(name) ) {
             this.createFormEvent(uri, name, raw, attr);
@@ -77,7 +85,7 @@
      */
     public void endElement(String uri, String name, String raw)
     throws SAXException {
-        if ( "a".equals(name) || "form".equals(name) ) {
+        if ( ((Boolean)areRemoteAnchors.pop()).booleanValue() ||
"form".equals(name) ) {
             this.xmlConsumer.endElement(CopletTransformer.NAMESPACE_URI,
                                         CopletTransformer.LINK_ELEM,
                                         "coplet:" + CopletTransformer.LINK_ELEM);
@@ -131,4 +139,29 @@
         final String v = SourceUtil.absolutize(base, link);
         return v;
     }
+    
+    /**
+     * Determine if the element is an url and if the url points to some
+     * remote source. 
+     * 
+     * @param name the name of the element
+     * @param attributes the attributes of the element
+     * @return true if the href url is an anchor pointing to a remote source
+     */
+    protected boolean isRemoteAnchor(String name, Attributes attributes)
+    {
+      if ("a".equals(name))
+      {
+        String link = attributes.getValue("href");
+        
+        // no empty link to current document 
+        if (link != null && link.trim().length() > 0)
+        {
+          // check reference to document fragment
+          if (!link.trim().startsWith("#")) return true;
+        }        
+      }
+      
+      return false;
+    }
 }
= SNIP & SNAP ==================================================

PS: if this snippet does not survive bugzilla, I can mail it to you.

Mime
View raw message