cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r124996 - in cocoon/trunk/src/blocks/template: java/org/apache/cocoon/template/jxtg java/org/apache/cocoon/template/jxtg/environment java/org/apache/cocoon/template/jxtg/expression java/org/apache/cocoon/template/jxtg/script java/org/apache/cocoon/template/jxtg/script/event test/org/apache/cocoon/components/expression test/org/apache/cocoon/environment test/org/apache/cocoon/template/jxtg
Date Wed, 12 Jan 2005 22:13:28 GMT
Author: danielf
Date: Wed Jan 12 14:13:27 2005
New Revision: 124996

URL: http://svn.apache.org/viewcvs?view=rev&rev=124996
Log:
Gathering expression functionality to JXTExpression.
Modified:
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java
   cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java
   cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java
   cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/JXTemplateGenerator.java	Wed Jan 12 14:13:27 2005
@@ -40,7 +40,6 @@
 import org.apache.cocoon.template.jxtg.environment.JXCacheKey;
 import org.apache.cocoon.template.jxtg.environment.JXSourceValidity;
 import org.apache.cocoon.template.jxtg.environment.MyVariables;
-import org.apache.cocoon.template.jxtg.environment.ValueHelper;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
 import org.apache.cocoon.template.jxtg.expression.MyJexlContext;
 import org.apache.cocoon.template.jxtg.script.Invoker;
@@ -290,8 +289,8 @@
         JXTExpression cacheKeyExpr = (JXTExpression) this.startDocument
                 .getTemplateProperty(JXTemplateGenerator.CACHE_KEY);
         try {
-            final Serializable templateKey = (Serializable) ValueHelper
-                    .getValue(cacheKeyExpr, globalJexlContext, jxpathContext);
+            final Serializable templateKey =
+                (Serializable) cacheKeyExpr.getValue(globalJexlContext, jxpathContext);
             if (templateKey != null) {
                 return new JXCacheKey(startDocument.getUri(), templateKey);
             }
@@ -312,8 +311,8 @@
         try {
             final SourceValidity sourceValidity = this.startDocument
                     .getSourceValidity();
-            final SourceValidity templateValidity = (SourceValidity) ValueHelper
-                    .getValue(validityExpr, globalJexlContext, jxpathContext);
+            final SourceValidity templateValidity =
+                (SourceValidity) validityExpr.getValue(globalJexlContext, jxpathContext);
             if (sourceValidity != null && templateValidity != null) {
                 return new JXSourceValidity(sourceValidity, templateValidity);
             }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/environment/ValueHelper.java	Wed Jan 12 14:13:27 2005
@@ -15,58 +15,14 @@
  */
 package org.apache.cocoon.template.jxtg.environment;
 
-import java.lang.reflect.InvocationTargetException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Locale;
 
-import org.apache.cocoon.template.jxtg.environment.JSIntrospector;
-import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.commons.jexl.Expression;
-import org.apache.commons.jexl.JexlContext;
-import org.apache.commons.jexl.util.Introspector;
-import org.apache.commons.jexl.util.introspection.Info;
-import org.apache.commons.jxpath.CompiledExpression;
-import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.lang.StringUtils;
-import org.mozilla.javascript.NativeArray;
-import org.w3c.dom.Node;
-import org.xml.sax.Locator;
 
 /**
  */
 public class ValueHelper {
 
-    private static final Iterator EMPTY_ITER = new Iterator() {
-        public boolean hasNext() {
-            return false;
-        }
-
-        public Object next() {
-            return null;
-        }
-
-        public void remove() {
-            // EMPTY
-        }
-    };
-
-    private static final Iterator NULL_ITER = new Iterator() {
-        public boolean hasNext() {
-            return true;
-        }
-
-        public Object next() {
-            return null;
-        }
-
-        public void remove() {
-            // EMPTY
-        }
-    };
-
     public static Locale parseLocale(String locale, String variant) {
         Locale ret = null;
         String language = locale;
@@ -90,182 +46,6 @@
         return ret;
     }
 
-    // Hack: try to prevent JXPath from converting result to a String
-    public static Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient)
-                throws Exception {
-        try {
-            Object compiled = expr.getCompiledExpression();
-            if (compiled instanceof CompiledExpression) {
-                CompiledExpression e = (CompiledExpression)compiled;
-                boolean oldLenient = jxpathContext.isLenient();
-                if (lenient != null) jxpathContext.setLenient(lenient.booleanValue());
-                try {
-                    Iterator iter = e.iteratePointers(jxpathContext);
-                    if (iter.hasNext()) {
-                        Pointer first = (Pointer)iter.next();
-                        if (iter.hasNext()) {
-                            List result = new LinkedList();
-                            result.add(first.getNode());
-                            boolean dom = (first.getNode() instanceof Node);
-                            while (iter.hasNext()) {
-                                Object obj = ((Pointer)iter.next()).getNode();
-                                dom = dom && (obj instanceof Node);
-                                result.add(obj);
-                            }
-                            Object[] arr;
-                            if (dom) {
-                                arr = new Node[result.size()];
-                            } else {
-                                arr = new Object[result.size()];
-                            }
-                            result.toArray(arr);
-                            return arr;
-                        }
-                        return first.getNode();                    
-                    }
-                    return null;
-                } finally {
-                    jxpathContext.setLenient(oldLenient);
-                }
-            } else if (compiled instanceof Expression) {
-                Expression e = (Expression)compiled;
-                return e.evaluate(jexlContext);
-            }
-            return expr.getRaw();
-        } catch (InvocationTargetException e) {
-            Throwable t = e.getTargetException();
-            if (t instanceof Exception) {
-                throw (Exception)t;
-            }
-            throw (Error)t;
-        }
-    }
-
-    public static Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
-        return getNode(expr, jexlContext, jxpathContext, null);
-    }
-
-    public static Iterator getIterator(final JXTExpression items, JexlContext jexlContext, JXPathContext jxpathContext, Locator loc) throws Exception {
-        Iterator iter = null;
-        if (items != null) {
-            if (items.getCompiledExpression() instanceof CompiledExpression) {
-                CompiledExpression compiledExpression = 
-                    (CompiledExpression) items.getCompiledExpression();
-                Object val =
-                    compiledExpression.getPointer(jxpathContext, items.getRaw()).getNode();
-                // FIXME: workaround for JXPath bug
-                iter =
-                    val instanceof NativeArray ?
-                    new JSIntrospector.NativeArrayIterator((NativeArray) val)
-                        : compiledExpression.iteratePointers(jxpathContext);
-            } else if (items.getCompiledExpression() instanceof Expression) {
-                Expression e = (Expression) items.getCompiledExpression();
-                Object result = e.evaluate(jexlContext);
-                if (result != null) {
-                    iter = Introspector.getUberspect().getIterator(
-                                                                   result,
-                                                                   new Info(
-                                                                            loc.getSystemId(),
-                                                                            loc.getLineNumber(),
-                                                                            loc.getColumnNumber()));
-                }
-                if (iter == null) {
-                    iter = EMPTY_ITER;
-                }
-            } else {
-                // literal value
-                iter = new Iterator() {
-                        Object val = items;
-                        
-                        public boolean hasNext() {
-                            return val != null;
-                        }
-                        
-                        public Object next() {
-                            Object res = val;
-                            val = null;
-                            return res;
-                        }
-                        
-                        public void remove() {
-                            // EMPTY
-                        }
-                    };
-            }
-        } else {
-            iter = NULL_ITER;
-        }
-        return iter;
-    }
-
-    public static Boolean getBooleanValue(JXTExpression expr, JexlContext jexlContext,
-                                    JXPathContext jxpathContext) throws Exception {
-        Object res = ValueHelper.getValue(expr, jexlContext, jxpathContext);
-        return res instanceof Boolean ? (Boolean)res : null;
-    }
-
-    public static String getStringValue(JXTExpression expr, JexlContext jexlContext,
-                                JXPathContext jxpathContext) throws Exception {
-        Object res = ValueHelper.getValue(expr, jexlContext, jxpathContext);
-        if (res != null) {
-            return res.toString();
-        }
-        if (expr != null && expr.getCompiledExpression() == null) {
-            return expr.getRaw();
-        }
-        return null;
-    }
-
-    public static Number getNumberValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
-        Object res = ValueHelper.getValue(expr, jexlContext, jxpathContext);
-        if (res instanceof Number) {
-            return (Number)res;
-        }
-        if (res != null) {
-            return Double.valueOf(res.toString());
-        }
-        return null;
-    }
-
-    public static int getIntValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
-        Object res = ValueHelper.getValue(expr, jexlContext, jxpathContext);
-        return res instanceof Number ? ((Number)res).intValue() : 0;
-    }
+}
 
