Package nux.xom.xquery

Examples of nux.xom.xquery.ResultSequenceSerializer$WrapSerializer


    tmp.delete();
    return doc;
  }
 
  private String serialize(Nodes nodes) {
    ResultSequenceSerializer serializer = new ResultSequenceSerializer();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    String xml;
    try {
      serializer.write(nodes, out);
      xml = out.toString("UTF-8"); // safe: UTF-8 support is required by JDK spec
    } catch (IOException e) {
      throw new RuntimeException("should never happen", e);
    }
   
View Full Code Here


      // prepare XQuery pool
      XQueryPool queryPool = new XQueryPool(
          new PoolConfig(), new XQueryFactory(null, resolver));
     
      ResultSequenceSerializer serializer = new ResultSequenceSerializer();
      serializer.setAlgorithm(algorithm);
      serializer.setEncoding(encoding);
      serializer.setIndent(indent);
     
      // now do the real work
      long runsStart = System.currentTimeMillis();
      for (int run=0; run < runs; run++) {
        if (isBench) {
          System.out.println("\n\n******************************************");
          System.out.println("run = " + run + ":");
        }
        for (int i=0; i < queries.size(); i++) {
          long start = System.currentTimeMillis();
          long serializationTime = 0;
          Object query = queries.get(i);
          XQuery xquery;
          if (query instanceof String) {
            xquery = queryPool.getXQuery((String)query, baseURI);
          } else if (query instanceof File) {
            xquery = queryPool.getXQuery((File)query, baseURI);
          } else {
            xquery = null; // disable XQuery for benchmarking
          }
         
          if (isBench) {
            System.out.println("query = " +query);
          }
          if (explain && run == 0 && xquery != null) {
            System.out.println("explain = \n" + xquery.explain());
          }
         
          XQuery morpher;
          if (update instanceof String) {
            morpher = queryPool.getXQuery((String)update, null);
          } else if (update instanceof File) {
            morpher = queryPool.getXQuery((File)update, null);
          } else {
            morpher = null;
          }
         
          int numSerials = 0;
          for (int j=0; j < inputFiles.length; j++) {
            Document doc = null;
            if (inputFiles[j] != null) {
              doc = docPool.getDocument(new File(inputFiles[j]));
            }
            if (explain && doc != null) {
              System.out.println("stats=" + toStatisticsString(doc));
            }

            for (int iter=0; iter < iterations; iter++) {
              Document doc2 = doc;
              if (morpher != null && doc2 != null) {
                doc2 = new Document(doc2); // immutable for multiple iterations
              }
             
              // run the query
              Nodes results;
              if (xomXPath) {
                if (doc2 == null) throw new UsageException(
                  "A context node is required by XOM's XPath engine, but missing.");
                results = doc2.query((String)query);
              } else if (xquery != null) {
                results = xquery.execute(doc2, null, variables).toNodes();
              } else {
                results = new Nodes(); // disable XQuery for benchmarking
                results.append(doc2);
              }
             
              if (morpher != null) {
                // interpret --query as select, interpret --update as morpher
                for (int k=0; doc2 == null && k < results.size(); k++) {
                  doc2 = results.get(k).getDocument();
                }
                XQueryUtil.update(results, morpher, null);
               
                // serialize modified document if there is one
                results = new Nodes();
                if (doc2 != null) results.append(doc2);
              }
             
              // serialize results onto output, if any
              File f = (File) outputFiles.get(j);
              OutputStream out = System.out;
              if (f != null) {
                if (f.getAbsolutePath().equals("/dev/null")) continue;
                out = new FileOutputStream(f);
              }
             
              long serializationStart = System.currentTimeMillis();
              serializer.write(results, out);
              if (out != System.out && out != System.err) out.close();
              serializationTime += System.currentTimeMillis() - serializationStart;
              numSerials++;
            }
          }
View Full Code Here

     * ResultSequenceSerializer ensures correct output of namespace
     * declarations even if element is not a root element, and it does
     * so without the potentially expensive node.copy() required by
     * nu.xom.Serializer
     */
    ResultSequenceSerializer serializer = new ResultSequenceSerializer();
    serializer.setIndent(4);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Nodes nodes = new Nodes();
    nodes.append(node);
    String xml;
    try {
      serializer.write(nodes, out);
      xml = out.toString("UTF-8"); // safe: UTF-8 support is required by JDK spec
    } catch (IOException e) {
      throw new RuntimeException("should never happen", e);
    }
   
View Full Code Here

        "attribute percent {round-half-to-even(100.0 * $e/@instances div /*/@descendants-or-self, 1)}," +
        "attribute instances {$e/@instances}, " +
        "attribute xpath {$e/saxon:path()}" +
      "}";
    Nodes nodes = XQueryUtil.xquery(summary, query);
    ResultSequenceSerializer rser = new ResultSequenceSerializer();
    rser.setIndent(4);
    rser.write(nodes, System.out);   
  }
View Full Code Here

TOP

Related Classes of nux.xom.xquery.ResultSequenceSerializer$WrapSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.