Package nu.xom

Examples of nu.xom.NodeFactory


  StaxBuilder(XMLInputFactory inputFactory, NodeFactory factory) {
    super(new DummyXMLReader(), false, factory);
    if (inputFactory == null)
      throw new IllegalArgumentException("XMLInputFactory must not be null");   
    this.inputFactory = inputFactory;
    if (factory == null) factory = new NodeFactory();
    this.factory = factory;
  }
View Full Code Here


  public Document deserialize(InputStream input, NodeFactory factory)
      throws BinaryParsingException, IOException {
   
    if (input == null)
      throw new IllegalArgumentException("input stream must not be null");
    if (factory == null) factory = new NodeFactory();
   
    // read document header
    if (page == null) page = new ArrayByteList(256);
    page.clear();
    if (!page.ensureRemaining(input, 4 + 1 + 1 + 4))
View Full Code Here

   */
  public StaxParser(XMLStreamReader reader, NodeFactory factory) {
    if (reader == null)
      throw new IllegalArgumentException("reader must not be null")
    this.reader = reader;
    if (factory == null) factory = new NodeFactory();
    this.factory = factory;
    if (DEBUG) System.err.println("StAX parser=" + reader.getClass().getName());
    if (!isNamespaceAware(reader))
      throw new IllegalArgumentException("reader must be namespace aware");
  }
View Full Code Here

        addAttributes(elem);
        return elem.getAttribute(0).copy();
      }
      case XMLStreamConstants.START_DOCUMENT:
      case XMLStreamConstants.END_DOCUMENT:
        return new NodeFactory().startMakingDocument();
      case XMLStreamConstants.PROCESSING_INSTRUCTION:
        return new ProcessingInstruction(
            reader.getPITarget(), reader.getPIData());
      case XMLStreamConstants.COMMENT:
        return new Comment(reader.getText());
      case XMLStreamConstants.SPACE:
      case XMLStreamConstants.CDATA:
      case XMLStreamConstants.ENTITY_REFERENCE:
      case XMLStreamConstants.CHARACTERS:
        return readText();
      case XMLStreamConstants.DTD: {
        Nodes nodes = null;
        try {
          nodes = readDocType(new NodeFactory());
        } catch (XMLStreamException e) {
          StaxUtil.wrapException(e);
        }
        if (nodes.size() > 0) return nodes.get(0);
        return null; // unsupported extended DTD API
View Full Code Here

    if (args.length == 0) { // simply convert from System.in to System.out
      InputStream in = new BufferedInputStream(System.in);
      if (codec.isBnuxDocument(in)) {
        StreamingSerializer ser = factory.createXMLSerializer(System.out, "UTF-8");
        NodeFactory redirector = XOMUtil.getRedirectingNodeFactory(ser);
        codec.deserialize(in, redirector);
      } else { // it's an XML document (or rubbish)
        StreamingSerializer ser = factory.createBinaryXMLSerializer(System.out, compressionLevel);
        NodeFactory redirector = XOMUtil.getRedirectingNodeFactory(ser);
        new Builder(redirector).build(in);
      }
      return;
    }
   
    for (int run=0; run < runs; run++) {
      long s = System.currentTimeMillis();
      for (int i=0; i < args.length; i++) {
        long start, end;
        String fileName = args[i];
        File file = new File(fileName);
        if (file.isDirectory()) continue; // ignore
        System.out.print(fileName + " --> ");
        InputStream in = new FileInputStream(file);       
        OutputStream out = null;
       
        if (fileName.endsWith(".bnux")) {
          NodeFactory redirector = null;
          if (readOnly) {
            redirector = XOMUtil.getNullNodeFactory();
          } else {
            String destFileName = fileName.substring(0, fileName.length() - ".bnux".length());
            System.out.print(destFileName);
            out = new FileOutputStream(destFileName);
            StreamingSerializer ser = factory.createXMLSerializer(out, "UTF-8");
            redirector = XOMUtil.getRedirectingNodeFactory(ser);
          }
         
          start = System.currentTimeMillis();
         
          codec.deserialize(in, redirector); // perform conversion       
        }
        else { // it's a textual XML document
          NodeFactory redirector = null;
          if (readOnly) {
            redirector = XOMUtil.getNullNodeFactory();
          } else {
            String destFileName = fileName + ".bnux";
            System.out.print(destFileName);
View Full Code Here

    if (mode.indexOf("pool") >= 0) {
      builder = BuilderPool.GLOBAL_POOL.getBuilder(false);
    }
   
    if (mode.equals("xom-V")) {
      builder = new Builder(new NodeFactory() {});
    } else if (mode.equals("xom-V-pool")) {
      builder = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          return new Builder(parser, false, new NodeFactory() {});    
        }
      }.createBuilder(false);
    }
   
    if (mode.equals("xom-NNF")) {
      builder = new Builder(XOMUtil.getNullNodeFactory());
    } else if (mode.equals("xom-NNF-pool")) {
      builder = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          return new Builder(parser, false, XOMUtil.getNullNodeFactory());    
        }
      }.createBuilder(false);
    }
   
    // saxon
    context = null;
    saxonSerializer = null;
    if (mode.equals("saxon")) {
      context = new StaticQueryContext(new Configuration());
      saxonSerializer = createIdentityTransform(
          new String[] {"net.sf.saxon.TransformerFactoryImpl"});
    }
   
    // DOM
    domBuilder = null;
    domSerializer = null;
    if (mode.equals("dom")) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      try {
        factory.setAttribute("http://apache.org/xml/features/dom/defer-node-expansion", Boolean.FALSE);
      } catch (IllegalArgumentException e) {
        // crimson does not implement this attribute
      }
      domBuilder = factory.newDocumentBuilder();
      domSerializer = createIdentityTransform(new String[] {
          "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl",
          "org.apache.xalan.processor.TransformerFactoryImpl"});
      System.err.println(domSerializer.getClass().getName());
    }
   
    // FastInfoSet
    fiBuilder = null
    fiSerializer = null;
    fiMethod = 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
    staxBuilder = null;
    if (mode.indexOf("stax") >= 0) {
      NodeFactory factory = null;
      if (mode.indexOf("NNF") >= 0) factory = XOMUtil.getNullNodeFactory();
      staxBuilder = StaxUtil.createBuilder(staxInputFactory, factory);
   
  }
