On Thursday 25 March 2004 12:31, Carsten Ziegeler wrote:
> Jon Evans wrote:
> > I had another thought, the bogus links have href="#". Is it
> > worth also coding a specific workaround to prevent it from
> > touching links with href="#"?
>
> Hmm, don't know. If the browser does not send a new request to
> resolve the anchor, yes those links should not be encoded.
>
> Carsten
See BUG: 27904
I've a fix for it.
--
lg, Chris
--- 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;
+ }
}