Package nu.xom

Examples of nu.xom.Document


    // prepare DocumentFactory and DocumentPool
    DocumentFactory docFactory = new DocumentFactory() {
      public Document createDocument(InputStream input, URI baseURI)
          throws ParsingException, IOException {
        long start = System.currentTimeMillis();
        Document doc;
        if (baseURI != null && baseURI.getPath().endsWith(".bnux")) {
          if (filter == null) {
            doc = getBinaryXMLFactory().createDocument(input, baseURI);
          } else {
            StreamingTransform myTransform = new StreamingTransform() {
              public Nodes transform(Element subtree) {
                return XQueryUtil.xquery(subtree, filterQuery);
              }
            };
 
            if (input == null && baseURI == null)
              throw new IllegalArgumentException("input and baseURI must not both be null");
            if (input == null) input = baseURI.toURL().openStream();
            try {
              doc = new BinaryXMLCodec().deserialize(input, filter.createNodeFactory(null, myTransform));
              if (baseURI != null) doc.setBaseURI(baseURI.toASCIIString());
            } finally {
              input.close(); // do what SAX XML parsers do
            }
          }
        } else {
View Full Code Here


  public Document getDocument(File input) throws ParsingException, IOException {
    if (input == null)
      throw new IllegalArgumentException("input must not be null");

    Object key = input;
    Document doc = entries.getDocument(key);
    if (doc == null) {
      doc = factory.createDocument(input);
      entries.putDocument(key, doc);
    }
    return doc;
View Full Code Here

  public Document getDocument(URI systemID) throws ParsingException, IOException {
    if (systemID == null)
      throw new IllegalArgumentException("systemID must not be null");

    Object key = systemID;
    Document doc = entries.getDocument(key);
    if (doc == null) {
      doc = factory.createDocument(null, systemID);
      entries.putDocument(key, doc);
    }
    return doc;
View Full Code Here

      throw new IllegalArgumentException("resolver must not be null");
    if (resourceName == null)
      throw new IllegalArgumentException("resourceName must not be null");
   
    Object key = Pool.createHashKeys(new Object[] {resourceName, baseURI});
    Document doc = entries.getDocument(key);
    if (doc == null) {
      InputStream input = resolver.getResourceAsStream(resourceName);
      if (input == null) {
        throw new MissingResourceException(
          "Resource '" + resourceName + "' could not be found by resolver: " +
View Full Code Here

      }
      checksum += data.length;
    }
   
    // deserialize
    Document doc2 = null;
    if (isDeserCmd || 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) {
//        XMLStreamReader reader = staxFactory.createXMLStreamReader(new ByteArrayInputStream(fileData));
        doc2 = StaxUtil.createBuilder(staxInputFactory, staxBuilder.getNodeFactory())
          .build(new ByteArrayInputStream(fileData));
//        doc2 = staxBuilder.build(staxreader);         
      } else if (mode.startsWith("xom")) {
        doc2 = builder.build(new ByteArrayInputStream(fileData));               
      } else if (mode.equals("saxon")) { // just for deser comparison
        context.buildDocument(new StreamSource(new ByteArrayInputStream(fileData)));
      } else if (mode.equals("dom")) {
        domDoc = null;
        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 = new StaxParser(fistaxReader, staxBuilder.getNodeFactory()).build();
      } else if (mode.startsWith("fi")) {
//        NodeFactory factory = null;
//        if (mode.equals("fi0-NNF")) factory = XOMUtil.getNullNodeFactory();
//        XMLReader parser = (XMLReader) Class.forName("com.sun.xml.fastinfoset.sax.SAXDocumentParser").newInstance();
//        fiBuilder = new Builder(parser, false, factory);
        doc2 = fiBuilder.build(new ByteArrayInputStream(data));
      } else {
        throw new IllegalArgumentException("illegal mode");
      }             
     
      if (doc2 != null) checksum += doc2.getBaseURI().length();       
    }     
  }
View Full Code Here

      public Element startMakingElement(String name, String namespace) {
        return null;
      }
     
      public Document startMakingDocument() {
        return new Document(new Element("dummy")); // unused dummy
      }
    };
  }
View Full Code Here

        try {
          serializer.writeXMLDeclaration();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
        return new Document(new Element("dummy")); // unused dummy
      }
     
      public void finishMakingDocument(Document document) {
        buffer = null;
        try {
View Full Code Here

    if (node == null)
      throw new IllegalArgumentException("node must not be null");
    if (unmarshaller == null)
      throw new IllegalArgumentException("unmarshaller must not be null");
   
    Document doc;
    if (node instanceof Document) {
      doc = (Document) node;
    }
    else if (node instanceof Element) {
      // do not modify elem's parent pointer
      doc = new Document((Element) node.copy());
    }
    else {
      throw new IllegalArgumentException("Illegal XOM node type" + node);
    }
   
View Full Code Here

   
    public Document build(Document doc, NodeFactory factory) {
      if (doc == null)
        throw new IllegalArgumentException("doc must not be null");
      if (factory == null || factory.getClass() == NodeFactory.class) {
        return new Document(doc); // no need to pipe through the default factory
      }
     
      Document result = factory.startMakingDocument();
      boolean hasRootElement = false;
      int k = 0;
     
      for (int i=0; i < doc.getChildCount(); i++) {
        Node child = doc.getChild(i);
        Nodes nodes;
        if (child instanceof Element) {
          Element elem = (Element) child;
          Element root = factory.makeRootElement(
              elem.getQualifiedName(), elem.getNamespaceURI());
          if (root == null) {
            throw new NullPointerException("Factory failed to create root element.");
          }
          result.setRootElement(root);
          appendNamespaces(elem, root);
          appendAttributes(elem, factory, root);
          build(elem, factory, root);
          nodes = factory.finishMakingElement(root);
        } else if (child instanceof Comment) {
          nodes = factory.makeComment(child.getValue());
        } else if (child instanceof ProcessingInstruction) {
          ProcessingInstruction pi = (ProcessingInstruction) child;
          nodes = factory.makeProcessingInstruction(
            pi.getTarget(), pi.getValue());
        } else if (child instanceof DocType) {
          DocType docType = (DocType) child;
          nodes = factory.makeDocType(
              docType.getRootElementName(),
              docType.getPublicID(),
              docType.getSystemID());
        } else {
          throw new IllegalArgumentException("Unrecognized node type");
        }
       
        // append nodes:
        for (int j=0; j < nodes.size(); j++) {
          Node node = nodes.get(j);
          if (node instanceof Element) { // replace fake root with real root
            if (hasRootElement) {
              throw new IllegalAddException(
                "Factory returned multiple root elements");
            }
            result.setRootElement((Element) node);
            hasRootElement = true;
          } else {
            result.insertChild(node, k);
          }
          k++;
        }
      }
     
View Full Code Here

//          throw new XMLException(
//          "SENR0001: W3C XQuery Serialization spec forbids top-level namespaces");
        } else if (node instanceof Document) {
          // Replace document with its children
          // Note that a Document can't have an atomic value or Text as child
          Document doc = (Document) node;
          for (int j=0; j < doc.getChildCount(); j++) {
            Node child = doc.getChild(j);
            if (mayBreakLine && indentYes && child instanceof Element) {
              breakLine();
            }
            writeChild(child);
            mayBreakLine = true;
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.