cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/serializers HTMLSerializer.java AbstractSerializer.java XMLSerializer.java
Date Fri, 11 Feb 2000 15:02:03 GMT
pier        00/02/11 07:02:03

  Modified:    src/org/apache/cocoon/serializers Tag: xml-cocoon2-alpha0
                        AbstractSerializer.java XMLSerializer.java
  Added:       src/org/apache/cocoon/serializers Tag: xml-cocoon2-alpha0
                        HTMLSerializer.java
  Log:
  Added and modified some standard raw serialization classes.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.2   +4 -2      xml-cocoon/src/org/apache/cocoon/serializers/Attic/AbstractSerializer.java
  
  Index: AbstractSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/serializers/Attic/AbstractSerializer.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- AbstractSerializer.java	2000/02/11 13:15:30	1.1.2.1
  +++ AbstractSerializer.java	2000/02/11 15:02:03	1.1.2.2
  @@ -8,6 +8,7 @@
   package org.apache.cocoon.serializers;
   
   import org.apache.cocoon.Cocoon;
  +import org.apache.cocoon.framework.ConfigurationException;
   import org.apache.cocoon.framework.Configurations;
   
   /**
  @@ -16,7 +17,7 @@
    *         Exoffice Technologies, INC.</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.1 $ $Date: 2000/02/11 13:15:30 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/02/11 15:02:03 $
    * @since Cocoon 2.0
    */
   public abstract class AbstractSerializer implements Serializer {
  @@ -30,7 +31,8 @@
        * <br>
        * By default this method only store configurations.
        */
  -    public void configure(Configurations conf) {
  +    public void configure(Configurations conf)
  +    throws ConfigurationException {
           this.configurations=conf;
       }
       
  
  
  
  1.1.2.2   +104 -68   xml-cocoon/src/org/apache/cocoon/serializers/Attic/XMLSerializer.java
  
  Index: XMLSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/serializers/Attic/XMLSerializer.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- XMLSerializer.java	2000/02/11 13:15:30	1.1.2.1
  +++ XMLSerializer.java	2000/02/11 15:02:03	1.1.2.2
  @@ -25,7 +25,7 @@
    *         Exoffice Technologies, INC.</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.1 $ $Date: 2000/02/11 13:15:30 $
  + * @version CVS $Revision: 1.1.2.2 $ $Date: 2000/02/11 15:02:03 $
    * @since Cocoon 2.0
    */
   public class XMLSerializer extends AbstractSerializer implements XMLConsumer {
  @@ -39,6 +39,12 @@
       private Hashtable namespacesPrefixUri=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 declared encoding */
  +    private String enc=null;
   
       /**
        * Return a new instance of this <code>XMLSerializer</code>.
  @@ -46,10 +52,11 @@
       public XMLConsumer getXMLConsumer(Request req, Response res, OutputStream out)
       throws IOException {
           String c=this.configurations.getParameter("contentType","text/xml");
  -        String e=this.configurations.getParameter("encoding","us-ascii");
  +        this.enc=this.configurations.getParameter("encoding","UTF-8");
           res.setContentType(c);
           XMLSerializer s=new XMLSerializer();
  -        s.out=new OutputStreamWriter(new BufferedOutputStream(out),e);
  +        s.out=new OutputStreamWriter(new BufferedOutputStream(out),this.enc);
  +        s.enc=this.enc;
           s.namespacesUriPrefix=new Hashtable();
           s.namespacesPrefixUri=new Hashtable();
           return(s);
  @@ -65,69 +72,15 @@
           this.loc=locator;
       }
   
  -    /** Print a string */
  -    private void print(String s)
  -    throws SAXException {
  -        char data[]=s.toCharArray();
  -        this.print(data,0,data.length);
  -    }
  -    
  -    /** Print data from a character array */
  -    private void print(char data[], int start, int len)
  -    throws SAXException {
  -        try {
  -            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 {
  -            this.out.write(c);
  -        } catch (IOException e) {
  -            throw new SAXException("IOException printing data",e);
  -        }
  -    }
  -
  -    /** Return the fully namespace qualified name */
  -    private String qualify(String uri, String loc, String raw)
  -    throws SAXException {
  -        if(uri.length()>0) {
  -            String pre=(String)this.namespacesUriPrefix.get(uri);
  -            if (pre==null) throw new SAXException("No prefix declared for "+
  -                                                  "namespace uri '"+uri+"'");
  -            if (pre.length()>0) return(pre+":"+loc);
  -            else return(loc);
  -        } else if(raw.length()>0) {
  -            return(raw);
  -        } else if(loc.length()>0) {
  -            return(loc);
  -        }
  -        throw new SAXException("Cannot qualify namespaced name");
  -    }
  -
  -    private void closeElement()
  -    throws SAXException {
  -        if(!this.openElement) return;
  -        this.print('>');
  -        this.openElement=false;
  -    }
  -
  -
       /**
        * Receive notification of the beginning of a document.
        */
       public void startDocument()
       throws SAXException {
  -        this.closeElement();
  -        String encoding=this.out.getEncoding();
  -        if (encoding==null) this.print("<?xml version=\"1.0\"?>");
  +        if (this.enc==null) this.print("<?xml version=\"1.0\"?>");
           else {
               this.print("<?xml version=\"1.0\" encoding=\"");
  -            this.print(encoding);
  +            this.print(this.enc);
               this.print("\"?>");
           }
           this.print('\n');
  @@ -199,7 +152,7 @@
                                       a.getRawName(x)));
               this.print('=');
               this.print('\"');
  -            this.print(a.getValue(x));
  +            this.printSafe(a.getValue(x));
               this.print('\"');
           }
           this.openElement=true;
  @@ -227,11 +180,8 @@
           
           this.print('<');
           this.print('/');
  -        if (raw.length()>0) this.print(raw);
  -        else {
  -            // do all namespace stuff
  -        }
  -        this.print('>');
  +        this.print(this.qualify(uri,loc,raw));
  +        this.closeElement();
       }
   
       /**
  @@ -244,7 +194,8 @@
       public void characters (char ch[], int start, int len)
       throws SAXException {
           this.closeElement();
  -        this.print(ch,start,len);
  +        if(this.cdata) this.print(ch,start,len);
  +        else this.printSafe(ch,start,len);
       }
   
       /**
  @@ -257,7 +208,8 @@
       public void ignorableWhitespace (char ch[], int start, int len)
       throws SAXException {
           this.closeElement();
  -        this.print(ch,start,len);
  +        if(this.cdata) this.print(ch,start,len);
  +        else this.printSafe(ch,start,len);
       }
   
       /**
  @@ -322,6 +274,8 @@
           }
           this.print('>');
           this.print('\n');
  +        // Set the DTD flag now, to avoid output
  +        this.dtd=true;
       }        
       
       /**
  @@ -329,7 +283,7 @@
        */
       public void endDTD ()
       throws SAXException {
  -        this.closeElement();
  +        this.dtd=false;
       }
   
       /**
  @@ -360,6 +314,7 @@
       throws SAXException {
           this.closeElement();
           this.print("<![CDATA[");
  +        this.cdata=true;
       }
   
       /**
  @@ -367,6 +322,7 @@
        */
       public void endCDATA ()
       throws SAXException {
  +        this.cdata=false;
           this.closeElement();
           this.print("]]>");
       }
  @@ -385,5 +341,85 @@
           this.print("<!--");
           this.print(ch,start,len);
           this.print("-->");
  +    }
  +
  +    /** Print a string */
  +    private void print(String s)
  +    throws SAXException {
  +        char data[]=s.toCharArray();
  +        this.print(data,0,data.length);
  +    }
  +    
  +    /** 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);
  +        }
  +    }
  +
  +    /** 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 {
  +        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);
  +        }
  +    }
  +
  +    /** Return the fully namespace qualified name */
  +    private String qualify(String uri, String loc, String raw)
  +    throws SAXException {
  +        if(uri.length()>0) {
  +            String pre=(String)this.namespacesUriPrefix.get(uri);
  +            if (pre==null) throw new SAXException("No prefix declared for "+
  +                                                  "namespace uri '"+uri+"'");
  +            if (pre.length()>0) return(pre+":"+loc);
  +            else return(loc);
  +        } else if(raw.length()>0) {
  +            return(raw);
  +        } else if(loc.length()>0) {
  +            return(loc);
  +        }
  +        throw new SAXException("Cannot qualify namespaced name");
  +    }
  +
  +    /** 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   +402 -0    xml-cocoon/src/org/apache/cocoon/serializers/Attic/HTMLSerializer.java
  
  
  
  

Mime
View raw message