You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@locus.apache.org on 2000/08/21 19:36:29 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon/serialization TextSerializer.java AbstractSerializer.java FOPSerializer.java HTMLSerializer.java SVGSerializer.java XMLSerializer.java ImageSerializer.java

stefano     00/08/21 10:36:28

  Modified:    src/org/apache/cocoon/serialization Tag: xml-cocoon2
                        AbstractSerializer.java FOPSerializer.java
                        HTMLSerializer.java SVGSerializer.java
                        XMLSerializer.java
  Added:       src/org/apache/cocoon/serialization Tag: xml-cocoon2
                        TextSerializer.java
  Removed:     src/org/apache/cocoon/serialization Tag: xml-cocoon2
                        ImageSerializer.java
  Log:
  using Xerces serialization API instead of Pier's code
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.6   +68 -9     xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractSerializer.java
  
  Index: AbstractSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractSerializer.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- AbstractSerializer.java	2000/08/16 05:08:17	1.1.2.5
  +++ AbstractSerializer.java	2000/08/21 17:36:25	1.1.2.6
  @@ -5,31 +5,90 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  + 
   package org.apache.cocoon.serialization;
   
   import java.io.BufferedOutputStream;
  -import java.io.IOException;
   import java.io.OutputStream;
  -import org.apache.avalon.utils.Parameters;
  +
  +import org.apache.xml.serialize.SerializerFactory;
  +import org.apache.xml.serialize.Method;
  +import org.apache.xml.serialize.OutputFormat;
  +
  +import org.apache.avalon.Configurable;
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
  +
   import org.apache.cocoon.sitemap.SitemapOutputComponent;
   import org.apache.cocoon.xml.AbstractXMLConsumer;
  +import org.apache.cocoon.xml.util.XMLConsumerBridge;
   
   /**
  - *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/16 05:08:17 $
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/21 17:36:25 $
    */
  -public abstract class AbstractSerializer extends AbstractXMLConsumer 
  -implements Serializer {
  -    /** The current <code>OutputStream</code>. */
  -    protected OutputStream output=null;
  +public abstract class AbstractSerializer extends XMLConsumerBridge 
  +implements Serializer, Configurable {
  +
  +    /**
  +     * The <code>OutputFormat</code> used by this serializer.
  +     */    
  +    protected OutputFormat format;
  +    
  +    /**
  +     * The <code>OutputStream</code> used by this serializer.
  +     */    
  +    protected OutputStream output;
  +
  +    /** 
  +     * Set the configurations for this serializer. 
  +     */
  +    public void setConfiguration(Configuration conf) 
  +      throws ConfigurationException {
  +
  +        format = new OutputFormat();
  +        format.setPreserveSpace(true);
  +
  +        Configuration encoding = conf.getConfiguration("encoding");
  +        if (encoding != null) {
  +            format.setEncoding(encoding.getValue());
  +        }
  +
  +        Configuration doctypePublic = conf.getConfiguration("doctype-public");
  +        Configuration doctypeSystem = conf.getConfiguration("doctype-system");
  +        if (doctypeSystem != null) {
  +            format.setDoctype((doctypePublic != null) ? doctypePublic.getValue() : null, doctypeSystem.getValue());
  +        }
  +
  +        Configuration indent = conf.getConfiguration("indent");
  +        if (indent != null) {
  +            format.setIndenting(true);
  +            format.setIndent(indent.getValueAsInt());
  +        }
  +
  +        Configuration preserveSpace = conf.getConfiguration("preserve-space");
  +        if (preserveSpace != null) {
  +            format.setPreserveSpace(preserveSpace.getValueAsBoolean());
  +        }
   
  +        Configuration declaration = conf.getConfiguration("xml-declaration");
  +        if (declaration != null) {
  +            format.setOmitXMLDeclaration(!declaration.getValueAsBoolean());
  +        }
  +        
  +        Configuration lineWidth = conf.getConfiguration("line-width");
  +        if (lineWidth != null) {
  +            format.setLineWidth(lineWidth.getValueAsInt());
  +        }        
  +    }
  +        
       /**
        * Set the <code>OutputStream</code> where the XML should be serialized.
        */
       public void setOutputStream(OutputStream out) {
  -        this.output=new BufferedOutputStream(out);
  +        this.output = out;
       }
   
       /**
  
  
  
  1.1.2.2   +5 -2      xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java
  
  Index: FOPSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- FOPSerializer.java	2000/08/17 17:06:25	1.1.2.1
  +++ FOPSerializer.java	2000/08/21 17:36:26	1.1.2.2
  @@ -5,6 +5,7 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  + 
   package org.apache.cocoon.serialization;
   
   import java.io.IOException;
  @@ -30,7 +31,7 @@
    * @author <a href="mailto:giacomo.pati@pwr.ch">Giacomo Pati</a>
    *         (PWR Organisation &amp; Entwicklung)
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.1.2.1 $ $Date: 2000/08/17 17:06:25 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/08/21 17:36:26 $
    *
    */
   public class FOPSerializer extends XMLConsumerBridge implements Serializer, MessageListener {
  @@ -48,6 +49,8 @@
           this.driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", Version.getVersion());
           this.driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
           this.driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
  +	    this.driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
  +	    this.driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
   
           // the use of static resources sucks for servlet enviornments
           // since we could have multiple FOP that all logs in this pipe
  @@ -60,8 +63,8 @@
        * Set the <code>OutputStream</code> where the XML should be serialized.
        */
       public void setOutputStream(OutputStream out) {
  -        this.setBridgedContentHandler(this.driver.getContentHandler());
           this.driver.setWriter(new PrintWriter(out));
  +        this.setBridgedContentHandler(this.driver.getContentHandler());
        }
    
       /** 
  
  
  
  1.1.2.5   +21 -345   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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- HTMLSerializer.java	2000/08/04 21:12:01	1.1.2.4
  +++ HTMLSerializer.java	2000/08/21 17:36:26	1.1.2.5
  @@ -5,363 +5,39 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  +
   package org.apache.cocoon.serialization;
   
  -import java.io.BufferedOutputStream;
  -import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.OutputStreamWriter;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import org.apache.cocoon.xml.XMLConsumer;
  -import org.apache.cocoon.xml.util.NamespacesTable;
  -import org.xml.sax.Attributes;
  -import org.xml.sax.Locator;
  -import org.xml.sax.SAXException;
  -
  -/**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/04 21:12:01 $
  - */
  -public class HTMLSerializer extends AbstractSerializer implements XMLConsumer {
  -    /** The namespaces table */
  -    private NamespacesTable ns=new NamespacesTable();
  -    /** The PrintStream used for output */
  -    private OutputStreamWriter out=null;
  -    /** The current locator */
  -    private Locator loc=null;
  -    /** A flag telling wether we're processing the DTD */
  -    private boolean dtd=false;
  -    /** A flag telling wether we're processing a CDATA section */
  -    private boolean cdata=false;
  -
  -    /**
  -     * Set the <code>OutputStream</code> where the XML should be serialized.
  -     */
  -    public void setOutputStream(OutputStream out) {
  -        super.setOutputStream(out);
  -        this.out=new OutputStreamWriter(super.output);;
  -    }
  -
  -    /**
  -     * Receive an object for locating the origin of SAX document events.
  -     *
  -     * @param locator An object that can return the location of any SAX
  -     *                document event.
  -     */
  -    public void setDocumentLocator(Locator locator) {
  -        this.loc=locator;
  -    }
  -
  -    /**
  -     * Receive notification of the beginning of a document.
  -     */
  -    public void startDocument()
  -    throws SAXException {
  -    }
   
  -    /**
  -     * Receive notification of the end of a document.
  -     */
  -    public void endDocument()
  -    throws SAXException {
  -        try {
  -            this.out.flush();
  -        } catch (IOException e) {
  -            throw new SAXException("IOException flushing stream",e);
  -        }
  -    }
  -
  -    /**
  -     * Begin the scope of a prefix-URI Namespace mapping.
  -     */
  -    public void startPrefixMapping(String prefix, String uri)
  -    throws SAXException {
  -        this.ns.addDeclaration(prefix,uri);
  -    }
  -
  -    /**
  -     * End the scope of a prefix-URI mapping.
  -     */
  -    public void endPrefixMapping(String prefix)
  -    throws SAXException {
  -        this.ns.removeDeclaration(prefix);
  -    }
  -
  -    /**
  -     * Receive notification of the beginning of an element.
  -     */
  -    public void startElement(String uri, String loc, String raw, Attributes a)
  -    throws SAXException {
  -        this.print('<');
  -
  -        this.print(this.ns.resolve(uri,raw,null,loc).getQName());
  -        for (int x=0; x<a.getLength(); x++) {
  -            String name=this.ns.resolve(a.getURI(x),a.getQName(x),null,
  -                                        a.getLocalName(x)).getQName();
  -            String value=a.getValue(x);
  -            if ((name.equals("checked"))  || (name.equals("compact"))  ||
  -                (name.equals("declare"))  || (name.equals("defer"))    ||
  -                (name.equals("disabled")) || (name.equals("ismap"))    ||
  -                (name.equals("multiple")) || (name.equals("nohref"))   ||
  -                (name.equals("noresize")) || (name.equals("noshade"))  ||
  -                (name.equals("nowrap"))   || (name.equals("readonly")) ||
  -                (name.equals("selected"))) {
  -                if(name.equals(value)) {
  -                    this.print(' ');
  -                    this.print(name);
  -                } else {
  -                    this.print(' ');
  -                    this.print(name);
  -                    this.print('=');
  -                    this.print('\"');
  -                    this.print(value);
  -                    this.print('\"');
  -                }
  -            } else {
  -                this.print(' ');
  -                this.print(name);
  -                this.print('=');
  -                this.print('\"');
  -                this.print(value);
  -                this.print('\"');
  -            }
  -
  -        }
  -        this.print('>');
  -    }
  -        
  -
  -    /**
  -     * Receive notification of the end of an element.
  -     *
  -     * @param uri The Namespace URI, or the empty string if the element has no
  -     *            Namespace URI or if Namespace
  -     *            processing is not being performed.
  -     * @param loc The local name (without prefix), or the empty string if
  -     *            Namespace processing is not being performed.
  -     * @param raw The raw XML 1.0 name (with prefix), or the empty string if
  -     *            raw names are not available.
  -     */
  -    public void endElement (String uri, String loc, String raw)
  -    throws SAXException {
  -        String name=this.ns.resolve(uri,raw,null,loc).getQName();
  -        if ((name.equalsIgnoreCase("AREA"))     || (name.equalsIgnoreCase("BASE"))     ||        
  -            (name.equalsIgnoreCase("BASEFONT")) || (name.equalsIgnoreCase("BR"))       ||          
  -            (name.equalsIgnoreCase("COL"))      || (name.equalsIgnoreCase("FRAME"))    ||       
  -            (name.equalsIgnoreCase("HR"))       || (name.equalsIgnoreCase("IMG"))      ||         
  -            (name.equalsIgnoreCase("INPUT"))    || (name.equalsIgnoreCase("ISINDEX"))  ||     
  -            (name.equalsIgnoreCase("LINK"))     || (name.equalsIgnoreCase("META"))     ||        
  -            (name.equalsIgnoreCase("PARA"))) return;
  -        this.print('<');
  -        this.print('/');
  -        this.print(name);
  -        this.print('>');
  -    }
  -
  -    /**
  -     * Receive notification of character data.
  -     *
  -     * @param ch The characters from the XML document.
  -     * @param start The start position in the array.
  -     * @param len The number of characters to read from the array.
  -     */
  -    public void characters (char ch[], int start, int len)
  -    throws SAXException {
  -        if(this.cdata) this.print(ch,start,len);
  -        else this.printSafe(ch,start,len);
  -    }
  -
  -    /**
  -     * Receive notification of ignorable whitespace in element content.
  -     *
  -     * @param ch The characters from the XML document.
  -     * @param start The start position in the array.
  -     * @param len The number of characters to read from the array.
  -     */
  -    public void ignorableWhitespace (char ch[], int start, int len)
  -    throws SAXException {
  -        if(this.cdata) this.print(ch,start,len);
  -        else this.printSafe(ch,start,len);
  -    }
  -
  -    /**
  -     * Receive notification of a processing instruction.
  -     *
  -     * @param target The processing instruction target.
  -     * @param data The processing instruction data, or null if none was
  -     *             supplied.
  -     */
  -    public void processingInstruction (String target, String data)
  -    throws SAXException {
  -        this.print("<?");
  -        this.print(target);
  -        this.print(' ');
  -        this.print(data);
  -        this.print("?>");
  -    }
  -
  -    /**
  -     * Receive notification of a skipped entity.
  -     *
  -     * @param name The name of the skipped entity.  If it is a  parameter
  -     *             entity, the name will begin with '%'.
  -     */
  -    public void skippedEntity (String name)
  -    throws SAXException {
  -        this.print('&');
  -        this.print(name);
  -        this.print(';');
  -    }
  -
  -    /**
  -     * Report the start of DTD declarations, if any.
  -     *
  -     * @param name The document type name.
  -     * @param publicId The declared public identifier for the external DTD
  -     *                 subset, or null if none was declared.
  -     * @param systemId The declared system identifier for the external DTD
  -     *                 subset, or null if none was declared.
  -     */
  -    public void startDTD (String name, String publicId, String systemId)
  -    throws SAXException {
  -        this.print("<!DOCTYPE ");
  -        this.print(name);
  -        if (publicId!=null) {
  -            this.print(" PUBLIC \"");
  -            this.print(publicId);
  -            this.print('\"');
  -            if (systemId!=null) {
  -                this.print(' ');
  -                this.print('\"');
  -                this.print(systemId);
  -                this.print('\"');
  -            }
  -        } else if (systemId!=null) {
  -            this.print(" SYSTEM \"");
  -            this.print(systemId);
  -            this.print('\"');
  -        }
  -        this.print('>');
  -        this.print('\n');
  -        // Set the DTD flag now, to avoid output
  -        this.dtd=true;
  -    }        
  -    
  -    /**
  -     * Report the end of DTD declarations.
  -     */
  -    public void endDTD ()
  -    throws SAXException {
  -        this.dtd=false;
  -    }
  -
  -    /**
  -     * Report the beginning of an entity.
  -     *
  -     * @param name The name of the entity. If it is a parameter entity, the
  -     *             name will begin with '%'.
  -     */
  -    public void startEntity (String name)
  -    throws SAXException {
  -    }        
  +import org.apache.cocoon.xml.XMLConsumer;
   
  -    /**
  -     * Report the end of an entity.
  -     *
  -     * @param name The name of the entity that is ending.
  -     */
  -    public void endEntity (String name)
  -    throws SAXException {
  -    }        
  +import org.apache.xml.serialize.SerializerFactory;
  +import org.apache.xml.serialize.Method;
  +import org.apache.xml.serialize.OutputFormat;
   
  -    /**
  -     * Report the start of a CDATA section.
  -     */
  -    public void startCDATA ()
  -    throws SAXException {
  -        this.print("<![CDATA[");
  -        this.cdata=true;
  -    }
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
   
  -    /**
  -     * Report the end of a CDATA section.
  -     */
  -    public void endCDATA ()
  -    throws SAXException {
  -        this.cdata=false;
  -        this.print("]]>");
  -    }
  -    
  +/**
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/21 17:36:26 $
  + */
   
  -    /**
  -     * Report an XML comment anywhere in the document.
  -     *
  -     * @param ch An array holding the characters in the comment.
  -     * @param start The starting position in the array.
  -     * @param len The number of characters to use from the array.
  -     */
  -    public void comment (char ch[], int start, int len)
  -    throws SAXException {
  -        this.print("<!--");
  -        this.print(ch,start,len);
  -        this.print("-->");
  -    }
  +public class HTMLSerializer extends AbstractSerializer implements XMLConsumer {
   
  -    /** Print a string */
  -    private void print(String s)
  -    throws SAXException {
  -        char data[]=s.toCharArray();
  -        this.print(data,0,data.length);
  -    }
  +    private SerializerFactory factory;
       
  -    /** Print data from a character array */
  -    private void print(char data[], int start, int len)
  -    throws SAXException {
  -        try {
  -            if(!this.dtd) this.out.write(data,start,len);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  -        }
  +    public HTMLSerializer() {
  +        this.factory = SerializerFactory.getSerializerFactory(Method.HTML);
       }
  -
  -    /** Print data from a character array */
  -    private void print(char c)
  -    throws SAXException {
  -        try {
  -            if(!this.dtd) this.out.write(c);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  -        }
  -    }
  -
  -    /** Print a string */
  -    private void printSafe(String s)
  -    throws SAXException {
  -        char data[]=s.toCharArray();
  -        this.printSafe(data,0,data.length);
  -    }
       
  -    /** Print data from a character array */
  -    private void printSafe(char data[], int start, int len)
  -    throws SAXException {
  -        int end=start+len;
  -        if(!this.dtd) for(int x=0; x<end; x++) this.printSafe(data[x]);
  -    }
  -
  -    /** Print data from a character array */
  -    private void printSafe(char c)
  -    throws SAXException {
  +    public void setOutputStream(OutputStream out) {
           try {
  -            if(this.dtd) return;
  -            if(c=='&') this.print("&amp;");
  -            else if(c=='<') this.print("&lt;");
  -            else if(c=='>') this.print("&gt;");
  -            else this.out.write(c);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  +            super.setOutputStream(out);
  +            this.setBridgedContentHandler(this.factory.makeSerializer(out, this.format).asContentHandler());
  +        } catch (Exception e) {
  +            throw new RuntimeException(e.toString());
           }
  -    }
  +    }    
   }
  
  
  
  1.1.2.6   +16 -109   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.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- SVGSerializer.java	2000/08/16 05:08:17	1.1.2.5
  +++ SVGSerializer.java	2000/08/21 17:36:26	1.1.2.6
  @@ -5,139 +5,46 @@
    * version 1.1,  a copy of wich has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  + 
   package org.apache.cocoon.serialization;
   
  -import org.apache.avalon.*;
  -import org.apache.avalon.utils.*;
  -import org.apache.cocoon.*;
  -import org.apache.cocoon.components.parser.Parser;
  -import org.apache.cocoon.xml.*;
  -import org.apache.cocoon.xml.util.*;
  -import com.sun.image.codec.jpeg.*;
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.io.PrintStream;
  -import java.io.*;
  -import java.net.URL;
  -import java.awt.*;
  -import java.awt.geom.AffineTransform;
  -import java.awt.image.*;
  -import java.util.*;
  -import javax.swing.*;
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.ext.*;
  -import org.w3c.dom.Attr;
  -import org.w3c.dom.CDATASection;
  -import org.w3c.dom.Comment;
  -import org.w3c.dom.Document;
  -import org.w3c.dom.DocumentFragment;
  -import org.w3c.dom.DocumentType;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.Entity;
  -import org.w3c.dom.EntityReference;
  -import org.w3c.dom.NamedNodeMap;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NodeList;
  -import org.w3c.dom.Notation;
  -import org.w3c.dom.ProcessingInstruction;
  -import org.w3c.dom.Text;
  -import org.csiro.svgv.display.*;
  -
   /**
  - * The ImagePrinter Printer writes images.
  - *
  - * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
  - * @author Copyright 1999 &copy; <a href="http://www.apache.org">The Apache
  - *         Software Foundation</a>. All rights reserved.
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/16 05:08:17 $
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/21 17:36:26 $
    */
  +
   public class SVGSerializer extends DOMBuilder implements Serializer, Composer {
      
  -    int R=0;
  -    int G=1;
  -    int B=2;
  -    int A=3;
  -
  -    /** The <code>ContentHandler</code> receiving SAX events. */
  -    private ContentHandler contentHandler=null;
  -    /** The <code>LexicalHandler</code> receiving SAX events. */
  -    private LexicalHandler lexicalHandler=null;
       /** The component manager instance */
  -    private ComponentManager manager=null;
  -    /** The current <code>OutputStream</code>. */
  -    private OutputStream output=null;
  -
  -    /**
  -     * Set the <code>OutputStream</code> where the XML should be serialized.
  -     */
  -    public void setOutputStream(OutputStream out) {
  -        this.output=new BufferedOutputStream(out);
  -        super.factory=(Parser)this.manager.getComponent("parser");
  -    }
  -
  -    /**
  -     * Set the <code>XMLConsumer</code> that will receive XML data.
  -     * <br>
  -     * This method will simply call <code>setContentHandler(consumer)</code>
  -     * and <code>setLexicalHandler(consumer)</code>.
  -     */
  -    public void setConsumer(XMLConsumer consumer) {
  -        this.contentHandler=consumer;
  -        this.lexicalHandler=consumer;
  -    }
  +    private ComponentManager manager = null;
   
  +    /** The current <code>OutputStream</code>. */
  +    private OutputStream output = null;
  +    
       /**
        * Set the current <code>ComponentManager</code> instance used by this
        * <code>Composer</code>.
        */
       public void setComponentManager(ComponentManager manager) {
  -        this.manager=manager;
  +        this.manager = manager;
       }
   
       /**
  -     * Set the <code>ContentHandler</code> that will receive XML data.
  -     * <br>
  -     * Subclasses may retrieve this <code>ContentHandler</code> instance
  -     * accessing the protected <code>super.contentHandler</code> field.
  -     */
  -    public void setContentHandler(ContentHandler content) {
  -        this.contentHandler=content;
  -    }
  -
  -    /**
  -     * Set the <code>LexicalHandler</code> that will receive XML data.
  -     * <br>
  -     * Subclasses may retrieve this <code>LexicalHandler</code> instance
  -     * accessing the protected <code>super.lexicalHandler</code> field.
  -     *
  -     * @exception IllegalStateException If the <code>LexicalHandler</code> or
  -     *                                  the <code>XMLConsumer</code> were
  -     *                                  already set.
  +     * Set the <code>OutputStream</code> where the XML should be serialized.
        */
  -    public void setLexicalHandler(LexicalHandler lexical) {
  -        this.lexicalHandler=lexical;
  +    public void setOutputStream(OutputStream out) {
  +        this.output = new BufferedOutputStream(out);
  +        super.factory = (Parser) this.manager.getComponent("parser");
       }
   
       /**
        * Receive notification of a successfully completed DOM tree generation.
        */
  -    public void notify(Document doc)
  -    throws SAXException {
  +    public void notify(Document doc) throws SAXException {
           try {
  -            //FIXME: There is no source anymore for serializers
  -            BufferedImage img=SvgToAwtConverter.convert(doc,null/*this.source*/);
  -            OutputStream out=this.output;
  -            // Write out image (highest quality for jpeg data)
  -            JPEGEncodeParam jpar=JPEGCodec.getDefaultJPEGEncodeParam(img);
  -            jpar.setQuality(1,true);
  -            JPEGImageEncoder jenc=JPEGCodec.createJPEGEncoder(out,jpar);
  -            jenc.encode(img);
  -            out.flush();
  -
  +            // (FIXME) (SM) we have to use an SVG rendere to create the image now.
           } catch(IOException e) {
  -            throw new SAXException("IOException writing image ",e);
  +            throw new SAXException("IOException writing image ", e);
           }
       }
   
  
  
  
  1.1.2.5   +19 -363   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.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- XMLSerializer.java	2000/08/04 21:12:03	1.1.2.4
  +++ XMLSerializer.java	2000/08/21 17:36:27	1.1.2.5
  @@ -5,383 +5,39 @@
    * version 1.1, a copy of which has been included  with this distribution in *
    * the LICENSE file.                                                         *
    *****************************************************************************/
  +
   package org.apache.cocoon.serialization;
   
  -import java.io.BufferedOutputStream;
  -import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.OutputStreamWriter;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
   
   import org.apache.cocoon.xml.XMLConsumer;
  -import org.apache.cocoon.xml.util.NamespacesTable;
  +
  +import org.apache.xml.serialize.SerializerFactory;
  +import org.apache.xml.serialize.Method;
  +import org.apache.xml.serialize.OutputFormat;
   
  -import org.xml.sax.Attributes;
  -import org.xml.sax.Locator;
  -import org.xml.sax.SAXException;
  +import org.apache.avalon.Configuration;
  +import org.apache.avalon.ConfigurationException;
   
   /**
  - *
  - * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
  - *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/08/04 21:12:03 $
  + * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  + * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/21 17:36:27 $
    */
  -public class XMLSerializer extends AbstractSerializer implements XMLConsumer {
  -    /** The namespaces table */
  -    private NamespacesTable ns=new NamespacesTable();
  -    /** The PrintStream used for output */
  -    private OutputStreamWriter out=null;
  -    /** The current locator */
  -    private Locator loc=null;
  -    /** A flag representing an open element (for "/>" or ">") */
  -    private boolean openElement=false;
  -    /** A flag telling wether we're processing the DTD */
  -    private boolean dtd=false;
  -    /** A flag telling wether we're processing a CDATA section */
  -    private boolean cdata=false;
  -    /** The table of the namespaces to declare */
  -    private Hashtable nstd=new Hashtable();
  -
  -    /**
  -     * Set the <code>OutputStream</code> where the XML should be serialized.
  -     */
  -    public void setOutputStream(OutputStream out) {
  -        super.setOutputStream(out);
  -        this.out=new OutputStreamWriter(super.output);;
  -    }
  -
  -    /**
  -     * Receive an object for locating the origin of SAX document events.
  -     *
  -     * @param locator An object that can return the location of any SAX
  -     *                document event.
  -     */
  -    public void setDocumentLocator(Locator locator) {
  -        this.loc=locator;
  -    }
  -
  -    /**
  -     * Receive notification of the beginning of a document.
  -     */
  -    public void startDocument()
  -    throws SAXException {
  -        this.print("<?xml version=\"1.0\"?>\n");
  -    }
  -
  -    /**
  -     * Receive notification of the end of a document.
  -     */
  -    public void endDocument()
  -    throws SAXException {
  -        this.closeElement();
  -        try {
  -            this.out.flush();
  -        } catch (IOException e) {
  -            throw new SAXException("IOException flushing stream",e);
  -        }
  -    }
  -
  -    /**
  -     * Begin the scope of a prefix-URI Namespace mapping.
  -     */
  -    public void startPrefixMapping(String prefix, String uri)
  -    throws SAXException {
  -        this.ns.addDeclaration(prefix,uri);
  -        this.nstd.put(prefix,uri);
  -    }
  -
  -    /**
  -     * End the scope of a prefix-URI mapping.
  -     */
  -    public void endPrefixMapping(String prefix)
  -    throws SAXException {
  -        this.ns.removeDeclaration(prefix);
  -    }
  -
  -    /**
  -     * Receive notification of the beginning of an element.
  -     */
  -    public void startElement(String uri, String loc, String raw, Attributes a)
  -    throws SAXException {
  -        this.closeElement();
  -        this.print('<');
  -
  -        this.print(this.ns.resolve(uri,raw,null,loc).getQName());
  -        for (int x=0; x<a.getLength(); x++) {
  -            this.print(' ');
  -            this.print(this.ns.resolve(a.getURI(x),a.getQName(x),null,
  -                                       a.getLocalName(x)).getQName());
  -            this.print('=');
  -            this.print('\"');
  -            this.printSafe(a.getValue(x));
  -            this.print('\"');
  -        }
  -
  -        Enumeration e=this.nstd.keys();
  -        while (e.hasMoreElements()) {
  -            this.print(' ');
  -            String nsname=(String)e.nextElement();
  -            String nsuri=(String)this.nstd.get(nsname);
  -            if (nsname.length()>0) {
  -                this.print("xmlns:");
  -                this.print(nsname);
  -            } else this.print("xmlns");
  -            this.print('=');
  -            this.print('\"');
  -            this.printSafe(nsuri);
  -            this.print('\"');
  -        }
  -        this.nstd.clear();
  -
  -        this.openElement=true;
  -    }
  -        
  -
  -    /**
  -     * Receive notification of the end of an element.
  -     *
  -     * @param uri The Namespace URI, or the empty string if the element has no
  -     *            Namespace URI or if Namespace
  -     *            processing is not being performed.
  -     * @param loc The local name (without prefix), or the empty string if
  -     *            Namespace processing is not being performed.
  -     * @param raw The raw XML 1.0 name (with prefix), or the empty string if
  -     *            raw names are not available.
  -     */
  -    public void endElement (String uri, String loc, String raw)
  -    throws SAXException {
  -        if (this.openElement) {
  -            this.print('/');
  -            this.closeElement();
  -            return;
  -        }
  -        this.print('<');
  -        this.print('/');
  -        this.print(this.ns.resolve(uri,raw,null,loc).getQName());
  -        this.print('>');
  -    }
  -
  -    /**
  -     * Receive notification of character data.
  -     *
  -     * @param ch The characters from the XML document.
  -     * @param start The start position in the array.
  -     * @param len The number of characters to read from the array.
  -     */
  -    public void characters (char ch[], int start, int len)
  -    throws SAXException {
  -        this.closeElement();
  -        if(this.cdata) this.print(ch,start,len);
  -        else this.printSafe(ch,start,len);
  -    }
  -
  -    /**
  -     * Receive notification of ignorable whitespace in element content.
  -     *
  -     * @param ch The characters from the XML document.
  -     * @param start The start position in the array.
  -     * @param len The number of characters to read from the array.
  -     */
  -    public void ignorableWhitespace (char ch[], int start, int len)
  -    throws SAXException {
  -        this.closeElement();
  -        if(this.cdata) this.print(ch,start,len);
  -        else this.printSafe(ch,start,len);
  -    }
   
  -    /**
  -     * Receive notification of a processing instruction.
  -     *
  -     * @param target The processing instruction target.
  -     * @param data The processing instruction data, or null if none was
  -     *             supplied.
  -     */
  -    public void processingInstruction (String target, String data)
  -    throws SAXException {
  -        this.closeElement();
  -        this.print("<?");
  -        this.print(target);
  -        this.print(' ');
  -        this.print(data);
  -        this.print("?>");
  -    }
  -
  -    /**
  -     * Receive notification of a skipped entity.
  -     *
  -     * @param name The name of the skipped entity.  If it is a  parameter
  -     *             entity, the name will begin with '%'.
  -     */
  -    public void skippedEntity (String name)
  -    throws SAXException {
  -        this.closeElement();
  -        this.print('&');
  -        this.print(name);
  -        this.print(';');
  -    }
  -
  -    /**
  -     * Report the start of DTD declarations, if any.
  -     *
  -     * @param name The document type name.
  -     * @param publicId The declared public identifier for the external DTD
  -     *                 subset, or null if none was declared.
  -     * @param systemId The declared system identifier for the external DTD
  -     *                 subset, or null if none was declared.
  -     */
  -    public void startDTD (String name, String publicId, String systemId)
  -    throws SAXException {
  -        this.print("<!DOCTYPE ");
  -        this.print(name);
  -        if (publicId!=null) {
  -            this.print(" PUBLIC \"");
  -            this.print(publicId);
  -            this.print('\"');
  -            if (systemId!=null) {
  -                this.print(' ');
  -                this.print('\"');
  -                this.print(systemId);
  -                this.print('\"');
  -            }
  -        } else if (systemId!=null) {
  -            this.print(" SYSTEM \"");
  -            this.print(systemId);
  -            this.print('\"');
  -        }
  -        this.print('>');
  -        this.print('\n');
  -        // Set the DTD flag now, to avoid output
  -        this.dtd=true;
  -    }        
  -    
  -    /**
  -     * Report the end of DTD declarations.
  -     */
  -    public void endDTD ()
  -    throws SAXException {
  -        this.dtd=false;
  -    }
  -
  -    /**
  -     * Report the beginning of an entity.
  -     *
  -     * @param name The name of the entity. If it is a parameter entity, the
  -     *             name will begin with '%'.
  -     */
  -    public void startEntity (String name)
  -    throws SAXException {
  -        this.closeElement();
  -    }        
  -
  -    /**
  -     * Report the end of an entity.
  -     *
  -     * @param name The name of the entity that is ending.
  -     */
  -    public void endEntity (String name)
  -    throws SAXException {
  -        this.closeElement();
  -    }        
  -
  -    /**
  -     * Report the start of a CDATA section.
  -     */
  -    public void startCDATA ()
  -    throws SAXException {
  -        this.closeElement();
  -        this.print("<![CDATA[");
  -        this.cdata=true;
  -    }
  -
  -    /**
  -     * Report the end of a CDATA section.
  -     */
  -    public void endCDATA ()
  -    throws SAXException {
  -        this.cdata=false;
  -        this.closeElement();
  -        this.print("]]>");
  -    }
  -    
  -
  -    /**
  -     * Report an XML comment anywhere in the document.
  -     *
  -     * @param ch An array holding the characters in the comment.
  -     * @param start The starting position in the array.
  -     * @param len The number of characters to use from the array.
  -     */
  -    public void comment (char ch[], int start, int len)
  -    throws SAXException {
  -        this.closeElement();
  -        this.print("<!--");
  -        this.print(ch,start,len);
  -        this.print("-->");
  -    }
  +public class XMLSerializer extends AbstractSerializer implements XMLConsumer {
   
  -    /** Print a string */
  -    private void print(String s)
  -    throws SAXException {
  -        if(s==null) return;
  -        char data[]=s.toCharArray();
  -        this.print(data,0,data.length);
  -    }
  +    private SerializerFactory factory;
       
  -    /** Print data from a character array */
  -    private void print(char data[], int start, int len)
  -    throws SAXException {
  -        try {
  -            if(!this.dtd) this.out.write(data,start,len);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  -        }
  -    }
  -
  -    /** Print data from a character array */
  -    private void print(char c)
  -    throws SAXException {
  -        try {
  -            if(!this.dtd) this.out.write(c);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  -        }
  +    public XMLSerializer() {
  +        this.factory = SerializerFactory.getSerializerFactory(Method.XML);
       }
  -
  -    /** Print a string */
  -    private void printSafe(String s)
  -    throws SAXException {
  -        if(s==null) return;
  -        char data[]=s.toCharArray();
  -        this.printSafe(data,0,data.length);
  -    }
       
  -    /** Print data from a character array */
  -    private void printSafe(char data[], int start, int len)
  -    throws SAXException {
  -        int end=start+len;
  -        if(!this.dtd) for(int x=start; x<end; x++) this.printSafe(data[x]);
  -    }
  -
  -    /** Print data from a character array */
  -    private void printSafe(char c)
  -    throws SAXException {
  +    public void setOutputStream(OutputStream out) {
           try {
  -            if(this.dtd) return;
  -            if(c=='&') this.print("&amp;");
  -            else if(c=='<') this.print("&lt;");
  -            else if(c=='>') this.print("&gt;");
  -            else this.out.write(c);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  +            super.setOutputStream(out);
  +            this.setBridgedContentHandler(this.factory.makeSerializer(out, this.format).asContentHandler());
  +        } catch (Exception e) {
  +            throw new RuntimeException(e.toString());
           }
  -    }
  -
  -    /** Close an element, if required */
  -    private void closeElement()
  -    throws SAXException {
  -        if(!this.openElement) return;
  -        this.print('>');
  -        this.openElement=false;
  -    }
  +    }    
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +43 -0     xml-cocoon/src/org/apache/cocoon/serialization/Attic/TextSerializer.java