+++ /dev/null
-package org.ibex.xml;
-import org.ibex.js.*;
-import org.ibex.util.*;
-import org.ibex.io.*;
-import java.io.*;
-import java.net.*;
-import java.util.*;
-
-public class JSRewriter extends XML.Node.Stream {
-
- private XML.Node.Stream in;
- private JSScope scope;
-
- public JSRewriter(XML.Node.Stream in) { this.in = in; this.scope = new JSScope(null); }
- public JSRewriter(XML.Node.Stream in, JSScope scope) { this.in = in; this.scope = scope; }
-
- public boolean _next(int level, XML.Node n) {
- if (!in.next(level, n)) return false;
- if (n.cdata != null) n.cdata = eval(n.cdata);
- else for(int i=1; i<n.numattrs; i+=2) n.attrs[i] = eval(n.attrs[i]);
- return true;
- }
-
- private String eval(String s) {
- if (s == null) return null;
- StringBuffer ret = new StringBuffer();
- while(s.indexOf("$[") != -1) {
- ret.append(s.substring(0, s.indexOf("$[")));
- s = s.substring(s.indexOf("$[")+2);
- String s2 = "return (" + s.substring(0, s.indexOf(']')) + ");\n";
- System.err.println("evaluating " + s2);
- try {
- JS js = JS.cloneWithNewParentScope(JS.fromReader("input", 0, new StringReader(s2)), scope);
- Object r = js.call(null, null, null, null, 0);
- System.err.println("output was " + r);
- ret.append(r == null ? "null" : r.toString());
- } catch (Exception e) {
- e.printStackTrace();
- ret.append(e.toString());
- }
- s = s.substring(s.indexOf(']') + 1);
- }
- ret.append(s);
- return ret.toString();
- }
-}
-
-