Package org.treetank.saxon.evaluator

Evaluators to simplify Saxon access.

See: Description

Package org.treetank.saxon.evaluator Description

Evaluators to simplify Saxon access.

Implemented as Callables, therefore can be used in ThreadPools.

Code example for use with XPathEvaluator:

      final File file = new File("src" + File.separator + "test"
             + File.separator + "resources" + File.separator + "testfile");
      Storage.truncateDatabase(file);
      final IStorage database = Storage.openDatabase(file);
      final XPathSelector selector = new XPathEvaluator(QUERYSTRING,
        database).call();

      final StringBuilder strBuilder = new StringBuilder();

      for (final XdmItem item : selector) {
        strBuilder.append(item.toString());
      }

      System.out.println(strBuilder.toString());
    
You can do everything you like with the resulting items. The method getStringValue() of the item get's the string value from the underlying node type. In case of an element it concatenates all descending text-nodes. To get the underlying node, which is a Treetank item instead of a Saxon item can be retrieved by using the identically named method getUnderlyingNode().

Code example for use with XQueryEvaluator

      final File file = new File("src" + File.separator + "test"
             + File.separator + "resources" + File.separator + "testfile");
      Storage.truncateDatabase(file);
      final IStorage database = Storage.openDatabase(file);

      final StringBuilder strBuilder = new StringBuilder();

      for (final XdmItem item : value) {
        strBuilder.append(item.toString());
      }

      System.out.println(strBuilder.toString());
    

Code example for use with XQueryEvaluatorOutputStream:

      final File file = new File("src" + File.separator + "test"
         + File.separator + "resources" + File.separator + "testfile");
      Storage.truncateDatabase(file);
      final IStorage database = Storage.openDatabase(file);
      final XQueryEvaluator xqe =
        new XQueryEvaluator(
          XQUERYSTRING,
          database,
          new ByteArrayOutputStream());
      final String result = xqe.call().toString();

      System.out.println(result);
    
Note that you can use other output streams as well.

Code example for use with XQueryEvaluatorSAXHandler:

  
      final StringBuilder strBuilder = new StringBuilder();
      final ContentHandler contHandler = new XMLFilterImpl() {

        public void startElement(
          final String uri,
          final String localName,
          final String qName,
          final Attributes atts) throws SAXException {
          strBuilder.append("<" + localName);

          for (int i = 0; i < atts.getLength(); i++) {
            strBuilder.append(" " + atts.getQName(i));
            strBuilder.append("=\"" + atts.getValue(i) + "\"");
          }

          strBuilder.append(">");
        }

        public void endElement(String uri, String localName, String qName)
            throws SAXException {
          strBuilder.append("");
        }

        public void characters(final char[] ch, final int start, final int length)
            throws SAXException {
          for (int i = start; i < start + length; i++) {
            strBuilder.append(ch[i]);
          }
        }
      };

      final File file = new File("src" + File.separator + "test"
             + File.separator + "resources" + File.separator + "testfile");
      Storage.truncateDatabase(file);
      final IStorage database = Storage.openDatabase(file);

      new XQueryEvaluatorSAXHandler(
          XQUERYSTRING,
          database,
          contHandler).run();

      System.out.println(strBuilder.toString());
    

Code example for use with XSLTEvaluator:

      final File file = new File("src" + File.separator + "test"
         + File.separator + "resources" + File.separator + "testfile");
      final File stylesheet = new File("src" + File.separator + "test"
         + File.separator + "resources" + File.separator + "stylesheet.xsl");
      final IStorage database = Storage.openDatabase(file);

      final OutputStream out = new ByteArrayOutputStream();

      final OutputStream out =
        new XSLTEvaluator(
            database,
            stylesheet,
            out).call();

      System.out.prinln(out.toString());
    

Author:
Johannes Lichtenberger, University of Konstanz

Copyright © 2013. All Rights Reserved.