You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@apache.org on 2003/05/16 16:39:03 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/xml/xlink ExtendedXLinkPipe.java
stephan 2003/05/16 07:39:03
Modified: . status.xml
src/java/org/apache/cocoon/xml/xlink ExtendedXLinkPipe.java
Log:
Patch 19786 applied.
Revision Changes Path
1.35 +3 -0 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- status.xml 16 May 2003 13:35:56 -0000 1.34
+++ status.xml 16 May 2003 14:39:02 -0000 1.35
@@ -180,6 +180,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="SMS" type="update" fixes-bug="19786" due-to="Torsten Knodt" due-to-email="torstenknodt@datas-world.de">
+ Extended the ExtendedXLinkPipe to be more extensible. Prepared is html and p3p.
+ </action>
<action dev="SMS" type="update" fixes-bug="14986" due-to="Michael Homeijer" due-to-email="m.homeijer@devote.nl">
Patch velocity generator, so that the scope of objects can be specified (request, session, sitemap).
</action>
1.2 +68 -48 cocoon-2.1/src/java/org/apache/cocoon/xml/xlink/ExtendedXLinkPipe.java
Index: ExtendedXLinkPipe.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/xml/xlink/ExtendedXLinkPipe.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExtendedXLinkPipe.java 9 Mar 2003 00:09:48 -0000 1.1
+++ ExtendedXLinkPipe.java 16 May 2003 14:39:02 -0000 1.2
@@ -53,6 +53,10 @@
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
/**
* This class extends the XLink semantic capabilities to understand those
@@ -68,66 +72,82 @@
* be a way to remove this, that will be a happy day for XML and for Cocoon too.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:torstenknodt@datas-world.de">Torsten Knodt</a>
* @version CVS $Id$
*/
public abstract class ExtendedXLinkPipe extends XLinkPipe {
- public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException {
- if (uri != null) {
- // Get namespaced attributes
-
- String href = attr.getValue(uri, "href");
- if (href != null) {
- simpleLink(href, null, null, null, null, null, uri, name, raw, attr);
- return;
- }
-
- String src = attr.getValue(uri, "src");
- if (src != null) {
- simpleLink(src, null, null, null, null, null, uri, name, raw, attr);
- return;
- }
-
- String background = attr.getValue(uri, "background");
- if (background != null) {
- simpleLink(background, null, null, null, null, null, uri, name, raw, attr);
- return;
- }
- } else {
- uri = "";
- }
+ private static Set arrayToSet(Object[] array) {
+ final Set set = new HashSet(array.length);
- // Get attributes without namespace too
+ for (int i = 0; i<array.length; i++)
+ set.add(array[i]);
+ return set;
+ }
- String href = attr.getValue("", "href");
- if (href != null) {
- simpleLink(href, null, null, null, null, null, uri, name, raw, attr);
- return;
+ private final Map MAP = new HashMap() {
+ {
+ put("", arrayToSet(new String[] {
+ "about", "action", "background", "data", "discuri", "href",
+ "longdesc", "src"
+ }));
+ put("http://www.w3.org/1999/xhtml", arrayToSet(new String[] {
+ "action", "background", "data", "href", "longdesc", "src"
+ }));
+ put("http://www.w3.org/2002/01/P3Pv1",
+ arrayToSet(new String[]{ "about",
+ "discuri" }));
}
+ };
- String src = attr.getValue("", "src");
- if (src != null) {
- simpleLink(src, null, null, null, null, null, uri, name, raw, attr);
- return;
- }
+ private int attrIndex = -1;
- String background = attr.getValue("", "background");
- if (background != null) {
- simpleLink(background, null, null, null, null, null, uri, name, raw, attr);
- return;
+ public void startElement(String uri, final String name, final String raw,
+ final Attributes attr) throws SAXException {
+ final Set attrList = (Set) MAP.get((uri==null) ? "" : uri);
+
+ if (attrList!=null) {
+ for (int i = 0; i<attr.getLength(); i++)
+ if (attr.getURI(i).equals("") &&
+ attrList.contains(attr.getLocalName(i))) {
+ final String att = attr.getValue(i);
+
+ if (att!=null) {
+ final String str = ": URI="+uri+" NAME="+name+" RAW="+
+ raw+" ATT="+attr.getLocalName(i)+
+ " NS="+uri+" VALUE="+att;
+
+ if (attrIndex!=-1) {
+ getLogger().warn("Possible internal error"+str);
+ }
+ getLogger().debug("Transforming to XLink"+str);
+ attrIndex = i;
+ simpleLink(att, null, null, null, null, null, uri,
+ name, raw, attr);
+ return;
+ }
+ }
}
super.startElement(uri, name, raw, attr);
}
- public void simpleLink(String href, String role, String arcrole, String title, String show, String actuate, String uri, String name, String raw, Attributes attr) throws SAXException {
- AttributesImpl newattr = new AttributesImpl(attr);
- int hrefIndex = attr.getIndex(uri, "href");
- if (hrefIndex > -1) newattr.setValue(hrefIndex, href);
- int srcIndex = attr.getIndex(uri, "src");
- if (srcIndex > -1) newattr.setValue(srcIndex, href);
- int backgroundIndex = attr.getIndex(uri, "background");
- if (backgroundIndex > -1) newattr.setValue(backgroundIndex, href);
- super.startElement(uri, name, raw, newattr);
+ public void simpleLink(final String href, final String role,
+ final String arcrole, final String title,
+ final String show, final String actuate,
+ final String uri, final String name,
+ final String raw,
+ final Attributes attr) throws SAXException {
+ if (attrIndex!=-1) {
+ AttributesImpl newattr = new AttributesImpl(attr);
+
+ newattr.setValue(attrIndex, href);
+ attrIndex = -1;
+ super.startElement(uri, name, raw, newattr);
+ } else {
+ super.simpleLink(href, role, arcrole, title, show, actuate, uri,
+ name, raw, attr);
+ }
+
}
}