Package nu.xom

Examples of nu.xom.Document


    if (args[2].equalsIgnoreCase("cache")) mode = 0;
    if (args[2].equalsIgnoreCase("nocache")) mode = 1;
    if (args[2].equalsIgnoreCase("xom")) mode = 2;
//    if (args[2].equalsIgnoreCase("jaxpxom")) mode = 3;
    boolean check = (runs == 1);
    Document doc = readDocument(args[3]); // e.g. "romeo.xml"
   
    for (int k=0; k < repeats; k++) { // for each repetition block
      for (int q=4; q < args.length; q++) { // for each query file
        Node[] contexts;
        String[] selects;
        int[] types;
        Object[] expected;
       
        if (args[q].endsWith(".xq")) { // it is an XQuery
          System.out.println("Now reading " + args[q]);
          contexts = new Node[] { doc };
          selects = new String[] { FileUtil.toString(new FileInputStream(args[q]), null) };
          types = new int[] {0};
          expected = new Object[] { "" };
        }
        else { // it is a document containing zero or more XPath queries
          Document queries = readDocument(args[q]); // e.g. "xpath/queries1.xml"
         
          Nodes paths = XQueryUtil.xquery(queries, "/paths/document/path");   
          contexts = new Node[paths.size()];
          selects = new String[paths.size()];
          types = new int[paths.size()];
View Full Code Here


 
  public static void main(String[] args) throws Exception {
    System.out.println("\nTree structure summary:");
    System.out.println("***********************\n");
    NodeFactory factory = new TreeStructureCollector();
    Document summary = new Builder(factory).build(new File(args[0]));
    Serializer ser = new Serializer(System.out);
    ser.setIndent(4);
    ser.write(summary);
//    System.out.println(XOMUtil.toPrettyXML(summary));

View Full Code Here

  // TODO: obsolete?
  public Document collect(Document doc) {
    startMakingDocument();
    collect(doc.getRootElement());
//    finishMakingDocument()
    return new Document(current);
  }
View Full Code Here

              pool.getBuilder(validate.equals("validate")) :
              new Builder(validate.equals("validate"))
          }
          checksum += builder.hashCode();
          if (! fileName.equals("nofile")) {
            Document doc = memory ?
                builder.build(new ByteArrayInputStream(bytes, 0, bytes.length)) :
                builder.build(new FileInputStream(fileName));
            //String str = doc.toXML();
            //System.out.print('.');
            checksum += doc.getChildCount();
          }       
        }
      };
      thread.start();
      thread.join();
View Full Code Here

      if (ignore(args[j])) continue;
      File file = new File(args[j]);
      if (file.isDirectory()) continue;
      System.out.println("now processing " + file);
     
      Document doc = new Builder().build(file);
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      for (int p=0; p < iterations; p++) {
        System.out.println("compressionLevel=" + compressionLevel);
        codec.serialize(doc, compressionLevel, out);
        if (testCompressionLevels) { // alternate on each iteration
          compressionLevel = (compressionLevel + 1) % 10;
        }
      }
     
      InputStream in = new ByteArrayInputStream(out.toByteArray());
      for (int p=0; p < iterations; p++) {
        Document doc2 = codec.deserialize(in, null);
        // check correctness
        if (cmd.equals("test")) {
          if (! Arrays.equals(XOMUtil.toCanonicalXML(doc), XOMUtil.toCanonicalXML(doc2))) {
            System.err.println("Canonical XML Mismatch: ");
            System.err.println("expected: " + doc.toXML());
            System.err.println("actual: " + doc2.toXML());                 
            printDiff(doc, doc2);
            System.exit(0);
          }
          if (!equalsDocTypeEquals(doc.getDocType(), doc2.getDocType())) { 
            System.err.println("DocType Mismatch: ");
            System.err.println("expected: " + doc.toXML());
            System.err.println("actual: " + doc2.toXML());
            System.exit(0);
          }
        }
      }   
    }   
View Full Code Here

          }
          if (file.getAbsolutePath().indexOf("-II-") >= 0) continue; // ignore invalid files
         
          System.out.println("\n" + k + ": now processing " + file + " ...");
          for (int p=0; p < 1; p++) {
            Document doc1 = getW3CBuilder().build(file);           
            Document doc2 = pooledBuilder.build(file);
           
            IOTestUtil.xomAssertEquals(doc1, doc2);
            IOTestUtil.canonicalAssertEquals(doc1, doc2);
          }
        }
View Full Code Here

          System.out.println("\n" + k + ": IGNORING " + file + " ...");
          continue;
        }
           
        System.out.println("\n" + k + ": now processing " + file + " ...");
        Document expected = getBuilder().build(file);
