if (uri.equals("http://xt.ibex.org/")) {
//#switch(e.getLocalName())
- case "if": e = new Template.If(e); break;
case "js": e = new Template.JSTag(e); break;
case "foreach": e = new Template.ForEach(e); break;
case "children": e = new Template.Children(e); break;
// merge original attributes with replacement template
e = new JSElement.Merge(t, e);
+ }
- } else if (uri.startsWith("java:")) {
- e = new Java(e);
+ XML.Attributes a = e.getAttributes();
+ for (int i=0; i < a.attrSize(); i++) {
+ // FIXME: questionable abuse of XML namespaces here
+ if ("if".equals(a.getKey(i)) && (
+ "http://xt.ibex.org/".equals(e.getUri()) ||
+ "http://xt.ibex.org/".equals(a.getUri(i)))) {
+ e = new Template.IfWrap(e);
+ }
}
// wrap children
public JSScope getParentScope() { return tscope; }
-
- public static final class If extends JSElement {
- public If(XML.Element e) { super(e); }
+ public static final class IfWrap extends JSElement {
+ public IfWrap(XML.Element e) { super(e); }
public void out(Writer w) throws IOException {
- super.out(w);
+ loadAttr();
try {
Object varIf = get("if"); if (varIf != null) undeclare("if");
- if (varIf != null && !Boolean.getBoolean((String)varIf)) return;
+ if (varIf != null && !"true".equals(varIf)) return;
} catch (JSExn e) { throw new RuntimeException(e); }
- List c = getChildren();
- for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(w);
+ wrapped.out(w);
}
}
}
public void out(Writer w) throws IOException {
- super.out(w);
+ loadAttr();
- try {
- Object varIf = get("if"); if (varIf != null) undeclare("if");
- if (varIf != null && !Boolean.getBoolean((String)varIf)) return;
-
- List c = getChildren();
- StringWriter s = new StringWriter();
- for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(s);
- exec(s.toString());
- } catch (JSExn e) { throw new RuntimeException(e); }
+ List c = getChildren();
+ StringWriter s = new StringWriter();
+ for (int i=0; i < c.size(); i++) ((Tree.Leaf)c.get(i)).out(s);
+ exec(s.toString());
}
}
public ForEach(XML.Element e) { super(e); }
public void out(Writer w) throws IOException {
- super.out(w);
+ loadAttr();
try {
Object varIn = get("in"); if (varIn != null) undeclare("in");
Object varPut = get("put"); if (varPut != null) undeclare("put");
- Object varIf = get("if"); if (varIf != null) undeclare("if");
- if (varIf != null && !Boolean.getBoolean((String)varIf)) return;
varIn = exec("return (" + varIn + ");");
if (varIn == null || (varIn instanceof JSArray)) throw new RuntimeException(
public Transaction(XML.Element e, Template.Scope s) { super(e); scope = s;} // TODO: check kids
public void out(Writer w) throws IOException {
- super.out(w);
+ loadAttr();
// TODO: <xt:use />
List c = getChildren();