-    public static Object getValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext) throws Exception {
-        return ValueHelper.getValue(expr, jexlContext, jxpathContext, null);
-    }
 
-    public static Object getValue(JXTExpression expr, JexlContext jexlContext,
-            JXPathContext jxpathContext, Boolean lenient) throws Exception {
-        if (expr != null) {
-            Object compiled = expr.getCompiledExpression();
-            try {
-                if (compiled instanceof CompiledExpression) {
-                    CompiledExpression e = (CompiledExpression) compiled;
-                    boolean oldLenient = jxpathContext.isLenient();
-                    if (lenient != null) {
-                        jxpathContext.setLenient(lenient.booleanValue());
-                    }
-                    try {
-                        return e.getValue(jxpathContext);
-                    } finally {
-                        jxpathContext.setLenient(oldLenient);
-                    }
-                } else if (compiled instanceof Expression) {
-                    Expression e = (Expression) compiled;
-                    return e.evaluate(jexlContext);
-                }
-                return compiled;
-            } catch (InvocationTargetException e) {
-                Throwable t = e.getTargetException();
-                if (t instanceof Exception) {
-                    throw (Exception) t;
-                }
-                throw (Error) t;
-            }
-        } else {
-            return null;
-        }
-    }
-}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/JXTExpression.java	Wed Jan 12 14:13:27 2005
@@ -15,8 +15,132 @@
  */
 package org.apache.cocoon.template.jxtg.expression;
 
+import java.io.IOException;
+import java.io.StringReader;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.JSIntrospector;
+import org.apache.commons.jexl.Expression;
+import org.apache.commons.jexl.ExpressionFactory;
+import org.apache.commons.jexl.JexlContext;
+import org.apache.commons.jexl.util.Introspector;
+import org.apache.commons.jexl.util.introspection.Info;
+import org.apache.commons.jxpath.CompiledExpression;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.Pointer;
+import org.mozilla.javascript.NativeArray;
+import org.w3c.dom.Node;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 public class JXTExpression extends Subst {
+
+    // Factory classes
+
+    public static JXTExpression compile(final String variable, boolean xpath)
+            throws Exception {
+        Object compiled;
+        if (xpath) {
+            compiled = JXPathContext.compile(variable);
+        } else {
+            compiled = ExpressionFactory.createExpression(variable);
+        }
+        return new JXTExpression(variable, compiled);
+    }
+
+    public static JXTExpression compileBoolean(String val, String msg,
+                                               Locator location) throws SAXException {
+        JXTExpression res = compileExpr(val, msg, location);
+        if (res.getCompiledExpression() == null && res.getRaw() != null) {
+            res.setCompiledExpression(Boolean.valueOf(res.getRaw()));
+        }
+        return res;
+    }
+
+    /*
+     * Compile an integer expression (returns either a Compiled Expression or an
+     * Integer literal)
+     */
+    public static JXTExpression compileInt(String val, String msg,
+            Locator location) throws SAXException {
+        JXTExpression res = compileExpr(val, msg, location);
+        if (res.getCompiledExpression() == null && res.getRaw() != null) {
+            res.setCompiledExpression(Integer.valueOf(res.getRaw()));
+        }
+        return res;
+    }
+
+    public static JXTExpression compileExpr(String inStr) throws Exception {
+        try {
+            if (inStr == null) {
+                return new JXTExpression(null, null);
+            }
+            StringReader in = new StringReader(inStr.trim());
+            int ch;
+            boolean xpath = false;
+            boolean inExpr = false;
+            StringBuffer expr = new StringBuffer();
+            while ((ch = in.read()) != -1) {
+                char c = (char) ch;
+                if (inExpr) {
+                    if (c == '\\') {
+                        ch = in.read();
+                        expr.append((ch == -1) ? '\\' : (char) ch);
+                    } else if (c == '}') {
+                        return compile(expr.toString(), xpath);
+                    } else {
+                        expr.append(c);
+                    }
+                } else {
+                    if (c == '$' || c == '#') {
+                        ch = in.read();
+                        if (ch == '{') {
+                            inExpr = true;
+                            xpath = c == '#';
+                            continue;
+                        }
+                    }
+                    // hack: invalid expression?
+                    // just return the original and swallow exception
+                    return new JXTExpression(inStr, null);
+                }
+            }
+            if (inExpr) {
+                // unclosed #{} or ${}
+                throw new Exception("Unterminated " + (xpath ? "#" : "$") + "{");
+            }
+        } catch (IOException ignored) {
+            ignored.printStackTrace();
+        }
+        return new JXTExpression(inStr, null);
+    }
+
+    /**
+     * Compile a single Jexl expr (contained in ${}) or XPath expression
+     * (contained in #{})
+     */
+
+    public static JXTExpression compileExpr(String expr, String errorPrefix,
+            Locator location) throws SAXParseException {
+        try {
+            return compileExpr(expr);
+        } catch (Exception exc) {
+            throw new SAXParseException(errorPrefix + exc.getMessage(),
+                    location, exc);
+        } catch (Error err) {
+            throw new SAXParseException(errorPrefix + err.getMessage(),
+                    location, new ErrorHolder(err));
+        }
+    }
+
+
+    // Members
+
     public JXTExpression(String raw, Object expr) {
         this.raw = raw;
         this.compiledExpression = expr;
@@ -25,15 +149,228 @@
     String raw;
     Object compiledExpression;
 
-    public Object getCompiledExpression() {
+    private Object getCompiledExpression() {
         return compiledExpression;
     }
 
-    public void setCompiledExpression(Object compiledExpression) {
+    private void setCompiledExpression(Object compiledExpression) {
         this.compiledExpression = compiledExpression;
     }
 
-    public String getRaw() {
+    private String getRaw() {
         return raw;
     }
-}
\ No newline at end of file
+
+    // Geting the value of the expression in various forms
+
+    // Hack: try to prevent JXPath from converting result to a String
+    public Object getNode(JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient)
+        throws Exception {
+        try {
+            Object compiled = this.getCompiledExpression();
+            if (compiled instanceof CompiledExpression) {
+                CompiledExpression e = (CompiledExpression)compiled;
+                boolean oldLenient = jxpathContext.isLenient();
+                if (lenient != null) jxpathContext.setLenient(lenient.booleanValue());
+                try {
+                    Iterator iter = e.iteratePointers(jxpathContext);
+                    if (iter.hasNext()) {
+                        Pointer first = (Pointer)iter.next();
+                        if (iter.hasNext()) {
+                            List result = new LinkedList();
+                            result.add(first.getNode());
+                            boolean dom = (first.getNode() instanceof Node);
+                            while (iter.hasNext()) {
+                                Object obj = ((Pointer)iter.next()).getNode();
+                                dom = dom && (obj instanceof Node);
+                                result.add(obj);
+                            }
+                            Object[] arr;
+                            if (dom) {
+                                arr = new Node[result.size()];
+                            } else {
+                                arr = new Object[result.size()];
+                            }
+                            result.toArray(arr);
+                            return arr;
+                        }
+                        return first.getNode();                    
+                    }
+                    return null;
+                } finally {
+                    jxpathContext.setLenient(oldLenient);
+                }
+            } else if (compiled instanceof Expression) {
+                Expression e = (Expression)compiled;
+                return e.evaluate(jexlContext);
+            }
+            return this.getRaw();
+        } catch (InvocationTargetException e) {
+            Throwable t = e.getTargetException();
+            if (t instanceof Exception) {
+                throw (Exception)t;
+            }
+            throw (Error)t;
+        }
+    }
+
+    public Object getNode(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        return getNode(jexlContext, jxpathContext, null);
+    }
+
+    public Iterator getIterator(JexlContext jexlContext, JXPathContext jxpathContext, Locator loc) throws Exception {
+        Iterator iter = null;
+        if (this.getCompiledExpression() != null || this.getRaw() != null) {
+            if (this.getCompiledExpression() instanceof CompiledExpression) {
+                CompiledExpression compiledExpression = 
+                    (CompiledExpression) this.getCompiledExpression();
+                Object val =
+                    compiledExpression.getPointer(jxpathContext, this.getRaw()).getNode();
+                // FIXME: workaround for JXPath bug
+                iter =
+                    val instanceof NativeArray ?
+                    new JSIntrospector.NativeArrayIterator((NativeArray) val)
+                        : compiledExpression.iteratePointers(jxpathContext);
+            } else if (this.getCompiledExpression() instanceof Expression) {
+                Expression e = (Expression) this.getCompiledExpression();
+                Object result = e.evaluate(jexlContext);
+                if (result != null) {
+                    iter = Introspector.getUberspect().getIterator(
+                                                                   result,
+                                                                   new Info(
+                                                                            loc.getSystemId(),
+                                                                            loc.getLineNumber(),
+                                                                            loc.getColumnNumber()));
+                }
+                if (iter == null) {
+                    iter = EMPTY_ITER;
+                }
+            } else {
+                // literal value
+                iter = new Iterator() {
+                        Object val = this;
+                        
+                        public boolean hasNext() {
+                            return val != null;
+                        }
+                        
+                        public Object next() {
+                            Object res = val;
+                            val = null;
+                            return res;
+                        }
+                        
+                        public void remove() {
+                            // EMPTY
+                        }
+                    };
+            }
+        } else {
+            iter = NULL_ITER;
+        }
+        return iter;
+    }
+
+    public Boolean getBooleanValue(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        Object res = getValue(jexlContext, jxpathContext);
+        return res instanceof Boolean ? (Boolean)res : null;
+    }
+
+    public String getStringValue(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        Object res = getValue(jexlContext, jxpathContext);
+        if (res != null) {
+            return res.toString();
+        }
+        if (this.getCompiledExpression() == null) {
+            return this.getRaw();
+        }
+        return null;
+    }
+
+    public Number getNumberValue(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        Object res = getValue(jexlContext, jxpathContext);
+        if (res instanceof Number) {
+            return (Number)res;
+        }
+        if (res != null) {
+            return Double.valueOf(res.toString());
+        }
+        return null;
+    }
+
+    public int getIntValue(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        Object res = getValue(jexlContext, jxpathContext);
+        return res instanceof Number ? ((Number)res).intValue() : 0;
+    }
+
+    public Object getValue(JexlContext jexlContext, JXPathContext jxpathContext)
+        throws Exception {
+        return getValue(jexlContext, jxpathContext, null);
+    }
+
+    public Object getValue(JexlContext jexlContext, JXPathContext jxpathContext,
+                                  Boolean lenient) throws Exception {
+        if (this.getCompiledExpression() != null) {
+            Object compiled = this.getCompiledExpression();
+            try {
+                if (compiled instanceof CompiledExpression) {
+                    CompiledExpression e = (CompiledExpression) compiled;
+                    boolean oldLenient = jxpathContext.isLenient();
+                    if (lenient != null) {
+                        jxpathContext.setLenient(lenient.booleanValue());
+                    }
+                    try {
+                        return e.getValue(jxpathContext);
+                    } finally {
+                        jxpathContext.setLenient(oldLenient);
+                    }
+                } else if (compiled instanceof Expression) {
+                    Expression e = (Expression) compiled;
+                    return e.evaluate(jexlContext);
+                }
+                return compiled;
+            } catch (InvocationTargetException e) {
+                Throwable t = e.getTargetException();
+                if (t instanceof Exception) {
+                    throw (Exception) t;
+                }
+                throw (Error) t;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    private static final Iterator EMPTY_ITER = new Iterator() {
+        public boolean hasNext() {
+            return false;
+        }
+
+        public Object next() {
+            return null;
+        }
+
+        public void remove() {
+            // EMPTY
+        }
+    };
+
+    private static final Iterator NULL_ITER = new Iterator() {
+        public boolean hasNext() {
+            return true;
+        }
+
+        public Object next() {
+            return null;
+        }
+
+        public void remove() {
+            // EMPTY
+        }
+    };
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java	Wed Jan 12 14:13:27 2005
@@ -26,7 +26,6 @@
 import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
 import org.apache.cocoon.template.jxtg.environment.LocatorFacade;
 import org.apache.cocoon.template.jxtg.environment.MyVariables;
-import org.apache.cocoon.template.jxtg.environment.ValueHelper;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
 import org.apache.cocoon.template.jxtg.expression.Literal;
 import org.apache.cocoon.template.jxtg.expression.MyJexlContext;
@@ -80,8 +79,7 @@
                     } else {
                         JXTExpression expr = (JXTExpression) subst;
                         try {
-                            Object val = ValueHelper.getNode(expr, jexlContext,
-                                    jxpathContext);
+                            Object val = expr.getNode(jexlContext, jxpathContext);
                             if (val instanceof Node) {
                                 executeDOM(consumer, (Node) val);
                                 continue;
@@ -141,14 +139,13 @@
                 StartIf startIf = (StartIf) ev;
                 Object val;
                 try {
-                    val = ValueHelper.getValue(startIf.getTest(), jexlContext,
-                            jxpathContext, Boolean.TRUE);
+                    val = startIf.getTest().getValue(jexlContext, jxpathContext,
+                                                     Boolean.TRUE);
                 } catch (Exception e) {
-                    throw new SAXParseException(e.getMessage(), ev
-                            .getLocation(), e);
+                    throw new SAXParseException(e.getMessage(), ev.getLocation(), e);
                 } catch (Error err) {
-                    throw new SAXParseException(err.getMessage(), ev
-                            .getLocation(), new ErrorHolder(err));
+                    throw new SAXParseException(err.getMessage(), ev.getLocation(),
+                                                new ErrorHolder(err));
                 }
                 boolean result = false;
                 if (val instanceof Boolean) {
@@ -167,22 +164,20 @@
                 int begin, end, step;
                 String var, varStatus;
                 try {
-                    iter = ValueHelper.getIterator(items,
-                                                   jexlContext, jxpathContext,
-                                                   ev.getLocation());
-                    begin = startForEach.getBegin() == null ? 0 : ValueHelper
-                            .getIntValue(startForEach.getBegin(), jexlContext,
-                                    jxpathContext);
-                    end = startForEach.getEnd() == null ? Integer.MAX_VALUE
-                            : ValueHelper.getIntValue(startForEach.getEnd(),
-                                    jexlContext, jxpathContext);
-                    step = startForEach.getStep() == null ? 1 : ValueHelper
-                            .getIntValue(startForEach.getStep(), jexlContext,
-                                    jxpathContext);
-                    var = ValueHelper.getStringValue(startForEach.getVar(),
-                            jexlContext, jxpathContext);
-                    varStatus = ValueHelper.getStringValue(startForEach
-                            .getVarStatus(), jexlContext, jxpathContext);
+                    iter = items.getIterator(jexlContext, jxpathContext,
+                                             ev.getLocation());
+                    begin = startForEach.getBegin() == null
+                        ? 0
+                        : startForEach.getBegin().getIntValue(jexlContext, jxpathContext);
+                    end = startForEach.getEnd() == null
+                        ? Integer.MAX_VALUE
+                        : startForEach.getEnd().getIntValue(jexlContext, jxpathContext);
+                    step = startForEach.getStep() == null
+                        ? 1
+                        : startForEach.getStep().getIntValue(jexlContext, jxpathContext);
+                    var = startForEach.getVar().getStringValue(jexlContext, jxpathContext);
+                    varStatus =
+                        startForEach.getVarStatus().getStringValue(jexlContext, jxpathContext);
                 } catch (Exception exc) {
                     throw new SAXParseException(exc.getMessage(), ev
                             .getLocation(), exc);
@@ -259,11 +254,10 @@
                 while (startWhen != null) {
                     Object val;
                     try {
-                        val = ValueHelper.getValue(startWhen.getTest(),
-                                jexlContext, jxpathContext, Boolean.TRUE);
+                        val = startWhen.getTest().getValue(jexlContext, jxpathContext,
+                                                           Boolean.TRUE);
                     } catch (Exception e) {
-                        throw new SAXParseException(e.getMessage(), ev
-                                .getLocation(), e);
+                        throw new SAXParseException(e.getMessage(), ev.getLocation(), e);
                     }
                     boolean result;
                     if (val instanceof Boolean) {
@@ -292,16 +286,13 @@
                 String var = null;
                 try {
                     if (startSet.getVar() != null) {
-                        var = ValueHelper.getStringValue(startSet.getVar(),
-                                jexlContext, jxpathContext);
+                        var = startSet.getVar().getStringValue(jexlContext, jxpathContext);
                     }
                     if (startSet.getValue() != null) {
-                        value = ValueHelper.getNode(startSet.getValue(),
-                                jexlContext, jxpathContext);
+                        value = startSet.getValue().getNode(jexlContext, jxpathContext);
                     }
                 } catch (Exception exc) {
-                    throw new SAXParseException(exc.getMessage(), ev
-                            .getLocation(), exc);
+                    throw new SAXParseException(exc.getMessage(), ev.getLocation(), exc);
                 }
                 if (value == null) {
                     NodeList nodeList = toDOMNodeList("set", startSet,
@@ -343,8 +334,7 @@
                                         .getSubstitutions().get(0);
                                 Object val;
                                 try {
-                                    val = ValueHelper.getNode(expr,
-                                            jexlContext, jxpathContext);
+                                    val = expr.getNode(jexlContext, jxpathContext);
                                 } catch (Exception e) {
                                     throw new SAXParseException(e.getMessage(),
                                             ev.getLocation(), e);
@@ -367,8 +357,7 @@
                                         JXTExpression expr = (JXTExpression) subst;
                                         Object val;
                                         try {
-                                            val = ValueHelper.getValue(expr,
-                                                    jexlContext, jxpathContext);
+                                            val = expr.getValue(jexlContext, jxpathContext);
                                         } catch (Exception e) {
                                             throw new SAXParseException(e
                                                     .getMessage(), ev
@@ -447,8 +436,7 @@
                                 JXTExpression expr = (JXTExpression) subst;
                                 Object val;
                                 try {
-                                    val = ValueHelper.getValue(expr,
-                                            jexlContext, jxpathContext);
+                                    val = expr.getValue(jexlContext, jxpathContext);
                                 } catch (Exception e) {
                                     throw new SAXParseException(e.getMessage(),
                                             ev.getLocation(), e);
@@ -549,8 +537,8 @@
                 StartOut startOut = (StartOut) ev;
                 Object val;
                 try {
-                    val = ValueHelper.getNode(startOut.getCompiledExpression(),
-                            jexlContext, jxpathContext, startOut.getLenient());
+                    val = startOut.getCompiledExpression().getNode(jexlContext, jxpathContext,
+                                                                   startOut.getLenient());
                     if (val instanceof Node) {
                         executeDOM(consumer, (Node) val);
                     } else if (val instanceof NodeList) {
@@ -585,8 +573,7 @@
                 StartEval startEval = (StartEval) ev;
                 JXTExpression expr = startEval.getValue();
                 try {
-                    Object val = ValueHelper.getNode(expr, jexlContext,
-                            jxpathContext);
+                    Object val = expr.getNode(jexlContext, jxpathContext);
                     if (!(val instanceof StartElement)) {
                         throw new Exception(
                                 "macro invocation required instead of: " + val);
@@ -644,8 +631,7 @@
                             JXTExpression expr = (JXTExpression) subst;
                             Object val;
                             try {
-                                val = ValueHelper.getValue(expr, jexlContext,
-                                        jxpathContext);
+                                val = expr.getValue(jexlContext, jxpathContext);
                             } catch (Exception exc) {
                                 throw new SAXParseException(exc.getMessage(),
                                         ev.getLocation(), exc);
@@ -669,12 +655,10 @@
                 MyJexlContext selectJexl = jexlContext;
                 if (startImport.getSelect() != null) {
                     try {
-                        Object obj = ValueHelper.getValue(startImport
-                                .getSelect(), jexlContext, jxpathContext);
-                        selectJXPath = jxpathContextFactory.newContext(null,
-                                obj);
-                        selectJXPath.setVariables(jxpathContext
-                                .getVariables());
+                        Object obj =
+                            startImport.getSelect().getValue(jexlContext, jxpathContext);
+                        selectJXPath = jxpathContextFactory.newContext(null, obj);
+                        selectJXPath.setVariables(jxpathContext.getVariables());
                         selectJexl = new MyJexlContext(jexlContext);
                         JXTemplateGenerator.fillContext(obj, selectJexl);
                     } catch (Exception exc) {
@@ -728,9 +712,8 @@
             } else {
                 JXTExpression expr = (JXTExpression) subst;
                 try {
-                    Object val = ValueHelper.getValue(expr, executionContext
-                            .getJexlContext(), executionContext
-                            .getJXPathContext());
+                    Object val = expr.getValue(executionContext.getJexlContext(),
+                                               executionContext.getJXPathContext());
                     chars = val != null ? val.toString().toCharArray()
                             : ArrayUtils.EMPTY_CHAR_ARRAY;
                 } catch (Exception e) {

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java	Wed Jan 12 14:13:27 2005
@@ -15,16 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script;
 
-import java.io.IOException;
-import java.io.StringReader;
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.JXTemplateGenerator;
-import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
 import org.apache.cocoon.template.jxtg.script.event.*;
-import org.apache.commons.jexl.ExpressionFactory;
-import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.lang.StringUtils;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
@@ -184,8 +179,8 @@
             if (StringUtils.equals(attributeURI, JXTemplateGenerator.NS)) {
                 getStartEvent().getTemplateProperties().put(
                         elementAttributes.getLocalName(i),
-                        compileExpr(elementAttributes.getValue(i), null,
-                                locator));
+                        JXTExpression.compileExpr(elementAttributes.getValue(i), null,
+                                                  locator));
                 elementAttributes.removeAttribute(i--);
             }
         }
@@ -267,106 +262,9 @@
     public void startEntity(String name) throws SAXException {
         addEvent(new StartEntity(locator, name));
     }
+}
 
-    public static JXTExpression compile(final String variable, boolean xpath)
-            throws Exception {
-        Object compiled;
-        if (xpath) {
-            compiled = JXPathContext.compile(variable);
-        } else {
-            compiled = ExpressionFactory.createExpression(variable);
-        }
-        return new JXTExpression(variable, compiled);
-    }
 
-    public static JXTExpression compileBoolean(String val, String msg,
-            Locator location) throws SAXException {
-        JXTExpression res = compileExpr(val, msg, location);
-        if (res != null) {
-            if (res.getCompiledExpression() == null) {
-                res.setCompiledExpression(Boolean.valueOf(res.getRaw()));
-            }
-            return res;
-        }
-        return null;
-    }
 
-    /*
-     * Compile an integer expression (returns either a Compiled Expression or an
-     * Integer literal)
-     */
-    public static JXTExpression compileInt(String val, String msg,
-            Locator location) throws SAXException {
-        JXTExpression res = compileExpr(val, msg, location);
-        if (res != null) {
-            if (res.getCompiledExpression() == null) {
-                res.setCompiledExpression(Integer.valueOf(res.getRaw()));
-            }
-            return res;
-        }
-        return null;
-    }
 
-    public static JXTExpression compileExpr(String inStr) throws Exception {
-        try {
-            if (inStr == null) {
-                return null;
-            }
-            StringReader in = new StringReader(inStr.trim());
-            int ch;
-            boolean xpath = false;
-            boolean inExpr = false;
-            StringBuffer expr = new StringBuffer();
-            while ((ch = in.read()) != -1) {
-                char c = (char) ch;
-                if (inExpr) {
-                    if (c == '\\') {
-                        ch = in.read();
-                        expr.append((ch == -1) ? '\\' : (char) ch);
-                    } else if (c == '}') {
-                        return compile(expr.toString(), xpath);
-                    } else {
-                        expr.append(c);
-                    }
-                } else {
-                    if (c == '$' || c == '#') {
-                        ch = in.read();
-                        if (ch == '{') {
-                            inExpr = true;
-                            xpath = c == '#';
-                            continue;
-                        }
-                    }
-                    // hack: invalid expression?
-                    // just return the original and swallow exception
-                    return new JXTExpression(inStr, null);
-                }
-            }
-            if (inExpr) {
-                // unclosed #{} or ${}
-                throw new Exception("Unterminated " + (xpath ? "#" : "$") + "{");
-            }
-        } catch (IOException ignored) {
-            ignored.printStackTrace();
-        }
-        return new JXTExpression(inStr, null);
-    }
 
-    /**
-     * Compile a single Jexl expr (contained in ${}) or XPath expression
-     * (contained in #{})
-     */
-
-    public static JXTExpression compileExpr(String expr, String errorPrefix,
-            Locator location) throws SAXParseException {
-        try {
-            return compileExpr(expr);
-        } catch (Exception exc) {
-            throw new SAXParseException(errorPrefix + exc.getMessage(),
-                    location, exc);
-        } catch (Error err) {
-            throw new SAXParseException(errorPrefix + err.getMessage(),
-                    location, new ErrorHolder(err));
-        }
-    }
-}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java	Wed Jan 12 14:13:27 2005
@@ -23,7 +23,6 @@
 import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
 import org.apache.cocoon.template.jxtg.expression.Literal;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -64,7 +63,7 @@
                                 String str = buf.toString();
                                 JXTExpression compiledExpression;
                                 try {
-                                    compiledExpression = Parser.compile(str,
+                                    compiledExpression = JXTExpression.compile(str,
                                             xpath);
                                 } catch (Exception exc) {
                                     throw new SAXParseException(exc
@@ -171,4 +170,4 @@
         this.endElement = endElement;
 
     }
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
@@ -31,7 +30,7 @@
         super(raw);
 
         String select = attrs.getValue("select");
-        this.value = Parser.compileExpr(select, "eval: \"select\":", getLocation());
+        this.value = JXTExpression.compileExpr(select, "eval: \"select\":", getLocation());
     }
 
     public JXTExpression getValue() {

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -44,11 +43,11 @@
 
         String items = attrs.getValue("items");
         String select = attrs.getValue("select");
-        this.var = Parser.compileExpr(attrs.getValue("var"), null, locator);
-        this.varStatus = Parser.compileExpr(attrs.getValue("varStatus"), null, locator);
-        this.begin = Parser.compileInt(attrs.getValue("begin"), name, locator);
-        this.end = Parser.compileInt(attrs.getValue("end"), name, locator);
-        this.step = Parser.compileInt(attrs.getValue("step"), name, locator);
+        this.var = JXTExpression.compileExpr(attrs.getValue("var"), null, locator);
+        this.varStatus = JXTExpression.compileExpr(attrs.getValue("varStatus"), null, locator);
+        this.begin = JXTExpression.compileInt(attrs.getValue("begin"), name, locator);
+        this.end = JXTExpression.compileInt(attrs.getValue("end"), name, locator);
+        this.step = JXTExpression.compileInt(attrs.getValue("step"), name, locator);
         String lenientValue = attrs.getValue("lenient");
         this.lenient = (lenientValue == null) ? null : Boolean.valueOf(lenientValue);
 
@@ -61,7 +60,7 @@
             throw new SAXParseException("forEach: only one of \"select\" or \"items\" may be specified",
                                         locator, null);
         }
-        this.items = Parser.compileExpr(items == null ? select : items, null, locator);
+        this.items = JXTExpression.compileExpr(items == null ? select : items, null, locator);
     }
 
     public JXTExpression getBegin() {

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java	Wed Jan 12 14:13:27 2005
@@ -23,7 +23,6 @@
 
 import org.apache.cocoon.template.jxtg.environment.ValueHelper;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.apache.commons.jexl.JexlContext;
 import org.apache.commons.jxpath.JXPathContext;
 import org.xml.sax.Attributes;
@@ -52,30 +51,27 @@
 
         Locator locator = getLocation();
 
-        this.var = Parser.compileExpr(attrs.getValue("var"), null, locator);
-        this.value = Parser.compileExpr(attrs.getValue("value"), null, locator);
-        this.type = Parser.compileExpr(attrs.getValue("type"), null, locator);
-        this.pattern = Parser.compileExpr(attrs.getValue("pattern"), null, locator);
-        this.timeZone = Parser.compileExpr(attrs.getValue("timeZone"), null, locator);
-        this.dateStyle = Parser.compileExpr(attrs.getValue("dateStyle"), null, locator);
-        this.timeStyle = Parser.compileExpr(attrs.getValue("timeStyle"), null, locator);
-        this.locale = Parser.compileExpr(attrs.getValue("locale"), null, locator);
+        this.var = JXTExpression.compileExpr(attrs.getValue("var"), null, locator);
+        this.value = JXTExpression.compileExpr(attrs.getValue("value"), null, locator);
+        this.type = JXTExpression.compileExpr(attrs.getValue("type"), null, locator);
+        this.pattern = JXTExpression.compileExpr(attrs.getValue("pattern"), null, locator);
+        this.timeZone = JXTExpression.compileExpr(attrs.getValue("timeZone"), null, locator);
+        this.dateStyle = JXTExpression.compileExpr(attrs.getValue("dateStyle"), null, locator);
+        this.timeStyle = JXTExpression.compileExpr(attrs.getValue("timeStyle"), null, locator);
+        this.locale = JXTExpression.compileExpr(attrs.getValue("locale"), null, locator);
     }
 
     public String format(JexlContext jexl, JXPathContext jxp) throws Exception {
-        String var = ValueHelper.getStringValue(this.var, jexl, jxp);
-        Object value = ValueHelper.getValue(this.value, jexl, jxp);
-        Object locVal = ValueHelper.getValue(this.locale, jexl, jxp);
-        String pattern = ValueHelper.getStringValue(this.pattern, jexl,
+        String var = this.var.getStringValue(jexl, jxp);
+        Object value = this.value.getValue(jexl, jxp);
+        Object locVal = this.locale.getValue(jexl, jxp);
+        String pattern = this.pattern.getStringValue(jexl,
                 jxp);
-        Object timeZone = ValueHelper
-                .getValue(this.timeZone, jexl, jxp);
+        Object timeZone = this.timeZone.getValue(jexl, jxp);
 
-        String type = ValueHelper.getStringValue(this.type, jexl, jxp);
-        String timeStyle = ValueHelper.getStringValue(this.timeStyle,
-                jexl, jxp);
-        String dateStyle = ValueHelper.getStringValue(this.dateStyle,
-                jexl, jxp);
+        String type = this.type.getStringValue(jexl, jxp);
+        String timeStyle = this.timeStyle.getStringValue(jexl, jxp);
+        String dateStyle = this.dateStyle.getStringValue(jexl, jxp);
 
         String formatted = null;
 

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java	Wed Jan 12 14:13:27 2005
@@ -24,7 +24,6 @@
 
 import org.apache.cocoon.template.jxtg.environment.ValueHelper;
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.apache.commons.jexl.JexlContext;
 import org.apache.commons.jxpath.JXPathContext;
 import org.apache.commons.lang.StringUtils;
@@ -69,53 +68,44 @@
 
         Locator locator = getLocation();
 
-        this.value = Parser.compileExpr(attrs.getValue("value"), null, locator);
-        this.type = Parser.compileExpr(attrs.getValue("type"), null, locator);
-        this.pattern = Parser.compileExpr(attrs.getValue("pattern"), null, locator);
+        this.value = JXTExpression.compileExpr(attrs.getValue("value"), null, locator);
+        this.type = JXTExpression.compileExpr(attrs.getValue("type"), null, locator);
+        this.pattern = JXTExpression.compileExpr(attrs.getValue("pattern"), null, locator);
         this.currencyCode =
-            Parser.compileExpr(attrs.getValue("currencyCode"), null, locator);
+            JXTExpression.compileExpr(attrs.getValue("currencyCode"), null, locator);
         this.currencySymbol =
-            Parser.compileExpr(attrs.getValue("currencySymbol"), null, locator);
+            JXTExpression.compileExpr(attrs.getValue("currencySymbol"), null, locator);
         this.isGroupingUsed =
-            Parser.compileBoolean(attrs.getValue("isGroupingUsed"), null, locator);
+            JXTExpression.compileBoolean(attrs.getValue("isGroupingUsed"), null, locator);
         this.maxIntegerDigits =
-            Parser.compileInt(attrs.getValue("maxIntegerDigits"), null, locator);
+            JXTExpression.compileInt(attrs.getValue("maxIntegerDigits"), null, locator);
         this.minIntegerDigits =
-            Parser.compileInt(attrs.getValue("minIntegerDigits"), null, locator);
+            JXTExpression.compileInt(attrs.getValue("minIntegerDigits"), null, locator);
         this.maxFractionDigits =
-            Parser.compileInt(attrs.getValue("maxFractionDigits"), null, locator);
+            JXTExpression.compileInt(attrs.getValue("maxFractionDigits"), null, locator);
         this.minFractionDigits =
-            Parser.compileInt(attrs.getValue("minFractionDigits"), null, locator);
-        this.locale = Parser.compileExpr(attrs.getValue("locale"), null, locator);
-        this.var = Parser.compileExpr(attrs.getValue("var"), null, locator);
+            JXTExpression.compileInt(attrs.getValue("minFractionDigits"), null, locator);
+        this.locale = JXTExpression.compileExpr(attrs.getValue("locale"), null, locator);
+        this.var = JXTExpression.compileExpr(attrs.getValue("var"), null, locator);
     }
 
     public String format(JexlContext jexl, JXPathContext jxp) throws Exception {
         // Determine formatting locale
-        String var = ValueHelper.getStringValue(this.var, jexl, jxp);
-        Number input = ValueHelper
-                .getNumberValue(this.value, jexl, jxp);
-        String type = ValueHelper.getStringValue(this.type, jexl, jxp);
-        String pattern = ValueHelper.getStringValue(this.pattern, jexl,
-                jxp);
-        String currencyCode = ValueHelper.getStringValue(
-                this.currencyCode, jexl, jxp);
-        String currencySymbol = ValueHelper.getStringValue(
-                this.currencySymbol, jexl, jxp);
-        Boolean isGroupingUsed = ValueHelper.getBooleanValue(
-                this.isGroupingUsed, jexl, jxp);
-        Number maxIntegerDigits = ValueHelper.getNumberValue(
-                this.maxIntegerDigits, jexl, jxp);
-        Number minIntegerDigits = ValueHelper.getNumberValue(
-                this.minIntegerDigits, jexl, jxp);
-        Number maxFractionDigits = ValueHelper.getNumberValue(
-                this.maxFractionDigits, jexl, jxp);
-        Number minFractionDigits = ValueHelper.getNumberValue(
-                this.minFractionDigits, jexl, jxp);
-        String localeStr = ValueHelper.getStringValue(this.locale,
-                jexl, jxp);
-        Locale loc = localeStr != null ? ValueHelper.parseLocale(
-                localeStr, null) : Locale.getDefault();
+        String var = this.var.getStringValue(jexl, jxp);
+        Number input = this.value.getNumberValue(jexl, jxp);
+        String type = this.type.getStringValue(jexl, jxp);
+        String pattern = this.pattern.getStringValue(jexl, jxp);
+        String currencyCode = this.currencyCode.getStringValue(jexl, jxp);
+        String currencySymbol = this.currencySymbol.getStringValue(jexl, jxp);
+        Boolean isGroupingUsed = this.isGroupingUsed.getBooleanValue(jexl, jxp);
+        Number maxIntegerDigits = this.maxIntegerDigits.getNumberValue(jexl, jxp);
+        Number minIntegerDigits = this.minIntegerDigits.getNumberValue(jexl, jxp);
+        Number maxFractionDigits = this.maxFractionDigits.getNumberValue(jexl, jxp);
+        Number minFractionDigits = this.minFractionDigits.getNumberValue(jexl, jxp);
+        String localeStr = this.locale.getStringValue(jexl, jxp);
+        Locale loc = localeStr != null
+            ? ValueHelper.parseLocale(localeStr, null)
+            : Locale.getDefault();
         String formatted;
         if (loc != null) {
             // Create formatter

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -35,7 +34,7 @@
         Locator locator = getLocation();
         String test = attrs.getValue("test");
         if (test != null) {
-            this.test = Parser.compileExpr(test, "if: \"test\": ", locator);
+            this.test = JXTExpression.compileExpr(test, "if: \"test\": ", locator);
         } else {
             throw new SAXParseException("if: \"test\" is required", locator, null);
         }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java	Wed Jan 12 14:13:27 2005
@@ -19,7 +19,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -52,7 +51,7 @@
             // as the context object in the imported template
             String context = attrs.getValue("context");
             if (context != null) {
-                select = Parser.compileExpr(context, "import: \"context\": ", locator);
+                select = JXTExpression.compileExpr(context, "import: \"context\": ", locator);
             }
         } else {
             throw new SAXParseException("import: \"uri\" is required", locator, null);

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -35,7 +34,8 @@
         Locator locator = getLocation();
         String value = attrs.getValue("value");
         if (value != null) {
-            this.compiledExpression = Parser.compileExpr(value, "out: \"value\": ", locator);
+            this.compiledExpression =
+                JXTExpression.compileExpr(value, "out: \"value\": ", locator);
             String lenientValue = attrs.getValue("lenient");
             this.lenient = lenientValue == null ? null : Boolean.valueOf(lenientValue);
         } else {

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -39,10 +38,10 @@
         JXTExpression varExpr = null;
         JXTExpression valueExpr = null;
         if (var != null) {
-            varExpr = Parser.compileExpr(var, "set: \"var\":", locator);
+            varExpr = JXTExpression.compileExpr(var, "set: \"var\":", locator);
         }
         if (value != null) {
-            valueExpr = Parser.compileExpr(value, "set: \"value\":", locator);
+            valueExpr = JXTExpression.compileExpr(value, "set: \"value\":", locator);
         }
         this.var = varExpr;
         this.value = valueExpr;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java&r1=124995&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java	Wed Jan 12 14:13:27 2005
@@ -18,7 +18,6 @@
 import java.util.Stack;
 
 import org.apache.cocoon.template.jxtg.expression.JXTExpression;
-import org.apache.cocoon.template.jxtg.script.Parser;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -40,7 +39,7 @@
         }
         String test = attrs.getValue("test");
         if (test != null) {
-            this.test = Parser.compileExpr(test, "when: \"test\": ", locator);
+            this.test = JXTExpression.compileExpr(test, "when: \"test\": ", locator);
             
             StartChoose startChoose = (StartChoose) stack.peek();
             if (startChoose.getFirstChoice() != null) {

Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java&r1=124995&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java	(original)
+++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/components/expression/ExpressionTestCase.java	Wed Jan 12 14:13:27 2005
@@ -15,10 +15,17 @@
  */
 package org.apache.cocoon.components.expression;
 
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.cocoon.CocoonTestCase;
 
 public class ExpressionTestCase extends CocoonTestCase {
+    private Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
+
+    protected Logger getLogger() {
+        return this.logger;
+    }
 
     public void testContext() {
         ExpressionContext parentContext = new ExpressionContext();
@@ -53,6 +60,7 @@
         assertNotNull("Test expression compilation", expression);
 
         assertEquals(new Long(3), expression.evaluate(new ExpressionContext()));
+        this.release(factory);
     }
 
     public void testFactoryJXPath() throws ExpressionException, ServiceException {
@@ -63,6 +71,7 @@
         assertNotNull("Test expression compilation", expression);
 
         assertEquals(new Double(3), expression.evaluate(new ExpressionContext()));
+        this.release(factory);
     }
 }
 

Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java&r1=124995&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java	(original)
+++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/environment/FOMTestCase.java	Wed Jan 12 14:13:27 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.cocoon.environment;
 
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.cocoon.SitemapComponentTestCase;
@@ -24,6 +26,11 @@
 import org.apache.cocoon.components.expression.ExpressionFactory;
 
 public class FOMTestCase extends SitemapComponentTestCase {
+    private Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
+
+    protected Logger getLogger() {
+        return this.logger;
+    }
 
     public void testFOMJexl() throws ExpressionException, ServiceException {
         ExpressionFactory factory = (ExpressionFactory)this.lookup(ExpressionFactory.ROLE);
@@ -37,6 +44,7 @@
 
         expression = factory.getExpression("jexl", "cocoon.request.protocol");
         assertEquals("HTTP/1.1", expression.evaluate(fomContext));
+        this.release(factory);
     }
 
     public void testFOMJXPath() throws ExpressionException, ServiceException {
@@ -51,6 +59,7 @@
 
         expression = factory.getExpression("jxpath", "$cocoon/request/protocol");
         assertEquals("HTTP/1.1", expression.evaluate(fomContext));
+        this.release(factory);
     }
 }
 

Modified: cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java?view=diff&rev=124996&p1=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java&r1=124995&p2=cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java&r2=124996
==============================================================================
--- cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java	(original)
+++ cocoon/trunk/src/blocks/template/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.java	Wed Jan 12 14:13:27 2005
@@ -28,7 +28,7 @@
 import org.apache.cocoon.environment.ObjectModelHelper;
 
 public class JXTemplateGeneratorTestCase extends SitemapComponentTestCase {
-    Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
+    private Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_WARN);
     String docBase = "resource://org/apache/cocoon/template/jxtg/";
     String JX = "jx";
     Map flowContext = new HashMap();
@@ -46,7 +46,7 @@
         return this.flowContext;
     }
 
-    public Logger getLogger() {
+    protected Logger getLogger() {
         return this.logger;
     }
 

Mime
View raw message