throw new SAXParseException(exc.getMessage(),
ev.location,
exc);
}
} else {
DOMBuilder builder = new DOMBuilder();
builder.startDocument();
builder.startElement(NS,
"set",
"set",
EMPTY_ATTRS);
execute(builder, jexlContext, jxpathContext,
startSet.next,
startSet.endInstruction);
builder.endElement(NS,
"set",
"set");
builder.endDocument();
Node node = builder.getDocument().getDocumentElement();
NodeList nodeList = node.getChildNodes();
int len = nodeList.getLength();
// JXPath doesn't handle NodeList, so convert
// it to an array
Node[] nodeArr = new Node[len];
for (int i = 0; i < len; i++) {
nodeArr[i] = nodeList.item(i);
}
value = nodeArr;
}
jxpathContext.getVariables().declareVariable(startSet.var,
value);
jexlContext.put(startSet.var, value);
ev = startSet.endInstruction.next;
continue;
} else if (ev instanceof StartElement) {
StartElement startElement = (StartElement)ev;
StartDefine def =
(StartDefine)definitions.get(startElement.qname);
if (def != null) {
Map attributeMap = new HashMap();
Iterator i = startElement.attributeEvents.iterator();
while (i.hasNext()) {
String attributeName;
Object attributeValue;
AttributeEvent attrEvent = (AttributeEvent)
i.next();
attributeName = attrEvent.localName;
if (attrEvent instanceof CopyAttribute) {
CopyAttribute copy =
(CopyAttribute)attrEvent;
attributeValue = copy.value;
} else if (attrEvent instanceof
SubstituteAttribute) {
SubstituteAttribute substEvent =
(SubstituteAttribute)attrEvent;
if (substEvent.substitutions.size() == 1 &&
substEvent.substitutions.get(0) instanceof
Expression) {
Expression expr = (Expression)
substEvent.substitutions.get(0);
Object val;
try {
val =
getNode(expr,
jexlContext,
jxpathContext);
} catch (Exception e) {
throw new SAXParseException(e.getMessage(),
ev.location,
e);
}
if (val == null) {
val = "";
}
attributeValue = val;
} else {
StringBuffer buf = new StringBuffer();
Iterator ii = substEvent.substitutions.iterator();
while (ii.hasNext()) {
Subst subst = (Subst)ii.next();
if (subst instanceof Literal) {
Literal lit = (Literal)subst;
buf.append(lit.value);
} else if (subst instanceof Expression) {
Expression expr = (Expression)subst;
Object val;
try {
val =
getValue(expr,
jexlContext,
jxpathContext);
} catch (Exception e) {
throw new SAXParseException(e.getMessage(),
ev.location,
e);
}
if (val == null) {
val = "";
}
buf.append(val.toString());
}
}
attributeValue = buf.toString();
}
} else {
throw new Error("this shouldn't have happened");
}
attributeMap.put(attributeName, attributeValue);
}
DOMBuilder builder = new DOMBuilder();
builder.startDocument();
builder.startElement(startElement.namespaceURI,
startElement.localName,
startElement.raw,
EMPTY_ATTRS);
executeRaw(builder,
startElement.next,
startElement.endElement);
builder.endElement(startElement.namespaceURI,
startElement.localName,
startElement.raw);
builder.endDocument();
Node node = builder.getDocument().getDocumentElement();
MyVariables vars =
(MyVariables)jxpathContext.getVariables();
Map saveLocals = vars.localVariables;
vars.localVariables = new HashMap();
MyJexlContext localJexlContext =