cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r169632 [1/4] - in /cocoon/blocks/unsupported/template/trunk: WEB-INF/xconf/ conf/ java/org/apache/cocoon/generation/ java/org/apache/cocoon/template/ java/org/apache/cocoon/template/environment/ java/org/apache/cocoon/template/expression/ java/org/apache/cocoon/template/instruction/ java/org/apache/cocoon/template/jxtg/ java/org/apache/cocoon/template/script/ java/org/apache/cocoon/template/script/event/ java/org/apache/cocoon/transformation/ test/org/apache/cocoon/template/jxtg/
Date Wed, 11 May 2005 12:08:37 GMT
Author: lgawron
Date: Wed May 11 05:08:34 2005
New Revision: 169632

URL: http://svn.apache.org/viewcvs?rev=169632&view=rev
Log:
o.a.c.template.jxtg -> o.a.c.template

Added:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateGenerator.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateTransformer.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/TransformerAdapter.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Attribute.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Call.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Choose.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Comment.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Define.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Eval.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/EvalBody.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/ForEach.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/FormatDate.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/FormatNumber.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/If.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Import.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Instruction.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/LoopTagStatus.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/MacroContext.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Otherwise.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Out.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Parameter.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/ParameterInstance.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Set.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Template.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/When.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultInstructionFactory.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/DefaultScriptManager.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/InstructionFactory.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/Invoker.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/Parser.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/ScriptManager.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/AttributeEvent.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/Characters.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/CopyAttribute.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndCDATA.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndDTD.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndDocument.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndElement.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndEntity.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndInstruction.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/EndPrefixMapping.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/Event.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/IgnorableWhitespace.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/ProcessingInstruction.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/SkippedEntity.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartCDATA.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartDTD.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartDocument.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartElement.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartEntity.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/StartPrefixMapping.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/SubstituteAttribute.java   (with props)
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/script/event/TextEvent.java   (with props)
Removed:
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/jxtg/
Modified:
    cocoon/blocks/unsupported/template/trunk/WEB-INF/xconf/cocoon-template.xconf
    cocoon/blocks/unsupported/template/trunk/conf/template-generator.xmap
    cocoon/blocks/unsupported/template/trunk/conf/template-transformer.xmap
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/generation/JXTemplateGenerator.java
    cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/transformation/JXTemplateTransformer.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=169632&r1=169631&r2=169632&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 05:08:34 2005
@@ -21,28 +21,28 @@
     +-->
 <components>
     <include src="context://WEB-INF/xconf/cocoon-template-expression.xconf"/>
-    <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">
+    <component role="org.apache.cocoon.template.script.ScriptManager" class="org.apache.cocoon.template.script.DefaultScriptManager"/>
+    <component role="org.apache.cocoon.template.script.InstructionFactory" class="org.apache.cocoon.template.script.DefaultInstructionFactory">
         <instructions targetNamespace="http://apache.org/cocoon/templates/jx/1.0">
-            <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"/>
+            <instruction name="template" class="org.apache.cocoon.template.instruction.Template"/>
+            <instruction name="forEach" class="org.apache.cocoon.template.instruction.ForEach"/>
+            <instruction name="if" class="org.apache.cocoon.template.instruction.If"/>
+            <instruction name="choose" class="org.apache.cocoon.template.instruction.Choose"/>
+            <instruction name="when" class="org.apache.cocoon.template.instruction.When"/>
+            <instruction name="otherwise" class="org.apache.cocoon.template.instruction.Otherwise"/>
+            <instruction name="out" class="org.apache.cocoon.template.instruction.Out"/>
+            <instruction name="import" class="org.apache.cocoon.template.instruction.Import"/>
+            <instruction name="set" class="org.apache.cocoon.template.instruction.Set"/>
+            <instruction name="macro" class="org.apache.cocoon.template.instruction.Define"/>
+            <instruction name="evalBody" class="org.apache.cocoon.template.instruction.EvalBody"/>
+            <instruction name="eval" class="org.apache.cocoon.template.instruction.Eval"/>
+            <instruction name="parameter" class="org.apache.cocoon.template.instruction.Parameter"/>
+            <instruction name="formatNumber" class="org.apache.cocoon.template.instruction.FormatNumber"/>
+            <instruction name="formatDate" class="org.apache.cocoon.template.instruction.FormatDate"/>
+            <instruction name="comment" class="org.apache.cocoon.template.instruction.Comment"/>
+            <instruction name="call" class="org.apache.cocoon.template.instruction.Call"/>
+            <instruction name="withParam" class="org.apache.cocoon.template.instruction.ParameterInstance"/>
+            <instruction name="attribute" class="org.apache.cocoon.template.instruction.Attribute"/>
         </instructions>
     </component>
 </components>

Modified: cocoon/blocks/unsupported/template/trunk/conf/template-generator.xmap
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/conf/template-generator.xmap?rev=169632&r1=169631&r2=169632&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/conf/template-generator.xmap (original)
+++ cocoon/blocks/unsupported/template/trunk/conf/template-generator.xmap Wed May 11 05:08:34 2005
@@ -24,7 +24,7 @@
 
     <map:generator name="jx"
                    logger="sitemap.generator.jx"
-                   src="org.apache.cocoon.template.jxtg.JXTemplateGenerator"
+                   src="org.apache.cocoon.template.JXTemplateGenerator"
                    label="content"
                    pool-max="16">
     </map:generator>

Modified: cocoon/blocks/unsupported/template/trunk/conf/template-transformer.xmap
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/conf/template-transformer.xmap?rev=169632&r1=169631&r2=169632&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/conf/template-transformer.xmap (original)
+++ cocoon/blocks/unsupported/template/trunk/conf/template-transformer.xmap Wed May 11 05:08:34 2005
@@ -16,5 +16,5 @@
 -->
 
 <xmap xpath="/sitemap/components/transformers" unless="transformer[@name='jx']">
-    <map:transformer logger="sitemap.transformer.jx" name="jx" pool-max="16" src="org.apache.cocoon.template.jxtg.JXTemplateTransformer"/>
+    <map:transformer logger="sitemap.transformer.jx" name="jx" pool-max="16" src="org.apache.cocoon.template.JXTemplateTransformer"/>
 </xmap>

Modified: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/generation/JXTemplateGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/generation/JXTemplateGenerator.java?rev=169632&r1=169631&r2=169632&view=diff
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/generation/JXTemplateGenerator.java (original)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/generation/JXTemplateGenerator.java Wed May 11 05:08:34 2005
@@ -20,5 +20,5 @@
  * @version SVN $Id$
  */
 public class JXTemplateGenerator extends
-        org.apache.cocoon.template.jxtg.JXTemplateGenerator {
+        org.apache.cocoon.template.JXTemplateGenerator {
 }

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateGenerator.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateGenerator.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateGenerator.java Wed May 11 05:08:34 2005
@@ -0,0 +1,161 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.caching.CacheableProcessingComponent;
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.environment.FlowObjectModelHelper;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.generation.ServiceableGenerator;
+import org.apache.cocoon.template.environment.ExecutionContext;
+import org.apache.cocoon.template.environment.JXCacheKey;
+import org.apache.cocoon.template.environment.JXSourceValidity;
+import org.apache.cocoon.template.expression.JXTExpression;
+import org.apache.cocoon.template.script.Invoker;
+import org.apache.cocoon.template.script.ScriptManager;
+import org.apache.cocoon.template.script.event.Event;
+import org.apache.cocoon.template.script.event.StartDocument;
+import org.apache.cocoon.xml.AttributeAwareXMLConsumerImpl;
+import org.apache.cocoon.xml.RedundantNamespacesFilter;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.excalibur.source.SourceValidity;
+import org.xml.sax.SAXException;
+
+/**
+ * @cocoon.sitemap.component.documentation Provides a generic page template with
+ *                                         embedded JSTL and XPath expression
+ *                                         substitution to access data sent by
+ *                                         Cocoon Flowscripts.
+ * 
+ * @cocoon.sitemap.component.name jx
+ * @cocoon.sitemap.component.label content
+ * @cocoon.sitemap.component.logger sitemap.generator.jx
+ * 
+ * @cocoon.sitemap.component.pooling.max 16
+ * 
+ * 
+ * @version SVN $Id: JXTemplateGenerator.java 169169 2005-05-08 21:23:28Z
+ *          lgawron $
+ */
+public class JXTemplateGenerator extends ServiceableGenerator implements
+        CacheableProcessingComponent {
+    /** The namespace used by this generator */
+    public final static String NS = "http://apache.org/cocoon/templates/jx/1.0";
+
+    public final static String CACHE_KEY = "cache-key";
+    public final static String VALIDITY = "cache-validity";
+
+    private ExpressionContext expressionContext;
+    private ScriptManager scriptManager;
+    private StartDocument startDocument;
+    private Map definitions;
+
+    public XMLConsumer getConsumer() {
+        return this.xmlConsumer;
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        scriptManager = (ScriptManager) this.manager.lookup(ScriptManager.ROLE);
+    }
+
+    public void dispose() {
+        this.manager.release(scriptManager);
+        super.dispose();
+    }
+
+    public void recycle() {
+        this.startDocument = null;
+        this.expressionContext = null;
+        this.definitions = null;
+        super.recycle();
+    }
+
+    public void setup(SourceResolver resolver, Map objectModel, String src,
+            Parameters parameters) throws ProcessingException, SAXException,
+            IOException {
+
+        super.setup(resolver, objectModel, src, parameters);
+        if (src != null)
+            startDocument = scriptManager.resolveTemplate(src);
+
+        this.expressionContext = FlowObjectModelHelper.getFOMExpressionContext(
+                objectModel, parameters);
+        this.definitions = new HashMap();
+    }
+
+    public void generate() throws IOException, SAXException,
+            ProcessingException {
+        performGeneration(this.startDocument, null);
+
+        // no need to reference compiled script anymore
+        this.startDocument = null;
+    }
+
+    public void performGeneration(Event startEvent, Event endEvent)
+            throws SAXException {
+        XMLConsumer consumer = new AttributeAwareXMLConsumerImpl(
+                new RedundantNamespacesFilter(this.xmlConsumer));
+        ((Map) expressionContext.get("cocoon")).put("consumer", consumer);
+        Invoker.execute(consumer, this.expressionContext, new ExecutionContext(
+                this.definitions, this.scriptManager), null, startEvent, null);
+    }
+
+    public Serializable getKey() {
+        JXTExpression cacheKeyExpr = (JXTExpression) this.startDocument
+                .getTemplateProperty(JXTemplateGenerator.CACHE_KEY);
+        if (cacheKeyExpr == null)
+            return null;
+        try {
+            final Serializable templateKey = (Serializable) cacheKeyExpr
+                    .getValue(this.expressionContext);
+            if (templateKey != null) {
+                return new JXCacheKey(this.startDocument.getUri(), templateKey);
+            }
+        } catch (Exception e) {
+            getLogger().error("error evaluating cache key", e);
+        }
+        return null;
+    }
+
+    public SourceValidity getValidity() {
+        JXTExpression validityExpr = (JXTExpression) this.startDocument
+                .getTemplateProperty(JXTemplateGenerator.VALIDITY);
+        if (validityExpr == null)
+            return null;
+        try {
+            final SourceValidity sourceValidity = this.startDocument
+                    .getSourceValidity();
+            final SourceValidity templateValidity = (SourceValidity) validityExpr
+                    .getValue(this.expressionContext);
+            if (sourceValidity != null && templateValidity != null) {
+                return new JXSourceValidity(sourceValidity, templateValidity);
+            }
+        } catch (Exception e) {
+            getLogger().error("error evaluating cache validity", e);
+        }
+        return null;
+    }
+}

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

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

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateTransformer.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateTransformer.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/JXTemplateTransformer.java Wed May 11 05:08:34 2005
@@ -0,0 +1,27 @@
+/*
+* Copyright 1999-2004 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;
+
+/**
+ * @version SVN $Id$
+ */
+public class JXTemplateTransformer extends TransformerAdapter {
+    /**
+     * This class is just a placeholder to provide a class name you
+     * can easily reference from your Sitemap. All of its functionality is 
+     * provided by its parent class.
+     */
+}

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

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

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/TransformerAdapter.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/TransformerAdapter.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/TransformerAdapter.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/TransformerAdapter.java Wed May 11 05:08:34 2005
@@ -0,0 +1,114 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.template.script.InstructionFactory;
+import org.apache.cocoon.template.script.Parser;
+import org.apache.cocoon.transformation.ServiceableTransformer;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.xml.sax.SAXException;
+
+/**
+ * Adapter that makes this generator usable as a transformer (Note there is a
+ * performance penalty for this however: you effectively recompile the template
+ * for every instance document)
+ * 
+ * @version SVN $Id$
+ */
+public class TransformerAdapter extends ServiceableTransformer {
+    static class TemplateConsumer extends Parser implements XMLConsumer,
+            Serviceable, Disposable {
+
+        private InstructionFactory instructionFactory;
+        private ServiceManager manager;
+
+        public TemplateConsumer() {
+            this.gen = new JXTemplateGenerator();
+        }
+
+        public void setup(SourceResolver resolver, Map objectModel, String src,
+                Parameters parameters) throws ProcessingException,
+                SAXException, IOException {
+            this.gen.setup(resolver, objectModel, null, parameters);
+        }
+
+        public void service(ServiceManager manager) throws ServiceException {
+            this.manager = manager;
+            this.gen.service(manager);
+            this.instructionFactory = (InstructionFactory) manager
+                    .lookup(InstructionFactory.ROLE);
+        }
+
+        public void dispose() {
+            this.manager.release(instructionFactory);
+        }
+
+        public void endDocument() throws SAXException {
+            super.endDocument();
+            gen.performGeneration(getStartEvent(), null);
+        }
+
+        void setConsumer(XMLConsumer consumer) {
+            gen.setConsumer(consumer);
+        }
+
+        protected void recycle() {
+            super.recycle();
+            gen.recycle();
+        }
+
+        JXTemplateGenerator gen;
+    }
+
+    TemplateConsumer templateConsumer = new TemplateConsumer();
+
+    public void recycle() {
+        super.recycle();
+        templateConsumer.recycle();
+    }
+
+    public void setup(SourceResolver resolver, Map objectModel, String src,
+            Parameters parameters) throws ProcessingException, SAXException,
+            IOException {
+        super.setup(resolver, objectModel, src, parameters);
+        templateConsumer.setup(resolver, objectModel, src, parameters);
+    }
+
+    public void service(ServiceManager manager) throws ServiceException {
+        super.service(manager);
+        templateConsumer.service(manager);
+    }
+
+    public void dispose() {
+        templateConsumer.dispose();
+        super.dispose();
+    }
+
+    public void setConsumer(XMLConsumer xmlConsumer) {
+        super.setConsumer(templateConsumer);
+        templateConsumer.setConsumer(xmlConsumer);
+    }
+}

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

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

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java Wed May 11 05:08:34 2005
@@ -0,0 +1,49 @@
+/*
+ * 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.environment;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+/**
+ * @version SVN $Id$
+ */
+public class ErrorHolder extends Exception {
+
+    private Error err;
+
+    public ErrorHolder(Error err) {
+        super(err.getMessage());
+        this.err = err;
+    }
+
+    public void printStackTrace(PrintStream ps) {
+        err.printStackTrace(ps);
+    }
+
+    public void printStackTrace(PrintWriter pw) {
+        err.printStackTrace(pw);
+    }
+
+    public void printStackTrace() {
+        err.printStackTrace();
+    }
+
+    public Error getError() {
+        return err;
+    }
+
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ErrorHolder.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java Wed May 11 05:08:34 2005
@@ -0,0 +1,41 @@
+/*
+ * 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.environment;
+
+import java.util.Map;
+
+import org.apache.cocoon.template.script.ScriptManager;
+
+/**
+ * @version SVN $Id$
+ */
+public class ExecutionContext {
+    private Map definitions;
+    private ScriptManager scriptManager;
+
+    public ExecutionContext(Map definitions, ScriptManager scriptManager) {
+        this.definitions = definitions;
+        this.scriptManager = scriptManager;
+    }
+
+    public Map getDefinitions() {
+        return this.definitions;
+    }
+
+    public ScriptManager getScriptManager() {
+        return this.scriptManager;
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ExecutionContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java Wed May 11 05:08:34 2005
@@ -0,0 +1,48 @@
+/*
+ * 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.environment;
+
+import java.io.Serializable;
+
+/**
+ * @version SVN $Id$
+ */
+public final class JXCacheKey implements Serializable {
+    private final String templateUri;
+    private final Serializable templateKey;
+
+    public JXCacheKey(String templateUri, Serializable templateKey) {
+        this.templateUri = templateUri;
+        this.templateKey = templateKey;
+    }
+
+    public int hashCode() {
+        return templateUri.hashCode() + templateKey.hashCode();
+    }
+
+    public String toString() {
+        return "jxtg:" + templateUri + "_" + templateKey;
+    }
+
+    public boolean equals(Object o) {
+        if (o instanceof JXCacheKey) {
+            JXCacheKey jxck = (JXCacheKey) o;
+            return this.templateUri.equals(jxck.templateUri)
+                    && this.templateKey.equals(jxck.templateKey);
+        }
+        return false;
+    }
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXCacheKey.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java Wed May 11 05:08:34 2005
@@ -0,0 +1,73 @@
+/*
+ * 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.environment;
+
+import java.io.Serializable;
+
+import org.apache.excalibur.source.SourceValidity;
+
+/**
+ * @version SVN $Id$
+ */
+public final class JXSourceValidity implements SourceValidity, Serializable {
+    private final SourceValidity sourceValidity;
+    private final SourceValidity templateValidity;
+
+    public JXSourceValidity(SourceValidity sourceValidity,
+            SourceValidity templateValidity) {
+        this.sourceValidity = sourceValidity;
+        this.templateValidity = templateValidity;
+    }
+
+    public int isValid() {
+        switch (sourceValidity.isValid()) {
+        case SourceValidity.INVALID:
+            return SourceValidity.INVALID;
+        case SourceValidity.UNKNOWN: {
+            if (templateValidity.isValid() == SourceValidity.INVALID) {
+                return SourceValidity.INVALID;
+            } else {
+                return SourceValidity.UNKNOWN;
+            }
+        }
+        case SourceValidity.VALID:
+            return templateValidity.isValid();
+        }
+        return SourceValidity.UNKNOWN;
+    }
+
+    public int isValid(SourceValidity otherValidity) {
+        if (otherValidity instanceof JXSourceValidity) {
+            JXSourceValidity otherJXValidity = (JXSourceValidity) otherValidity;
+            switch (sourceValidity.isValid(otherJXValidity.sourceValidity)) {
+            case SourceValidity.INVALID:
+                return SourceValidity.INVALID;
+            case SourceValidity.UNKNOWN: {
+                if (templateValidity.isValid(otherJXValidity.templateValidity) == SourceValidity.INVALID) {
+                    return SourceValidity.INVALID;
+                } else {
+                    return SourceValidity.UNKNOWN;
+                }
+            }
+            case SourceValidity.VALID:
+                return templateValidity
+                        .isValid(otherJXValidity.templateValidity);
+            }
+        }
+        return 0;
+    }
+
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/JXSourceValidity.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java Wed May 11 05:08:34 2005
@@ -0,0 +1,51 @@
+/*
+ * 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.environment;
+
+import org.xml.sax.Locator;
+
+/**
+ * Facade to the Locator to be set on the consumer prior to sending other
+ * events, location member changeable
+ * @version SVN $Id$
+ */
+public class LocatorFacade implements Locator {
+    private Locator locator;
+
+    public LocatorFacade(Locator initialLocator) {
+        this.locator = initialLocator;
+    }
+
+    public void setDocumentLocator(Locator newLocator) {
+        this.locator = newLocator;
+    }
+
+    public int getColumnNumber() {
+        return this.locator.getColumnNumber();
+    }
+
+    public int getLineNumber() {
+        return this.locator.getLineNumber();
+    }
+
+    public String getPublicId() {
+        return this.locator.getPublicId();
+    }
+
+    public String getSystemId() {
+        return this.locator.getSystemId();
+    }
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/LocatorFacade.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java Wed May 11 05:08:34 2005
@@ -0,0 +1,52 @@
+/*
+ * 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.environment;
+
+import java.util.Locale;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * @version SVN $Id$
+ */
+public class ValueHelper {
+
+    public static Locale parseLocale(String locale, String variant) {
+        Locale ret = null;
+        String language = locale;
+        String country = null;
+        int index = StringUtils.indexOfAny(locale, "-_");
+    
+        if (index > -1) {
+            language = locale.substring(0, index);
+            country = locale.substring(index + 1);
+        }
+        if (StringUtils.isEmpty(language)) {
+            throw new IllegalArgumentException("No language in locale");
+        }
+        if (country == null) {
+            ret = variant != null ? new Locale(language, "", variant) : new Locale(language, ""); 
+        } else if (country.length() > 0) {
+            ret = variant != null ? new Locale(language, country, variant) : new Locale(language, country); 
+        } else {
+            throw new IllegalArgumentException("Empty country in locale");
+        }
+        return ret;
+    }
+
+}
+
+

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/environment/ValueHelper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java Wed May 11 05:08:34 2005
@@ -0,0 +1,287 @@
+/*
+ * 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.expression;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+
+import org.apache.cocoon.components.expression.Expression;
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.components.expression.jexl.JexlCompiler;
+import org.apache.cocoon.components.expression.jxpath.JXPathCompiler;
+import org.apache.cocoon.components.expression.jxpath.JXPathExpression;
+import org.apache.cocoon.template.environment.ErrorHolder;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class JXTExpression extends Subst {
+
+    private String raw;
+    private Object compiledExpression;
+
+    private static JXPathCompiler jxpathCompiler = new JXPathCompiler();
+    private static JexlCompiler jexlCompiler = new JexlCompiler();
+    private static String JXPATH = "jxpath";
+    private static String JEXL = "jexl";
+
+    // Factory methods
+
+    public static JXTExpression compile(final String expression, boolean xpath)
+        throws Exception {
+        Expression compiled;
+        if (xpath) {
+            compiled = jxpathCompiler.compile(JXPATH, expression);
+        } else {
+            compiled = jexlCompiler.compile(JEXL, expression);
+        }
+        return new JXTExpression(expression, compiled);
+    }
+
+    public static JXTExpression compileBoolean(String val, String msg,
+                                               Locator location) throws SAXException {
+        JXTExpression res = compileExpr(val, msg, location);
+        if (res != null && res.getCompiledExpression() == null && res.getRaw() != null) {
+            res.setCompiledExpression(Boolean.valueOf(res.getRaw()));
+        }
+        return res;
+    }
+
+    /*
+     * Compile an integer expression (returns either a Compiled Expression or an
+     * Integer literal)
+     */
+    public static JXTExpression compileInt(String val, String msg,
+            Locator location) throws SAXException {
+        JXTExpression res = compileExpr(val, msg, location);
+        if (res != null && res.getCompiledExpression() == null && res.getRaw() != null) {
+            res.setCompiledExpression(Integer.valueOf(res.getRaw()));
+        }
+        return res;
+    }
+
+    public static JXTExpression compileExpr(String inStr) throws Exception {
+        try {
+            if (inStr == null) {
+                return null;
+            }
+            StringReader in = new StringReader(inStr.trim());
+            int ch;
+            boolean xpath = false;
+            boolean inExpr = false;
+            StringBuffer expr = new StringBuffer();
+            while ((ch = in.read()) != -1) {
+                char c = (char) ch;
+                if (inExpr) {
+                    if (c == '\\') {
+                        ch = in.read();
+                        expr.append((ch == -1) ? '\\' : (char) ch);
+                    } else if (c == '}') {
+                        return compile(expr.toString(), xpath);
+                    } else {
+                        expr.append(c);
+                    }
+                } else {
+                    if (c == '$' || c == '#') {
+                        ch = in.read();
+                        if (ch == '{') {
+                            inExpr = true;
+                            xpath = c == '#';
+                            continue;
+                        }
+                    }
+                    // hack: invalid expression?
+                    // just return the original and swallow exception
+                    return new JXTExpression(inStr, null);
+                }
+            }
+            if (inExpr) {
+                // unclosed #{} or ${}
+                throw new Exception("Unterminated " + (xpath ? "#" : "$") + "{");
+            }
+        } catch (IOException ignored) {
+            ignored.printStackTrace();
+        }
+        return new JXTExpression(inStr, null);
+    }
+
+    /**
+     * Compile a single Jexl expr (contained in ${}) or XPath expression
+     * (contained in #{})
+     */
+
+    public static JXTExpression compileExpr(String expr, String errorPrefix,
+                                            Locator location) throws SAXParseException {
+        try {
+            return compileExpr(expr);
+        } catch (Exception exc) {
+            throw new SAXParseException(errorPrefix + exc.getMessage(),
+                    location, exc);
+        } catch (Error err) {
+            throw new SAXParseException(errorPrefix + err.getMessage(),
+                    location, new ErrorHolder(err));
+        }
+    }
+
+
+    // Members
+
+    private JXTExpression(String raw, Object expr) {
+        this.raw = raw;
+        this.compiledExpression = expr;
+    }
+
+    private Object getCompiledExpression() {
+        return compiledExpression;
+    }
+
+    private void setCompiledExpression(Object compiledExpression) {
+        this.compiledExpression = compiledExpression;
+    }
+
+    private String getRaw() {
+        return raw;
+    }
+
+    // Geting the value of the expression in various forms
+
+    // Hack: try to prevent JXPath from converting result to a String
+    public Object getNode(ExpressionContext expressionContext)
+        throws Exception {
+        Object compiled = this.getCompiledExpression();
+        if (compiled instanceof Expression)
+            return ((Expression)compiled).getNode(expressionContext);
+        return this.getRaw();
+    }
+
+    public Iterator getIterator(ExpressionContext expressionContext)
+        throws Exception {
+        Iterator iter = null;
+        if (this.getCompiledExpression() != null || this.getRaw() != null) {
+            if (this.getCompiledExpression() instanceof Expression) {
+                iter =
+                    ((Expression)this.getCompiledExpression()).iterate(expressionContext);
+            } else {
+                // literal value
+                iter = new Iterator() {
+                        Object val = this;
+                        
+                        public boolean hasNext() {
+                            return val != null;
+                        }
+                        
+                        public Object next() {
+                            Object res = val;
+                            val = null;
+                            return res;
+                        }
+                        
+                        public void remove() {
+                            // EMPTY
+                        }
+                    };
+            }
+        } else {
+            iter = NULL_ITER;
+        }
+        return iter;
+    }
+
+    public Boolean getBooleanValue(ExpressionContext expressionContext)
+        throws Exception {
+        Object res = getValue(expressionContext);
+        return res instanceof Boolean ? (Boolean)res : null;
+    }
+
+    public String getStringValue(ExpressionContext expressionContext)
+        throws Exception {
+        Object res = getValue(expressionContext);
+        if (res != null) {
+            return res.toString();
+        }
+        if (this.getCompiledExpression() == null) {
+            return this.getRaw();
+        }
+        return null;
+    }
+
+    public Number getNumberValue(ExpressionContext expressionContext)
+        throws Exception {
+        Object res = getValue(expressionContext);
+        if (res instanceof Number) {
+            return (Number)res;
+        }
+        if (res != null) {
+            return Double.valueOf(res.toString());
+        }
+        return null;
+    }
+
+    public int getIntValue(ExpressionContext expressionContext)
+        throws Exception {
+        Object res = getValue(expressionContext);
+        return res instanceof Number ? ((Number)res).intValue() : 0;
+    }
+
+    public Object getValue(ExpressionContext expressionContext)
+        throws Exception {
+        if (this.getCompiledExpression() != null) {
+            Object compiled = this.getCompiledExpression();
+            if (compiled instanceof Expression)
+                return ((Expression)compiled).evaluate(expressionContext);
+            else
+                return compiled;
+        } else
+            return null;
+    }
+
+    public void setLenient(Boolean lenient) {
+        if (this.compiledExpression instanceof Expression)
+            ((Expression)this.compiledExpression).setProperty(JXPathExpression.LENIENT, lenient);
+    }
+
+    public static final Iterator EMPTY_ITER = new Iterator() {
+        public boolean hasNext() {
+            return false;
+        }
+
+        public Object next() {
+            return null;
+        }
+
+        public void remove() {
+            // EMPTY
+        }
+    };
+
+    static public final Iterator NULL_ITER = new Iterator() {
+        public boolean hasNext() {
+            return true;
+        }
+
+        public Object next() {
+            return null;
+        }
+
+        public void remove() {
+            // EMPTY
+        }
+    };
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/JXTExpression.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java Wed May 11 05:08:34 2005
@@ -0,0 +1,43 @@
+/*
+ * 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.expression;
+
+/*
+  From efficiency reasons it might be better to split this class in
+  two, one that represent attribute content that are strings and one
+  for Character content that are handled as char arrays. Here the
+  content is stored as a char array as there in most cases will be
+  much more content in elements than in attributes, so it is better to
+  avoid copying there. 
+*/
+/**
+ * @version SVN $Id$
+ */
+public class Literal extends Subst {
+    public Literal(String val) {
+        this.value = val.toCharArray();
+    }
+
+    public String getValue() {
+        return new String(this.value);
+    }
+
+    public char[] getCharArray() {
+        return value;
+    }
+
+    private final char[] value;
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Literal.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java Wed May 11 05:08:34 2005
@@ -0,0 +1,23 @@
+/*
+ * 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.expression;
+
+/**
+ * @version SVN $Id$
+ */
+public class Subst {
+    // VOID
+}
\ No newline at end of file

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Subst.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java Wed May 11 05:08:34 2005
@@ -0,0 +1,164 @@
+/*
+ * 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.expression;
+
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.environment.ErrorHolder;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * @version SVN $Id$
+ */
+public class Substitutions {
+
+    final private List substitutions;
+    final private boolean hasSubstitutions;
+
+    public Substitutions(Locator location, String stringTemplate) throws SAXException {
+        this(location, new StringReader(stringTemplate));
+    }
+
+    public Substitutions(Locator location, char[] chars, int start, int length)
+        throws SAXException {
+        this(location, new CharArrayReader(chars, start, length));
+    }
+
+    private Substitutions(Locator location, Reader in) throws SAXException {
+        LinkedList substitutions = new LinkedList();
+        StringBuffer buf = new StringBuffer();
+        buf.setLength(0);
+        int ch;
+        boolean inExpr = false;
+        boolean xpath = false;
+        try {
+        top:
+            while ((ch = in.read()) != -1) {
+                // column++;
+                char c = (char) ch;
+            processChar:
+                while (true) {
+                    if (inExpr) {
+                        if (c == '\\') {
+                            ch = in.read();
+                            buf.append(ch == -1 ? '\\' : (char) ch);
+                        } else if (c == '}') {
+                            String str = buf.toString();
+                            JXTExpression compiledExpression;
+                            try {
+                                compiledExpression = JXTExpression.compile(str, xpath);
+                            } catch (Exception exc) {
+                                throw new SAXParseException(exc.getMessage(),
+                                                            location, exc);
+                            } catch (Error err) {
+                                throw new SAXParseException(err.getMessage(),
+                                                            location,
+                                                            new ErrorHolder(err));
+                            }
+                            substitutions.add(compiledExpression);
+                            buf.setLength(0);
+                            inExpr = false;
+                        } else {
+                            buf.append(c);
+                        }
+                    } else if (c == '$' || c == '#') {
+                        ch = in.read();
+                        if (ch == '{') {
+                            xpath = c == '#';
+                            inExpr = true;
+                            if (buf.length() > 0) {
+                                substitutions.add(new Literal(buf.toString()));
+                                buf.setLength(0);
+                            }
+                            continue top;
+                        }
+                        buf.append(c);
+                        if (ch != -1) {
+                            c = (char) ch;
+                            continue processChar;
+                        }
+                    } else {
+                        buf.append(c);
+                    }
+                    break;
+                }
+            }
+        } catch (IOException ignored) {
+            // won't happen
+            ignored.printStackTrace();
+        }
+        if (inExpr) {
+            // unclosed #{} or ${}
+            String msg = "Unterminated " + (xpath ? "#" : "$") + "{";
+            throw new SAXParseException(msg, location, null);
+        }
+        substitutions.add(new Literal(buf.toString()));
+
+        this.substitutions = substitutions;
+        this.hasSubstitutions = !substitutions.isEmpty();
+    }
+
+    public boolean hasSubstitutions() {
+        return this.hasSubstitutions;
+    }
+
+    public Iterator iterator() {
+        return this.substitutions.iterator();
+    }
+
+    public int size() {
+        return this.substitutions.size();
+    }
+
+    public Object get(int pos) {
+        return this.substitutions.get(pos);
+    }
+
+    public String toString(Locator location, ExpressionContext expressionContext)
+        throws SAXException {
+        StringBuffer buf = new StringBuffer();
+        Iterator iterSubst = iterator();
+        while (iterSubst.hasNext()) {
+            Subst subst = (Subst) iterSubst.next();
+            if (subst instanceof Literal) {
+                Literal lit = (Literal) subst;
+                buf.append(lit.getValue());
+            } else if (subst instanceof JXTExpression) {
+                JXTExpression expr = (JXTExpression) subst;
+                Object val;
+                try {
+                    val = expr.getValue(expressionContext);
+                } catch (Exception e) {
+                    throw new SAXParseException(e.getMessage(), location, e);
+                } catch (Error err) {
+                    throw new SAXParseException(err.getMessage(), location,
+                                                new ErrorHolder(err));
+                }
+                buf.append(val != null ? val.toString() : "");
+            }
+        }
+        return buf.toString();
+    }
+}

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/expression/Substitutions.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Attribute.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Attribute.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Attribute.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Attribute.java Wed May 11 05:08:34 2005
@@ -0,0 +1,72 @@
+/*
+ * Created on 2005-04-19
+ */
+package org.apache.cocoon.template.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.environment.ExecutionContext;
+import org.apache.cocoon.template.expression.JXTExpression;
+import org.apache.cocoon.template.script.event.Event;
+import org.apache.cocoon.template.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/instruction/Attribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Call.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Call.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Call.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Call.java Wed May 11 05:08:34 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.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.environment.ErrorHolder;
+import org.apache.cocoon.template.environment.ExecutionContext;
+import org.apache.cocoon.template.expression.JXTExpression;
+import org.apache.cocoon.template.script.Invoker;
+import org.apache.cocoon.template.script.event.AttributeEvent;
+import org.apache.cocoon.template.script.event.Characters;
+import org.apache.cocoon.template.script.event.Event;
+import org.apache.cocoon.template.script.event.IgnorableWhitespace;
+import org.apache.cocoon.template.script.event.StartElement;
+import org.apache.cocoon.template.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/instruction/Call.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Choose.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Choose.java?rev=169632&view=auto
==============================================================================
--- cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Choose.java (added)
+++ cocoon/blocks/unsupported/template/trunk/java/org/apache/cocoon/template/instruction/Choose.java Wed May 11 05:08:34 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.instruction;
+
+import java.util.Stack;
+
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.environment.ExecutionContext;
+import org.apache.cocoon.template.script.Invoker;
+import org.apache.cocoon.template.script.event.Event;
+import org.apache.cocoon.template.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/instruction/Choose.java
------------------------------------------------------------------------------
    svn:eol-style = native

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



Mime
View raw message