Package javax.xml.transform.sax

Examples of javax.xml.transform.sax.SAXResult


        parse(new InputSource(systemId));
    }

    public void setContentHandler (ContentHandler handler)
    {
  _transformerHandler.setResult(new SAXResult(handler));
  if (getParent() == null) {
                try {
                    createParent();
                }
                catch (SAXException  e) {
View Full Code Here


  // Return the content handler for this Result object
  try {
      // Result object could be SAXResult, DOMResult, or StreamResult
      if (result instanceof SAXResult) {
                final SAXResult target = (SAXResult)result;
                final ContentHandler handler = target.getHandler();

    _tohFactory.setHandler(handler);

                /**
                 * Fix for bug 24414
                 * If the lexicalHandler is set then we need to get that
                 * for obtaining the lexical information
                 */
                LexicalHandler lexicalHandler = target.getLexicalHandler();

                if (lexicalHandler != null ) {
        _tohFactory.setLexicalHandler(lexicalHandler);
    }

    _tohFactory.setOutputType(TransletOutputHandlerFactory.SAX);
    return _tohFactory.getSerializationHandler();
            }
      else if (result instanceof DOMResult) {
    _tohFactory.setNode(((DOMResult) result).getNode());
    _tohFactory.setNextSibling(((DOMResult) result).getNextSibling());
    _tohFactory.setOutputType(TransletOutputHandlerFactory.DOM);
    return _tohFactory.getSerializationHandler();
            }
      else if (result instanceof StreamResult) {
    // Get StreamResult
    final StreamResult target = (StreamResult) result; 

    // StreamResult may have been created with a java.io.File,
    // java.io.Writer, java.io.OutputStream or just a String
    // systemId.

    _tohFactory.setOutputType(TransletOutputHandlerFactory.STREAM);

    // try to get a Writer from Result object
    final Writer writer = target.getWriter();
    if (writer != null) {
        _tohFactory.setWriter(writer);
        return _tohFactory.getSerializationHandler();
    }

    // or try to get an OutputStream from Result object
    final OutputStream ostream = target.getOutputStream();
    if (ostream != null) {
        _tohFactory.setOutputStream(ostream);
        return _tohFactory.getSerializationHandler();
    }

View Full Code Here

    reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHFirst);
    for (int i = 1; i < vTHandler.size(); i++)
    {
      TransformerHandler tHFrom = (TransformerHandler)vTHandler.elementAt(i-1);
      TransformerHandler tHTo = (TransformerHandler)vTHandler.elementAt(i);
      tHFrom.setResult(new SAXResult(tHTo));     
    }
    TransformerHandler tHLast = (TransformerHandler)vTHandler.lastElement();
    Transformer trans = tHLast.getTransformer();
    Properties outputProps = trans.getOutputProperties();
    Serializer serializer = SerializerFactory.getSerializer(outputProps);
   
    FileOutputStream out = new FileOutputStream(target);
    try
    {
      serializer.setOutputStream(out);
      tHLast.setResult(new SAXResult(serializer.asContentHandler()));
      reader.parse(source);
    }
    finally
    {
      // Always clean up the FileOutputStream,
View Full Code Here

    }
  }

  public void dom2sax(Node node, ContentHandler handler) {
    try {
      mTransformer.transform(new DOMSource(node), new SAXResult(handler));
    } catch (TransformerException e) {
      throw new UIMARuntimeException(e);
    }
  }
View Full Code Here

      // SAX events, and transform them to the result.
      TransformerHandler handler
        = stfactory.newTransformerHandler(new StreamSource(xslID));

      // Set the result handling to be a serialization to System.out.
      Result result = new SAXResult(new ExampleContentHandler());
      handler.setResult(result);
     
      // Create a reader, and set it's content handler to be the TransformerHandler.
      XMLReader reader=null;
View Full Code Here

      // Create an XMLReader.
      XMLReader reader = XMLReaderFactory.createXMLReader();
      reader.setContentHandler(tHandler1);
      reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);

      tHandler1.setResult(new SAXResult(tHandler2));
      tHandler2.setResult(new SAXResult(tHandler3));

      // transformer3 outputs SAX events to the serializer.
      Serializer serializer = SerializerFactory.getSerializer
                          (OutputPropertiesFactory.getDefaultMethodProperties("xml"));       
      serializer.setOutputStream(System.out);
      tHandler3.setResult(new SAXResult(serializer.asContentHandler()));

      // Parse the XML input document. The input ContentHandler and output ContentHandler
      // work in separate threads to optimize performance.  
      reader.parse("foo.xml");
    }
View Full Code Here

        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");

        ContentHandler contentHandler = createContentHandler(writer);
        Result result = new SAXResult(contentHandler);

        for (int i = 0; i < bodyChildrenLength; i++) {
          if (i != 0) {
            writer.write(", ");
          }
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    protected <T extends Result>T createSAXResult(
            Class<T> resultClass) throws SQLException {

        SAXResult result = null;

        try {
            result = (resultClass == null) ? new SAXResult()
                    : (SAXResult) resultClass.newInstance();
        } catch (SecurityException ex) {
            throw Exceptions.resultInstantiation(ex);
        } catch (InstantiationException ex) {
            throw Exceptions.resultInstantiation(ex);
        } catch (IllegalAccessException ex) {
            throw Exceptions.resultInstantiation(ex);
        } catch (ClassCastException ex) {
            throw Exceptions.resultInstantiation(ex);
        }

        SAX2DOMBuilder handler = null;

        try {
            handler = new SAX2DOMBuilder();
        } catch (ParserConfigurationException ex) {
            throw Exceptions.resultInstantiation(ex);
        }
        this.domResult = new DOMResult();

        result.setHandler(handler);
        this.domResult.setNode(handler.getDocument());

        return (T) result;
    }
View Full Code Here

               Transformer serializer = tf.newTransformer();
               serializer.setOutputProperty(OutputKeys.ENCODING, "UTF8");
               serializer.setOutputProperty(OutputKeys.INDENT, "yes");

               // Transform -> SAX event stream
               SAXResult saxResult = new SAXResult(new NoKernelNamespaceSAXFilter(hd));

               // DOM -> Transform
               serializer.transform(new DOMSource(doc), saxResult);

               // Reuse the parsed document
View Full Code Here

      Transformer serializer = tf.newTransformer();
      serializer.setOutputProperty(OutputKeys.ENCODING, "UTF8");
      serializer.setOutputProperty(OutputKeys.INDENT, "yes");

      // Transform -> SAX event stream
      SAXResult saxResult = new SAXResult(new NoKernelNamespaceSAXFilter(hd));

      // DOM -> Transform
      serializer.transform(new DOMSource(doc), saxResult);

      // Reuse the parsed document
View Full Code Here

TOP

Related Classes of javax.xml.transform.sax.SAXResult

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.