dims        01/02/20 13:06:50

  Modified:    src/org/apache/cocoon/components/language/markup Tag:
                        xml-cocoon2 LogicsheetCodeGenerator.java
               src/org/apache/cocoon/serialization Tag: xml-cocoon2
                        AbstractTextSerializer.java HTMLSerializer.java
                        SVGSerializer.java TextSerializer.java
                        XMLSerializer.java
  Log:
  Moving to TRaX Serializers as per Scott Boag's suggestion. This will ensure 
that we
  can be independent of Xerces.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.12  +27 -25    
xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/LogicsheetCodeGenerator.java
  
  Index: LogicsheetCodeGenerator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/Attic/LogicsheetCodeGenerator.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- LogicsheetCodeGenerator.java      2001/01/22 21:56:34     1.1.2.11
  +++ LogicsheetCodeGenerator.java      2001/02/20 21:06:43     1.1.2.12
  @@ -10,6 +10,7 @@
   import java.io.StringWriter;
   import java.util.ArrayList;
   import java.util.List;
  +import java.util.Properties;
   
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
  @@ -17,14 +18,13 @@
   
   import java.io.IOException;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.Serializer;
  -import org.apache.xml.serialize.OutputFormat;
  -
  -
  +import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.TransformerConfigurationException;
   import javax.xml.transform.sax.TransformerHandler;
   import javax.xml.transform.sax.SAXResult;
  +import javax.xml.transform.sax.SAXTransformerFactory;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.OutputKeys;
   import javax.xml.transform.TransformerException;
   
   import org.apache.log.Logger;
  @@ -35,7 +35,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
  - * @version CVS $Revision: 1.1.2.11 $ $Date: 2001/01/22 21:56:34 $
  + * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/02/20 21:06:43 $
    */
   public class LogicsheetCodeGenerator implements MarkupCodeGenerator, 