View Full Code Here

   * method does not look across multiple Text nodes.
   *
   * @return a node factory
   */
  public static NodeFactory getIgnoreWhitespaceOnlyTextNodeFactory() {
    return new NodeFactory() {
      private final Nodes NONE = new Nodes();
     
      public Nodes makeText(String text) {
        return Normalizer.isWhitespaceOnly(text) ?
          NONE :
View Full Code Here

    if (child == null)
      throw new IllegalArgumentException("child must not be null");
    if (log == null)
      throw new IllegalArgumentException("logStream must not be null");
   
    return new NodeFactory() {   
      private int level = 0;
     
      public Nodes makeAttribute(String name, String URI, String value, Attribute.Type type) {
        log("", new Attribute(name, URI, value, type));
        return child.makeAttribute(name, URI, value, type);
View Full Code Here

   * many, but not all XML use cases (round-tripping).
   *
   * @return a node factory
   */
  public static NodeFactory getTextTrimmingNodeFactory() {
    return new NodeFactory() {
      private final Nodes NONE = new Nodes();
     
      public Nodes makeText(String text) {
        text = Normalizer.trim(text);
        return text.length() == 0 ? NONE : super.makeText(text);
View Full Code Here

   * empty document instead. This improves validation performance.
   *
   * @return a node factory
   */
  public static NodeFactory getNullNodeFactory() {
    return new NodeFactory() {
      private final Nodes NONE = new Nodes();
           
      public Nodes makeAttribute(String name, String URI, String value, Attribute.Type type) {
        return NONE;
      }
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.