Package nu.xom

Examples of nu.xom.NodeFactory


   
    /*
     * Buffers a start tag until attributes and namespaces have been attached
     * by the Builder, and only then calls serializer.writeStartTag(Elem).
     */
    return new NodeFactory() {
     
      private Element buffer = null;
      private final Nodes NONE = new Nodes();
      private final NodeBuilder nodeBuilder = new NodeBuilder();
           
View Full Code Here


  }
   
  private void run(File file) throws Exception {
    Document expected = getBuilder().build(file);
   
    NodeFactory factory = new NodeFactory();
    XMLInputFactory staxFactory = createXMLInputFactory();
    Document actual = StaxUtil.createBuilder(staxFactory, factory).build(file);
   
    IOTestUtil.xomAssertEquals(expected, actual);
    IOTestUtil.canonicalAssertEquals(expected, actual);   
View Full Code Here

   *             if no XSLTransform can be obtained for the given stylesheet;
   *             in particular when the supplied stylesheet is not
   *             syntactically correct XSLT
   */
  protected XSLTransform newTransform(Document stylesheet, TransformerFactory transformerFactory) throws XSLException {
    return new XSLTransform(stylesheet, new NodeFactory(), transformerFactory);
  }
View Full Code Here

  private final Element DUMMY = new Element("dummy");
 
  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

    return x.indexOf(y) >= 0;
  }

  protected static Builder getBuilder() {
//    if (!ENABLE_BUILDER_POOL) return new Builder();
    if (!ENABLE_BUILDER_POOL) return new Builder(new NodeFactory() {});
    return BuilderPool.GLOBAL_POOL.getBuilder(false);
  }
View Full Code Here

      }

     
      // bnux and XOM
      BinaryXMLCodec codec = new BinaryXMLCodec();
      NodeFactory bnuxFactory = null;
      if (mode.startsWith("bnux")) {
        if (mode.indexOf("NNF") >= 0) {
          bnuxFactory = XOMUtil.getNullNodeFactory();
        }
      }

      Builder builder = new Builder();
//      Builder builder = BuilderPool.GLOBAL_POOL.getBuilder(false);
      if (mode.equals("xom-V")) {
        builder = new Builder(new NodeFactory() {});
      }
      if (mode.equals("xom-NNF")) {
        builder = new Builder(XOMUtil.getNullNodeFactory());
      }
     
      // saxon
      StaticQueryContext context = null;
      Transformer saxonSerializer = null;
      if (mode.equals("saxon")) {
        context = new StaticQueryContext(new Configuration());
        String clazz = "net.sf.saxon.TransformerFactoryImpl";
        System.setProperty("javax.xml.transform.TransformerFactory", clazz);
        saxonSerializer = TransformerFactory.newInstance().newTransformer();
      }
     
      // DOM
      DocumentBuilder domBuilder = null;
      Transformer domSerializer = null;
      if (mode.equals("dom")) {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
        domBuilder = factory.newDocumentBuilder();
        String clazz = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
//        String clazz = "org.apache.xalan.processor.TransformerFactoryImpl";
        System.setProperty("javax.xml.transform.TransformerFactory", clazz);
        domSerializer = TransformerFactory.newInstance().newTransformer();
        System.err.println(domSerializer.getClass().getName());
      }
     
      // FastInfoSet
      Object fiSerializer = null;
