Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 39217 invoked from network); 27 Jan 2005 22:59:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Jan 2005 22:59:36 -0000 Received: (qmail 93041 invoked by uid 500); 27 Jan 2005 22:59:35 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 92985 invoked by uid 500); 27 Jan 2005 22:59:35 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 92972 invoked by uid 99); 27 Jan 2005 22:59:35 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 27 Jan 2005 14:59:35 -0800 Received: (qmail 39102 invoked by uid 65534); 27 Jan 2005 22:59:33 -0000 Date: 27 Jan 2005 22:59:33 -0000 Message-ID: <20050127225933.39097.qmail@minotaur.apache.org> From: danielf@apache.org To: cvs@cocoon.apache.org Subject: svn commit: r128442 - /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/script/Invoker.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: danielf Date: Thu Jan 27 14:59:32 2005 New Revision: 128442 URL: http://svn.apache.org/viewcvs?view=rev&rev=128442 Log: Factored out Substitutions to String. Modified: 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/script/Invoker.java 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&rev=128442&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java&r1=128441&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/expression/Substitutions.java&r2=128442 ============================================================================== --- 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 Thu Jan 27 14:59:32 2005 @@ -22,6 +22,9 @@ 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.ErrorHolder; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; @@ -130,5 +133,31 @@ 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(); } } 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&rev=128442&p1=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java&r1=128441&p2=cocoon/trunk/src/blocks/template/java/org/apache/cocoon/template/jxtg/script/Invoker.java&r2=128442 ============================================================================== --- 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 Thu Jan 27 14:59:32 2005 @@ -69,12 +69,12 @@ char[] chars; if (subst instanceof Literal) { chars = ((Literal)subst).getCharArray(); - consumer.characters(chars, 0, chars.length); + consumer.characters(chars, 0, chars.length); } else { JXTExpression expr = (JXTExpression) subst; try { Object val = expr.getNode(expressionContext); - executeNode(consumer, val); + executeNode(consumer, val); } catch (Exception e) { throw new SAXParseException(e.getMessage(), ev.getLocation(), e); @@ -149,31 +149,9 @@ } attributeValue = val != null ? val : ""; } else { - StringBuffer buf = new StringBuffer(); - Iterator iterSubst = - substEvent.getSubstitutions().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(), - ev.getLocation(), e); - } catch (Error err) { - throw new SAXParseException(err.getMessage(), - ev.getLocation(), - new ErrorHolder(err)); - } - buf.append(val != null ? val.toString() : ""); - } - } - attributeValue = buf.toString(); + attributeValue = + substEvent.getSubstitutions().toString(ev.getLocation(), + expressionContext); } } else { throw new Error("this shouldn't have happened"); @@ -215,33 +193,13 @@ copy.getLocalName(), copy.getRaw(), copy.getType(), copy.getValue()); } else if (attrEvent instanceof SubstituteAttribute) { - StringBuffer buf = new StringBuffer(); SubstituteAttribute substEvent = (SubstituteAttribute) attrEvent; - Iterator iterSubst = substEvent.getSubstitutions().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(), - ev.getLocation(), e); - } catch (Error err) { - throw new SAXParseException(err.getMessage(), - ev.getLocation(), - new ErrorHolder(err)); - } - buf.append(val != null ? val.toString() : ""); - } - } + String attributeValue = + substEvent.getSubstitutions().toString(ev.getLocation(), + expressionContext); attrs.addAttribute(attrEvent.getNamespaceURI(), attrEvent.getLocalName(), attrEvent.getRaw(), - attrEvent.getType(), buf.toString()); + attrEvent.getType(), attributeValue); } } consumer.startElement(startElement.getNamespaceURI(), @@ -313,32 +271,32 @@ } public static void executeNode(final XMLConsumer consumer, Object val) - throws SAXException { + throws SAXException { - if (val instanceof Node) { - executeDOM(consumer, (Node) val); - } else if (val instanceof NodeList) { - NodeList nodeList = (NodeList) val; - int len = nodeList.getLength(); - for (int i = 0; i < len; i++) { - Node n = nodeList.item(i); - executeDOM(consumer, n); - } - } else if (val instanceof Node[]) { - Node[] nodeList = (Node[]) val; - int len = nodeList.length; - for (int i = 0; i < len; i++) { - Node n = nodeList[i]; - executeDOM(consumer, n); - } - } else if (val instanceof XMLizable) { - ((XMLizable) val).toSAX(new IncludeXMLConsumer(consumer)); - } else { - char[] ch = - val == null ? ArrayUtils.EMPTY_CHAR_ARRAY - : val.toString().toCharArray(); - consumer.characters(ch, 0, ch.length); - } + if (val instanceof Node) { + executeDOM(consumer, (Node) val); + } else if (val instanceof NodeList) { + NodeList nodeList = (NodeList) val; + int len = nodeList.getLength(); + for (int i = 0; i < len; i++) { + Node n = nodeList.item(i); + executeDOM(consumer, n); + } + } else if (val instanceof Node[]) { + Node[] nodeList = (Node[]) val; + int len = nodeList.length; + for (int i = 0; i < len; i++) { + Node n = nodeList[i]; + executeDOM(consumer, n); + } + } else if (val instanceof XMLizable) { + ((XMLizable) val).toSAX(new IncludeXMLConsumer(consumer)); + } else { + char[] ch = + val == null ? ArrayUtils.EMPTY_CHAR_ARRAY + : val.toString().toCharArray(); + consumer.characters(ch, 0, ch.length); + } } /**