cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r169630 [1/2] - in /cocoon/blocks/unsupported/template/trunk: WEB-INF/xconf/ java/org/apache/cocoon/template/jxtg/instruction/ java/org/apache/cocoon/template/jxtg/script/ test/org/apache/cocoon/template/jxtg/
Date Wed, 11 May 2005 11:51:21 GMT
Author: lgawron
Date: Wed May 11 04:51:20 2005
New Revision: 169630

URL: http://svn.apache.org/viewcvs?rev=169630&view=rev
Log:
remove "Start" prefix from instruction definitions

Added:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Out.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Parameter.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ParameterInstance.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Set.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Template.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/When.java   (with props)
Removed:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartAttribute.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartCall.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartChoose.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartComment.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartDefine.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartEval.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartEvalBody.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartForEach.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartFormatDate.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartIf.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartOtherwise.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartParameter.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartParameterInstance.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartTemplate.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/StartWhen.java
Modified:
    cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/script/Invoker.java
    cocoon/blocks/unsupported/template/trunk/test/org/apache/cocoon/template/jxtg/JXTemplateGeneratorTestCase.xtest

Modified: cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf?rev=169630&r1=169629&r2=169630&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf (original)
+++ cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf Wed May 11 04:51:20 2005
@@ -24,25 +24,25 @@
     <component role="org.apache.cocoon.template.jxtg.script.ScriptManager" class="org.apache.cocoon.template.jxtg.script.DefaultScriptManager"/>
     <component role="org.apache.cocoon.template.jxtg.script.InstructionFactory" class="org.apache.cocoon.template.jxtg.script.DefaultInstructionFactory">
         <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
-            <instruction name="template" class="org.apache.cocoon.template.jxtg.instruction.StartTemplate"/>
-            <instruction name="forEach" class="org.apache.cocoon.template.jxtg.instruction.StartForEach"/>
-            <instruction name="if" class="org.apache.cocoon.template.jxtg.instruction.StartIf"/>
-            <instruction name="choose" class="org.apache.cocoon.template.jxtg.instruction.StartChoose"/>
-            <instruction name="when" class="org.apache.cocoon.template.jxtg.instruction.StartWhen"/>
-            <instruction name="otherwise" class="org.apache.cocoon.template.jxtg.instruction.StartOtherwise"/>
-            <instruction name="out" class="org.apache.cocoon.template.jxtg.instruction.StartOut"/>
-            <instruction name="import" class="org.apache.cocoon.template.jxtg.instruction.StartImport"/>
-            <instruction name="set" class="org.apache.cocoon.template.jxtg.instruction.StartSet"/>
-            <instruction name="macro" class="org.apache.cocoon.template.jxtg.instruction.StartDefine"/>
-            <instruction name="evalBody" class="org.apache.cocoon.template.jxtg.instruction.StartEvalBody"/>
-            <instruction name="eval" class="org.apache.cocoon.template.jxtg.instruction.StartEval"/>
-            <instruction name="parameter" class="org.apache.cocoon.template.jxtg.instruction.StartParameter"/>
-            <instruction name="formatNumber" class="org.apache.cocoon.template.jxtg.instruction.StartFormatNumber"/>
-            <instruction name="formatDate" class="org.apache.cocoon.template.jxtg.instruction.StartFormatDate"/>
-            <instruction name="comment" class="org.apache.cocoon.template.jxtg.instruction.StartComment"/>
-            <instruction name="call" class="org.apache.cocoon.template.jxtg.instruction.StartCall"/>
-            <instruction name="withParam" class="org.apache.cocoon.template.jxtg.instruction.StartParameterInstance"/>
-            <instruction name="attribute" class="org.apache.cocoon.template.jxtg.instruction.StartAttribute"/>
+            <instruction name="template" class="org.apache.cocoon.template.jxtg.instruction.Template"/>
+            <instruction name="forEach" class="org.apache.cocoon.template.jxtg.instruction.ForEach"/>
+            <instruction name="if" class="org.apache.cocoon.template.jxtg.instruction.If"/>
+            <instruction name="choose" class="org.apache.cocoon.template.jxtg.instruction.Choose"/>
+            <instruction name="when" class="org.apache.cocoon.template.jxtg.instruction.When"/>
+            <instruction name="otherwise" class="org.apache.cocoon.template.jxtg.instruction.Otherwise"/>
+            <instruction name="out" class="org.apache.cocoon.template.jxtg.instruction.Out"/>
+            <instruction name="import" class="org.apache.cocoon.template.jxtg.instruction.Import"/>
+            <instruction name="set" class="org.apache.cocoon.template.jxtg.instruction.Set"/>
+            <instruction name="macro" class="org.apache.cocoon.template.jxtg.instruction.Define"/>
+            <instruction name="evalBody" class="org.apache.cocoon.template.jxtg.instruction.EvalBody"/>
+            <instruction name="eval" class="org.apache.cocoon.template.jxtg.instruction.Eval"/>
+            <instruction name="parameter" class="org.apache.cocoon.template.jxtg.instruction.Parameter"/>
+            <instruction name="formatNumber" class="org.apache.cocoon.template.jxtg.instruction.FormatNumber"/>
+            <instruction name="formatDate" class="org.apache.cocoon.template.jxtg.instruction.FormatDate"/>
+            <instruction name="comment" class="org.apache.cocoon.template.jxtg.instruction.Comment"/>
+            <instruction name="call" class="org.apache.cocoon.template.jxtg.instruction.Call"/>
+            <instruction name="withParam" class="org.apache.cocoon.template.jxtg.instruction.ParameterInstance"/>
+            <instruction name="attribute" class="org.apache.cocoon.template.jxtg.instruction.Attribute"/>
         </instructions>
     </component>
 </components>

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java Wed May 11 04:51:20 2005
@@ -0,0 +1,72 @@
+/*
+ * Created on 2005-04-19
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.AttributeAwareXMLConsumer;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Attribute extends Instruction {
+    private JXTExpression name;
+    private JXTExpression value;
+
+    public Attribute(StartElement raw, Attributes attrs, Stack stack)
+            throws SAXException {
+        super(raw);
+
+        Locator locator = getLocation();
+        String name = attrs.getValue("name");
+        if (name == null) {
+            throw new SAXParseException("parameter: \"name\" is required",
+                    locator, null);
+        }
+        this.name = JXTExpression.compileExpr(name, "parameter: \"name\": ",
+                locator);
+
+        String value = attrs.getValue("value");
+        if (value == null)
+            throw new SAXParseException("parameter: \"value\" is required",
+                    locator, null);
+
+        this.value = JXTExpression.compileExpr(value, "parameter: \"value\": ",
+                locator);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, MacroContext macroContext,
+            Event startEvent, Event endEvent) throws SAXException {
+
+        String nameStr = null;
+        String valueStr = "";
+        try {
+            nameStr = this.name.getStringValue(expressionContext);
+            valueStr = this.value.getStringValue(expressionContext);
+        } catch (Exception exc) {
+            throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+        }
+        if (consumer instanceof AttributeAwareXMLConsumer) {
+            AttributeAwareXMLConsumer c = (AttributeAwareXMLConsumer) consumer;
+            c.attribute("", nameStr, nameStr, "CDATA", valueStr == null ? ""
+                    : valueStr);
+        } else
+            throw new SAXParseException("consumer is not attribute aware",
+                    getLocation());
+        return getEndInstruction().getNext();
+    }
+
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Attribute.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java Wed May 11 04:51:20 2005
@@ -0,0 +1,246 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.AttributeEvent;
+import org.apache.cocoon.template.jxtg.script.event.Characters;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.IgnorableWhitespace;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.template.jxtg.script.event.TextEvent;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.commons.lang.StringUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Call extends Instruction {
+    private Object macro;
+    private JXTExpression targetNamespace;
+    private Map parameters;
+    private Event body;
+
+    public Call(Define definition, StartElement startElement)
+            throws SAXException {
+        super(startElement);
+        this.parameters = new HashMap();
+        setBody(startElement);
+        setNext(startElement.getNext());
+        setDefinition(definition);
+
+        Iterator i = startElement.getAttributeEvents().iterator();
+        while (i.hasNext()) {
+            AttributeEvent attrEvent = (AttributeEvent) i.next();
+            addParameterInstance(attrEvent);
+        }
+    }
+
+    public Call(StartElement raw, Attributes attrs, Stack stack)
+            throws SAXException {
+        super(raw);
+        this.parameters = new HashMap();
+        Locator locator = getLocation();
+
+        String name = attrs.getValue("macro");
+        if (name == null) {
+            throw new SAXParseException("if: \"test\" is required", locator,
+                    null);
+        }
+        this.macro = JXTExpression.compileExpr(name, "call: \"macro\": ",
+                locator);
+
+        String namespace = StringUtils.defaultString(attrs
+                .getValue("targetNamespace"));
+        this.targetNamespace = JXTExpression.compileExpr(namespace,
+                "call: \"targetNamespace\": ", locator);
+    }
+
+    public void setDefinition(Define definition) {
+        this.macro = definition;
+    }
+
+    public void addParameterInstance(AttributeEvent attributeEvent)
+            throws SAXException {
+        ParameterInstance parameter = new ParameterInstance(
+                attributeEvent);
+        this.parameters.put(parameter.getName(), parameter);
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, MacroContext macroContext,
+            Event startEvent, Event endEvent) throws SAXException {
+        Map attributeMap = new HashMap();
+        Iterator i = parameters.keySet().iterator();
+        while (i.hasNext()) {
+            String parameterName = (String) i.next();
+            ParameterInstance parameter = (ParameterInstance) parameters
+                    .get(parameterName);
+            Object parameterValue = parameter.getValue(expressionContext);
+            attributeMap.put(parameterName, parameterValue);
+        }
+        ExpressionContext localExpressionContext = new ExpressionContext(
+                expressionContext);
+        HashMap macro = new HashMap();
+        macro.put("body", this.body);
+        macro.put("arguments", attributeMap);
+        localExpressionContext.put("macro", macro);
+
+        Define definition = resolveMacroDefinition(expressionContext,
+                executionContext);
+        Iterator iter = definition.getParameters().entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry e = (Map.Entry) iter.next();
+            String key = (String) e.getKey();
+            Parameter startParam = (Parameter) e.getValue();
+            Object default_ = startParam.getDefaultValue();
+            Object val = attributeMap.get(key);
+            if (val == null) {
+                val = default_;
+            }
+            localExpressionContext.put(key, val);
+        }
+
+        Event macroBodyStart = getNext();
+        Event macroBodyEnd = null;
+
+        if (getEndInstruction() != null)
+            macroBodyEnd = getEndInstruction();
+        else
+            macroBodyEnd = getStartElement().getEndElement();
+        
+        MacroContext newMacroContext = new MacroContext(definition.getQname(),
+                macroBodyStart, macroBodyEnd);
+        try {
+            Invoker.execute(consumer, localExpressionContext, executionContext,
+                    newMacroContext, definition.getBody(), definition
+                            .getEndInstruction());
+        } catch (SAXParseException exc) {
+            throw new SAXParseException(newMacroContext.getMacroQName() + ": "
+                    + exc.getMessage(), location, exc);
+        }
+
+        if (getEndInstruction() != null)
+            return getEndInstruction().getNext();
+        else
+            return getStartElement().getEndElement().getNext();
+    }
+
+    /**
+     * @param executionContext
+     * @return
+     * @throws SAXParseException
+     */
+    private Define resolveMacroDefinition(
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext) throws SAXParseException {
+        if (this.macro instanceof Define)
+            return (Define) macro;
+
+        Object macroName;
+        Object namespace;
+        JXTExpression macroNameExpression = (JXTExpression) macro;
+        try {
+            macroName = macroNameExpression.getValue(expressionContext);
+            namespace = targetNamespace.getValue(expressionContext);
+            if (namespace == null)
+                namespace = "";
+        } catch (Exception e) {
+            throw new SAXParseException(e.getMessage(), getLocation(), e);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(),
+                    new ErrorHolder(err));
+        }
+        Define definition = (Define) executionContext
+                .getDefinitions()
+                .get("{" + namespace.toString() + "}" + macroName.toString());
+        if (definition == null)
+            throw new SAXParseException("no macro definition: " + macroName,
+                    getLocation());
+        return definition;
+    }
+
+    /**
+     * @param startElement
+     */
+    public void setBody(Event body) {
+        this.body = body;
+
+    }
+
+    public void endNotify() throws SAXException {
+        // FIXME: copy/pasted from StartDefine (almost)
+        Event e = next;
+        boolean params = true;
+        while (e != this.getEndInstruction()) {
+            if (e instanceof ParameterInstance) {
+                ParameterInstance startParamInstance = (ParameterInstance) e;
+                if (!params) {
+                    throw new SAXParseException(
+                            "<parameter value> not allowed here: \""
+                                    + startParamInstance.name + "\"",
+                            startParamInstance.getLocation(), null);
+                }
+                Object prev = this.parameters.put(startParamInstance.name,
+                        startParamInstance);
+                if (prev != null) {
+                    throw new SAXParseException("duplicate parameter value: \""
+                            + startParamInstance.name + "\"", location, null);
+                }
+                e = startParamInstance.getEndInstruction();
+            } else if (e instanceof IgnorableWhitespace) {
+                // EMPTY
+            } else if (e instanceof Characters) {
+                // check for whitespace
+                char[] ch = ((TextEvent) e).getRaw();
+                int len = ch.length;
+                for (int i = 0; i < len; i++) {
+                    if (!Character.isWhitespace(ch[i])) {
+                        if (params) {
+                            params = false;
+                            this.body = e;
+                        }
+                        break;
+                    }
+                }
+            } else {
+                if (params) {
+                    params = false;
+                    this.body = e;
+                }
+            }
+            e = e.getNext();
+        }
+        if (this.body == null) {
+            this.body = this.getEndInstruction();
+        }
+        setNext(this.body);
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Call.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java Wed May 11 04:51:20 2005
@@ -0,0 +1,91 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Choose extends Instruction {
+
+    private When firstChoice;
+    private Otherwise otherwise;
+
+    public Choose(StartElement raw, Attributes attrs, Stack stack) {
+        super(raw);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        When startWhen = this.firstChoice;
+        while (startWhen != null) {
+            Object val;
+            try {
+                val = startWhen.getTest().getValue(expressionContext);
+            } catch (Exception e) {
+                throw new SAXParseException(e.getMessage(), getLocation(), e);
+            }
+            boolean result;
+            if (val instanceof Boolean) {
+                result = ((Boolean) val).booleanValue();
+            } else {
+                result = (val != null);
+            }
+            if (result) {
+                Invoker.execute(consumer, expressionContext, executionContext,
+                                macroContext, startWhen.getNext(),
+                                startWhen.getEndInstruction());
+                break;
+            }
+            startWhen = startWhen.getNextChoice();
+        }
+        if (startWhen == null && this.otherwise != null) {
+            Invoker.execute(consumer, expressionContext, executionContext,
+                            macroContext, this.otherwise.getNext(),
+                            this.otherwise.getEndInstruction());
+        }
+        return getEndInstruction().getNext();
+    }
+
+    public void setFirstChoice(When firstChoice) {
+        this.firstChoice = firstChoice;
+    }
+
+    public When getFirstChoice() {
+        return firstChoice;
+    }
+
+    public void setOtherwise(Otherwise otherwise) {
+        this.otherwise = otherwise;
+    }
+
+    public Otherwise getOtherwise() {
+        return otherwise;
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Choose.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java Wed May 11 04:51:20 2005
@@ -0,0 +1,71 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Properties;
+import java.util.Stack;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.commons.lang.StringUtils;
+import org.w3c.dom.NodeList;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Comment extends Instruction {
+    public Comment(StartElement raw, Attributes attrs, Stack stack) {
+        // <jx:comment>This will be parsed</jx:comment>
+        super(raw);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        // Parse the body of the comment
+        NodeList nodeList =
+            Invoker.toDOMNodeList("comment", this,
+                                  expressionContext, executionContext,
+                                  macroContext);
+        // JXPath doesn't handle NodeList, so convert it to an array
+        int len = nodeList.getLength();
+        final StringBuffer buf = new StringBuffer();
+        Properties omit = XMLUtils.createPropertiesForXML(true);
+        for (int i = 0; i < len; i++) {
+            try {
+                String str = XMLUtils.serializeNode(nodeList.item(i), omit);
+                buf.append(StringUtils.substringAfter(str, ">")); // cut
+                // the XML header
+            } catch (ProcessingException e) {
+                throw new SAXParseException(e.getMessage(), getLocation(), e);
+            }
+        }
+        char[] chars = new char[buf.length()];
+        buf.getChars(0, chars.length, chars, 0);
+        consumer.comment(chars, 0, chars.length);
+        return getEndInstruction().getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Comment.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java Wed May 11 04:51:20 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.script.event.Characters;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.IgnorableWhitespace;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.template.jxtg.script.event.TextEvent;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.commons.lang.StringUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Define extends Instruction {
+
+    private final String name;
+    private final String namespace;
+    private final String qname;
+    private final Map parameters;
+    private Event body;
+
+    public Define(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 Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        executionContext.getDefinitions().put(this.qname, this);
+        return getEndInstruction().getNext();
+    }
+
+    public void endNotify() throws SAXException {
+        Event e = next;
+        boolean params = true;
+        while (e != this.getEndInstruction()) {
+            if (e instanceof Parameter) {
+                Parameter startParam = (Parameter) e;
+                if (!params) {
+                    throw new SAXParseException(
+                            "<parameter> not allowed here: \""
+                                    + startParam.name + "\"", startParam
+                                    .getLocation(), null);
+                }
+                Object prev = this.parameters.put(startParam.name, startParam);
+                if (prev != null) {
+                    throw new SAXParseException("duplicate parameter: \""
+                            + startParam.name + "\"", location, null);
+                }
+                e = startParam.getEndInstruction();
+            } else if (e instanceof IgnorableWhitespace) {
+                // EMPTY
+            } else if (e instanceof Characters) {
+                // check for whitespace
+                char[] ch = ((TextEvent) e).getRaw();
+                int len = ch.length;
+                for (int i = 0; i < len; i++) {
+                    if (!Character.isWhitespace(ch[i])) {
+                        if (params) {
+                            params = false;
+                            this.body = e;
+                        }
+                        break;
+                    }
+                }
+            } else {
+                if (params) {
+                    params = false;
+                    this.body = e;
+                }
+            }
+            e = e.getNext();
+        }
+        if (this.body == null) {
+            this.body = this.getEndInstruction();
+        }
+    }
+
+    public Map getParameters() {
+        return parameters;
+    }
+
+    private void setBody(Event body) {
+        this.body = body;
+    }
+
+    public Event getBody() {
+        return body;
+    }
+
+    public String getQname() {
+        return qname;
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Define.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java Wed May 11 04:51:20 2005
@@ -0,0 +1,69 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Eval extends Instruction {
+    private final JXTExpression value;
+
+    public Eval(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
+        super(raw);
+
+        String select = attrs.getValue("select");
+        this.value = JXTExpression.compileExpr(select, "eval: \"select\":", getLocation());
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        try {
+            Object val = this.value.getNode(expressionContext);
+            if (!(val instanceof StartElement)) {
+                throw new Exception("macro invocation required instead of: " + val);
+            }
+            StartElement call = (StartElement) val;
+            
+            //FIXME: eval does not allow to call macro providing macro body
+            MacroContext newMacroContext = new MacroContext( call.getQname(), null, null );
+            Invoker.execute(consumer, expressionContext, executionContext,
+                            newMacroContext, call.getNext(), call.getEndElement());
+        } catch (Exception exc) {
+            throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(), new ErrorHolder(err));
+        }
+        return getEndInstruction().getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Eval.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java Wed May 11 04:51:20 2005
@@ -0,0 +1,54 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class EvalBody extends Instruction {
+    public EvalBody(StartElement raw, Attributes attrs, Stack stack) {
+        super(raw);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        try {
+            Invoker.execute(consumer, expressionContext, executionContext,
+                            null, macroContext.getBodyStart(), macroContext.getBodyEnd());
+        } catch (Exception exc) {
+            throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(),
+                                        new ErrorHolder(err));
+        }
+        return getEndInstruction().getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/EvalBody.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java Wed May 11 04:51:20 2005
@@ -0,0 +1,155 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class ForEach extends Instruction {
+
+    private final JXTExpression items;
+    private final JXTExpression var;
+    private final JXTExpression varStatus;
+    private final JXTExpression begin;
+    private final JXTExpression end;
+    private final JXTExpression step;
+    private final Boolean lenient;
+
+    public ForEach(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 = 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);
+
+        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 = JXTExpression.compileExpr(items == null ? select : items, null, locator);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        Iterator iter = null;
+        int begin, end, step;
+        String var = null, varStatus = null;
+        try {
+            iter = (this.items != null ) 
+                    ? this.items.getIterator(expressionContext)
+                    : JXTExpression.NULL_ITER;
+            begin = this.begin == null
+                ? 0
+                : this.begin.getIntValue(expressionContext);
+            end = this.end == null
+                ? Integer.MAX_VALUE
+                : this.end.getIntValue(expressionContext);
+            step = this.step == null
+                ? 1
+                : this.step.getIntValue(expressionContext);
+
+            if ( this.var != null )
+                var = this.var.getStringValue(expressionContext);
+            
+            if ( this.varStatus != null )
+                varStatus = this.varStatus.getStringValue(expressionContext);
+        } catch (Exception exc) {
+            throw new SAXParseException(exc.getMessage(),
+                                        getLocation(), exc);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(),
+                                        getLocation(), new ErrorHolder(err));
+        }
+        ExpressionContext localExpressionContext =
+            new ExpressionContext(expressionContext);
+        int i = 0;
+        // Move to the begin row
+        while (i < begin && iter.hasNext()) {
+            iter.next();
+            i++;
+        }
+        LoopTagStatus status = null;
+        if (varStatus != null) {
+            status = new LoopTagStatus();
+            status.setBegin(begin);
+            status.setEnd(end);
+            status.setStep(step);
+            status.setFirst(true);
+            localExpressionContext.put(varStatus, status);
+        }
+        int skipCounter, count = 1;
+        while (i <= end && iter.hasNext()) {
+            Object value = iter.next();
+            localExpressionContext.setContextBean(value);
+            if (var != null) {
+                localExpressionContext.put(var, value);
+            }
+            if (status != null) {
+                status.setIndex(i);
+                status.setCount(count);
+                status.setFirst(i == begin);
+                status.setCurrent(value);
+                status.setLast((i == end || !iter.hasNext()));
+            }
+            Invoker.execute(consumer, localExpressionContext, executionContext,
+                            macroContext, getNext(), getEndInstruction());
+            // Skip rows
+            skipCounter = step;
+            while (--skipCounter > 0 && iter.hasNext()) {
+                iter.next();
+            }
+            // Increase index
+            i += step;
+            count++;
+        }
+        return getEndInstruction().getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/ForEach.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java Wed May 11 04:51:20 2005
@@ -0,0 +1,189 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.Stack;
+import java.util.TimeZone;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.environment.ValueHelper;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class FormatDate extends Instruction {
+    private static final String DATE = "date";
+    private static final String TIME = "time";
+    private static final String DATETIME = "both";
+
+    private JXTExpression var;
+    private JXTExpression value;
+    private JXTExpression type;
+    private JXTExpression pattern;
+    private JXTExpression timeZone;
+    private JXTExpression dateStyle;
+    private JXTExpression timeStyle;
+    private JXTExpression locale;
+
+    public FormatDate(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException{
+        super(raw);
+
+        Locator locator = getLocation();
+
+        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 Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        try {
+            String result = format(expressionContext);
+            if (result != null) {
+                char[] chars = result.toCharArray();
+                consumer.characters(chars, 0, chars.length);
+            }
+        } catch (Exception e) {
+            throw new SAXParseException(e.getMessage(), getLocation(), e);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(), new ErrorHolder(err));
+        }
+        return getNext();
+    }
+
+    private String format(ExpressionContext expressionContext) throws Exception {
+        String var = this.var.getStringValue(expressionContext);
+        Object value = this.value.getValue(expressionContext);
+        Object locVal = this.locale.getValue(expressionContext);
+        String pattern = this.pattern.getStringValue(expressionContext);
+        Object timeZone = this.timeZone.getValue(expressionContext);
+
+        String type = this.type.getStringValue(expressionContext);
+        String timeStyle = this.timeStyle.getStringValue(expressionContext);
+        String dateStyle = this.dateStyle.getStringValue(expressionContext);
+
+        String formatted = null;
+
+        // Create formatter
+        Locale locale;
+        if (locVal != null) {
+            locale = locVal instanceof Locale ? (Locale) locVal
+                : ValueHelper.parseLocale(locVal.toString(), null);
+        } else {
+            locale = Locale.getDefault();
+        }
+        DateFormat formatter = createFormatter(locale, type, dateStyle,
+                timeStyle);
+        // Apply pattern, if present
+        if (pattern != null) {
+            try {
+                ((SimpleDateFormat) formatter).applyPattern(pattern);
+            } catch (ClassCastException cce) {
+                formatter = new SimpleDateFormat(pattern, locale);
+            }
+        }
+        // Set time zone
+        TimeZone tz = null;
+        if ((timeZone instanceof String) && ((String) timeZone).equals("")) {
+            timeZone = null;
+        }
+        if (timeZone != null) {
+            if (timeZone instanceof String) {
+                tz = TimeZone.getTimeZone((String) timeZone);
+            } else if (timeZone instanceof TimeZone) {
+                tz = (TimeZone) timeZone;
+            } else {
+                throw new IllegalArgumentException("Illegal timeZone value: \""
+                        + timeZone + "\"");
+            }
+        }
+        if (tz != null) {
+            formatter.setTimeZone(tz);
+        }
+        formatted = formatter.format(value);
+        if (var != null) {
+            expressionContext.put(var, formatted);
+            return null;
+        }
+        return formatted;
+    }
+
+    private DateFormat createFormatter(Locale loc, String type,
+            String dateStyle, String timeStyle) throws Exception {
+        DateFormat formatter = null;
+        if ((type == null) || DATE.equalsIgnoreCase(type)) {
+            formatter = DateFormat.getDateInstance(getStyle(dateStyle), loc);
+        } else if (TIME.equalsIgnoreCase(type)) {
+            formatter = DateFormat.getTimeInstance(getStyle(timeStyle), loc);
+        } else if (DATETIME.equalsIgnoreCase(type)) {
+            formatter = DateFormat.getDateTimeInstance(getStyle(dateStyle),
+                    getStyle(timeStyle), loc);
+        } else {
+            throw new IllegalArgumentException("Invalid type: \"" + type + "\"");
+        }
+        return formatter;
+    }
+
+    private static final String DEFAULT = "default";
+    private static final String SHORT = "short";
+    private static final String MEDIUM = "medium";
+    private static final String LONG = "long";
+    private static final String FULL = "full";
+
+    private int getStyle(String style) {
+        int ret = DateFormat.DEFAULT;
+        if (style != null) {
+            if (DEFAULT.equalsIgnoreCase(style)) {
+                ret = DateFormat.DEFAULT;
+            } else if (SHORT.equalsIgnoreCase(style)) {
+                ret = DateFormat.SHORT;
+            } else if (MEDIUM.equalsIgnoreCase(style)) {
+                ret = DateFormat.MEDIUM;
+            } else if (LONG.equalsIgnoreCase(style)) {
+                ret = DateFormat.LONG;
+            } else if (FULL.equalsIgnoreCase(style)) {
+                ret = DateFormat.FULL;
+            } else {
+                throw new IllegalArgumentException(
+                        "Invalid style: \""
+                                + style
+                                + "\": should be \"default\" or \"short\" or \"medium\" or \"long\" or \"full\"");
+            }
+        }
+        return ret;
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatDate.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java Wed May 11 04:51:20 2005
@@ -0,0 +1,281 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.lang.reflect.Method;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.environment.ValueHelper;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.commons.lang.StringUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class FormatNumber extends Instruction {
+
+    private JXTExpression value;
+    private JXTExpression type;
+    private JXTExpression pattern;
+    private JXTExpression currencyCode;
+    private JXTExpression currencySymbol;
+    private JXTExpression isGroupingUsed;
+    private JXTExpression maxIntegerDigits;
+    private JXTExpression minIntegerDigits;
+    private JXTExpression maxFractionDigits;
+    private JXTExpression minFractionDigits;
+    private JXTExpression locale;
+
+    private JXTExpression var;
+
+    private static Class currencyClass;
+    private static final String NUMBER = "number";
+    private static final String CURRENCY = "currency";
+    private static final String PERCENT = "percent";
+
+    static {
+        try {
+            currencyClass = Class.forName("java.util.Currency");
+            // container's runtime is J2SE 1.4 or greater
+        } catch (Exception cnfe) {
+            // EMPTY
+        }
+    }
+
+    public FormatNumber(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
+        super(raw);
+
+        Locator locator = getLocation();
+
+        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 =
+            JXTExpression.compileExpr(attrs.getValue("currencyCode"), null, locator);
+        this.currencySymbol =
+            JXTExpression.compileExpr(attrs.getValue("currencySymbol"), null, locator);
+        this.isGroupingUsed =
+            JXTExpression.compileBoolean(attrs.getValue("isGroupingUsed"), null, locator);
+        this.maxIntegerDigits =
+            JXTExpression.compileInt(attrs.getValue("maxIntegerDigits"), null, locator);
+        this.minIntegerDigits =
+            JXTExpression.compileInt(attrs.getValue("minIntegerDigits"), null, locator);
+        this.maxFractionDigits =
+            JXTExpression.compileInt(attrs.getValue("maxFractionDigits"), null, locator);
+        this.minFractionDigits =
+            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 Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        try {
+            String result = format(expressionContext);
+            if (result != null) {
+                char[] chars = result.toCharArray();
+                consumer.characters(chars, 0, chars.length);
+            }
+        } catch (Exception e) {
+            throw new SAXParseException(e.getMessage(), getLocation(), e);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(),
+                                        new ErrorHolder(err));
+        }
+        return getNext();
+    }
+
+    private String format(ExpressionContext expressionContext) throws Exception {
+        // Determine formatting locale
+        String var = this.var.getStringValue(expressionContext);
+        Number input = this.value.getNumberValue(expressionContext);
+        String type = this.type.getStringValue(expressionContext);
+        String pattern = this.pattern.getStringValue(expressionContext);
+        String currencyCode = this.currencyCode.getStringValue(expressionContext);
+        String currencySymbol = this.currencySymbol.getStringValue(expressionContext);
+        Boolean isGroupingUsed = this.isGroupingUsed.getBooleanValue(expressionContext);
+        Number maxIntegerDigits = this.maxIntegerDigits.getNumberValue(expressionContext);
+        Number minIntegerDigits = this.minIntegerDigits.getNumberValue(expressionContext);
+        Number maxFractionDigits = this.maxFractionDigits.getNumberValue(expressionContext);
+        Number minFractionDigits = this.minFractionDigits.getNumberValue(expressionContext);
+        String localeStr = this.locale.getStringValue(expressionContext);
+        Locale loc = localeStr != null
+            ? ValueHelper.parseLocale(localeStr, null)
+            : Locale.getDefault();
+        String formatted;
+        if (loc != null) {
+            // Create formatter
+            NumberFormat formatter = null;
+            if (StringUtils.isNotEmpty(pattern)) {
+                // if 'pattern' is specified, 'type' is ignored
+                DecimalFormatSymbols symbols = new DecimalFormatSymbols(loc);
+                formatter = new DecimalFormat(pattern, symbols);
+            } else {
+                formatter = createFormatter(loc, type);
+            }
+            if (StringUtils.isNotEmpty(pattern)
+                    || CURRENCY.equalsIgnoreCase(type)) {
+                setCurrency(formatter, currencyCode, currencySymbol);
+            }
+            configureFormatter(formatter, isGroupingUsed, maxIntegerDigits,
+                    minIntegerDigits, maxFractionDigits, minFractionDigits);
+            formatted = formatter.format(input);
+        } else {
+            // no formatting locale available, use toString()
+            formatted = input.toString();
+        }
+        if (var != null) {
+            expressionContext.put(var, formatted);
+            return null;
+        }
+        return formatted;
+    }
+
+    private NumberFormat createFormatter(Locale loc, String type)
+            throws Exception {
+        NumberFormat formatter = null;
+        if ((type == null) || NUMBER.equalsIgnoreCase(type)) {
+            formatter = NumberFormat.getNumberInstance(loc);
+        } else if (CURRENCY.equalsIgnoreCase(type)) {
+            formatter = NumberFormat.getCurrencyInstance(loc);
+        } else if (PERCENT.equalsIgnoreCase(type)) {
+            formatter = NumberFormat.getPercentInstance(loc);
+        } else {
+            throw new IllegalArgumentException("Invalid type: \"" + type
+                    + "\": should be \"number\" or \"currency\" or \"percent\"");
+        }
+        return formatter;
+    }
+
+    /*
+     * Applies the 'groupingUsed', 'maxIntegerDigits', 'minIntegerDigits',
+     * 'maxFractionDigits', and 'minFractionDigits' attributes to the given
+     * formatter.
+     */
+    private void configureFormatter(NumberFormat formatter,
+            Boolean isGroupingUsed, Number maxIntegerDigits,
+            Number minIntegerDigits, Number maxFractionDigits,
+            Number minFractionDigits) {
+        if (isGroupingUsed != null)
+            formatter.setGroupingUsed(isGroupingUsed.booleanValue());
+        if (maxIntegerDigits != null)
+            formatter.setMaximumIntegerDigits(maxIntegerDigits.intValue());
+        if (minIntegerDigits != null)
+            formatter.setMinimumIntegerDigits(minIntegerDigits.intValue());
+        if (maxFractionDigits != null)
+            formatter.setMaximumFractionDigits(maxFractionDigits.intValue());
+        if (minFractionDigits != null)
+            formatter.setMinimumFractionDigits(minFractionDigits.intValue());
+    }
+
+    /*
+     * Override the formatting locale's default currency symbol with the
+     * specified currency code (specified via the "currencyCode" attribute) or
+     * currency symbol (specified via the "currencySymbol" attribute).
+     * 
+     * If both "currencyCode" and "currencySymbol" are present, "currencyCode"
+     * takes precedence over "currencySymbol" if the java.util.Currency class is
+     * defined in the container's runtime (that is, if the container's runtime
+     * is J2SE 1.4 or greater), and "currencySymbol" takes precendence over
+     * "currencyCode" otherwise.
+     * 
+     * If only "currencyCode" is given, it is used as a currency symbol if
+     * java.util.Currency is not defined.
+     * 
+     * Example:
+     * 
+     * JDK "currencyCode" "currencySymbol" Currency symbol being displayed
+     * -----------------------------------------------------------------------
+     * all --- --- Locale's default currency symbol
+     * 
+     * <1.4 EUR --- EUR >=1.4 EUR --- Locale's currency symbol for Euro
+     * 
+     * all --- \u20AC \u20AC
+     * 
+     * <1.4 EUR \u20AC \u20AC >=1.4 EUR \u20AC Locale's currency symbol for Euro
+     */
+    private void setCurrency(NumberFormat formatter, String currencyCode,
+            String currencySymbol) throws Exception {
+        String code = null;
+        String symbol = null;
+
+        if (currencyCode == null) {
+            if (currencySymbol == null) {
+                return;
+            }
+            symbol = currencySymbol;
+        } else if (currencySymbol != null) {
+            if (currencyClass != null) {
+                code = currencyCode;
+            } else {
+                symbol = currencySymbol;
+            }
+        } else if (currencyClass != null) {
+            code = currencyCode;
+        } else {
+            symbol = currencyCode;
+        }
+        if (code != null) {
+            Object[] methodArgs = new Object[1];
+
+            /*
+             * java.util.Currency.getInstance()
+             */
+            Method m = currencyClass.getMethod("getInstance",
+                    new Class[] { String.class });
+
+            methodArgs[0] = code;
+            Object currency = m.invoke(null, methodArgs);
+
+            /*
+             * java.text.NumberFormat.setCurrency()
+             */
+            Class[] paramTypes = new Class[1];
+            paramTypes[0] = currencyClass;
+            Class numberFormatClass = Class.forName("java.text.NumberFormat");
+            m = numberFormatClass.getMethod("setCurrency", paramTypes);
+            methodArgs[0] = currency;
+            m.invoke(formatter, methodArgs);
+        } else {
+            /*
+             * Let potential ClassCastException propagate up (will almost never
+             * happen)
+             */
+            DecimalFormat df = (DecimalFormat) formatter;
+            DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
+            dfs.setCurrencySymbol(symbol);
+            df.setDecimalFormatSymbols(dfs);
+        }
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/FormatNumber.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java Wed May 11 04:51:20 2005
@@ -0,0 +1,79 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class If extends Instruction {
+    private final JXTExpression test;
+
+    public If(StartElement raw, Attributes attrs, Stack stack) 
+        throws SAXException {
+
+        super(raw);
+
+        Locator locator = getLocation();
+        String test = attrs.getValue("test");
+        if (test != null) {
+            this.test = JXTExpression.compileExpr(test, "if: \"test\": ", locator);
+            // Why is test lenient?
+            this.test.setLenient(Boolean.TRUE);
+        } else {
+            throw new SAXParseException("if: \"test\" is required", locator, null);
+        }
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+
+        Object val;
+        try {
+            val = this.test.getValue(expressionContext);
+        } catch (Exception e) {
+            throw new SAXParseException(e.getMessage(), getLocation(), e);
+        } catch (Error err) {
+            throw new SAXParseException(err.getMessage(), getLocation(),
+                                        new ErrorHolder(err));
+        }
+        boolean result = false;
+        if (val instanceof Boolean) {
+            result = ((Boolean) val).booleanValue();
+        } else {
+            result = (val != null);
+        }
+        if (!result) {
+            return getEndInstruction().getNext();
+        }
+        return getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/If.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java Wed May 11 04:51:20 2005
@@ -0,0 +1,145 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Iterator;
+import java.util.Stack;
+
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.environment.TemplateObjectModelHelper;
+import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.template.jxtg.expression.JXTExpression;
+import org.apache.cocoon.template.jxtg.expression.Literal;
+import org.apache.cocoon.template.jxtg.expression.Subst;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.template.jxtg.script.event.AttributeEvent;
+import org.apache.cocoon.template.jxtg.script.event.CopyAttribute;
+import org.apache.cocoon.template.jxtg.script.event.Event;
+import org.apache.cocoon.template.jxtg.script.event.StartDocument;
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.apache.cocoon.template.jxtg.script.event.SubstituteAttribute;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Import extends Instruction {
+
+    private final AttributeEvent uri;
+    private final JXTExpression select;
+
+    public Import(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 = JXTExpression.compileExpr(context, "import: \"context\": ", locator);
+            }
+        } else {
+            throw new SAXParseException("import: \"uri\" is required", locator, null);
+        }
+        this.uri = uri;
+        this.select = select;
+    }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext, ExecutionContext executionContext,
+                         MacroContext macroContext, Event startEvent, Event endEvent) 
+        throws SAXException {
+        String uri;
+        AttributeEvent e = this.uri;
+        if (e instanceof CopyAttribute) {
+            CopyAttribute copy = (CopyAttribute) e;
+            uri = copy.getValue();
+        } else {
+            StringBuffer buf = new StringBuffer();
+            SubstituteAttribute substAttr = (SubstituteAttribute) e;
+            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) {
+                    JXTExpression expr = (JXTExpression) subst;
+                    Object val;
+                    try {
+                        val = expr.getValue(expressionContext);
+                    } 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();
+        }
+        StartDocument doc;
+        try {
+            doc = executionContext.getScriptManager().resolveTemplate(uri);
+        } catch (ProcessingException exc) {
+            throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+        }
+        ExpressionContext selectExpressionContext = expressionContext;
+        if (this.select != null) {
+            try {
+                Object obj = this.select.getValue(expressionContext);
+                selectExpressionContext = new ExpressionContext(expressionContext);
+                selectExpressionContext.setContextBean(obj);
+                TemplateObjectModelHelper.fillContext(obj, selectExpressionContext);
+            } catch (Exception exc) {
+                throw new SAXParseException(exc.getMessage(), getLocation(), exc);
+            } catch (Error err) {
+                throw new SAXParseException(err.getMessage(), getLocation(),
+                                            new ErrorHolder(err));
+            }
+        }
+        try {
+            Invoker.execute(consumer, expressionContext, executionContext,
+                            macroContext, doc.getNext(), doc.getEndDocument());
+        } catch (Exception exc) {
+            throw new SAXParseException(
+                                        "Exception occurred in imported template " + uri
+                                        + ": " + exc.getMessage(), getLocation(), exc);
+        }
+        return getEndInstruction().getNext();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Import.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java?rev=169630&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java Wed May 11 04:51:20 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.template.jxtg.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.template.jxtg.script.event.StartElement;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Otherwise extends Instruction {
+    public Otherwise(StartElement raw, Attributes attrs, Stack stack)
+        throws SAXException {
+
+        super(raw);
+
+        if (stack.size() != 0 && (stack.peek() instanceof Choose)) {
+            Choose startChoose = (Choose) stack.peek();
+            startChoose.setOtherwise(this);
+        } else {
+            throw new SAXParseException("<otherwise> must be within <choose>",
+                                        getLocation(), null);
+        }
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/instruction/Otherwise.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message