--- /dev/null
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import fxslt.memory.TatooEngine;
+import fxslt.memory.TatooEngine.CustomBlock;
+import fxslt.memory.TatooEngine.Tree;
+import fxslt.memory.TatooEngine.Automaton;
+import fxslt.memory.MutableNodeList;
+
+import javax.xml.transform.*;
+import javax.xml.transform.dom.*;
+import javax.xml.transform.stream.*;
+
+
+public class TatooTest {
+ static long timer;
+ public static void start_timer() {
+ timer = System.nanoTime();
+ }
+ public static void stop_timer (String msg) {
+ long time = System.nanoTime() - timer;
+ System.err.println(msg + " " + time/1000000 + "ms");
+ System.err.flush();
+ }
+
+ public static void main(String args[])
+ {
+
+ try {
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setCoalescing(true);
+ dbf.setNamespaceAware(true);
+
+ start_timer();
+ Document doc = dbf.newDocumentBuilder().parse(args[0]);
+ stop_timer("Parsing document");
+
+ MutableNodeList mnl = new MutableNodeList();
+ start_timer();
+ CustomBlock<Tree> tree = TatooEngine.init_document (doc);
+ stop_timer("Initializing document");
+
+ mnl.add(doc);
+
+ start_timer();
+ CustomBlock<Automaton> auto = TatooEngine.compile(args[1]);
+ stop_timer("Compiling query");
+
+ start_timer();
+ NodeList nodes = TatooEngine.evaluate(auto, tree, mnl);
+ stop_timer("Evaluating query");
+
+ if (args.length >= 3 && args[2] == "print" ) {
+ start_timer ();
+ Transformer serializer = TransformerFactory.newInstance().newTransformer();
+ serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ StreamResult o = new StreamResult(System.out);
+ System.out.println("<xml_result num=\"1\">");
+ for(int i = 0; i < nodes.getLength(); i++){
+ Node n = nodes.item(i);
+ switch (n.getNodeType()) {
+ case Node.ATTRIBUTE_NODE:
+ System.out.print (n.getNodeName() + "=" + n.getNodeValue());
+ break;
+ default:
+ serializer.transform(new DOMSource(nodes.item(i)), o);
+ break;
+ };
+ System.out.println();
+ };
+ System.out.println("</xml_result>");
+ stop_timer("Serializing document");
+ }
+ System.err.println("Number of results: " + nodes.getLength());
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+}