Package org.apache.xml.serializer

Examples of org.apache.xml.serializer.Serializer


      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


      // 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
                             (OutputPropertiesFactory.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

      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

        if (p.containsKey("standalone"))
        {
            p.remove("standalone");
        }
        Serializer serializer = SerializerFactory.getSerializer(p);
        serializer.setOutputStream(o);
        return (SerializationHandler) serializer;
    }
View Full Code Here

      if (null == m_serializationHandler)
      {
        // if we didn't get one from the pool, go make a new one

       
        Serializer serializer = org.apache.xml.serializer.SerializerFactory.getSerializer(
            m_textformat.getProperties());
        m_serializationHandler = (SerializationHandler) serializer;
      }

        m_serializationHandler.setTransformer(this);
View Full Code Here

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

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

        m_serializer = serializer;

        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!");

        m_resultContentHandler = serializer.asContentHandler();
      }
      catch (IOException ioe)
      {
        throw new TransformerException(ioe);
      }
View Full Code Here

    if (!m_foundFirstElement && null != m_serializer)
    {
      m_foundFirstElement = true;

      Serializer newSerializer;

      try
      {
        newSerializer = SerializerSwitcher.switchSerializerIfHTML(uri,
                localName, m_outputFormat.getProperties(), m_serializer);
      }
      catch (TransformerException te)
      {
        throw new SAXException(te);
      }

      if (newSerializer != m_serializer)
      {
        try
        {
          m_resultContentHandler = newSerializer.asContentHandler();
        }
        catch (IOException ioe// why?
        {
          throw new SAXException(ioe);
        }
View Full Code Here

      Properties htmlProperties = htmlOutputProperties.getProperties();

      try
      {
//        Serializer oldSerializer = transformer.getSerializer();
        Serializer oldSerializer = null;

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

          Writer writer = oldSerializer.getWriter();

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

            if (null != os)
              serializer.setOutputStream(os);
          }

//          transformer.setSerializer(serializer);

          ContentHandler ch = serializer.asContentHandler();

          transformer.setContentHandler(ch);
        }
      }
      catch (java.io.IOException e)
View Full Code Here

   */
  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

      tHFrom.setResult(new SAXResult(tHTo));     
    }
    TransformerHandler tHLast = (TransformerHandler)vTHandler.lastElement();
    Transformer trans = tHLast.getTransformer();
    Properties outputProps = trans.getOutputProperties();
    Serializer serializer = SerializerFactory.getSerializer(outputProps);
    serializer.setOutputStream(new FileOutputStream(target));
    tHLast.setResult(new SAXResult(serializer.asContentHandler()));
   
    reader.parse(source);
  }
View Full Code Here

TOP

Related Classes of org.apache.xml.serializer.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.