cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abag...@locus.apache.org
Subject cvs commit: xml-stylebook/src/org/apache/stylebook/printers HTMLPrinter.java
Date Fri, 09 Jun 2000 17:54:23 GMT
abagchi     00/06/09 10:54:22

  Modified:    src/org/apache/stylebook/printers HTMLPrinter.java
  Log:
  Now prints UNICODE characters
  
  Revision  Changes    Path
  1.4       +209 -194  xml-stylebook/src/org/apache/stylebook/printers/HTMLPrinter.java
  
  Index: HTMLPrinter.java
  ===================================================================
  RCS file: /home/cvs/xml-stylebook/src/org/apache/stylebook/printers/HTMLPrinter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HTMLPrinter.java	1999/11/29 02:03:22	1.3
  +++ HTMLPrinter.java	2000/06/09 17:54:22	1.4
  @@ -10,7 +10,8 @@
   import org.apache.stylebook.*;
   import java.io.IOException;
   import java.io.OutputStream;
  -import java.io.PrintStream;
  +import java.io.OutputStreamWriter;
  +import java.io.BufferedWriter;
   import org.w3c.dom.Attr;
   import org.w3c.dom.CDATASection;
   import org.w3c.dom.Comment;
  @@ -33,10 +34,13 @@
    * @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.3 $ $Date: 1999/11/29 02:03:22 $
  + * @version CVS $Revision: 1.4 $ $Date: 2000/06/09 17:54:22 $
    */
  -public class HTMLPrinter extends AbstractComponent implements Printer {
  +public class HTMLPrinter extends AbstractComponent implements Printer
  +{
   
  +    final static String ENCODING = "Unicode";
  +
       /**
        * Print a DOM Document.
        *
  @@ -47,253 +51,264 @@
        * @exception CreationException If the Document cannot be printed.
        */
       public void print(Document doc, CreationContext c, OutputStream out)
  -    throws CreationException, IOException {
  -        printDocument(doc,new PrintStream(out));
  -    }
  +    throws CreationException, IOException {       
  +        BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(out,ENCODING));
  +        printDocument(doc, writer);
  +        writer.flush();        
  +    }     
  +
   
       /** Process a nodelist calling the appropriate print...() method. */
  -    private void printNodeList(NodeList list, PrintStream out) {
  -        for (int x=0;x<list.getLength();x++) {
  +    private void printNodeList(NodeList list, BufferedWriter out) throws IOException {
  +        for ( int x=0;x<list.getLength();x++ )
  +        {
               Node node=list.item(x);
  -            switch (node.getNodeType()) {
  -                case Node.ATTRIBUTE_NODE:
  -                    printAttribute((Attr)node,out);
  -                    break;
  -                case Node.CDATA_SECTION_NODE:
  -                    printCDATASection((CDATASection)node,out);
  -                    break;
  -                case Node.COMMENT_NODE:
  -                    printComment((Comment)node,out);
  -                    break;
  -                case Node.DOCUMENT_FRAGMENT_NODE:
  -                    printDocumentFragment((DocumentFragment)node,out);
  -                    break;
  -                case Node.DOCUMENT_NODE:
  -                    printDocument((Document)node,out);
  -                    break;
  -                case Node.DOCUMENT_TYPE_NODE:
  -                    printDocumentType((DocumentType)node,out);
  -                    break;
  -                case Node.ELEMENT_NODE:
  -                    printElement((Element)node,out);
  -                    break;
  -                case Node.ENTITY_NODE:
  -                    printEntity((Entity)node,out);
  -                    break;
  -                case Node.ENTITY_REFERENCE_NODE:
  -                    printEntityReference((EntityReference)node,out);
  -                    break;
  -                case Node.NOTATION_NODE:
  -                    printNotation((Notation)node,out);
  -                    break;
  -                case Node.PROCESSING_INSTRUCTION_NODE:
  -                    printProcessingInstruction((ProcessingInstruction)node,out);
  -                    break;
  -                case Node.TEXT_NODE:
  -                    printText((Text)node,out);
  -                    break;
  +            switch ( node.getNodeType() )
  +            {
  +            case Node.ATTRIBUTE_NODE:
  +                printAttribute((Attr)node,out);
  +                break;
  +            case Node.CDATA_SECTION_NODE:
  +                printCDATASection((CDATASection)node,out);
  +                break;
  +            case Node.COMMENT_NODE:
  +                printComment((Comment)node,out);
  +                break;
  +            case Node.DOCUMENT_FRAGMENT_NODE:
  +                printDocumentFragment((DocumentFragment)node,out);
  +                break;
  +            case Node.DOCUMENT_NODE:
  +                printDocument((Document)node,out);
  +                break;
  +            case Node.DOCUMENT_TYPE_NODE:
  +                printDocumentType((DocumentType)node,out);
  +                break;
  +            case Node.ELEMENT_NODE:
  +                printElement((Element)node,out);
  +                break;
  +            case Node.ENTITY_NODE:
  +                printEntity((Entity)node,out);
  +                break;
  +            case Node.ENTITY_REFERENCE_NODE:
  +                printEntityReference((EntityReference)node,out);
  +                break;
  +            case Node.NOTATION_NODE:
  +                printNotation((Notation)node,out);
  +                break;
  +            case Node.PROCESSING_INSTRUCTION_NODE:
  +                printProcessingInstruction((ProcessingInstruction)node,out);
  +                break;
  +            case Node.TEXT_NODE:
  +                printText((Text)node,out);                   
  +                break;
               }
           }
       }
   
       /** Print an ATTRIBUTE (name="value") node. */
  -    private void printAttribute(Attr node, PrintStream out) {
  -        out.print(node.getName()+"=\""+node.getValue()+"\"");
  +    private void printAttribute(Attr node, BufferedWriter out) throws IOException {
  +        out.write(node.getName()+"=\""+node.getValue()+"\"");
       }
   
       /** Print a CDATA (<[CDATA[ ... ]]>) node. */
  -    private void printCDATASection(CDATASection node, PrintStream out) {
  +    private void printCDATASection(CDATASection node, BufferedWriter out) throws IOException
{
           printString(node.getData(),out);
       }
   
       /** Print a COMMENT (<!-- ... -->) node. */
  -    private void printComment(Comment node, PrintStream out) {
  -        out.print("<!--"+node.getData()+"-->");
  +    private void printComment(Comment node, BufferedWriter out) throws IOException {
  +        out.write("<!--"+node.getData()+"-->");
       }
   
       /** Print a DOCUMENT FRAGMENT (????) node. */
  -    private void printDocumentFragment(DocumentFragment node, PrintStream out) {
  -        out.print("<!-- Document Fragment Node -->");
  +    private void printDocumentFragment(DocumentFragment node, BufferedWriter out) throws
IOException {
  +        out.write("<!-- Document Fragment Node -->");
       }
   
       /** Print a DOCUMENT node. */
  -    private void printDocument(Document node, PrintStream out) {
  +    private void printDocument(Document node, BufferedWriter out) throws IOException {
           printNodeList(node.getChildNodes(),out);
       }
   
       /** Print a DOCUMENT TYPE (<!DOCTYPE ... bla bla bla>) node. */
  -    private void printDocumentType(DocumentType node, PrintStream out) {
  -        out.print("<!-- DOCTYPE "+node.getName()+" -->");
  +    private void printDocumentType(DocumentType node, BufferedWriter out) throws IOException
{
  +        out.write("<!-- DOCTYPE "+node.getName()+" -->");
       }
   
       /** Print a ELEMENT (do I need to supply the example ??? :) node. */
  -    private void printElement(Element node, PrintStream out) {
  +    private void printElement(Element node, BufferedWriter out) throws IOException {
           String tag=node.getTagName().toUpperCase();
  -        out.print("<"+tag);
  +        out.write("<"+tag);
           // Process attributes
           NamedNodeMap atts=node.getAttributes();
  -        if ((null!=atts) && (atts.getLength()>0)) {
  -            for (int x=0; x<atts.getLength(); x++) {
  -                out.print(' ');
  +        if ( (null!=atts) && (atts.getLength()>0) )
  +        {
  +            for ( int x=0; x<atts.getLength(); x++ )
  +            {
  +                out.write(' ');
                   printAttribute((Attr)atts.item(x),out);
               }
           }
  -        out.print(">");
  +        out.write(">");
           // Process child nodes
  -        if ((null!=node.getChildNodes()) && 
  -            (node.getChildNodes().getLength()>0)) {
  +        if ( (null!=node.getChildNodes()) && 
  +        (node.getChildNodes().getLength()>0) )
  +        {
               printNodeList(node.getChildNodes(),out);
           }
  -        
  +
           // Print the END tag...
  -        if(tag.equals("AREA")) return;
  -        else if(tag.equals("BASE")) return;
  -        else if(tag.equals("BASEFONT")) return;
  -        else if(tag.equals("BR")) return;
  -        else if(tag.equals("COL")) return;
  -        else if(tag.equals("FRAME")) return;
  -        else if(tag.equals("HR")) return;
  -        else if(tag.equals("IMG")) return;
  -        else if(tag.equals("INPUT")) return;
  -        else if(tag.equals("ISINDEX")) return;
  -        else if(tag.equals("LINK")) return;
  -        else if(tag.equals("META")) return;
  -        else if(tag.equals("PARAM")) return;
  -        out.print("</"+tag+">");
  +        if ( tag.equals("AREA") ) return;
  +        else if ( tag.equals("BASE") ) return;
  +        else if ( tag.equals("BASEFONT") ) return;
  +        else if ( tag.equals("BR") ) return;
  +        else if ( tag.equals("COL") ) return;
  +        else if ( tag.equals("FRAME") ) return;
  +        else if ( tag.equals("HR") ) return;
  +        else if ( tag.equals("IMG") ) return;
  +        else if ( tag.equals("INPUT") ) return;
  +        else if ( tag.equals("ISINDEX") ) return;
  +        else if ( tag.equals("LINK") ) return;
  +        else if ( tag.equals("META") ) return;
  +        else if ( tag.equals("PARAM") ) return;
  +        out.write("</"+tag+">");
       }
   
       /** Print a ENTITY node (NOTE: This should be used with DOCTYPE). */
  -    private void printEntity(Entity node, PrintStream out) {
  -        out.print("<!-- Entity Node -->");
  +    private void printEntity(Entity node, BufferedWriter out) throws IOException {
  +        out.write("<!-- Entity Node -->");
       }
   
       /** Print a ENTITY REFERENCE node (NOTE: Again, used in within DOCTYPE). */
  -    private void printEntityReference(EntityReference node, PrintStream out) {
  +    private void printEntityReference(EntityReference node, BufferedWriter out) throws
IOException {
           printString(node.getFirstChild().getNodeValue(),out);
       }
   
       /** Print a NOTATION node (NOTE: Again -3rd-, used in within DOCTYPE). */
  -    private void printNotation(Notation node, PrintStream out) {
  -        out.print("<!-- Notation Node -->");
  +    private void printNotation(Notation node, BufferedWriter out) throws IOException {
  +        out.write("<!-- Notation Node -->");
       }
   
       /** Print a PROCESSING INSTRUCTION (<?name ...?>) node. */
  -    private void printProcessingInstruction(ProcessingInstruction node, PrintStream out)
{
  -        out.print("<!-- PI:"+node.getTarget()+" "+node.getData()+"-->");
  +    private void printProcessingInstruction(ProcessingInstruction node, BufferedWriter
out) throws IOException {
  +        out.write("<!-- PI:"+node.getTarget()+" "+node.getData()+"-->");
       }
   
       /** Print a TEXT (see example for ELEMENT) node. */
  -    private void printText(Text node, PrintStream out) {
  +    private void printText(Text node, BufferedWriter out) throws IOException {
           printString(node.getData(),out);
       }
  -    
  -    private void printString(String data, PrintStream out) {
  -        for (int x=0; x<data.length(); x++) {
  -            char c=data.charAt(x);
  -            if (c=='\n') out.println();
  -            else if (c==34) out.print("&quot;");
  -            else if (c==38) out.print("&amp;");
  -            else if (c==60) out.print("&lt;");
  -            else if (c==62) out.print("&gt;");
  -            else if (c==8364) out.print("&euro;");
  -            else if ((c>=160) && (c<=255)) switch (c) {
  -                case 160: out.print("&nbsp;");   break;
  -                case 161: out.print("&iexcl;");  break;
  -                case 162: out.print("&cent;");   break;
  -                case 163: out.print("&pound;");  break;
  -                case 164: out.print("&curren;"); break;
  -                case 165: out.print("&yen;");    break;
  -                case 166: out.print("&brvbar;"); break;
  -                case 167: out.print("&sect;");   break;
  -                case 168: out.print("&uml;");    break;
  -                case 169: out.print("&copy;");   break;
  -                case 170: out.print("&ordf;");   break;
  -                case 171: out.print("&laquo;");  break;
  -                case 172: out.print("&not;");    break;
  -                case 173: out.print("&shy;");    break;
  -                case 174: out.print("&reg;");    break;
  -                case 175: out.print("&macr;");   break;
  -                case 176: out.print("&deg;");    break;
  -                case 177: out.print("&plusmn;"); break;
  -                case 178: out.print("&sup2;");   break;
  -                case 179: out.print("&sup3;");   break;
  -                case 180: out.print("&acute;");  break;
  -                case 181: out.print("&micro;");  break;
  -                case 182: out.print("&para;");   break;
  -                case 183: out.print("&middot;"); break;
  -                case 184: out.print("&cedil;");  break;
  -                case 185: out.print("&sup1;");   break;
  -                case 186: out.print("&ordm;");   break;
  -                case 187: out.print("&raquo;");  break;
  -                case 188: out.print("&frac14;"); break;
  -                case 189: out.print("&frac12;"); break;
  -                case 190: out.print("&frac34;"); break;
  -                case 191: out.print("&iquest;"); break;
  -                case 192: out.print("&Agrave;"); break;
  -                case 193: out.print("&Aacute;"); break;
  -                case 194: out.print("&Acirc;");  break;
  -                case 195: out.print("&Atilde;"); break;
  -                case 196: out.print("&Auml;");   break;
  -                case 197: out.print("&Aring;");  break;
  -                case 198: out.print("&AElig;");  break;
  -                case 199: out.print("&Ccedil;"); break;
  -                case 200: out.print("&Egrave;"); break;
  -                case 201: out.print("&Eacute;"); break;
  -                case 202: out.print("&Ecirc;");  break;
  -                case 203: out.print("&Euml;");   break;
  -                case 204: out.print("&Igrave;"); break;
  -                case 205: out.print("&Iacute;"); break;
  -                case 206: out.print("&Icirc;");  break;
  -                case 207: out.print("&Iuml;");   break;
  -                case 208: out.print("&ETH;");    break;
  -                case 209: out.print("&Ntilde;"); break;
  -                case 210: out.print("&Ograve;"); break;
  -                case 211: out.print("&Oacute;"); break;
  -                case 212: out.print("&Ocirc;");  break;
  -                case 213: out.print("&Otilde;"); break;
  -                case 214: out.print("&Ouml;");   break;
  -                case 215: out.print("&times;");  break;
  -                case 216: out.print("&Oslash;"); break;
  -                case 217: out.print("&Ugrave;"); break;
  -                case 218: out.print("&Uacute;"); break;
  -                case 219: out.print("&Ucirc;");  break;
  -                case 220: out.print("&Uuml;");   break;
  -                case 221: out.print("&Yacute;"); break;
  -                case 222: out.print("&THORN;");  break;
  -                case 223: out.print("&szlig;");  break;
  -                case 224: out.print("&agrave;"); break;
  -                case 225: out.print("&aacute;"); break;
  -                case 226: out.print("&acirc;");  break;
  -                case 227: out.print("&atilde;"); break;
  -                case 228: out.print("&auml;");   break;
  -                case 229: out.print("&aring;");  break;
  -                case 230: out.print("&aelig;");  break;
  -                case 231: out.print("&ccedil;"); break;
  -                case 232: out.print("&egrave;"); break;
  -                case 233: out.print("&eacute;"); break;
  -                case 234: out.print("&ecirc;");  break;
  -                case 235: out.print("&euml;");   break;
  -                case 236: out.print("&igrave;"); break;
  -                case 237: out.print("&iacute;"); break;
  -                case 238: out.print("&icirc;");  break;
  -                case 239: out.print("&iuml;");   break;
  -                case 240: out.print("&eth;");    break;
  -                case 241: out.print("&ntilde;"); break;
  -                case 242: out.print("&ograve;"); break;
  -                case 243: out.print("&oacute;"); break;
  -                case 244: out.print("&ocirc;");  break;
  -                case 245: out.print("&otilde;"); break;
  -                case 246: out.print("&ouml;");   break;
  -                case 247: out.print("&divide;"); break;
  -                case 248: out.print("&oslash;"); break;
  -                case 249: out.print("&ugrave;"); break;
  -                case 250: out.print("&uacute;"); break;
  -                case 251: out.print("&ucirc;");  break;
  -                case 252: out.print("&uuml;");   break;
  -                case 253: out.print("&yacute;"); break;
  -                case 254: out.print("&thorn;");  break;
  -                case 255: out.print("&yuml;");   break;
  -            } else out.print(c);
  +
  +    private void printString(String data, BufferedWriter out) throws IOException {
  +        for ( int x=0; x<data.length(); x++ )
  +        {
  +            char c=data.charAt(x);           
  +            if ( c=='\n' ) out.write("\n");
  +            else if ( c==34 ) out.write("&quot;");
  +            else if ( c==38 ) out.write("&amp;");
  +            else if ( c==60 ) out.write("&lt;");
  +            else if ( c==62 ) out.write("&gt;");
  +            else if ( c==8364 ) out.write("&euro;");
  +            else if ( (c>=160) && (c<=255) ) switch ( c )
  +                {
  +                case 160: out.write("&nbsp;");   break;
  +                case 161: out.write("&iexcl;");  break;
  +                case 162: out.write("&cent;");   break;
  +                case 163: out.write("&pound;");  break;
  +                case 164: out.write("&curren;"); break;
  +                case 165: out.write("&yen;");    break;
  +                case 166: out.write("&brvbar;"); break;
  +                case 167: out.write("&sect;");   break;
  +                case 168: out.write("&uml;");    break;
  +                case 169: out.write("&copy;");   break;
  +                case 170: out.write("&ordf;");   break;
  +                case 171: out.write("&laquo;");  break;
  +                case 172: out.write("&not;");    break;
  +                case 173: out.write("&shy;");    break;
  +                case 174: out.write("&reg;");    break;
  +                case 175: out.write("&macr;");   break;
  +                case 176: out.write("&deg;");    break;
  +                case 177: out.write("&plusmn;"); break;
  +                case 178: out.write("&sup2;");   break;
  +                case 179: out.write("&sup3;");   break;
  +                case 180: out.write("&acute;");  break;
  +                case 181: out.write("&micro;");  break;
  +                case 182: out.write("&para;");   break;
  +                case 183: out.write("&middot;"); break;
  +                case 184: out.write("&cedil;");  break;
  +                case 185: out.write("&sup1;");   break;
  +                case 186: out.write("&ordm;");   break;
  +                case 187: out.write("&raquo;");  break;
  +                case 188: out.write("&frac14;"); break;
  +                case 189: out.write("&frac12;"); break;
  +                case 190: out.write("&frac34;"); break;
  +                case 191: out.write("&iquest;"); break;
  +                case 192: out.write("&Agrave;"); break;
  +                case 193: out.write("&Aacute;"); break;
  +                case 194: out.write("&Acirc;");  break;
  +                case 195: out.write("&Atilde;"); break;
  +                case 196: out.write("&Auml;");   break;
  +                case 197: out.write("&Aring;");  break;
  +                case 198: out.write("&AElig;");  break;
  +                case 199: out.write("&Ccedil;"); break;
  +                case 200: out.write("&Egrave;"); break;
  +                case 201: out.write("&Eacute;"); break;
  +                case 202: out.write("&Ecirc;");  break;
  +                case 203: out.write("&Euml;");   break;
  +                case 204: out.write("&Igrave;"); break;
  +                case 205: out.write("&Iacute;"); break;
  +                case 206: out.write("&Icirc;");  break;
  +                case 207: out.write("&Iuml;");   break;
  +                case 208: out.write("&ETH;");    break;
  +                case 209: out.write("&Ntilde;"); break;
  +                case 210: out.write("&Ograve;"); break;
  +                case 211: out.write("&Oacute;"); break;
  +                case 212: out.write("&Ocirc;");  break;
  +                case 213: out.write("&Otilde;"); break;
  +                case 214: out.write("&Ouml;");   break;
  +                case 215: out.write("&times;");  break;
  +                case 216: out.write("&Oslash;"); break;
  +                case 217: out.write("&Ugrave;"); break;
  +                case 218: out.write("&Uacute;"); break;
  +                case 219: out.write("&Ucirc;");  break;
  +                case 220: out.write("&Uuml;");   break;
  +                case 221: out.write("&Yacute;"); break;
  +                case 222: out.write("&THORN;");  break;
  +                case 223: out.write("&szlig;");  break;
  +                case 224: out.write("&agrave;"); break;
  +                case 225: out.write("&aacute;"); break;
  +                case 226: out.write("&acirc;");  break;
  +                case 227: out.write("&atilde;"); break;
  +                case 228: out.write("&auml;");   break;
  +                case 229: out.write("&aring;");  break;
  +                case 230: out.write("&aelig;");  break;
  +                case 231: out.write("&ccedil;"); break;
  +                case 232: out.write("&egrave;"); break;
  +                case 233: out.write("&eacute;"); break;
  +                case 234: out.write("&ecirc;");  break;
  +                case 235: out.write("&euml;");   break;
  +                case 236: out.write("&igrave;"); break;
  +                case 237: out.write("&iacute;"); break;
  +                case 238: out.write("&icirc;");  break;
  +                case 239: out.write("&iuml;");   break;
  +                case 240: out.write("&eth;");    break;
  +                case 241: out.write("&ntilde;"); break;
  +                case 242: out.write("&ograve;"); break;
  +                case 243: out.write("&oacute;"); break;
  +                case 244: out.write("&ocirc;");  break;
  +                case 245: out.write("&otilde;"); break;
  +                case 246: out.write("&ouml;");   break;
  +                case 247: out.write("&divide;"); break;
  +                case 248: out.write("&oslash;"); break;
  +                case 249: out.write("&ugrave;"); break;
  +                case 250: out.write("&uacute;"); break;
  +                case 251: out.write("&ucirc;");  break;
  +                case 252: out.write("&uuml;");   break;
  +                case 253: out.write("&yacute;"); break;
  +                case 254: out.write("&thorn;");  break;
  +                case 255: out.write("&yuml;");   break;
  +                }
  +            else out.write(c);
           }
       }        
   }
  
  
  

Mime
View raw message