cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r111751 - in cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script: . event
Date Mon, 13 Dec 2004 22:25:08 GMT
Author: danielf
Date: Mon Dec 13 14:25:06 2004
New Revision: 111751

URL: http://svn.apache.org/viewcvs?view=rev&rev=111751
Log:
Refactored out most of the code that constructs executable tags from the Parser to the constructors of the tags.
Modified:
   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/StartChoose.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.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/StartEvalBody.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/StartOtherwise.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/StartParameter.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/StartTemplate.java
   cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Parser.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -131,23 +131,6 @@
             EndInstruction endInstruction = new EndInstruction(locator,
                     startInstruction);
             newEvent = endInstruction;
-            if (start instanceof StartWhen) {
-                StartWhen startWhen = (StartWhen) start;
-                StartChoose startChoose = (StartChoose) stack.peek();
-                if (startChoose.getFirstChoice() != null) {
-                    StartWhen w = startChoose.getFirstChoice();
-                    while (w.getNextChoice() != null) {
-                        w = w.getNextChoice();
-                    }
-                    w.setNextChoice(startWhen);
-                } else {
-                    startChoose.setFirstChoice(startWhen);
-                }
-            } else if (start instanceof StartOtherwise) {
-                StartOtherwise startOtherwise = (StartOtherwise) start;
-                StartChoose startChoose = (StartChoose) stack.peek();
-                startChoose.setOtherwise(startOtherwise);
-            }
         } else {
             StartElement startElement = (StartElement) start;
             newEvent = new EndElement(locator, startElement);
@@ -211,234 +194,39 @@
                 localName, qname, elementAttributes);
         if (JXTemplateGenerator.NS.equals(namespaceURI)) {
             if (localName.equals(FOR_EACH)) {
-                String items = attrs.getValue("items");
-                String select = attrs.getValue("select");
-                JXTExpression begin = compileInt(attrs.getValue("begin"),
-                        FOR_EACH, locator);
-                JXTExpression end = compileInt(attrs.getValue("end"), FOR_EACH,
-                        locator);
-                JXTExpression step = compileInt(attrs.getValue("step"),
-                        FOR_EACH, locator);
-                JXTExpression var = compileExpr(attrs.getValue("var"), null,
-                        locator);
-                JXTExpression varStatus = compileExpr(attrs
-                        .getValue("varStatus"), null, locator);
-                if (items == null) {
-                    if (select == null && (begin == null || end == null)) {
-                        throw new SAXParseException(
-                                "forEach: \"select\", \"items\", or both \"begin\" and \"end\" must be specified",
-                                locator, null);
-                    }
-                } else if (select != null) {
-                    throw new SAXParseException(
-                            "forEach: only one of \"select\" or \"items\" may be specified",
-                            locator, null);
-                }
-                JXTExpression expr = compileExpr(
-                        items == null ? select : items, null, locator);
-                String lenientValue = attrs.getValue("lenient");
-                Boolean lenient = (lenientValue == null) ? null : Boolean
-                        .valueOf(lenientValue);
-                StartForEach startForEach = new StartForEach(startElement,
-                        expr, var, varStatus, begin, end, step, lenient);
-                newEvent = startForEach;
+                newEvent = new StartForEach(startElement, attrs, stack);
             } else if (localName.equals(FORMAT_NUMBER)) {
-                JXTExpression value = compileExpr(attrs.getValue("value"),
-                        null, locator);
-                JXTExpression type = compileExpr(attrs.getValue("type"), null,
-                        locator);
-                JXTExpression pattern = compileExpr(attrs.getValue("pattern"),
-                        null, locator);
-                JXTExpression currencyCode = compileExpr(attrs
-                        .getValue("currencyCode"), null, locator);
-                JXTExpression currencySymbol = compileExpr(attrs
-                        .getValue("currencySymbol"), null, locator);
-                JXTExpression isGroupingUsed = compileBoolean(attrs
-                        .getValue("isGroupingUsed"), null, locator);
-                JXTExpression maxIntegerDigits = compileInt(attrs
-                        .getValue("maxIntegerDigits"), null, locator);
-                JXTExpression minIntegerDigits = compileInt(attrs
-                        .getValue("minIntegerDigits"), null, locator);
-                JXTExpression maxFractionDigits = compileInt(attrs
-                        .getValue("maxFractionDigits"), null, locator);
-                JXTExpression minFractionDigits = compileInt(attrs
-                        .getValue("minFractionDigits"), null, locator);
-                JXTExpression var = compileExpr(attrs.getValue("var"), null,
-                        locator);
-                JXTExpression locale = compileExpr(attrs.getValue("locale"),
-                        null, locator);
-                StartFormatNumber startFormatNumber = new StartFormatNumber(
-                        startElement, var, value, type, pattern, currencyCode,
-                        currencySymbol, isGroupingUsed, maxIntegerDigits,
-                        minIntegerDigits, maxFractionDigits, minFractionDigits,
-                        locale);
-                newEvent = startFormatNumber;
+                newEvent = new StartFormatNumber(startElement, attrs, stack);
             } else if (localName.equals(FORMAT_DATE)) {
-                JXTExpression var = compileExpr(attrs.getValue("var"), null,
-                        locator);
-                JXTExpression value = compileExpr(attrs.getValue("value"),
-                        null, locator);
-                JXTExpression type = compileExpr(attrs.getValue("type"), null,
-                        locator);
-                JXTExpression pattern = compileExpr(attrs.getValue("pattern"),
-                        null, locator);
-                JXTExpression timeZone = compileExpr(
-                        attrs.getValue("timeZone"), null, locator);
-                JXTExpression dateStyle = compileExpr(attrs
-                        .getValue("dateStyle"), null, locator);
-                JXTExpression timeStyle = compileExpr(attrs
-                        .getValue("timeStyle"), null, locator);
-                JXTExpression locale = compileExpr(attrs.getValue("locale"),
-                        null, locator);
-                StartFormatDate startFormatDate = new StartFormatDate(
-                        startElement, var, value, type, pattern, timeZone,
-                        dateStyle, timeStyle, locale);
-                newEvent = startFormatDate;
+                newEvent = new StartFormatDate(startElement, attrs, stack);
             } else if (localName.equals(CHOOSE)) {
-                StartChoose startChoose = new StartChoose(startElement);
-                newEvent = startChoose;
+                newEvent = new StartChoose(startElement, attrs, stack);
             } else if (localName.equals(WHEN)) {
-                if (stack.size() == 0 || !(stack.peek() instanceof StartChoose)) {
-                    throw new SAXParseException(
-                            "<when> must be within <choose>", locator, null);
-                }
-                String test = attrs.getValue("test");
-                if (test != null) {
-                    JXTExpression expr = compileExpr(test, "when: \"test\": ",
-                            locator);
-                    StartWhen startWhen = new StartWhen(startElement, expr);
-                    newEvent = startWhen;
-                } else {
-                    throw new SAXParseException("when: \"test\" is required",
-                            locator, null);
-                }
+                newEvent = new StartWhen(startElement, attrs, stack);
             } else if (localName.equals(OUT)) {
-                String value = attrs.getValue("value");
-                if (value != null) {
-                    JXTExpression expr = compileExpr(value, "out: \"value\": ",
-                            locator);
-                    String lenientValue = attrs.getValue("lenient");
-                    Boolean lenient = lenientValue == null ? null : Boolean
-                            .valueOf(lenientValue);
-                    newEvent = new StartOut(startElement, expr, lenient);
-                } else {
-                    throw new SAXParseException("out: \"value\" is required",
-                            locator, null);
-                }
+                newEvent = new StartOut(startElement, attrs, stack);
             } else if (localName.equals(OTHERWISE)) {
-                if (stack.size() != 0 && (stack.peek() instanceof StartChoose)) {
-                    StartOtherwise startOtherwise = new StartOtherwise(
-                            startElement);
-                    newEvent = startOtherwise;
-                } else {
-                    throw new SAXParseException(
-                            "<otherwise> must be within <choose>", locator,
-                            null);
-                }
+                newEvent = new StartOtherwise(startElement, attrs, stack);
             } else if (localName.equals(IF)) {
-                String test = attrs.getValue("test");
-                if (test != null) {
-                    JXTExpression expr = compileExpr(test, "if: \"test\": ",
-                            locator);
-                    StartIf startIf = new StartIf(startElement, expr);
-                    newEvent = startIf;
-                } else {
-                    throw new SAXParseException("if: \"test\" is required",
-                            locator, null);
-                }
+                newEvent = new StartIf(startElement, attrs, stack);
             } else if (localName.equals(MACRO)) {
-                // <macro name="myTag" targetNamespace="myNamespace">
-                // <parameter name="paramName" required="Boolean"
-                // default="value"/>
-                // body
-                // </macro>
-                String namespace = StringUtils.defaultString(attrs
-                        .getValue("targetNamespace"));
-                String name = attrs.getValue("name");
-                if (name != null) {
-                    StartDefine startDefine = new StartDefine(startElement,
-                            namespace, name);
-                    newEvent = startDefine;
-                } else {
-                    throw new SAXParseException("macro: \"name\" is required",
-                            locator, null);
-                }
+                newEvent = new StartDefine(startElement, attrs, stack);
             } else if (localName.equals(PARAMETER)) {
-                if (stack.size() == 0 || !(stack.peek() instanceof StartDefine)) {
-                    throw new SAXParseException("<parameter> not allowed here",
-                            locator, null);
-                } else {
-                    String name = attrs.getValue("name");
-                    String optional = attrs.getValue("optional");
-                    String default_ = attrs.getValue("default");
-                    if (name != null) {
-                        StartParameter startParameter = new StartParameter(
-                                startElement, name, optional, default_);
-                        newEvent = startParameter;
-                    } else {
-                        throw new SAXParseException(
-                                "parameter: \"name\" is required", locator,
-                                null);
-                    }
-                }
+                newEvent = new StartParameter(startElement, attrs, stack);
             } else if (localName.equals(EVALBODY)) {
-                newEvent = new StartEvalBody(startElement);
+                newEvent = new StartEvalBody(startElement, attrs, stack);
             } else if (localName.equals(EVAL)) {
-                String value = attrs.getValue("select");
-                JXTExpression valueExpr = compileExpr(value,
-                        "eval: \"select\":", locator);
-                newEvent = new StartEval(startElement, valueExpr);
+                newEvent = new StartEval(startElement, attrs, stack);
             } else if (localName.equals(SET)) {
-                String var = attrs.getValue("var");
-                String value = attrs.getValue("value");
-                JXTExpression varExpr = null;
-                JXTExpression valueExpr = null;
-                if (var != null) {
-                    varExpr = compileExpr(var, "set: \"var\":", locator);
-                }
-                if (value != null) {
-                    valueExpr = compileExpr(value, "set: \"value\":", locator);
-                }
-                StartSet startSet = new StartSet(startElement, varExpr,
-                        valueExpr);
-                newEvent = startSet;
+                newEvent = new StartSet(startElement, attrs, stack);
             } else if (localName.equals(IMPORT)) {
-                // <import uri="${root}/foo/bar.xml" context="${foo}"/>
-                AttributeEvent uri = null;
-                Iterator iter = startElement.getAttributeEvents().iterator();
-                while (iter.hasNext()) {
-                    AttributeEvent e = (AttributeEvent) iter.next();
-                    if (e.getLocalName().equals("uri")) {
-                        uri = e;
-                        break;
-                    }
-                }
-                if (uri != null) {
-                    // If "context" is present then its value will be used
-                    // as the context object in the imported template
-                    String select = attrs.getValue("context");
-                    JXTExpression expr = null;
-                    if (select != null) {
-                        expr = compileExpr(select, "import: \"context\": ",
-                                locator);
-                    }
-                    StartImport startImport = new StartImport(startElement,
-                            uri, expr);
-                    newEvent = startImport;
-                } else {
-                    throw new SAXParseException("import: \"uri\" is required",
-                            locator, null);
-                }
+                newEvent = new StartImport(startElement, attrs, stack);
             } else if (localName.equals(TEMPLATE)) {
-                StartTemplate startTemplate = new StartTemplate(startElement);
-                newEvent = startTemplate;
+                newEvent = new StartTemplate(startElement, attrs, stack);
             } else if (localName.equals(COMMENT)) {
-                // <jx:comment>This will be parsed</jx:comment>
-                StartComment startJXComment = new StartComment(startElement);
-                newEvent = startJXComment;
+                newEvent = new StartComment(startElement, attrs, stack);
             } else {
-                throw new SAXParseException("unrecognized tag: " + localName,
-                        locator, null);
+                throw new SAXParseException("unrecognized tag: " + localName, locator, null);
             }
         } else {
             newEvent = startElement;
@@ -582,4 +370,4 @@
                     location, new ErrorHolder(err));
         }
     }
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartChoose.java	Mon Dec 13 14:25:06 2004
@@ -15,8 +15,16 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
 public class StartChoose extends StartInstruction {
-    public StartChoose(StartElement raw) {
+
+    private StartWhen firstChoice;
+    private StartOtherwise otherwise;
+
+    public StartChoose(StartElement raw, Attributes attrs, Stack stack) {
         super(raw);
     }
 
@@ -35,7 +43,4 @@
     public StartOtherwise getOtherwise() {
         return otherwise;
     }
-
-    private StartWhen firstChoice;
-    private StartOtherwise otherwise;
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartComment.java	Mon Dec 13 14:25:06 2004
@@ -15,8 +15,13 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
 public class StartComment extends StartInstruction {
-    public StartComment(StartElement raw) {
+    public StartComment(StartElement raw, Attributes attrs, Stack stack) {
+        // <jx:comment>This will be parsed</jx:comment>
         super(raw);
     }
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDefine.java	Mon Dec 13 14:25:06 2004
@@ -17,18 +17,16 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Stack;
 
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.Parser;
+import org.apache.commons.lang.StringUtils;
+import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
 public class StartDefine extends StartInstruction {
-    public StartDefine(StartElement raw, String namespace, String name) {
-        super(raw);
-        this.namespace = namespace;
-        this.name = name;
-        this.qname = "{" + namespace + "}" + name;
-        this.parameters = new HashMap();
-    }
 
     final String name;
     final String namespace;
@@ -36,6 +34,26 @@
     private final Map parameters;
     private Event body;
 
+    public StartDefine(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
+        super(raw);
+
+        // <macro name="myTag" targetNamespace="myNamespace">
+        // <parameter name="paramName" required="Boolean"
+        // default="value"/>
+        // body
+        // </macro>
+        this.namespace = StringUtils.defaultString(attrs.getValue("targetNamespace"));
+        this.name = attrs.getValue("name");
+        if (this.name == null) {
+            throw new SAXParseException("macro: \"name\" is required", getLocation(), null);
+        }
+        
+        this.qname = "{" + namespace + "}" + name;
+        this.parameters = new HashMap();
+    }
+
     public void finish() throws SAXException {
         Event e = next;
         boolean params = true;
@@ -97,4 +115,4 @@
     public String getQname() {
         return qname;
     }
-}
\ 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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEval.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,17 +15,26 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
 
 public class StartEval extends StartInstruction {
-    public StartEval(StartElement raw, JXTExpression value) {
+    private final JXTExpression value;
+
+    public StartEval(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
         super(raw);
-        this.value = value;
+
+        String select = attrs.getValue("select");
+        this.value = Parser.compileExpr(select, "eval: \"select\":", getLocation());
     }
 
     public JXTExpression getValue() {
         return value;
     }
-
-    private final JXTExpression value;
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEvalBody.java	Mon Dec 13 14:25:06 2004
@@ -15,8 +15,12 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
 public class StartEvalBody extends StartInstruction {
-    public StartEvalBody(StartElement raw) {
+    public StartEvalBody(StartElement raw, Attributes attrs, Stack stack) {
         super(raw);
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartForEach.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,21 +15,16 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
+import org.xml.sax.SAXParseException;
 
 public class StartForEach extends StartInstruction {
-    public StartForEach(StartElement raw, JXTExpression items,
-            JXTExpression var, JXTExpression varStatus, JXTExpression begin,
-            JXTExpression end, JXTExpression step, Boolean lenient) {
-        super(raw);
-        this.items = items;
-        this.var = var;
-        this.varStatus = varStatus;
-        this.begin = begin;
-        this.end = end;
-        this.step = step;
-        this.lenient = lenient;
-    }
 
     final JXTExpression items;
     final JXTExpression var;
@@ -39,6 +34,36 @@
     final JXTExpression step;
     final Boolean lenient;
 
+    public StartForEach(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
+        super(raw);
+
+        String name = raw.getLocalName();
+        Locator locator = getLocation();
+
+        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);
+        String lenientValue = attrs.getValue("lenient");
+        this.lenient = (lenientValue == null) ? null : Boolean.valueOf(lenientValue);
+
+        if (items == null) {
+            if (select == null && (begin == null || end == null)) {
+                throw new SAXParseException("forEach: \"select\", \"items\", or both \"begin\" and \"end\" must be specified",
+                                            locator, null);
+            }
+        } else if (select != null) {
+            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);
+    }
+
     public JXTExpression getBegin() {
         return begin;
     }
@@ -66,4 +91,4 @@
     public JXTExpression getVarStatus() {
         return varStatus;
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatDate.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -18,12 +18,17 @@
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Locale;
+import java.util.Stack;
 import java.util.TimeZone;
 
 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;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartFormatDate extends StartInstruction {
 
@@ -40,19 +45,21 @@
     JXTExpression timeStyle;
     JXTExpression locale;
 
-    public StartFormatDate(StartElement raw, JXTExpression var,
-            JXTExpression value, JXTExpression type, JXTExpression pattern,
-            JXTExpression timeZone, JXTExpression dateStyle,
-            JXTExpression timeStyle, JXTExpression locale) {
+    public StartFormatDate(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException{
+        
         super(raw);
-        this.var = var;
-        this.value = value;
-        this.type = type;
-        this.pattern = pattern;
-        this.timeZone = timeZone;
-        this.dateStyle = dateStyle;
-        this.timeStyle = timeStyle;
-        this.locale = locale;
+
+        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);
     }
 
     public String format(JexlContext jexl, JXPathContext jxp) throws Exception {
@@ -161,4 +168,4 @@
         }
         return ret;
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartFormatNumber.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -20,12 +20,17 @@
 import java.text.DecimalFormatSymbols;
 import java.text.NumberFormat;
 import java.util.Locale;
+import java.util.Stack;
 
 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;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartFormatNumber extends StartInstruction {
 
@@ -57,25 +62,32 @@
         }
     }
 
-    public StartFormatNumber(StartElement raw, JXTExpression var,
-            JXTExpression value, JXTExpression type, JXTExpression pattern,
-            JXTExpression currencyCode, JXTExpression currencySymbol,
-            JXTExpression isGroupingUsed, JXTExpression maxIntegerDigits,
-            JXTExpression minIntegerDigits, JXTExpression maxFractionDigits,
-            JXTExpression minFractionDigits, JXTExpression locale) {
+    public StartFormatNumber(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
         super(raw);
-        this.var = var;
-        this.value = value;
-        this.type = type;
-        this.pattern = pattern;
-        this.currencyCode = currencyCode;
-        this.currencySymbol = currencySymbol;
-        this.isGroupingUsed = isGroupingUsed;
-        this.maxIntegerDigits = maxIntegerDigits;
-        this.minIntegerDigits = minIntegerDigits;
-        this.maxFractionDigits = maxFractionDigits;
-        this.minFractionDigits = minFractionDigits;
-        this.locale = locale;
+
+        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.currencyCode =
+            Parser.compileExpr(attrs.getValue("currencyCode"), null, locator);
+        this.currencySymbol =
+            Parser.compileExpr(attrs.getValue("currencySymbol"), null, locator);
+        this.isGroupingUsed =
+            Parser.compileBoolean(attrs.getValue("isGroupingUsed"), null, locator);
+        this.maxIntegerDigits =
+            Parser.compileInt(attrs.getValue("maxIntegerDigits"), null, locator);
+        this.minIntegerDigits =
+            Parser.compileInt(attrs.getValue("minIntegerDigits"), null, locator);
+        this.maxFractionDigits =
+            Parser.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);
     }
 
     public String format(JexlContext jexl, JXPathContext jxp) throws Exception {
@@ -250,4 +262,4 @@
             df.setDecimalFormatSymbols(dfs);
         }
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartIf.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,17 +15,33 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
+import org.xml.sax.SAXParseException;
 
 public class StartIf extends StartInstruction {
-    public StartIf(StartElement raw, JXTExpression test) {
+    final JXTExpression test;
+
+    public StartIf(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
         super(raw);
-        this.test = test;
-    }
 
-    final JXTExpression test;
+        Locator locator = getLocation();
+        String test = attrs.getValue("test");
+        if (test != null) {
+            this.test = Parser.compileExpr(test, "if: \"test\": ", locator);
+        } else {
+            throw new SAXParseException("if: \"test\" is required", locator, null);
+        }
+    }
 
     public JXTExpression getTest() {
         return test;
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartImport.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,12 +15,48 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Iterator;
+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;
+import org.xml.sax.SAXParseException;
 
 public class StartImport extends StartInstruction {
-    public StartImport(StartElement raw, AttributeEvent uri,
-            JXTExpression select) {
+
+    private final AttributeEvent uri;
+    private final JXTExpression select;
+
+    public StartImport(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
         super(raw);
+
+        // <import uri="${root}/foo/bar.xml" context="${foo}"/>
+        Locator locator = getLocation();
+        Iterator iter = raw.getAttributeEvents().iterator();
+        AttributeEvent uri = null;
+        JXTExpression select = null;
+        while (iter.hasNext()) {
+            AttributeEvent e = (AttributeEvent) iter.next();
+            if (e.getLocalName().equals("uri")) {
+                uri = e;
+                break;
+            }
+        }
+        if (uri != null) {
+            // If "context" is present then its value will be used
+            // as the context object in the imported template
+            String context = attrs.getValue("context");
+            if (context != null) {
+                select = Parser.compileExpr(context, "import: \"context\": ", locator);
+            }
+        } else {
+            throw new SAXParseException("import: \"uri\" is required", locator, null);
+        }
         this.uri = uri;
         this.select = select;
     }
@@ -32,7 +68,4 @@
     public JXTExpression getSelect() {
         return select;
     }
-
-    private final AttributeEvent uri;
-    private final JXTExpression select;
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOtherwise.java	Mon Dec 13 14:25:06 2004
@@ -15,8 +15,24 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
 public class StartOtherwise extends StartInstruction {
-    public StartOtherwise(StartElement raw) {
+    public StartOtherwise(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
         super(raw);
+
+        if (stack.size() != 0 && (stack.peek() instanceof StartChoose)) {
+            StartChoose startChoose = (StartChoose) stack.peek();
+            startChoose.setOtherwise(this);
+        } else {
+            throw new SAXParseException("<otherwise> must be within <choose>",
+                                        getLocation(), null);
+        }
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartOut.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,13 +15,32 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
+import org.xml.sax.SAXParseException;
 
 public class StartOut extends StartInstruction {
-    public StartOut(StartElement raw, JXTExpression expr, Boolean lenient) {
+    private final JXTExpression compiledExpression;
+    private final Boolean lenient;
+
+    public StartOut(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
         super(raw);
-        this.compiledExpression = expr;
-        this.lenient = lenient;
+        Locator locator = getLocation();
+        String value = attrs.getValue("value");
+        if (value != null) {
+            this.compiledExpression = Parser.compileExpr(value, "out: \"value\": ", locator);
+            String lenientValue = attrs.getValue("lenient");
+            this.lenient = lenientValue == null ? null : Boolean.valueOf(lenientValue);
+        } else {
+            throw new SAXParseException("out: \"value\" is required", locator, null);
+        }
     }
 
     public JXTExpression getCompiledExpression() {
@@ -31,7 +50,4 @@
     public Boolean getLenient() {
         return lenient;
     }
-
-    private final JXTExpression compiledExpression;
-    private final Boolean lenient;
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartParameter.java	Mon Dec 13 14:25:06 2004
@@ -15,20 +15,37 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
 public class StartParameter extends StartInstruction {
-    public StartParameter(StartElement raw, String name, String optional,
-            String defaultValue) {
+    final String name;
+    final String optional;
+    private final String defaultValue;
+
+    public StartParameter(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
         super(raw);
-        this.name = name;
-        this.optional = optional;
-        this.defaultValue = defaultValue;
+
+        Locator locator = getLocation();
+        if (stack.size() == 0 || !(stack.peek() instanceof StartDefine)) {
+            throw new SAXParseException("<parameter> not allowed here", locator, null);
+        } else {
+            this.name = attrs.getValue("name");
+            this.optional = attrs.getValue("optional");
+            this.defaultValue = attrs.getValue("default");
+            if (this.name == null) {
+                throw new SAXParseException("parameter: \"name\" is required", locator, null);
+            }
+        }
     }
 
     public String getDefaultValue() {
         return defaultValue;
     }
-
-    final String name;
-    final String optional;
-    private final String defaultValue;
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartSet.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,13 +15,37 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
 
 public class StartSet extends StartInstruction {
-    public StartSet(StartElement raw, JXTExpression var, JXTExpression value) {
+
+    private final JXTExpression var;
+    private final JXTExpression value;
+
+    public StartSet(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
         super(raw);
-        this.var = var;
-        this.value = value;
+
+        Locator locator = getLocation();
+        String var = attrs.getValue("var");
+        String value = attrs.getValue("value");
+        JXTExpression varExpr = null;
+        JXTExpression valueExpr = null;
+        if (var != null) {
+            varExpr = Parser.compileExpr(var, "set: \"var\":", locator);
+        }
+        if (value != null) {
+            valueExpr = Parser.compileExpr(value, "set: \"value\":", locator);
+        }
+        this.var = varExpr;
+        this.value = valueExpr;
     }
 
     public JXTExpression getVar() {
@@ -31,7 +55,4 @@
     public JXTExpression getValue() {
         return value;
     }
-
-    private final JXTExpression var;
-    private final JXTExpression value;
-}
\ No newline at end of file
+}

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java?view=diff&rev=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java&r2=111751
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java	(original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartTemplate.java	Mon Dec 13 14:25:06 2004
@@ -15,8 +15,12 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
 public class StartTemplate extends StartInstruction {
-    public StartTemplate(StartElement raw) {
+    public StartTemplate(StartElement raw, Attributes attrs, Stack stack) {
         super(raw);
     }
-}
\ No newline at end of file
+}

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=111751&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java&r1=111750&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartWhen.java&r2=111751
==============================================================================
--- 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	Mon Dec 13 14:25:06 2004
@@ -15,12 +15,46 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+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;
+import org.xml.sax.SAXParseException;
 
 public class StartWhen extends StartInstruction {
-    public StartWhen(StartElement raw, JXTExpression test) {
+    private final JXTExpression test;
+    private StartWhen nextChoice;
+
+    public StartWhen(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
         super(raw);
-        this.test = test;
+
+        Locator locator = getLocation();
+
+        if (stack.size() == 0 || !(stack.peek() instanceof StartChoose)) {
+            throw new SAXParseException("<when> must be within <choose>", locator, null);
+        }
+        String test = attrs.getValue("test");
+        if (test != null) {
+            this.test = Parser.compileExpr(test, "when: \"test\": ", locator);
+            
+            StartChoose startChoose = (StartChoose) stack.peek();
+            if (startChoose.getFirstChoice() != null) {
+                StartWhen w = startChoose.getFirstChoice();
+                while (w.getNextChoice() != null) {
+                    w = w.getNextChoice();
+                }
+                w.setNextChoice(this);
+            } else {
+                startChoose.setFirstChoice(this);
+            }
+        } else {
+            throw new SAXParseException("when: \"test\" is required", locator, null);
+        }
     }
 
     public JXTExpression getTest() {
@@ -34,7 +68,4 @@
     public StartWhen getNextChoice() {
         return nextChoice;
     }
-
-    private final JXTExpression test;
-    private StartWhen nextChoice;
-}
\ No newline at end of file
+}

Mime
View raw message