//        System.out.println(expected.toXML());
        System.out.print("*");
       
        for (int enc = 0; enc < encodings.length; enc++) {
          try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
           
            StreamingSerializer ser;
//            ser = factory.createXMLSerializer(out, encoding);
//            ((nu.xom.Serializer) ser).setIndent(4);
            ser = factory.createStaxSerializer(outFactory.createXMLStreamWriter(out, encodings[enc]));
            ser.write(expected);
           
//            String s = new String(out.toByteArray());
//            s =  s.substring(0, Math.min(2000, s.length()));
//            System.out.println("\n" + s + "\n");
//            log(out.toByteArray());
            InputStream in = new ByteArrayInputStream(out.toByteArray());
            Document actual = getBuilder().build(in, file.toURI().toASCIIString());
           
            IOTestUtil.xomAssertEquals(expected, actual);
            IOTestUtil.canonicalAssertEquals(expected, actual);   
          } catch (Throwable e) {
            bugs++;
View Full Code Here

//    System.setProperty("nux.xom.pool.PoolConfig.invalidationPeriod", "1000");
   
    final PoolConfig config = new PoolConfig();
    int k = -1;
   
    Document doc = null;
    if (args.length > ++k && !args[k].equals("-"))
      doc = new Builder().build(args[k]);
   
    int threads = 1;
    if (args.length > ++k) threads = Math.max(1, Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setCompressionLevel(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setMaxEntries(Integer.parseInt(args[k]));
   
    if (args.length > ++k) config.setFileMonitoring(new Boolean(args[k]).booleanValue());
   
    if (args.length > ++k) config.setCapacity(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxIdleTime(Long.parseLong(args[k]));
   
    if (args.length > ++k) config.setMaxLifeTime(Long.parseLong(args[k]));
   
    int printStep = 10;
    if (args.length > ++k) printStep = Math.max(1, Integer.parseInt(args[k]));
   
    final DocumentMap pool = new DocumentMap(config);
   
    for (int j=0; j < threads; j++) {
      final int t = j;
      final Document xmlDoc = doc;
      final int step = printStep;
      Runnable runner = new Runnable() {
        public void run() {
          try {
            int i = 0;
            while (true) {
              if (i % step == 0) System.out.println("t="+ t + ", index=" + i);
              Document doc;
              if (xmlDoc == null) {
                Element root = new Element("root");
                Element child = new Element("child");
                root.appendChild(child);
                for (int j=0; j < 10000; j++) child.appendChild("xxxxxxxxxxxxxxxxxx" + j);
                doc = new Document(root);
              }
              else {
                doc = xmlDoc;
                if (config.getCompressionLevel() == -1) doc = new Document(doc);
              }
             
              Object key = new Integer(i + t*100);
//              Object key = new Integer(-1);
              pool.putDocument(key, doc);
View Full Code Here

  public XMLMatrix(File file, boolean append) throws ParsingException, IOException {
    this.file = file;
    if (append && file.exists()) {
      this.doc = BuilderPool.GLOBAL_POOL.getBuilder(false).build(file);
    } else {
      this.doc = new Document(new Element(file.getName()));
    }
  }
View Full Code Here

              baseURI = baseURI.substring("file:/".length());
              if (!baseURI.startsWith("//")) baseURI = "//" + baseURI;
              baseURI = "file:/" + baseURI;
            }
  //          System.out.println("baseURI: " + baseURI);
            Document doc = new Builder().build(file);
           
            byte[] data = codec.serialize(doc, compressionLevel);
            if (!cmd.equals("test")) doc = new BinaryXMLCodec().deserialize(data); // use "interned" strings
            byte[] fileData = FileUtil.toByteArray(new FileInputStream(file));
            long fileLength = file.length();
            int encodedSize = 0;
           
            org.w3c.dom.Document domDoc = null;
            if (mode.equals("dom")) {
              domDoc = domBuilder.parse(file);
            }
           
            NodeInfo saxonDoc = null;
            if (mode.equals("saxon")) {
              saxonDoc = context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
            }
   
            if (mode.startsWith("fi")) {
              if (mode.indexOf("stax") >= 0) {
//                data = serializeWithStax(doc, staxOutputFactory);
                data = serializeWithFastInfosetStax(doc, (XMLStreamWriter)fiSerializer, fiMethod, new ByteArrayOutputStream());
              } else {
                data = serializeWithFastInfoset(doc, (ContentHandler)fiSerializer, fiMethod, new ByteArrayOutputStream());
              }
            }
   
            // run the benchmark
            long start = System.currentTimeMillis();
            for (int i = 0; i < iterations; i++) {
              try {
                // serialize
                if (cmd.equals("ser") || cmd.equals("serdeser") || cmd.equals("test")) {
                  ByteArrayOutputStream out = createOutputStream(cmd.equals("ser"));
                  if (mode.startsWith("bnux")) {
                    if (mode.indexOf("stream") < 0) {
                      codec.serialize(doc, compressionLevel, out);
                      data = out.toByteArray();
                    } else {
                      data = serializeWithStreamingBnux(doc, compressionLevel, out);
                    }
                  } else if (mode.startsWith("xom")) {
                    if (mode.indexOf("stax") >= 0) {
                      data = serializeWithStax(doc, staxOutputFactory, out);
                    } else if (mode.indexOf("stream") < 0) {
                      data = serializeWithXOM(doc, out);
                    } else {
                      data = serializeWithStreamingXOM(doc, out);
                    }
                  } else if (mode.equals("saxon")) {
                    saxonSerializer.transform(saxonDoc, new StreamResult(out));
                    data = out.toByteArray();
                  } else if (mode.equals("dom")) {
                    domSerializer.transform(new DOMSource(domDoc), new StreamResult(out));
                    data = out.toByteArray();
                  } else if (mode.startsWith("fi")) {
                    if (mode.indexOf("stax") >= 0) {
//                      data = serializeWithStax(doc, staxOutputFactory);
                      data = serializeWithFastInfosetStax(doc, (XMLStreamWriter)fiSerializer, fiMethod, out);
                    } else {
                      data = serializeWithFastInfoset(doc, (ContentHandler)fiSerializer, fiMethod, out);
                    }
                  } else {
                    throw new IllegalArgumentException("illegal mode");
                  }
                  checksum += data.length;
                }
                encodedSize = data.length;
                doneEncoded += encodedSize;
               
                // deserialize
                Document doc2 = null;
                if (cmd.equals("deser") || cmd.equals("serdeser") || cmd.equals("test")) {
                  if (mode.startsWith("bnux")) {
                    doc2 = codec.deserialize(new ByteArrayInputStream(data), bnuxFactory);
                  } else if (mode.startsWith("xom") && mode.indexOf("stax") >= 0) {
                    doc2 = staxBuilder.build(new ByteArrayInputStream(fileData));         
                  } else if (mode.startsWith("xom")) {
                    if (mode.indexOf("stream") < 0) {
                      doc2 = builder.build(new ByteArrayInputStream(fileData), baseURI);
                    } else {
                      doc2 = builder.build(new ByteArrayInputStream(data), baseURI);
                    }
                  } else if (mode.equals("saxon")) { // just for deser comparison
                    context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
                  } else if (mode.equals("dom")) {
                    domDoc = domBuilder.parse(new ByteArrayInputStream(fileData));
  //                  System.err.println(domDoc.getClass().getName());
                  } else if (mode.startsWith("fi") && mode.indexOf("stax") >=0 ) {
                    fistaxMethod.invoke(fistaxReader, new Object[] {new ByteArrayInputStream(data)});
  //                  doc2 = staxBuilder.build(fistaxReader);
                    doc2 = new StaxParser(fistaxReader, staxBuilder.getNodeFactory()).build();
                  } else if (mode.startsWith("fi")) {
                    doc2 = fiBuilder.build(new ByteArrayInputStream(data));
                  } else {
                    throw new IllegalArgumentException("illegal mode");
                  }             
                  if (doc2 != null) checksum += doc2.getBaseURI().length();
                }
               
                // check correctness
                if (cmd.equals("test")) {
                  IOTestUtil.xomAssertEquals(doc, doc2);
                  IOTestUtil.canonicalAssertEquals(doc, doc2);
  //                if (! Arrays.equals(XOMUtil.toCanonicalXML(doc), XOMUtil.toCanonicalXML(doc2))) {
  //                  System.err.println("Canonical XML Mismatch: ");
  //                  System.err.println("expected: " + doc.toXML());
  //                  System.err.println("actual: " + doc2.toXML());                 
  //                  printDiff(doc, doc2);
  //                  System.exit(0);
  //                }
                  if (!equalsDocTypeEquals(doc.getDocType(), doc2.getDocType())) { 
                    System.err.println("DocType Mismatch: ");
                    System.err.println("expected: " + doc.toXML());
                    System.err.println("actual: " + doc2.toXML());
                    System.exit(0);
                  }
                }
              } catch (RuntimeException e) {
                System.err.println("FATAL ERROR: " + e);
View Full Code Here

TOP

Related Classes of nu.xom.Document

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.