Loggable {
   
  @@ -43,8 +43,6 @@
   
       private Logicsheet corelogicsheet;
   
  -    private Serializer serializer;
  -
       private ContentHandler serializerContentHandler;
   
       private XMLReader rootReader;
  @@ -57,23 +55,27 @@
       * The default constructor
       */
       public LogicsheetCodeGenerator() {
  -        // set the serializer which would act as ContentHandler for the last 
transformer
  -        // FIXME (SSA) change a home made content handler, that extract the 
PCDATA
  -        // from the last remaining element
  -        SerializerFactory factory = 
SerializerFactory.getSerializerFactory(Method.TEXT);
  -        OutputFormat outformat = new OutputFormat();
  -        // FIXME (SSA) set the right encoding set
  -        //outformat.setEncoding("");
  -        // FIXME (SSA) remove the nice identing. For debug purpose only.
  -        outformat.setIndent(4);
  -        outformat.setPreserveSpace(true);
  -        this.serializer = factory.makeSerializer(outformat);
  -        this.writer = new StringWriter();
  -        this.serializer.setOutputCharStream(writer);
  +
  +        SAXTransformerFactory factory = (SAXTransformerFactory) 
TransformerFactory.newInstance();
  +        Properties format = new Properties();
  +
           try {
  -            this.serializerContentHandler = 
this.serializer.asContentHandler();
  -        } catch (IOException ioe) {
  -            log.error("This should never happen, because we're not dealing 
with IO file, but rather with StringWriter", ioe);
  +            // set the serializer which would act as ContentHandler for the 
last transformer
  +            // FIXME (SSA) change a home made content handler, that extract 
the PCDATA
  +            // from the last remaining element
  +            TransformerHandler handler = factory.newTransformerHandler();
  +
  +            // Set the output properties
  +            format.put(OutputKeys.METHOD,"text");
  +            // FIXME (SSA) remove the nice identing. For debug purpose only.
  +            format.put(OutputKeys.INDENT,"yes"); 
  +            handler.getTransformer().setOutputProperties(format);
  +
  +            this.writer = new StringWriter();
  +            handler.setResult(new StreamResult(writer));
  +            this.serializerContentHandler = handler;
  +        } catch (TransformerConfigurationException tce) {
  +            log.error("LogicsheetCodeGenerator: unable to get 
TransformerHandler", tce);
           }
       }
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +42 -64    
xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractTextSerializer.java
  
  Index: AbstractTextSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractTextSerializer.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- AbstractTextSerializer.java       2001/02/12 14:17:39     1.1.2.6
  +++ AbstractTextSerializer.java       2001/02/20 21:06:45     1.1.2.7
  @@ -8,102 +8,80 @@
   
   package org.apache.cocoon.serialization;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.OutputFormat;
  +import java.util.Properties;
   
   import org.apache.avalon.Configurable;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.ConfigurationException;
   
  +import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.OutputKeys;
  +import javax.xml.transform.sax.SAXTransformerFactory;
  +
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2001/02/12 14:17:39 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2001/02/20 21:06:45 $
    */
   public abstract class AbstractTextSerializer extends AbstractSerializer 
implements Configurable {
   
       /**
  -     * The <code>OutputFormat</code> used by this serializer.
  +     * The trax <code>TransformerFactory</code> used by this serializer.
        */
  -    protected OutputFormat format;
  +    protected SAXTransformerFactory factory = (SAXTransformerFactory) 
TransformerFactory.newInstance();
   
       /**
  +     * The <code>Properties</code> used by this serializer.
  +     */
  +    protected Properties format = new Properties();
  +
  +    /**
        * Set the configurations for this serializer.
        */
       public void configure(Configuration conf)
         throws ConfigurationException {
   
  -        Configuration encoding = conf.getChild("encoding");
  +        Configuration cdataSectionElements = 
conf.getChild("cdata-section-elements");
           Configuration dtPublic = conf.getChild("doctype-public");
           Configuration dtSystem = conf.getChild("doctype-system");
  +        Configuration encoding = conf.getChild("encoding");
           Configuration indent = conf.getChild("indent");
  -        Configuration preserveSpace = conf.getChild("preserve-space");
  -        Configuration declaration = conf.getChild("xml-declaration");
  -        Configuration lineWidth = conf.getChild("line-width");
  -
  -        String doctypePublic = null;
  -
  -        format = new OutputFormat();
  -        format.setPreserveSpace(true);
  +        Configuration mediaType = conf.getChild("media-type");
  +        Configuration method = conf.getChild("method");
  +        Configuration omitXMLDeclaration = 
conf.getChild("omit-xml-declaration");
  +        Configuration standAlone = conf.getChild("standalone");
  +        Configuration version = conf.getChild("version");
   
  -        if (! encoding.getLocation().equals("-")) {
  -            try {
  -                format.setEncoding(encoding.getValue());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No value for encoding--but expected", ce);
  -            }
  +        if (! cdataSectionElements.getLocation().equals("-")) {
  +            
format.put(OutputKeys.CDATA_SECTION_ELEMENTS,cdataSectionElements.getValue());
           }
  -
           if (! dtPublic.getLocation().equals("-")) {
  -            try {
  -                doctypePublic = dtPublic.getValue();
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No Public Doctype--but expected", ce);
  -            }
  +            format.put(OutputKeys.DOCTYPE_PUBLIC,dtPublic.getValue());
           }
  -
           if (! dtSystem.getLocation().equals("-")) {
  -            try {
  -                format.setDoctype(doctypePublic, dtSystem.getValue());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No System Doctype--but expected", ce);
  -            }
  +            format.put(OutputKeys.DOCTYPE_SYSTEM,dtSystem.getValue());
           }
  -
  +        if (! encoding.getLocation().equals("-")) {
  +            format.put(OutputKeys.ENCODING,encoding.getValue());
  +        }
           if (! indent.getLocation().equals("-")) {
  -            format.setIndenting(true);
  -            try {
  -                format.setIndent(indent.getValueAsInt());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No indent value or invalid value--but 
expected", ce);
  -            }
  -        }
  -
  -        if (! preserveSpace.getLocation().equals("-")) {
  -            try {
  -                format.setPreserveSpace(preserveSpace.getValueAsBoolean());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No preserve-space value--but expected", 
ce);
  -            }
  -        }
  -
  -        if (! declaration.getLocation().equals("-")) {
  -            try {
  -                
format.setOmitXMLDeclaration(!declaration.getValueAsBoolean());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No declaration value or invalid 
value--but expected", ce);
  -            }
  +            format.put(OutputKeys.INDENT,indent.getValue());
           }
  -
  -
  -        if (! lineWidth.getLocation().equals("-")) {
  -            try {
  -                format.setLineWidth(lineWidth.getValueAsInt());
  -            } catch (ConfigurationException ce) {
  -                getLogger().debug("No line-width value or invalid value--but 
expected", ce);
  -            }
  +        if (! mediaType.getLocation().equals("-")) {
  +            format.put(OutputKeys.MEDIA_TYPE,mediaType.getValue());
  +        }
  +        if (! method.getLocation().equals("-")) {
  +            format.put(OutputKeys.METHOD,method.getValue());
  +        }
  +        if (! omitXMLDeclaration.getLocation().equals("-")) {
  +            
format.put(OutputKeys.OMIT_XML_DECLARATION,omitXMLDeclaration.getValue());
  +        }
  +        if (! standAlone.getLocation().equals("-")) {
  +            format.put(OutputKeys.STANDALONE,standAlone.getValue());
  +        }
  +        if (! version.getLocation().equals("-")) {
  +            format.put(OutputKeys.VERSION,version.getValue());
           }
       }
   }
  
  
  
  1.1.2.13  +11 -8     
xml-cocoon/src/org/apache/cocoon/serialization/Attic/HTMLSerializer.java
  
  Index: HTMLSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/HTMLSerializer.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- HTMLSerializer.java       2001/02/19 15:58:10     1.1.2.12
  +++ HTMLSerializer.java       2001/02/20 21:06:46     1.1.2.13
  @@ -10,23 +10,23 @@
   
   import java.io.OutputStream;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.OutputFormat;
  -
   import org.apache.avalon.util.pool.Pool;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.ConfigurationException;
   import org.apache.cocoon.PoolClient;
   
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.OutputKeys;
  +
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/02/19 15:58:10 $
  + * @version CVS $Revision: 1.1.2.13 $ $Date: 2001/02/20 21:06:46 $
    */
   
   public class HTMLSerializer extends AbstractTextSerializer implements 
PoolClient {
   
  -    private SerializerFactory factory;
  +    private TransformerHandler handler;
   
       private Pool pool;
   
  @@ -39,13 +39,16 @@
       }
   
       public HTMLSerializer() {
  -        this.factory = SerializerFactory.getSerializerFactory(Method.HTML);
       }
   
       public void setOutputStream(OutputStream out) {
           try {
               super.setOutputStream(out);
  -            this.setContentHandler(this.factory.makeSerializer(out, 
this.format).asContentHandler());
  +            handler = factory.newTransformerHandler();
  +            format.put(OutputKeys.METHOD,"html");
  +            handler.setResult(new StreamResult(out));
  +            handler.getTransformer().setOutputProperties(format);
  +            this.setContentHandler(handler);
           } catch (Exception e) {
               getLogger().error("HTMLSerializer.setOutputStream()", e);
               throw new RuntimeException(e.toString());
  
  
  
  1.1.2.24  +1 -5      
xml-cocoon/src/org/apache/cocoon/serialization/Attic/SVGSerializer.java
  
  Index: SVGSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/SVGSerializer.java,v
  retrieving revision 1.1.2.23
  retrieving revision 1.1.2.24
  diff -u -r1.1.2.23 -r1.1.2.24
  --- SVGSerializer.java        2001/02/19 15:58:10     1.1.2.23
  +++ SVGSerializer.java        2001/02/20 21:06:46     1.1.2.24
  @@ -27,10 +27,6 @@
   import org.apache.batik.transcoder.*;
   import org.apache.batik.refimpl.transcoder.AbstractTranscoder;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.OutputFormat;
  -
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   
  @@ -38,7 +34,7 @@
    * A Batik based Serializer for generating PNG/JPG images
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Davanum Srinivas</a>
  - * @version CVS $Revision: 1.1.2.23 $ $Date: 2001/02/19 15:58:10 $
  + * @version CVS $Revision: 1.1.2.24 $ $Date: 2001/02/20 21:06:46 $
    */
   public class SVGSerializer extends SVGBuilder implements Composer, 
Serializer, Configurable, PoolClient {
   
  
  
  
  1.1.2.9   +10 -7     
xml-cocoon/src/org/apache/cocoon/serialization/Attic/TextSerializer.java
  
  Index: TextSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/TextSerializer.java,v
  retrieving revision 1.1.2.8
  retrieving revision 1.1.2.9
  diff -u -r1.1.2.8 -r1.1.2.9
  --- TextSerializer.java       2001/02/19 15:58:10     1.1.2.8
  +++ TextSerializer.java       2001/02/20 21:06:47     1.1.2.9
  @@ -10,9 +10,9 @@
   
   import java.io.OutputStream;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.OutputFormat;
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.OutputKeys;
   
   import org.apache.avalon.util.pool.Pool;
   import org.apache.avalon.Configuration;
  @@ -21,12 +21,12 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.8 $ $Date: 2001/02/19 15:58:10 $
  + * @version CVS $Revision: 1.1.2.9 $ $Date: 2001/02/20 21:06:47 $
    */
   
   public class TextSerializer extends AbstractTextSerializer implements 
PoolClient {
   
  -    private SerializerFactory factory;
  +    private TransformerHandler handler;
   
       private Pool pool;
   
  @@ -39,13 +39,16 @@
       }
   
       public TextSerializer() {
  -        this.factory = SerializerFactory.getSerializerFactory(Method.TEXT);
       }
   
       public void setOutputStream(OutputStream out) {
           try {
               super.setOutputStream(out);
  -            this.setContentHandler(this.factory.makeSerializer(out, 
this.format).asContentHandler());
  +            handler = factory.newTransformerHandler();
  +            format.put(OutputKeys.METHOD,"text");
  +            handler.setResult(new StreamResult(out));
  +            handler.getTransformer().setOutputProperties(format);
  +            this.setContentHandler(handler);
           } catch (Exception e) {
               getLogger().error("TextSerializer.setOutputStream()", e);
               throw new RuntimeException(e.toString());
  
  
  
  1.1.2.13  +10 -7     
xml-cocoon/src/org/apache/cocoon/serialization/Attic/XMLSerializer.java
  
  Index: XMLSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/XMLSerializer.java,v
  retrieving revision 1.1.2.12
  retrieving revision 1.1.2.13
  diff -u -r1.1.2.12 -r1.1.2.13
  --- XMLSerializer.java        2001/02/19 15:58:10     1.1.2.12
  +++ XMLSerializer.java        2001/02/20 21:06:47     1.1.2.13
  @@ -10,9 +10,9 @@
   
   import java.io.OutputStream;
   
  -import org.apache.xml.serialize.SerializerFactory;
  -import org.apache.xml.serialize.Method;
  -import org.apache.xml.serialize.OutputFormat;
  +import javax.xml.transform.sax.TransformerHandler;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.OutputKeys;
   
   import org.apache.avalon.util.pool.Pool;
   import org.apache.avalon.Configuration;
  @@ -21,12 +21,12 @@
   
   /**
    * @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/02/19 15:58:10 $
  + * @version CVS $Revision: 1.1.2.13 $ $Date: 2001/02/20 21:06:47 $
    */
   
   public class XMLSerializer extends AbstractTextSerializer implements 
PoolClient {
   
  -    private SerializerFactory factory;
  +    private TransformerHandler handler;
   
       private Pool pool;
   
  @@ -39,13 +39,16 @@
       }
   
       public XMLSerializer() {
  -        this.factory = SerializerFactory.getSerializerFactory(Method.XML);
       }
   
       public void setOutputStream(OutputStream out) {
           try {
               super.setOutputStream(out);
  -            this.setContentHandler(this.factory.makeSerializer(out, 
this.format).asContentHandler());
  +            this.handler = factory.newTransformerHandler();
  +            format.put(OutputKeys.METHOD,"xml");
  +            handler.setResult(new StreamResult(out));
  +            handler.getTransformer().setOutputProperties(format);
  +            this.setContentHandler(handler);
           } catch (Exception e) {
               getLogger().error("XMLSerializer.setOutputStream()", e);
               throw new RuntimeException(e.toString());
  
  
  

Reply via email to