You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/06/13 10:16:47 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly TestParser.java
jstrachan 2002/06/13 01:16:47
Modified: jelly/src/java/org/apache/commons/jelly/tags/core
CoreTagLibrary.java
jelly/src/java/org/apache/commons/jelly/impl
ScriptBlock.java
jelly/src/java/org/apache/commons/jelly TagSupport.java
jelly/src/test/org/apache/commons/jelly TestParser.java
Added: jelly/src/java/org/apache/commons/jelly/tags/core
WhitespaceTag.java
Log:
Removed unnecessary complication in ScriptBlock. I did add a List and an Array for speed but this led to complications in modifications to the List not being live. Have now removed the array so the list is live and things work more nicely.
Removed the minor hack added to TagSupport.trim() to get around the problem in ScriptBlock.
Defaulted whitespace trimming to true. Then any tag can explicitly turn off trimming via a trim="false" attribute.
Also added the new <whitespace> tag which will preserve whitespace inside its body.
Revision Changes Path
1.11 +7 -6 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
Index: CoreTagLibrary.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- CoreTagLibrary.java 5 Jun 2002 18:03:38 -0000 1.10
+++ CoreTagLibrary.java 13 Jun 2002 08:16:47 -0000 1.11
@@ -97,7 +97,8 @@
// extensions to JSTL
registerTag("expr", ExprTag.class);
- registerTag("new", NewTag.class);
+ registerTag("new", NewTag.class);
+ registerTag("whitespace", WhitespaceTag.class);
}
}
1.1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/WhitespaceTag.java
Index: WhitespaceTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTag.java,v 1.7 2002/06/12 20:38:37 werken Exp $
* $Revision: 1.7 $
* $Date: 2002/06/12 20:38:37 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: JellyTag.java,v 1.7 2002/06/12 20:38:37 werken Exp $
*/
package org.apache.commons.jelly.tags.core;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A simple tag used to preserve whitespace inside its body
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision: 1.7 $
*/
public class WhitespaceTag extends TagSupport {
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog( WhitespaceTag.class );
public WhitespaceTag() {
setTrim(false);
}
// Tag interface
//-------------------------------------------------------------------------
public void doTag(XMLOutput output) throws Exception {
if ( log.isDebugEnabled() ) {
log.debug( "Running body: " + getBody() );
}
getBody().run(context, output);
}
}
1.7 +17 -22 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java
Index: ScriptBlock.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ScriptBlock.java 17 May 2002 15:18:11 -0000 1.6
+++ ScriptBlock.java 13 Jun 2002 08:16:47 -0000 1.7
@@ -77,16 +77,9 @@
*/
public class ScriptBlock implements Script {
- private static final Script[] EMPTY_ARRAY = {
- };
-
/** The list of scripts */
private List list = new ArrayList();
- /** Compiled form uses arrays for speed
- * - no Iterator, object allocation or typecast */
- private Script[] scripts = EMPTY_ARRAY;
-
public ScriptBlock() {
}
@@ -104,12 +97,10 @@
list.remove(script);
}
- /** Gets the child scripts that make up this block */
- public Script[] getScripts() {
- return scripts;
- }
-
- /** Allows direct modification of the List of scripts */
+ /**
+ * Gets the child scripts that make up this block. This list is live
+ * so that it can be modified if requried
+ */
public List getScriptList() {
return list;
}
@@ -122,20 +113,24 @@
Script script = (Script) list.get(0);
return script.compile();
}
- scripts = new Script[size];
- list.toArray(scripts);
// now compile children
for (int i = 0; i < size; i++) {
- Script script = scripts[i];
- script.compile();
+ Script script = (Script) list.get(i);
+ list.set(i, script.compile());
}
return this;
}
/** Evaluates the body of a tag */
public void run(JellyContext context, XMLOutput output) throws Exception {
+/*
for (int i = 0, size = scripts.length; i < size; i++) {
Script script = scripts[i];
+ script.run(context, output);
+ }
+*/
+ for (Iterator iter = list.iterator(); iter.hasNext(); ) {
+ Script script = (Script) iter.next();
script.run(context, output);
}
}
1.9 +23 -27 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java
Index: TagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TagSupport.java 12 Jun 2002 19:28:08 -0000 1.8
+++ TagSupport.java 13 Jun 2002 08:16:47 -0000 1.9
@@ -107,37 +107,36 @@
return null;
}
- public TagSupport()
- {
+ public TagSupport() {
}
- public TagSupport(boolean shouldTrim)
- {
+ public TagSupport(boolean shouldTrim) {
setTrim( shouldTrim );
}
- public void setTrim(boolean shouldTrim)
- {
+ public void setTrim(boolean shouldTrim) {
if ( shouldTrim ) {
this.shouldTrim = Boolean.TRUE;
- } else {
+ }
+ else {
this.shouldTrim = Boolean.FALSE;
}
}
- public boolean getTrim()
- {
+ public boolean getTrim() {
if ( this.shouldTrim == null ) {
Tag parent = getParent();
if ( parent == null ) {
- return false;
- } else {
+ return true;
+ }
+ else {
if ( parent instanceof TagSupport ) {
TagSupport parentSupport = (TagSupport) parent;
this.shouldTrim = ( parentSupport.getTrim() ? Boolean.TRUE : Boolean.FALSE );
- } else {
- this.shouldTrim = Boolean.FALSE;
+ }
+ else {
+ this.shouldTrim = Boolean.TRUE;
}
}
}
@@ -209,8 +208,7 @@
* Find all text nodes inside the top level of this body and
* if they are just whitespace then remove them
*/
- protected void trimBody() { // throws Exception {
- // System.err.println( "trimBody() " + this.getClass().getName() );
+ protected void trimBody() {
if ( body instanceof ScriptBlock ) {
ScriptBlock block = (ScriptBlock) body;
List list = block.getScriptList();
@@ -220,14 +218,12 @@
TextScript textScript = (TextScript) script;
String text = textScript.getText();
text = text.trim();
- // if ( text.length() == 0 ) {
- // list.remove(i);
- // System.err.println( "removeText(" + i + ")" );
- // }
- // else {
- // System.err.println( "setText(" + text + ")" );
+ if ( text.length() == 0 ) {
+ list.remove(i);
+ }
+ else {
textScript.setText(text);
- // }
+ }
}
}
}
1.2 +4 -4 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestParser.java
Index: TestParser.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestParser.java 30 May 2002 14:27:07 -0000 1.1
+++ TestParser.java 13 Jun 2002 08:16:47 -0000 1.2
@@ -65,6 +65,7 @@
import java.io.InputStream;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
@@ -132,10 +133,9 @@
}
else if ( script instanceof ScriptBlock ) {
ScriptBlock block = (ScriptBlock) script;
- Script[] scripts = block.getScripts();
- for ( int i = 0; i < scripts.length; i++ ) {
- assertTagsHaveParent( scripts[i], parent );
+ for ( Iterator iter = block.getScriptList().iterator(); iter.hasNext(); ) {
+ assertTagsHaveParent( (Script) iter.next(), parent );
}
}
}
-}
+}
\ No newline at end of file
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>