You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by da...@apache.org on 2005/01/27 23:59:33 UTC
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
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);
+ }
}
/**