polx 2004/10/28 15:21:44
Modified: jelly/src/java/org/apache/commons/jelly XMLOutput.java
jelly/src/java/org/apache/commons/jelly/impl
ExpressionScript.java
jelly/src/java/org/apache/commons/jelly/tags/core
MuteTag.java
jelly/src/test/org/apache/commons/jelly TestXMLOutput.java
Log:
objectData is now used... namely... by Expression children.
This allows MuteTag to avoid the string of these expressions.
paul
Revision Changes Path
1.20 +15 -7
jakarta-commons/jelly/src/java/org/apache/commons/jelly/XMLOutput.java
Index: XMLOutput.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/XMLOutput.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- XMLOutput.java 28 Oct 2004 20:10:50 -0000 1.19
+++ XMLOutput.java 28 Oct 2004 22:21:43 -0000 1.20
@@ -51,17 +51,18 @@
/** empty attributes */
private static final Attributes EMPTY_ATTRIBUTES = new AttributesImpl();
+ /** The Log to which logging calls will be made. */
+ private static final Log log = LogFactory.getLog(XMLOutput.class);
+
+ /** the default for escaping of text */
+ private static final boolean DEFAULT_ESCAPE_TEXT = false;
+
/** The SAX ContentHandler that output goes to */
private ContentHandler contentHandler;
/** The SAX LexicalHandler that output goes to */
private LexicalHandler lexicalHandler;
- /** The Log to which logging calls will be made. */
- private static final Log log = LogFactory.getLog(XMLOutput.class);
-
- /** the default for escaping of text */
- private static final boolean DEFAULT_ESCAPE_TEXT = false;
public XMLOutput() {
}
@@ -786,7 +787,14 @@
* @exception SAXException The application may raise an exception.
*/
public void objectData(Object object) throws SAXException {
- // do nothing
+ String output=null;
+ if(object!=null) {
+ output=object.toString();
+ write(output);
+ } else {
+ // we could have a "configurable null-toString"...
+ write("null");
+ }
}
// Properties
1.9 +3 -3
jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/ExpressionScript.java
Index: ExpressionScript.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/impl/ExpressionScript.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ExpressionScript.java 9 Sep 2004 12:26:22 -0000 1.8
+++ ExpressionScript.java 28 Oct 2004 22:21:44 -0000 1.9
@@ -63,11 +63,11 @@
/** Evaluates the body of a tag */
public void run(JellyContext context, XMLOutput output) throws
JellyTagException {
- String text = expression.evaluateAsString(context);
- if ( text != null ) {
+ Object result = expression.evaluate(context);
+ if ( result != null ) {
try {
- output.write(text);
+ output.objectData(result);
} catch (SAXException e) {
throw new JellyTagException("Could not write to XMLOutput",e);
}
1.3 +16 -6
jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/MuteTag.java
Index: MuteTag.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/tags/core/MuteTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MuteTag.java 8 Sep 2004 04:35:22 -0000 1.2
+++ MuteTag.java 28 Oct 2004 22:21:44 -0000 1.3
@@ -38,12 +38,22 @@
public void doTag(XMLOutput output) throws JellyTagException {
- super.invokeBody(makeMuteOutput());
+ super.invokeBody(new MuteXMLOutput());
}
- private XMLOutput makeMuteOutput() {
- return new XMLOutput(new DefaultHandler());
- }
-
} // class TagSupport
+
+/**
+ * An XMLOutput which really outputs nothing, in particular, avoids calling
+ * toString() in objects returned...
+ */
+class MuteXMLOutput extends XMLOutput {
+ public MuteXMLOutput() {
+ super(new DefaultHandler());
+ }
+
+ public void objectData(Object o) {
+ // do nothing, not even invoke the toString!
+ }
+}
1.2 +11 -0
jakarta-commons/jelly/src/test/org/apache/commons/jelly/TestXMLOutput.java
Index: TestXMLOutput.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/TestXMLOutput.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestXMLOutput.java 27 Oct 2004 17:39:41 -0000 1.1
+++ TestXMLOutput.java 28 Oct 2004 22:21:44 -0000 1.2
@@ -67,4 +67,15 @@
assertEquals("<html></html>",bos.toString());
}
+ public void testOutputData() throws Exception {
+ setUpScript("outputData.jelly");
+ Script script = getJelly().compileScript();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ XMLOutput ouput = XMLOutput.createXMLOutput(bos);
+
+ script.run(getJellyContext(),ouput);
+ ouput.flush();
+ assertEquals("[string]",bos.toString().trim());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]