Package org.apache.xalan.serialize

Examples of org.apache.xalan.serialize.Serializer


   */
  public static Serializer switchSerializerIfHTML(
          String ns, String localName, Properties props, Serializer oldSerializer)
            throws TransformerException
  {
    Serializer newSerializer = oldSerializer;

    if (((null == ns) || (ns.length() == 0))
            && localName.equalsIgnoreCase("html"))
    {
      // System.out.println("transformer.getOutputPropertyNoDefault(OutputKeys.METHOD): "+
      //              transformer.getOutputPropertyNoDefault(OutputKeys.METHOD));    
      // Access at level of hashtable to see if the method has been set.
      if (null != getOutputPropertyNoDefault(OutputKeys.METHOD, props))
        return newSerializer;

      // Getting the output properties this way won't cause a clone of
      // the properties.
      Properties prevProperties = props;
     
      // We have to make sure we get an output properties with the proper
      // defaults for the HTML method.  The easiest way to do this is to
      // have the OutputProperties class do it.
      OutputProperties htmlOutputProperties = new OutputProperties(Method.HTML);

      htmlOutputProperties.copyFrom(prevProperties, true);
      Properties htmlProperties = htmlOutputProperties.getProperties();

//      try
      {
        if (null != oldSerializer)
        {
          Serializer serializer =
            SerializerFactory.getSerializer(htmlProperties);

          Writer writer = oldSerializer.getWriter();

          if (null != writer)
            serializer.setWriter(writer);
          else
          {
            OutputStream os = serializer.getOutputStream();

            if (null != os)
              serializer.setOutputStream(os);
          }
          newSerializer = serializer;
        }
      }
//      catch (java.io.IOException e)
View Full Code Here


   
      // xmlFilter3 uses xmlFilter2 as its reader.
      xmlFilter3.setParent(xmlFilter2);
   
      // xmlFilter3 outputs SAX events to the serializer.
      Serializer serializer = SerializerFactory.getSerializer
                                   (OutputProperties.getDefaultMethodProperties("xml"));       
      serializer.setOutputStream(System.out);
      xmlFilter3.setContentHandler(serializer.asContentHandler());

      // Perform the series of transformations as follows:
      //   - transformer3 gets its parent (transformer2) as the XMLReader/XMLFilter
      //     and calls transformer2.parse(new InputSource("foo.xml")).
      //   - transformer2 gets its parent (transformer1) as the XMLReader/XMLFilter
View Full Code Here

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

      // transformer3 outputs SAX events to the serializer.
      Serializer serializer = SerializerFactory.getSerializer
                                   (OutputProperties.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

      // Perform the transformation, placing the output in the DOMResult.
      transformer.transform(domSource, domResult);
   
      //Instantiate an XML serializer and use it to serialize the output DOM to System.out
      // using a default output format.
      Serializer serializer = SerializerFactory.getSerializer
                                   (OutputProperties.getDefaultMethodProperties("xml"));
      serializer.setOutputStream(System.out);
      serializer.asDOMSerializer().serialize(domResult.getNode());
  }
    else
    {
      throw new org.xml.sax.SAXNotSupportedException("DOM node processing not supported!");
    }
View Full Code Here

      // includes "lexical" events (e.g., comments and CDATA).
      reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
     
       FileOutputStream fos = new FileOutputStream("birds.out");
     
      Serializer serializer = SerializerFactory.getSerializer
                              (OutputProperties.getDefaultMethodProperties("xml"));
      serializer.setOutputStream(fos);
  
     
      // Set the result handling to be a serialization to the file output stream.
      Result result = new SAXResult(serializer.asContentHandler());
      handler.setResult(result);
     
      // Parse the XML input document.
      reader.parse("birds.xml");
     
View Full Code Here

      // Perform the transformation, placing the output in the DOMResult.
      transformer.transform(xmlDomSource, domResult);
   
      //Instantiate an Xalan XML serializer and use it to serialize the output DOM to System.out
      // using a default output format.
      Serializer serializer = SerializerFactory.getSerializer
                                   (OutputProperties.getDefaultMethodProperties("xml"));
      serializer.setOutputStream(System.out);
      serializer.asDOMSerializer().serialize(domResult.getNode());
  }
    else
    {
      throw new org.xml.sax.SAXNotSupportedException("DOM node processing not supported!");
    }
View Full Code Here

      StreamResult sresult = (StreamResult) outputTarget;
      String method = format.getProperty(OutputKeys.METHOD);

      try
      {
        Serializer serializer =
          SerializerFactory.getSerializer(format.getProperties());

        if (null != sresult.getWriter())
          serializer.setWriter(sresult.getWriter());
        else if (null != sresult.getOutputStream())
          serializer.setOutputStream(sresult.getOutputStream());
        else if (null != sresult.getSystemId())
        {
          String fileURL = sresult.getSystemId();

          if (fileURL.startsWith("file:///"))
          {
            if (fileURL.substring(8).indexOf(":") >0)
              fileURL = fileURL.substring(8);
            else
              fileURL = fileURL.substring(7);
          }

          m_outputStream = new java.io.FileOutputStream(fileURL);

          serializer.setOutputStream(m_outputStream);
        }
        else
          throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_OUTPUT_SPECIFIED, null)); //"No output specified!");

        handler = serializer.asContentHandler();

        this.setSerializer(serializer);
      }
      catch (UnsupportedEncodingException uee)
      {
View Full Code Here

    StringWriter sw = (StringWriter) m_stringWriterObjectPool.getInstance();

    m_resultTreeHandler =
      (ResultTreeHandler) m_textResultHandlerObjectPool.getInstance();

    Serializer serializer = m_resultTreeHandler.getSerializer();

    try
    {
      if (null == serializer)
      {
        serializer =
          SerializerFactory.getSerializer(m_textformat.getProperties());

        m_resultTreeHandler.setSerializer(serializer);
        serializer.setWriter(sw);

        ContentHandler shandler = serializer.asContentHandler();

        m_resultTreeHandler.init(this, shandler);
      }
      else
      {
View Full Code Here

TOP

Related Classes of org.apache.xalan.serialize.Serializer

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.