Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 72777 invoked from network); 1 Oct 2002 18:27:44 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 1 Oct 2002 18:27:44 -0000 Received: (qmail 9001 invoked by uid 97); 1 Oct 2002 18:28:27 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 8922 invoked by uid 97); 1 Oct 2002 18:28:26 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 8896 invoked by uid 98); 1 Oct 2002 18:28:26 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) X-Server-Uuid: 6E802067-ECFC-4FC2-A617-DD5220DD9CBB Message-ID: <7382FCA44E27D411BD4A00508BD68F95053CD36D@pigeon.tumbleweed.com> From: "Martin Cooper" To: "'Jakarta Commons Developers List'" Subject: RE: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache /commons/jelly/tags/core FileTag.java Date: Tue, 1 Oct 2002 11:26:13 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) X-WSS-ID: 1187367C95309-01-01 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Never mind. I should catch up on commons-user before I react to commit messages... ;-} -- Martin Cooper > -----Original Message----- > From: Martin Cooper [mailto:martin.cooper@tumbleweed.com] > Sent: Tuesday, October 01, 2002 11:19 AM > To: 'Jakarta Commons Developers List' > Subject: RE: cvs commit: > jakarta-commons-sandbox/jelly/src/java/org/apache > /commons/jelly/tags/core FileTag.java > > > > > > -----Original Message----- > > From: jstrachan@apache.org [mailto:jstrachan@apache.org] > > Sent: Tuesday, October 01, 2002 9:45 AM > > To: jakarta-commons-sandbox-cvs@apache.org > > Subject: cvs commit: > > jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jell > y/tags/cor > > e FileTag.java > > > > > > jstrachan 2002/10/01 09:45:23 > > > > Modified: jelly/src/test/org/apache/commons/jelly suite.jelly > > jelly/src/java/org/apache/commons/jelly/tags/core > > FileTag.java > > Log: > > Added patch to so that a variable can be specified > > instead of a file name and the body will be turned into a > > variable string. > > > > Its not a brilliantly named tag but the following could > > generate some XML as a String > > > > > > > > > > > > > > I now have a value ${foo} > > I'm most likely misunderstanding what is all about, > but isn't the > above the same thing as this? > > > > > > > > -- > Martin Cooper > > > > > > Revision Changes Path > > 1.4 +10 -0 > > jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jell > y/suite.jelly > > > > Index: suite.jelly > > > =================================================================== > > RCS file: > > /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/co > mmons/jelly/suite.jelly,v > > retrieving revision 1.3 > > retrieving revision 1.4 > > diff -u -r1.3 -r1.4 > > --- suite.jelly 24 Sep 2002 11:39:50 -0000 1.3 > > +++ suite.jelly 1 Oct 2002 16:45:23 -0000 1.4 > > @@ -106,4 +106,14 @@ > > > > expected="org.apache.commons.jelly.define.Customer" > > actual="${customer.class.name}"/> > > > > + > > + > > + > > + hello > > + > > + > > + > + expected='<foo x="1">hello</foo>' > > + actual="${foo}"/> > > + > > > > > > > > > > 1.3 +60 -21 > > jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jell > y/tags/core/FileTag.java > > > > Index: FileTag.java > > > =================================================================== > > RCS file: > > /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/co > mmons/jelly/tags/core/FileTag.java,v > > retrieving revision 1.2 > > retrieving revision 1.3 > > diff -u -r1.2 -r1.3 > > --- FileTag.java 29 Jul 2002 18:14:21 -0000 1.2 > > +++ FileTag.java 1 Oct 2002 16:45:23 -0000 1.3 > > @@ -56,11 +56,12 @@ > > */ > > package org.apache.commons.jelly.tags.core; > > > > -import java.io.FileOutputStream; > > +import java.io.FileWriter; > > import java.io.IOException; > > -import java.io.OutputStream; > > +import java.io.StringWriter; > > +import java.io.Writer; > > > > -import org.apache.commons.jelly.MissingAttributeException; > > +import org.apache.commons.jelly.JellyException; > > import org.apache.commons.jelly.TagSupport; > > import org.apache.commons.jelly.XMLOutput; > > > > @@ -69,12 +70,13 @@ > > import org.dom4j.io.XMLWriter; > > > > /** > > - * A tag that pipes its body to a file. > > + * A tag that pipes its body to a file denoted by the name > > attribute or to an in memory String > > + * which is then output to a variable denoted by the var > variable. > > * > > * @author Vinay Chandran > > */ > > -public class FileTag extends TagSupport > > -{ > > +public class FileTag extends TagSupport { > > + private String var; > > private String name; > > private boolean omitXmlDeclaration = false; > > private String outputMode = "xml"; > > @@ -87,19 +89,22 @@ > > // Tag interface > > > > //------------------------------------------------------------ > > ------------- > > public void doTag(final XMLOutput output) throws Exception { > > - if ( name == null ) { > > - throw new MissingAttributeException( "name" ); > > + if ( name != null ) { > > + Writer writer = new FileWriter(name); > > + writeBody(writer); > > + } > > + else if (var != null) { > > + StringWriter writer = new StringWriter(); > > + writeBody(writer); > > + context.setVariable(var, writer.toString()); > > } > > - XMLOutput newOutput = createXMLOutput(); > > - try { > > - newOutput.startDocument(); > > - invokeBody(newOutput); > > - newOutput.endDocument(); > > - } > > - finally { > > - newOutput.close(); > > + else { > > + throw new JellyException( "This tag must have > > either the 'name' or the 'var' variables defined" ); > > } > > } > > + > > + // Properties > > + > > //------------------------------------------------------------ > > ------------- > > > > /** > > * Sets the file name for the output > > @@ -137,9 +142,45 @@ > > this.encoding = encoding; > > } > > > > + /** > > + * Returns the var. > > + * @return String > > + */ > > + public String getVar() { > > + return var; > > + } > > + > > + /** > > + * Sets the var. > > + * @param var The var to set > > + */ > > + public void setVar(String var) { > > + this.var = var; > > + } > > + > > // Implementation methods > > > > //------------------------------------------------------------ > > ------------- > > - protected XMLOutput createXMLOutput() throws Exception { > > + > > + /** > > + * Writes the body fo this tag to the given Writer > > + */ > > + protected void writeBody(Writer writer) throws Exception { > > + > > + XMLOutput newOutput = createXMLOutput(writer); > > + try { > > + newOutput.startDocument(); > > + invokeBody(newOutput); > > + newOutput.endDocument(); > > + } > > + finally { > > + newOutput.close(); > > + } > > + } > > + > > + /** > > + * A Factory method to create a new XMLOutput from the > > given Writer. > > + */ > > + protected XMLOutput createXMLOutput(Writer writer) > > throws Exception { > > > > OutputFormat format = null; > > if (prettyPrint) { > > @@ -155,12 +196,10 @@ > > format.setSuppressDeclaration(true); > > } > > > > - OutputStream out = new FileOutputStream(name); > > - > > boolean isHtml = outputMode != null && > > outputMode.equalsIgnoreCase( "html" ); > > final XMLWriter xmlWriter = (isHtml) > > - ? new HTMLWriter(out, format) > > - : new XMLWriter(out, format); > > + ? new HTMLWriter(writer, format) > > + : new XMLWriter(writer, format); > > > > XMLOutput answer = new XMLOutput() { > > public void close() throws IOException { > > > > > > > > > > -- > > To unsubscribe, e-mail: > > > > For additional commands, e-mail: > > > > > > > > > -- > To unsubscribe, e-mail: > > For additional commands, e-mail: > > > -- To unsubscribe, e-mail: For additional commands, e-mail: