cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r155016 - in cocoon/trunk/src/blocks/template/java/org/apache/cocoon: environment/ template/jxtg/expression/ template/jxtg/instruction/ template/jxtg/script/ template/jxtg/script/event/
Date Wed, 23 Feb 2005 14:41:57 GMT
Author: lgawron
Date: Wed Feb 23 06:41:48 2005
New Revision: 155016

URL: http://svn.apache.org/viewcvs?view=rev&rev=155016
Log:
breaking down o.a.c.template.jxtg.script.Invoker

Modified:
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Characters.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndCDATA.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDTD.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDocument.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndElement.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndEntity.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndPrefixMapping.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Event.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/IgnorableWhitespace.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/ProcessingInstruction.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/SkippedEntity.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartCDATA.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDTD.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDocument.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEntity.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartInstruction.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartPrefixMapping.java
    cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/TextEvent.java

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/environment/FlowObjectModelHelper.java Wed Feb 23 06:41:48 2005
@@ -20,7 +20,6 @@
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.components.flow.FlowHelper;
-import org.apache.cocoon.environment.TemplateObjectModelHelper;
 
 
 /**

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java Wed Feb 23 06:41:48 2005
@@ -29,8 +29,6 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
-
 public class Substitutions {
 
     final private List substitutions;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartFormatNumber.java Wed Feb 23 06:41:48 2005
@@ -24,8 +24,8 @@
 
 import org.apache.cocoon.components.expression.ExpressionContext;
 import org.apache.cocoon.template.jxtg.environment.ErrorHolder;
-import org.apache.cocoon.template.jxtg.environment.ValueHelper;
 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;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartImport.java Wed Feb 23 06:41:48 2005
@@ -26,14 +26,14 @@
 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.StartElement;
 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.StartInstruction;
 import org.apache.cocoon.template.jxtg.script.event.SubstituteAttribute;
-import org.apache.cocoon.template.jxtg.script.Invoker;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartOut.java Wed Feb 23 06:41:48 2005
@@ -20,10 +20,10 @@
 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.Invoker;
 import org.apache.cocoon.template.jxtg.script.event.Event;
 import org.apache.cocoon.template.jxtg.script.event.StartElement;
 import org.apache.cocoon.template.jxtg.script.event.StartInstruction;
-import org.apache.cocoon.template.jxtg.script.Invoker;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/instruction/StartSet.java Wed Feb 23 06:41:48 2005
@@ -20,10 +20,10 @@
 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.Invoker;
 import org.apache.cocoon.template.jxtg.script.event.Event;
 import org.apache.cocoon.template.jxtg.script.event.StartElement;
 import org.apache.cocoon.template.jxtg.script.event.StartInstruction;
-import org.apache.cocoon.template.jxtg.script.Invoker;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java Wed Feb 23 06:41:48 2005
@@ -25,11 +25,14 @@
 import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
 import org.apache.cocoon.template.jxtg.environment.LocatorFacade;
 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.instruction.StartDefine;
 import org.apache.cocoon.template.jxtg.instruction.StartParameter;
-import org.apache.cocoon.template.jxtg.script.event.*;
+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.StartElement;
+import org.apache.cocoon.template.jxtg.script.event.StartInstruction;
+import org.apache.cocoon.template.jxtg.script.event.SubstituteAttribute;
 import org.apache.cocoon.xml.IncludeXMLConsumer;
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.cocoon.xml.dom.DOMBuilder;
@@ -48,11 +51,9 @@
     private static final Attributes EMPTY_ATTRS = new AttributesImpl();
 
     public static void execute(final XMLConsumer consumer,
-                               ExpressionContext expressionContext,
-                               ExecutionContext executionContext,
-                               StartElement macroCall,
-                               Event startEvent, Event endEvent)
-            throws SAXException {
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
 
         Event ev = startEvent;
         LocatorFacade loc = new LocatorFacade(ev.getLocation());
@@ -61,217 +62,84 @@
             loc.setDocumentLocator(ev.getLocation());
 
             // ContentHandler methods
-            if (ev instanceof Characters) {
-                TextEvent text = (TextEvent) ev;
-                Iterator iter = text.getSubstitutions().iterator();
-                while (iter.hasNext()) {
-                    Subst subst = (Subst)iter.next();
-                    char[] chars;
-                    if (subst instanceof Literal) {
-                        chars = ((Literal)subst).getCharArray();
-                        consumer.characters(chars, 0, chars.length);
-                    } else {
-                        JXTExpression expr = (JXTExpression) subst;
-                        try {
-                            Object val = expr.getNode(expressionContext);
-                            executeNode(consumer, val);
-                        } catch (Exception e) {
-                            throw new SAXParseException(e.getMessage(),
-                                                        ev.getLocation(), e);
-                        } catch (Error err) {
-                            throw new SAXParseException(err.getMessage(),
-                                                        ev.getLocation(),
-                                                        new ErrorHolder(err));
-                        }
-                    }
-                }
-            } else if (ev instanceof EndDocument) {
-                consumer.endDocument();
-            } else if (ev instanceof EndElement) {
-                EndElement endElement = (EndElement) ev;
-                StartElement startElement = endElement.getStartElement();
-                consumer.endElement(startElement.getNamespaceURI(),
-                        startElement.getLocalName(), startElement.getRaw());
-            } else if (ev instanceof EndPrefixMapping) {
-                EndPrefixMapping endPrefixMapping = (EndPrefixMapping) ev;
-                consumer.endPrefixMapping(endPrefixMapping.getPrefix());
-            } else if (ev instanceof IgnorableWhitespace) {
-                TextEvent text = (TextEvent) ev;
-                characters(expressionContext, executionContext, text,
-                           new CharHandler() {
-                                   public void characters(char[] ch, int offset, int len)
-                                       throws SAXException {
-                                       consumer.ignorableWhitespace(ch, offset, len);
-                                   }
-                               });
-            } else if (ev instanceof ProcessingInstruction) {
-                ProcessingInstruction pi = (ProcessingInstruction) ev;
-                consumer.processingInstruction(pi.getTarget(), pi.getData());
-            } else if (ev instanceof SkippedEntity) {
-                SkippedEntity skippedEntity = (SkippedEntity) ev;
-                consumer.skippedEntity(skippedEntity.getName());
-            } else if (ev instanceof StartDocument) {
-                if (((StartDocument) ev).getEndDocument() != null) {
-                    // if this isn't a document fragment
-                    consumer.startDocument();
-                }
-            } else if (ev instanceof StartElement) {
+            if (ev instanceof StartElement) {
                 StartElement startElement = (StartElement) ev;
                 StartDefine def = (StartDefine) executionContext
                         .getDefinitions().get(startElement.getQname());
-                if (def != null) {
-                    Map attributeMap = new HashMap();
-                    Iterator i = startElement.getAttributeEvents().iterator();
-                    while (i.hasNext()) {
-                        String attributeName;
-                        Object attributeValue;
-                        AttributeEvent attrEvent = (AttributeEvent) i.next();
-                        attributeName = attrEvent.getLocalName();
-                        if (attrEvent instanceof CopyAttribute) {
-                            CopyAttribute copy = (CopyAttribute) attrEvent;
-                            attributeValue = copy.getValue();
-                        } else if (attrEvent instanceof SubstituteAttribute) {
-                            SubstituteAttribute substEvent = (SubstituteAttribute) attrEvent;
-                            if (substEvent.getSubstitutions().size() == 1
-                                && substEvent.getSubstitutions().get(0) instanceof JXTExpression) {
-                                JXTExpression expr = (JXTExpression) substEvent
-                                        .getSubstitutions().get(0);
-                                Object val;
-                                try {
-                                    val = expr.getNode(expressionContext);
-                                } catch (Exception e) {
-                                    throw new SAXParseException(e.getMessage(),
-                                                                ev.getLocation(), e);
-                                } catch (Error err) {
-                                    throw new SAXParseException(err.getMessage(),
-                                                                ev.getLocation(),
-                                                                new ErrorHolder(err));
-                                }
-                                attributeValue = val != null ? val : "";
-                            } else {
-                                attributeValue =
-                                    substEvent.getSubstitutions().toString(ev.getLocation(),
-                                                                           expressionContext);
-                            }
-                        } else {
-                            throw new Error("this shouldn't have happened");
-                        }
-                        attributeMap.put(attributeName, attributeValue);
-                    }
-                    ExpressionContext localExpressionContext =
-                        new ExpressionContext(expressionContext);
-                    HashMap macro = new HashMap();
-                    macro.put("body", startElement);
-                    macro.put("arguments", attributeMap);
-                    localExpressionContext.put("macro", macro);
-                    Iterator iter = def.getParameters().entrySet().iterator();
-                    while (iter.hasNext()) {
-                        Map.Entry e = (Map.Entry) iter.next();
-                        String key = (String) e.getKey();
-                        StartParameter startParam =
-                            (StartParameter) e.getValue();
-                        Object default_ = startParam.getDefaultValue();
-                        Object val = attributeMap.get(key);
-                        if (val == null) {
-                            val = default_;
-                        }
-                        localExpressionContext.put(key, val);
-                    }
-                    call(ev.getLocation(), startElement, consumer,
-                         localExpressionContext, executionContext,
-                         def.getBody(), def.getEndInstruction());
-                    ev = startElement.getEndElement().getNext();
+                if (def == null) {
+                    ev = ev.execute(consumer, expressionContext,
+                            executionContext, macroCall, startEvent, endEvent);
                     continue;
                 }
+
+                // this is a macro call
+                Map attributeMap = new HashMap();
                 Iterator i = startElement.getAttributeEvents().iterator();
-                AttributesImpl attrs = new AttributesImpl();
                 while (i.hasNext()) {
+                    String attributeName;
+                    Object attributeValue;
                     AttributeEvent attrEvent = (AttributeEvent) i.next();
+                    attributeName = attrEvent.getLocalName();
                     if (attrEvent instanceof CopyAttribute) {
                         CopyAttribute copy = (CopyAttribute) attrEvent;
-                        attrs.addAttribute(copy.getNamespaceURI(),
-                                           copy.getLocalName(), copy.getRaw(),
-                                           copy.getType(), copy.getValue());
+                        attributeValue = copy.getValue();
                     } else if (attrEvent instanceof SubstituteAttribute) {
                         SubstituteAttribute substEvent = (SubstituteAttribute) attrEvent;
-                        String attributeValue =
-                            substEvent.getSubstitutions().toString(ev.getLocation(),
-                                                                   expressionContext);
-                        attrs.addAttribute(attrEvent.getNamespaceURI(),
-                                           attrEvent.getLocalName(), attrEvent.getRaw(),
-                                           attrEvent.getType(), attributeValue);
+                        if (substEvent.getSubstitutions().size() == 1
+                                && substEvent.getSubstitutions().get(0) instanceof JXTExpression) {
+                            JXTExpression expr = (JXTExpression) substEvent
+                                    .getSubstitutions().get(0);
+                            Object val;
+                            try {
+                                val = expr.getNode(expressionContext);
+                            } catch (Exception e) {
+                                throw new SAXParseException(e.getMessage(), ev
+                                        .getLocation(), e);
+                            } catch (Error err) {
+                                throw new SAXParseException(err.getMessage(),
+                                        ev.getLocation(), new ErrorHolder(err));
+                            }
+                            attributeValue = val != null ? val : "";
+                        } else {
+                            attributeValue = substEvent.getSubstitutions()
+                                    .toString(ev.getLocation(),
+                                            expressionContext);
+                        }
+                    } else {
+                        throw new Error("this shouldn't have happened");
                     }
+                    attributeMap.put(attributeName, attributeValue);
                 }
-                consumer.startElement(startElement.getNamespaceURI(),
-                                      startElement.getLocalName(), startElement.getRaw(),
-                                      attrs);
-            } else if (ev instanceof StartPrefixMapping) {
-                StartPrefixMapping startPrefixMapping = (StartPrefixMapping) ev;
-                consumer.startPrefixMapping(startPrefixMapping.getPrefix(),
-                                            startPrefixMapping.getUri());
-
-                // LexicalHandler methods
-            } else if (ev instanceof EndCDATA) {
-                consumer.endCDATA();
-            } else if (ev instanceof EndDTD) {
-                consumer.endDTD();
-            } else if (ev instanceof EndEntity) {
-                consumer.endEntity(((EndEntity) ev).getName());
-            } else if (ev instanceof StartCDATA) {
-                consumer.startCDATA();
-            } else if (ev instanceof StartDTD) {
-                StartDTD startDTD = (StartDTD) ev;
-                consumer.startDTD(startDTD.getName(), startDTD.getPublicId(),
-                                  startDTD.getSystemId());
-            } else if (ev instanceof StartEntity) {
-                consumer.startEntity(((StartEntity) ev).getName());
-
-                // Instructions
-            } else if (ev instanceof StartInstruction) {
-                ev = ((StartInstruction)ev).execute(consumer,
-                                                    expressionContext, executionContext,
-                                                    macroCall, startEvent, endEvent);
-                continue;
-            }
-            ev = ev.getNext();
-        }
-    }
-
-    interface CharHandler {
-        public void characters(char[] ch, int offset, int length)
-                throws SAXException;
-    }
-
-    private static void characters(ExpressionContext expressionContext,
-                                   ExecutionContext executionContext,
-                                   TextEvent event, CharHandler handler)
-        throws SAXException {
-        Iterator iter = event.getSubstitutions().iterator();
-        while (iter.hasNext()) {
-            Object subst = iter.next();
-            char[] chars;
-            if (subst instanceof Literal) {
-                chars = ((Literal) subst).getCharArray();
-            } else {
-                JXTExpression expr = (JXTExpression) subst;
-                try {
-                    Object val = expr.getValue(expressionContext);
-                    chars = val != null ? val.toString().toCharArray()
-                            : ArrayUtils.EMPTY_CHAR_ARRAY;
-                } catch (Exception e) {
-                    throw new SAXParseException(e.getMessage(), event
-                            .getLocation(), e);
-                } catch (Error err) {
-                    throw new SAXParseException(err.getMessage(), event
-                            .getLocation(), new ErrorHolder(err));
+                ExpressionContext localExpressionContext = new ExpressionContext(
+                        expressionContext);
+                HashMap macro = new HashMap();
+                macro.put("body", startElement);
+                macro.put("arguments", attributeMap);
+                localExpressionContext.put("macro", macro);
+                Iterator iter = def.getParameters().entrySet().iterator();
+                while (iter.hasNext()) {
+                    Map.Entry e = (Map.Entry) iter.next();
+                    String key = (String) e.getKey();
+                    StartParameter startParam = (StartParameter) e.getValue();
+                    Object default_ = startParam.getDefaultValue();
+                    Object val = attributeMap.get(key);
+                    if (val == null) {
+                        val = default_;
+                    }
+                    localExpressionContext.put(key, val);
                 }
-            }
-            handler.characters(chars, 0, chars.length);
+                call(ev.getLocation(), startElement, consumer,
+                        localExpressionContext, executionContext,
+                        def.getBody(), def.getEndInstruction());
+                ev = startElement.getEndElement().getNext();
+            } else 
+                ev = ev.execute(consumer, expressionContext, executionContext,
+                        macroCall, startEvent, endEvent);
         }
     }
 
     public static void executeNode(final XMLConsumer consumer, Object val)
-        throws SAXException {
+            throws SAXException {
 
         if (val instanceof Node) {
             executeDOM(consumer, (Node) val);
@@ -292,16 +160,14 @@
         } else if (val instanceof XMLizable) {
             ((XMLizable) val).toSAX(new IncludeXMLConsumer(consumer));
         } else {
-            char[] ch =
-                val == null ? ArrayUtils.EMPTY_CHAR_ARRAY
-                : val.toString().toCharArray();
+            char[] ch = val == null ? ArrayUtils.EMPTY_CHAR_ARRAY : val
+                    .toString().toCharArray();
             consumer.characters(ch, 0, ch.length);
         }
     }
 
     /**
-     * dump a DOM document, using an IncludeXMLConsumer to filter out start/end
-     * document events
+     * dump a DOM document, using an IncludeXMLConsumer to filter out start/end document events
      */
     public static void executeDOM(final XMLConsumer consumer, Node node)
             throws SAXException {
@@ -311,32 +177,28 @@
     }
 
     private static void call(Locator location, StartElement macroCall,
-                             final XMLConsumer consumer,
-                             ExpressionContext expressionContext,
-                             ExecutionContext executionContext,
-                             Event startEvent, Event endEvent)
-        throws SAXException {
+            final XMLConsumer consumer, ExpressionContext expressionContext,
+            ExecutionContext executionContext, Event startEvent, Event endEvent)
+            throws SAXException {
         try {
-            execute(consumer, expressionContext, executionContext,
-                    macroCall, startEvent, endEvent);
+            execute(consumer, expressionContext, executionContext, macroCall,
+                    startEvent, endEvent);
         } catch (SAXParseException exc) {
             throw new SAXParseException(macroCall.getLocalName() + ": "
-                                        + exc.getMessage(), location, exc);
+                    + exc.getMessage(), location, exc);
         }
     }
 
     public static NodeList toDOMNodeList(String elementName,
-                                         StartInstruction si,
-                                         ExpressionContext expressionContext,
-                                         ExecutionContext executionContext,
-                                         StartElement macroCall)
+            StartInstruction si, ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall)
             throws SAXException {
         DOMBuilder builder = new DOMBuilder();
         builder.startDocument();
         builder.startElement(JXTemplateGenerator.NS, elementName, elementName,
-                             EMPTY_ATTRS);
-        execute(builder, expressionContext, executionContext,
-                macroCall, si.getNext(), si.getEndInstruction());
+                EMPTY_ATTRS);
+        execute(builder, expressionContext, executionContext, macroCall, si
+                .getNext(), si.getEndInstruction());
         builder.endElement(JXTemplateGenerator.NS, elementName, elementName);
         builder.endDocument();
         Node node = builder.getDocument().getDocumentElement();

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Characters.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Characters.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Characters.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Characters.java Wed Feb 23 06:41:48 2005
@@ -15,12 +15,49 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Iterator;
+
+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.expression.Literal;
+import org.apache.cocoon.template.jxtg.expression.Subst;
+import org.apache.cocoon.template.jxtg.script.Invoker;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 public class Characters extends TextEvent {
     public Characters(Locator location, char[] chars, int start, int length)
             throws SAXException {
         super(location, chars, start, length);
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        Iterator iter = getSubstitutions().iterator();
+        while (iter.hasNext()) {
+            Subst subst = (Subst) iter.next();
+            char[] chars;
+            if (subst instanceof Literal) {
+                chars = ((Literal) subst).getCharArray();
+                consumer.characters(chars, 0, chars.length);
+            } else {
+                JXTExpression expr = (JXTExpression) subst;
+                try {
+                    Object val = expr.getNode(expressionContext);
+                    Invoker.executeNode(consumer, val);
+                } catch (Exception e) {
+                    throw new SAXParseException(e.getMessage(), getLocation(), e);
+                } catch (Error err) {
+                    throw new SAXParseException(err.getMessage(), getLocation(), new ErrorHolder(err));
+                }
+            }
+        }
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndCDATA.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndCDATA.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndCDATA.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndCDATA.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,22 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndCDATA extends Event {
     public EndCDATA(Locator location) {
         super(location);
+    }
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endCDATA();
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDTD.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDTD.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDTD.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDTD.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,23 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndDTD extends Event {
     public EndDTD(Locator location) {
         super(location);
+    }
+    
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endDTD();
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDocument.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDocument.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDocument.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndDocument.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,22 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndDocument extends Event {
     public EndDocument(Locator location) {
         super(location);
+    }
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endDocument();
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndElement.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndElement.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndElement.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndElement.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndElement extends Event {
     public EndElement(Locator location, StartElement startElement) {
@@ -27,5 +31,14 @@
 
     public StartElement getStartElement() {
         return startElement;
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endElement(startElement.getNamespaceURI(), startElement
+                .getLocalName(), startElement.getRaw());
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndEntity.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndEntity.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndEntity.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndEntity.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndEntity extends Event {
     public EndEntity(Locator location, String name) {
@@ -28,4 +32,13 @@
     }
 
     private final String name;
+    
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endEntity( getName() );
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndPrefixMapping.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndPrefixMapping.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndPrefixMapping.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/EndPrefixMapping.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class EndPrefixMapping extends Event {
     public EndPrefixMapping(Locator location, String prefix) {
@@ -27,5 +31,13 @@
 
     public String getPrefix() {
         return prefix;
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.endPrefixMapping(getPrefix());
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Event.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Event.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Event.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/Event.java Wed Feb 23 06:41:48 2005
@@ -57,4 +57,12 @@
         }
         return buf.toString();
     }
+
+    public Event execute(final XMLConsumer consumer,
+                         ExpressionContext expressionContext,
+                         ExecutionContext executionContext,
+                         StartElement macroCall, Event startEvent, Event endEvent) 
+        throws SAXException {
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/IgnorableWhitespace.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/IgnorableWhitespace.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/IgnorableWhitespace.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/IgnorableWhitespace.java Wed Feb 23 06:41:48 2005
@@ -15,6 +15,9 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
@@ -22,5 +25,19 @@
     public IgnorableWhitespace(Locator location, char[] chars, int start,
             int length) throws SAXException {
         super(location, chars, start, length);
+    }
+
+    public Event execute(final XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+            characters(expressionContext, executionContext, this,
+                new CharHandler() {
+                    public void characters(char[] ch, int offset, int len)
+                            throws SAXException {
+                        consumer.ignorableWhitespace(ch, offset, len);
+                    }
+                });
+            return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/ProcessingInstruction.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/ProcessingInstruction.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/ProcessingInstruction.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/ProcessingInstruction.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class ProcessingInstruction extends Event {
     public ProcessingInstruction(Locator location, String target, String data) {
@@ -34,4 +38,13 @@
 
     private final String target;
     private final String data;
+    
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.processingInstruction(getTarget(), getData());
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/SkippedEntity.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/SkippedEntity.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/SkippedEntity.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/SkippedEntity.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class SkippedEntity extends Event {
     public SkippedEntity(Locator location, String name) {
@@ -27,5 +31,13 @@
 
     public String getName() {
         return name;
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.skippedEntity(getName());
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartCDATA.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartCDATA.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartCDATA.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartCDATA.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,22 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartCDATA extends Event {
     public StartCDATA(Locator location) {
         super(location);
+    }
+    
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.startCDATA();
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDTD.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDTD.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDTD.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDTD.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartDTD extends Event {
     public StartDTD(Locator location, String name, String publicId,
@@ -41,4 +45,12 @@
     private final String name;
     private final String publicId;
     private final String systemId;
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.startDTD(getName(), getPublicId(), getSystemId());
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDocument.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDocument.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDocument.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartDocument.java Wed Feb 23 06:41:48 2005
@@ -18,8 +18,12 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.excalibur.source.SourceValidity;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartDocument extends Event {
     public StartDocument(Locator location) {
@@ -73,5 +77,14 @@
      */
     public Object getTemplateProperty(String name) {
         return getTemplateProperties().get(name);
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        if (getEndDocument() != null)
+            consumer.startDocument();
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartElement.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,14 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
 import org.apache.cocoon.template.jxtg.expression.Substitutions;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
@@ -39,12 +43,15 @@
             String qname = attrs.getQName(i);
             String type = attrs.getType(i);
             String value = attrs.getValue(i);
-            Substitutions substitutions = new Substitutions(getLocation(), value);
+            Substitutions substitutions = new Substitutions(getLocation(),
+                    value);
             if (substitutions.hasSubstitutions()) {
-                getAttributeEvents().add(new SubstituteAttribute(uri, local, qname, type,
-                                                                 substitutions));
+                getAttributeEvents().add(
+                        new SubstituteAttribute(uri, local, qname, type,
+                                substitutions));
             } else {
-                getAttributeEvents().add(new CopyAttribute(uri, local, qname, type, value));
+                getAttributeEvents().add(
+                        new CopyAttribute(uri, local, qname, type, value));
             }
         }
         this.attributes = new AttributesImpl(attrs);
@@ -85,5 +92,31 @@
     public void setEndElement(EndElement endElement) {
         this.endElement = endElement;
 
+    }
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        Iterator i = getAttributeEvents().iterator();
+        AttributesImpl attrs = new AttributesImpl();
+        while (i.hasNext()) {
+            AttributeEvent attrEvent = (AttributeEvent) i.next();
+            if (attrEvent instanceof CopyAttribute) {
+                CopyAttribute copy = (CopyAttribute) attrEvent;
+                attrs.addAttribute(copy.getNamespaceURI(), copy.getLocalName(),
+                        copy.getRaw(), copy.getType(), copy.getValue());
+            } else if (attrEvent instanceof SubstituteAttribute) {
+                SubstituteAttribute substEvent = (SubstituteAttribute) attrEvent;
+                String attributeValue = substEvent.getSubstitutions().toString(
+                        getLocation(), expressionContext);
+                attrs.addAttribute(attrEvent.getNamespaceURI(), attrEvent
+                        .getLocalName(), attrEvent.getRaw(), attrEvent
+                        .getType(), attributeValue);
+            }
+        }
+        consumer.startElement(getNamespaceURI(), getLocalName(), getRaw(),
+                attrs);
+        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEntity.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEntity.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEntity.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartEntity.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartEntity extends Event {
     public StartEntity(Locator location, String name) {
@@ -28,4 +32,12 @@
     }
 
     private final String name;
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.startEntity(getName());
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartInstruction.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartInstruction.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartInstruction.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartInstruction.java Wed Feb 23 06:41:48 2005
@@ -15,10 +15,6 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
-import org.apache.cocoon.components.expression.ExpressionContext;
-import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
-import org.apache.cocoon.xml.XMLConsumer;
-import org.xml.sax.SAXException;
 
 public abstract class StartInstruction extends Event {
 
@@ -36,13 +32,5 @@
 
     public void setEndInstruction(EndInstruction endInstruction) {
         this.endInstruction = endInstruction;
-    }
-
-    public Event execute(final XMLConsumer consumer,
-                         ExpressionContext expressionContext,
-                         ExecutionContext executionContext,
-                         StartElement macroCall, Event startEvent, Event endEvent) 
-        throws SAXException {
-        return getNext();
     }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartPrefixMapping.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartPrefixMapping.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartPrefixMapping.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/StartPrefixMapping.java Wed Feb 23 06:41:48 2005
@@ -15,7 +15,11 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import org.apache.cocoon.components.expression.ExpressionContext;
+import org.apache.cocoon.template.jxtg.environment.ExecutionContext;
+import org.apache.cocoon.xml.XMLConsumer;
 import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
 
 public class StartPrefixMapping extends Event {
     public StartPrefixMapping(Locator location, String prefix, String uri) {
@@ -34,4 +38,12 @@
 
     private final String prefix;
     private final String uri;
+
+    public Event execute(XMLConsumer consumer,
+            ExpressionContext expressionContext,
+            ExecutionContext executionContext, StartElement macroCall,
+            Event startEvent, Event endEvent) throws SAXException {
+        consumer.startPrefixMapping(getPrefix(), getUri());
+        return getNext();
+    }
 }

Modified: cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/TextEvent.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/TextEvent.java?view=diff&r1=155015&r2=155016
==============================================================================
--- cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/TextEvent.java (original)
+++ cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/event/TextEvent.java Wed Feb 23 06:41:48 2005
@@ -15,9 +15,18 @@
  */
 package org.apache.cocoon.template.jxtg.script.event;
 
+import java.util.Iterator;
+
+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.expression.Literal;
 import org.apache.cocoon.template.jxtg.expression.Substitutions;
+import org.apache.commons.lang.ArrayUtils;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 public class TextEvent extends Event {
     public TextEvent(Locator location, char[] chars, int start, int length)
@@ -38,4 +47,39 @@
     public Substitutions getSubstitutions() {
         return substitutions;
     }
+    
+    interface CharHandler {
+        public void characters(char[] ch, int offset, int length)
+                throws SAXException;
+    }
+
+    protected static void characters(ExpressionContext expressionContext,
+                                   ExecutionContext executionContext,
+                                   TextEvent event, CharHandler handler)
+        throws SAXException {
+        Iterator iter = event.getSubstitutions().iterator();
+        while (iter.hasNext()) {
+            Object subst = iter.next();
+            char[] chars;
+            if (subst instanceof Literal) {
+                chars = ((Literal) subst).getCharArray();
+            } else {
+                JXTExpression expr = (JXTExpression) subst;
+                try {
+                    Object val = expr.getValue(expressionContext);
+                    chars = val != null ? val.toString().toCharArray()
+                            : ArrayUtils.EMPTY_CHAR_ARRAY;
+                } catch (Exception e) {
+                    throw new SAXParseException(e.getMessage(), event
+                            .getLocation(), e);
+                } catch (Error err) {
+                    throw new SAXParseException(err.getMessage(), event
+                            .getLocation(), new ErrorHolder(err));
+                }
+            }
+            handler.characters(chars, 0, chars.length);
+        }
+    }
+
+    
 }



Mime
View raw message