You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by di...@apache.org on 2001/01/03 16:38:29 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/xml/dom DOMStreamer.java
dims 01/01/03 07:38:28
Modified: src/org/apache/cocoon/components/language/markup/xsp Tag:
xml-cocoon2 XSPObjectHelper.java
src/org/apache/cocoon/components/language/markup/xsp/java
Tag: xml-cocoon2 xsp.xsl
src/org/apache/cocoon/xml/dom Tag: xml-cocoon2
DOMStreamer.java
Added: src/org/apache/cocoon/xml Tag: xml-cocoon2 XMLFragment.java
Log:
Patch from Sylvain Wallez <sy...@anyware-tech.com> - "[C2][Patch] XMLFragment (again)"
Revision Changes Path
No revision
No revision
1.1.2.7 +220 -2 xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPObjectHelper.java
Index: XSPObjectHelper.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPObjectHelper.java,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- XSPObjectHelper.java 2000/12/08 20:39:04 1.1.2.6
+++ XSPObjectHelper.java 2001/01/03 15:38:02 1.1.2.7
@@ -7,19 +7,28 @@
*****************************************************************************/
package org.apache.cocoon.components.language.markup.xsp;
+import java.util.Collection;
+import java.util.Iterator;
+
import org.xml.sax.ContentHandler;
import org.xml.sax.helpers.AttributesImpl;
-
import org.xml.sax.SAXException;
+import org.w3c.dom.Node;
+
import org.apache.log.Logger;
import org.apache.log.LogKit;
+import org.apache.cocoon.xml.XMLFragment;
+import org.apache.cocoon.xml.dom.DOMStreamer;
+
/**
* Base class for XSP's object model manipulation logicsheets
*
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/12/08 20:39:04 $
+ * @author <a href="sylvain.wallez@anyware-tech.com">Sylvain Wallez</a>
+ * (Cocoon1 <code>xspExpr()</code> methods port)
+ * @version CVS $Revision: 1.1.2.7 $ $Date: 2001/01/03 15:38:02 $
*/
public class XSPObjectHelper {
/**
@@ -153,5 +162,214 @@
throws SAXException
{
contentHandler.characters(data.toCharArray(), 0, data.length());
+ }
+
+ // <xsp:expr> methods
+
+ /**
+ * Implementation of <xsp:expr> for <code>char</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, char v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>byte</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, byte v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>boolean</code> :
+ * outputs characters representing the value (true / false).
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, boolean v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>int</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, int v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>long</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, long v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>long</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, float v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>double</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, double v) throws SAXException
+ {
+ data(contentHandler, String.valueOf(v));
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>String</code> :
+ * outputs characters representing the value.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, String text) throws SAXException
+ {
+ if (text != null)
+ {
+ data(contentHandler, text);
+ }
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>XMLFragment</code> :
+ * outputs the value by calling <code>v.toSax(contentHandler)</code>.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the XML fragment
+ */
+ public static void xspExpr(ContentHandler contentHandler, XMLFragment v) throws SAXException
+ {
+ if (v != null)
+ {
+ v.toSAX(contentHandler);
+ }
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>org.w3c.dom.Node</code> :
+ * converts the Node to a SAX event stream.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, Node v) throws SAXException
+ {
+ if (v != null)
+ {
+ DOMStreamer streamer = new DOMStreamer(contentHandler);
+ streamer.stream(v);
+ }
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>java.util.Collection</code> :
+ * outputs the value by calling <code>xspExpr()</code> on each element of the
+ * collection.
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the XML fragment
+ */
+ public static void xspExpr(ContentHandler contentHandler, Collection v) throws SAXException
+ {
+ if (v != null)
+ {
+ Iterator iterator = v.iterator();
+ while (iterator.hasNext())
+ {
+ xspExpr(contentHandler, iterator.next());
+ }
+ }
+ }
+
+ /**
+ * Implementation of <xsp:expr> for <code>Object</code> depending on its class :
+ * <ul>
+ * <li>if it's an array, call <code>xspExpr()</code> on all its elements,</li>
+ * <li>if it's class has a specific <code>xspExpr()</code>implementation, use it,</li>
+ * <li>else, output it's string representation.</li>
+ * </ul>
+ *
+ * @param contentHandler the SAX content handler
+ * @param v the value
+ */
+ public static void xspExpr(ContentHandler contentHandler, Object v) throws SAXException
+ {
+ if (v == null)
+ {
+ return;
+ }
+
+ // Array: recurse over each element
+ if (v.getClass().isArray())
+ {
+ Object[] elements = (Object[]) v;
+
+ for (int i = 0; i < elements.length; i++)
+ {
+ xspExpr(contentHandler, elements[i]);
+ }
+ return;
+ }
+
+ // Check handled object types in case they were not typed in the XSP
+
+ // XMLFragment
+ if (v instanceof XMLFragment)
+ {
+ xspExpr(contentHandler, (XMLFragment)v);
+ return;
+ }
+
+ // Node
+ if (v instanceof Node)
+ {
+ xspExpr(contentHandler, (Node)v);
+ return;
+ }
+
+ // Collection
+ if (v instanceof Collection)
+ {
+ xspExpr(contentHandler, (Collection)v);
+ return;
+ }
+
+ // Give up: hope it's a string or has a meaningful string representation
+ data(contentHandler, String.valueOf(v));
}
}
No revision
No revision
1.1.2.19 +4 -3 xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/xsp.xsl
Index: xsp.xsl
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/xsp.xsl,v
retrieving revision 1.1.2.18
retrieving revision 1.1.2.19
diff -u -r1.1.2.18 -r1.1.2.19
--- xsp.xsl 2001/01/02 11:09:51 1.1.2.18
+++ xsp.xsl 2001/01/03 15:38:11 1.1.2.19
@@ -11,7 +11,7 @@
<!--
* @author <a href="mailto:ricardo@apache.org>Ricardo Rocha</a>
- * @version CVS $Revision: 1.1.2.18 $ $Date: 2001/01/02 11:09:51 $
+ * @version CVS $Revision: 1.1.2.19 $ $Date: 2001/01/03 15:38:11 $
-->
<!-- XSP Core logicsheet for the Java language -->
@@ -51,6 +51,7 @@
import org.apache.cocoon.util.*;
import org.apache.cocoon.components.language.markup.xsp.XSPGenerator;
+ import org.apache.cocoon.components.language.markup.xsp.XSPObjectHelper;
import org.apache.cocoon.components.language.markup.xsp.XSPRequestHelper;
import org.apache.cocoon.components.language.markup.xsp.XSPResponseHelper;
@@ -278,8 +279,8 @@
(<xsl:value-of select="."/>)
</xsl:when>
<xsl:otherwise>
- <!-- Coerce to String and output as character data -->
- this.characters(String.valueOf(<xsl:value-of select="."/>));
+ <!-- Output the value as elements or character data depending on its type -->
+ XSPObjectHelper.xspExpr(contentHandler, <xsl:value-of select="."/>);
</xsl:otherwise>
</xsl:choose>
</xsl:template>
No revision
No revision
1.1.2.1 +38 -0 xml-cocoon/src/org/apache/cocoon/xml/Attic/XMLFragment.java
No revision
No revision
1.1.2.3 +4 -2 xml-cocoon/src/org/apache/cocoon/xml/dom/Attic/DOMStreamer.java
Index: DOMStreamer.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/xml/dom/Attic/DOMStreamer.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- DOMStreamer.java 2000/12/08 20:41:03 1.1.2.2
+++ DOMStreamer.java 2001/01/03 15:38:23 1.1.2.3
@@ -37,7 +37,7 @@
*
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
- * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/12/08 20:41:03 $
+ * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/01/03 15:38:23 $
*/
public class DOMStreamer extends AbstractXMLProducer {
@@ -126,7 +126,9 @@
// Do nothing for ENTITY and NOTATION nodes
break;
case Node.DOCUMENT_FRAGMENT_NODE:
- throw new SAXException("Unexpected Document Fragment node");
+ // Process all children
+ processChildren(n);
+ break;
case Node.ATTRIBUTE_NODE:
throw new SAXException("Unexpected Attribute node");
default: