cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gkossakow...@apache.org
Subject svn commit: r566675 - in /cocoon/trunk: blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/
Date Thu, 16 Aug 2007 12:16:27 GMT
Author: gkossakowski
Date: Thu Aug 16 05:16:26 2007
New Revision: 566675

URL: http://svn.apache.org/viewvc?view=rev&rev=566675
Log:
COCOON-2112:
  * Remove StringTemplateParser interface dependency on JXTExpression and adapt rest of the
code. This makes cocoon-template less dependent of expression interfaces and classes
  * Restructure code in AbstractStringTemplateParser so it's more cleaner
  * Allow Literal class to be not only String literal but also Integer and Boolean literal.

Modified:
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
    cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ParameterInstance.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/AbstractStringTemplateParser.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/JXTExpression.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Literal.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/StringTemplateParser.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Subst.java
    cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Substitutions.java

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/Import.java
Thu Aug 16 05:16:26 2007
@@ -24,8 +24,6 @@
 import org.apache.cocoon.template.environment.ErrorHolder;
 import org.apache.cocoon.template.environment.ExecutionContext;
 import org.apache.cocoon.template.environment.ParsingContext;
-import org.apache.cocoon.template.expression.JXTExpression;
-import org.apache.cocoon.template.expression.Literal;
 import org.apache.cocoon.template.expression.Subst;
 import org.apache.cocoon.template.script.Invoker;
 import org.apache.cocoon.template.script.event.AttributeEvent;
@@ -95,22 +93,15 @@
             Iterator i = substAttr.getSubstitutions().iterator();
             while (i.hasNext()) {
                 Subst subst = (Subst) i.next();
-                if (subst instanceof Literal) {
-                    Literal lit = (Literal) subst;
-                    buf.append(lit.getValue());
-                } else if (subst instanceof JXTExpression) {
-                    Subst expr = (Subst) subst;
-                    Object val;
-                    try {
-                        val = expr.getValue(objectModel);
-                    } catch (Exception exc) {
-                        throw new SAXParseException(exc.getMessage(), getLocation(), exc);
-                    } catch (Error err) {
-                        throw new SAXParseException(err.getMessage(),
-                                                    getLocation(), new ErrorHolder(err));
-                    }
-                    buf.append(val != null ? val.toString() : "");
+                Object val;
+                try {
+                    val = subst.getValue(objectModel);
+                } catch (Exception exc) {
+                    throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+                } catch (Error err) {
+                    throw new SAXParseException(err.getMessage(), getLocation(), new ErrorHolder(err));
                 }
+                buf.append(val != null ? val.toString() : "");
             }
             uri = buf.toString();
         }

Modified: cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ParameterInstance.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ParameterInstance.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ParameterInstance.java
(original)
+++ cocoon/trunk/blocks/cocoon-template/cocoon-template-impl/src/main/java/org/apache/cocoon/template/instruction/ParameterInstance.java
Thu Aug 16 05:16:26 2007
@@ -70,7 +70,7 @@
     }
 
     public Object getValue(ObjectModel objectModel) throws SAXException {
-        if (this.value instanceof JXTExpression)
+        if (this.value instanceof Subst)
             return getExpressionValue((Subst) this.value, objectModel);
         else if (this.value instanceof CopyAttribute) {
             CopyAttribute copy = (CopyAttribute) this.value;

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/AbstractStringTemplateParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/AbstractStringTemplateParser.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/AbstractStringTemplateParser.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/AbstractStringTemplateParser.java
Thu Aug 16 05:16:26 2007
@@ -41,9 +41,9 @@
      * @see org.apache.cocoon.template.expression.StringTemplateParser#compileBoolean(java.lang.String,
java.lang.String, org.xml.sax.Locator)
      */
     public Subst compileBoolean(String val, String msg, Locator location) throws SAXException
{
-        JXTExpression res = compileExpr(val, msg, location);
-        if (res != null && res.getCompiledExpression() == null && res.getRaw()
!= null) {
-            res.setCompiledExpression(Boolean.valueOf(res.getRaw()));
+        Subst res = compileExpr(val, msg, location);
+        if (res instanceof Literal) {
+            res = new Literal(Boolean.valueOf(res.getRaw()));
         }
         return res;
     }
@@ -52,9 +52,9 @@
      * @see org.apache.cocoon.template.expression.StringTemplateParser#compileInt(java.lang.String,
java.lang.String, org.xml.sax.Locator)
      */
     public Subst compileInt(String val, String msg, Locator location) throws SAXException
{
-        JXTExpression res = compileExpr(val, msg, location);
-        if (res != null && res.getCompiledExpression() == null && res.getRaw()
!= null) {
-            res.setCompiledExpression(Integer.valueOf(res.getRaw()));
+        Subst res = compileExpr(val, msg, location);
+        if (res instanceof Literal) {
+            res = new Literal(Integer.valueOf(res.getRaw()));
         }
         return res;
     }
@@ -62,14 +62,14 @@
     /**
      * @see org.apache.cocoon.template.expression.StringTemplateParser#compileExpr(java.lang.String,
java.lang.String, org.xml.sax.Locator)
      */
-    public JXTExpression compileExpr(String inStr, String errorPrefix, Locator location)
throws SAXParseException {
+    public Subst compileExpr(String inStr, String errorPrefix, Locator location) throws SAXParseException
{
         if (inStr == null) {
             return null;
         }
         StringReader in = new StringReader(inStr.trim());
         List substitutions = parseSubstitutions(in, errorPrefix, location);
         if (substitutions.size() == 0 || !(substitutions.get(0) instanceof JXTExpression))
-            return new JXTExpression(inStr, null);
+            return new Literal(inStr);
 
         return (JXTExpression) substitutions.get(0);
     }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/JXTExpression.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/JXTExpression.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/JXTExpression.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/JXTExpression.java
Thu Aug 16 05:16:26 2007
@@ -28,7 +28,7 @@
 public class JXTExpression implements Subst {
 
     private String raw;
-    Object compiledExpression;
+    private Object compiledExpression;
 
     public JXTExpression(String raw, Object expr) {
         this.raw = raw;

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Literal.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Literal.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Literal.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Literal.java
Thu Aug 16 05:16:26 2007
@@ -32,52 +32,67 @@
  * @version $Id$
  */
 public class Literal implements Subst {
+    
+    private final char[] charValue;
+    private final Object value;
+    
     public Literal(String val) {
-        this.value = val.toCharArray();
+        this.value = val;
+        this.charValue = val.toCharArray();
     }
-
-    public String getValue() {
-        return new String(this.value);
+    
+    public Literal(Integer val) {
+        this.value = val;
+        this.charValue = val.toString().toCharArray();
+    }
+    
+    public Literal(Boolean val) {
+        this.value = val;
+        this.charValue = val.toString().toCharArray();
     }
 
     public char[] getCharArray() {
-        return value;
+        return charValue;
     }
 
     public void setLenient(Boolean lenient) {
+        //ignore
     }
 
     public Object getValue(ObjectModel objectModel) throws Exception {
-        return null;
+        return value;
     }
 
     public int getIntValue(ObjectModel objectModel) throws Exception {
-        return 0;
+        return value instanceof Integer ? ((Integer)value).intValue() : Integer.parseInt(getStringValue(objectModel));
     }
 
     public Number getNumberValue(ObjectModel objectModel) throws Exception {
-        return null;
+        throw new UnsupportedOperationException();
     }
 
     public String getStringValue(ObjectModel objectModel) throws Exception {
-        return null;
+        return value.toString();
     }
 
     public Boolean getBooleanValue(ObjectModel objectModel) throws Exception {
-        return null;
+        throw new UnsupportedOperationException();
     }
 
     public Iterator getIterator(ObjectModel objectModel) throws Exception {
-        return null;
+        throw new UnsupportedOperationException();
     }
 
     public Object getNode(ObjectModel objectModel) throws Exception {
-        return null;
+        return value;
     }
 
     public Object getCompiledExpression() {
-        return null;
+        throw new UnsupportedOperationException();
+    }
+
+    public String getRaw() {
+        return value.toString();
     }
 
-    private final char[] value;
 }

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/StringTemplateParser.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/StringTemplateParser.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/StringTemplateParser.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/StringTemplateParser.java
Thu Aug 16 05:16:26 2007
@@ -42,7 +42,7 @@
      */
     Subst compileInt(String val, String msg, Locator location) throws SAXException;
 
-    JXTExpression compileExpr(String inStr, String errorPrefix, Locator location) throws
SAXParseException;
+    Subst compileExpr(String inStr, String errorPrefix, Locator location) throws SAXParseException;
 
     /**
      * Parse a set of expressions spaced with literals

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Subst.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Subst.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Subst.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Subst.java
Thu Aug 16 05:16:26 2007
@@ -43,6 +43,8 @@
 
     public void setLenient(Boolean lenient);
 
+    public String getRaw();
+
     public static final Iterator EMPTY_ITER = new Iterator() {
             public boolean hasNext() {
                 return false;

Modified: cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Substitutions.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Substitutions.java?view=diff&rev=566675&r1=566674&r2=566675
==============================================================================
--- cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Substitutions.java
(original)
+++ cocoon/trunk/core/cocoon-expression-language/cocoon-expression-language-impl/src/main/java/org/apache/cocoon/template/expression/Substitutions.java
Thu Aug 16 05:16:26 2007
@@ -70,22 +70,16 @@
         Iterator iterSubst = iterator();
         while (iterSubst.hasNext()) {
             Subst subst = (Subst) iterSubst.next();
-            if (subst instanceof Literal) {
-                Literal lit = (Literal) subst;
-                buf.append(lit.getValue());
-            } else if (subst instanceof JXTExpression) {
-                Subst expr = (Subst) subst;
-                Object val;
-                try {
-                    val = expr.getValue(objectModel);
-                } catch (Exception e) {
-                    throw new SAXParseException(e.getMessage(), location, e);
-                //FIXME: Don't catch java.lang.Error
-                //} catch (Error err) {
-                //    throw new SAXParseException(err.getMessage(), location, new ErrorHolder(err));
-                }
-                buf.append(val != null ? val.toString() : "");
+            Object val;
+            try {
+                val = subst.getValue(objectModel);
+            } catch (Exception e) {
+                throw new SAXParseException(e.getMessage(), location, e);
+            //FIXME: Don't catch java.lang.Error
+            //} catch (Error err) {
+            //    throw new SAXParseException(err.getMessage(), location, new ErrorHolder(err));
             }
+            buf.append(val != null ? val.toString() : "");
         }
         return buf.toString();
     }



Mime
View raw message