//      XMLStreamWriter fiStaxSerializer = null;
      Builder fiBuilder = null
      Method fiMethod = null;
     
      XMLStreamReader fistaxReader = null;
      Method fistaxMethod = null;
      if (mode.startsWith("fi")) {
        NodeFactory factory = null;
        if (mode.indexOf("NNF") >= 0) factory = XOMUtil.getNullNodeFactory();
        XMLReader parser = (XMLReader) Class.forName("com.sun.xml.fastinfoset.sax.SAXDocumentParser").newInstance();
        fiBuilder = new Builder(parser, false, factory);
       
        if (mode.indexOf("stax") >= 0) {
          fiSerializer = (XMLStreamWriter) Class.forName("com.sun.xml.fastinfoset.stax.StAXDocumentSerializer").newInstance();       
        } else {
          fiSerializer = (ContentHandler) Class.forName("com.sun.xml.fastinfoset.sax.SAXDocumentSerializer").newInstance();
        }
       
        if (mode.startsWith("fi1")) { // enable "full indexing"
          Method method;
          method = fiSerializer.getClass().getMethod(
              "setAttributeValueSizeLimit", new Class[] {Integer.TYPE});
          method.invoke(fiSerializer, new Object[] {new Integer(Integer.MAX_VALUE)});
          method = fiSerializer.getClass().getMethod(
              "setCharacterContentChunkSizeLimit", new Class[] {Integer.TYPE});
          method.invoke(fiSerializer, new Object[] {new Integer(Integer.MAX_VALUE)});
        }
       
        fiMethod = fiSerializer.getClass().getMethod(
            "setOutputStream", new Class[] { OutputStream.class});
       
        if (mode.indexOf("stax") >= 0) {
          fistaxReader = (XMLStreamReader) Class.forName("com.sun.xml.fastinfoset.stax.StAXDocumentParser").newInstance();
          fistaxMethod = fistaxReader.getClass().getMethod(
              "setInputStream", new Class[] { InputStream.class});
        }
      }
     
      // StAX
      Builder staxBuilder = null;
      if (mode.indexOf("stax") >= 0) {
        NodeFactory factory = null;
        if (mode.indexOf("NNF") >= 0) factory = XOMUtil.getNullNodeFactory();
        staxBuilder = StaxUtil.createBuilder(staxInputFactory, factory);
      }
     
      for (int j=5; j < args.length; j++) {
View Full Code Here

    }

    private static class StaxStreamConverter {

        private static Document convert(XMLStreamReader streamReader) throws XMLStreamException {
            NodeFactory nodeFactory = new NodeFactory();
            Document document = null;
            Element element = null;
            ParentNode parent = null;
            boolean documentFinished = false;
            while (streamReader.hasNext()) {
                int event = streamReader.next();
                switch (event) {
                    case XMLStreamConstants.START_DOCUMENT:
                        document = nodeFactory.startMakingDocument();
                        parent = document;
                        break;
                    case XMLStreamConstants.END_DOCUMENT:
                        nodeFactory.finishMakingDocument(document);
                        documentFinished = true;
                        break;
                    case XMLStreamConstants.START_ELEMENT:
                        if (document == null) {
                            document = nodeFactory.startMakingDocument();
                            parent = document;
                        }
                        String name = QNameUtils.toQualifiedName(streamReader.getName());
                        if (element == null) {
                            element = nodeFactory.makeRootElement(name, streamReader.getNamespaceURI());
                            document.setRootElement(element);
                        }
                        else {
                            element = nodeFactory.startMakingElement(name, streamReader.getNamespaceURI());
                            parent.appendChild(element);
                        }
                        convertNamespaces(streamReader, element);
                        convertAttributes(streamReader, nodeFactory);
                        parent = element;
                        break;
                    case XMLStreamConstants.END_ELEMENT:
                        nodeFactory.finishMakingElement(element);
                        parent = parent.getParent();
                        break;
                    case XMLStreamConstants.ATTRIBUTE:
                        convertAttributes(streamReader, nodeFactory);
                        break;
                    case XMLStreamConstants.CHARACTERS:
                        nodeFactory.makeText(streamReader.getText());
                        break;
                    case XMLStreamConstants.COMMENT:
                        nodeFactory.makeComment(streamReader.getText());
                        break;
                    default:
                        break;
                }
            }
            if (!documentFinished) {
                nodeFactory.finishMakingDocument(document);
            }
            return document;
        }
View Full Code Here

     *
     * @throws XSLException when the supplied document
     *      is not syntactically correct XSLT
     */
    public XSLTransform(Document stylesheet) throws XSLException {
        this(stylesheet, new NodeFactory());
    }
View Full Code Here

     */
    public XSLTransform(Document stylesheet, NodeFactory factory)
      throws XSLException {
       
        this(new XOMSource(stylesheet));
        if (factory == null) this.factory = new NodeFactory();
        else this.factory = factory;
       
    }
View Full Code Here

       
        File stylesheet = new File(inputDir, "identity.xsl");
        Builder builder = new Builder();
        Document stylesheetDoc = builder.build(stylesheet);
        XSLTransform xform = new XSLTransform(stylesheetDoc,
          new NodeFactory() {
            public Nodes makeComment(String text) {
                return new Nodes(new Attribute("comment", text));  
            }
        });
View Full Code Here

TOP

Related Classes of nu.xom.NodeFactory

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.