sboag       00/10/02 16:41:45

  Modified:    java/src/org/apache/xml/serialize/transition
                        BaseMarkupSerializer.java HTMLSerializer.java
                        IndentPrinter.java Printer.java
  Log:
  Mainly changes for linefeed normalization.  Pretty ugly... I need to come 
back and revisit these, and probably put them at a higher level.
  
  Revision  Changes    Path
  1.2       +10 -1     
xml-xalan/java/src/org/apache/xml/serialize/transition/BaseMarkupSerializer.java
  
  Index: BaseMarkupSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/BaseMarkupSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseMarkupSerializer.java 2000/10/02 02:43:12     1.1
  +++ BaseMarkupSerializer.java 2000/10/02 23:41:44     1.2
  @@ -138,7 +138,7 @@
    * another element.
    *
    *
  - * @version $Revision: 1.1 $ $Date: 2000/10/02 02:43:12 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/02 23:41:44 $
    * @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
    * @see Serializer
    * @see DOMSerializer
  @@ -331,6 +331,10 @@
           reset();
       }
   
  +    public OutputStream getOutputStream()
  +    {
  +      return _output;
  +    }
   
       /**
        * Specifies a writer to which the document should be serialized.
  @@ -349,6 +353,11 @@
           _writer = writer;
           _output = null;
           reset();
  +    }
  +    
  +    public Writer getWriter()
  +    {
  +      return _writer;
       }
   
       /**
  
  
  
  1.2       +13 -8     
xml-xalan/java/src/org/apache/xml/serialize/transition/HTMLSerializer.java
  
  Index: HTMLSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/HTMLSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HTMLSerializer.java       2000/10/02 02:43:12     1.1
  +++ HTMLSerializer.java       2000/10/02 23:41:44     1.2
  @@ -117,7 +117,7 @@
    * </ul>
    *
    *
  - * @version $Revision: 1.1 $ $Date: 2000/10/02 02:43:12 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/02 23:41:44 $
    * @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
    * @see Serializer
    */
  @@ -173,7 +173,7 @@
       public HTMLSerializer( OutputFormat format )
       {
           super();
  -        if(null != format)
  +        if(null == format)
           {
             format = new OutputFormat();
             format.setMethod(Method.HTML);
  @@ -194,7 +194,7 @@
       public HTMLSerializer( Writer writer, OutputFormat format )
       {
           super();
  -        if(null != format)
  +        if(null == format)
           {
             format = new OutputFormat();
             format.setMethod(Method.HTML);
  @@ -214,7 +214,7 @@
       public HTMLSerializer( OutputStream output, OutputFormat format )
       {
           super();
  -        if(null != format)
  +        if(null == format)
           {
             format = new OutputFormat();
             format.setMethod(Method.HTML);
  @@ -225,7 +225,7 @@
       
       public void setOutputFormat( OutputFormat format )
       {
  -        if(null != format)
  +        if(null == format)
           {
             format = new OutputFormat();
             format.setMethod(Method.HTML);
  @@ -270,9 +270,11 @@
               // Indent this element on a new line if the first
               // content of the parent element or immediately
               // following an element.
  -            if ( _indenting && ! state.preserveSpace &&
  -                 ( state.empty || state.afterElement ) )
  +            if ( _indenting && !state.preserveSpace &&
  +                 (  state.empty ||  state.afterElement ) )
  +            {
                   _printer.breakLine();
  +            }
           }
           preserveSpace = state.preserveSpace;
   
  @@ -442,7 +444,7 @@
               // [keith] Provided this is not an anchor.
               // HTML: some elements do not print closing tag (e.g. LI)
               if ( htmlName == null || ! HTMLdtd.isOnlyOpening( htmlName ) ) {
  -                if ( _indenting && ! state.preserveSpace && 
state.afterElement )
  +                if ( _indenting && !state.preserveSpace && 
state.afterElement )
                       _printer.breakLine();
                   // Must leave CData section first (Illegal in HTML, but 
still)
                   if ( state.inCData )
  @@ -631,6 +633,8 @@
               // If the public and system identifiers were not specified
               // in the output format, use the appropriate ones for HTML
               // or XHTML.
  +          // -sb See http://www.w3.org/TR/xslt#section-HTML-Output-Method
  +            /*
               if ( _docTypePublicId == null && _docTypeSystemId == null ) {
                   if ( _xhtml ) {
                       _docTypePublicId = DTD.XHTMLPublicId;
  @@ -640,6 +644,7 @@
                       _docTypeSystemId = DTD.HTMLSystemId;
                   }
               }
  +          */
   
               // -sb
               // if ( ! _format.getOmitDocumentType() ) 
  
  
  
  1.2       +92 -14    
xml-xalan/java/src/org/apache/xml/serialize/transition/IndentPrinter.java
  
  Index: IndentPrinter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/IndentPrinter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IndentPrinter.java        2000/10/02 02:43:12     1.1
  +++ IndentPrinter.java        2000/10/02 23:41:44     1.2
  @@ -69,7 +69,7 @@
    * Extends [EMAIL PROTECTED] Printer} and adds support for indentation and 
line
    * wrapping.
    *
  - * @version $Revision: 1.1 $ $Date: 2000/10/02 02:43:12 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/02 23:41:44 $
    * @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
    */
   class IndentPrinter
  @@ -207,26 +207,104 @@
        */
       public void printText( String text )
       {
  -        _text.append( text );
  +      // _text.append( text );
  +      // Need linefeed normalization.  Yuck.  -sb
  +      int n = text.length();
  +      for(int i = 0; i < n; i++)
  +      {
  +        char c = text.charAt( i );
  +        if ((0x0D == c) && ((i+1) < n) && (0x0A==text.charAt( i+1 ))) 
  +        {
  +          breakLine();
  +          i++;
  +        }
  +        else if ((0x0A == c) && ((i+1) < n) && (0x0D==text.charAt( i+1 ))) 
  +        {
  +          breakLine();
  +          i++;
  +        }
  +        else if((0x0A == c) || ('\n' == c))
  +        {
  +          breakLine();
  +        }
  +        else
  +        {
  +          _text.append(c);
  +        }
  +      }
       }
       
       
       public void printText( StringBuffer text )
       {
  -        _text.append( text );
  +        // _text.append( text );
  +      // Need linefeed normalization.  Yuck.  -sb
  +      int n = text.length();
  +      for(int i = 0; i < n; i++)
  +      {
  +        char c = text.charAt( i );
  +        if ((0x0D == c) && ((i+1) < n) && (0x0A==text.charAt( i+1 ))) 
  +        {
  +          breakLine();
  +          i++;
  +        }
  +        else if ((0x0A == c) && ((i+1) < n) && (0x0D==text.charAt( i+1 ))) 
  +        {
  +          breakLine();
  +          i++;
  +        }
  +        else if((0x0A == c) || ('\n' == c))
  +        {
  +          breakLine();
  +        }
  +        else
  +        {
  +          _text.append(c);
  +        }
  +      }
       }
   
   
       public void printText( char ch )
  -    {
  +    {       
  +      if((0x0A == ch) || ('\n' == ch))
  +      {
  +        breakLine();
  +      }
  +      else
  +      {
           _text.append( ch );
  +      }
       }
   
   
       public void printText( char[] chars, int start, int length )
       {
  -        _text.append( chars, start, length );
  -    }
  +       //  _text.append( chars, start, length );
  +      while ( length-- > 0 ) {
  +        // -sb Normalize linebreaks.
  +        char c = chars[ start ];
  +        if ((0x0D == c) && (length>1) && (0x0A==chars[ start+1 ])) 
  +        {
  +          breakLine();
  +          ++start;
  +        }
  +        else if ((0x0A == c) && (length>1) && (0x0D==chars[ start+1 ])) 
  +        {
  +          breakLine();
  +          ++start;
  +        }
  +        else if((0x0A == c) || ('\n' == c))
  +        {
  +          breakLine();
  +        }
  +        else
  +        {
  +          _text.append(c);
  +        }
  +        ++start;
  +      }
  +   }
       
   
       /**
  @@ -303,7 +381,8 @@
       public void breakLine( boolean preserveSpace )
       {
           // Equivalent to calling printSpace and forcing a flushLine.
  -        if ( _text.length() > 0 ) {
  +        if ( _text.length() > 0 ) 
  +        {
               while ( _spaces > 0 ) {
                   _line.append( ' ' );
                   --_spaces;
  @@ -335,7 +414,8 @@
       {
           int     indent;
           
  -        if ( _line.length() > 0 ) {
  +        if ( _line.length() > 0 ) 
  +        {
               try {
                   
                   if ( _format.getIndent() && ! preserveSpace ) {
  @@ -393,9 +473,8 @@
        */
       public void indent()
       {
  -      // -sb TBD: Define way to set the indent amount
  -      _nextIndent += 2;
  -      // _nextIndent += _format.getIndent();
  +      _nextIndent += _format.getIndentAmount();
  +      // System.out.print("+"+_nextIndent);
       }
   
   
  @@ -404,15 +483,14 @@
        */
       public void unindent()
       {
  -      // -sb TBD: Define way to set the indent amount
  -      _nextIndent -= 2;
  -      // _nextIndent -= _format.getIndent();
  +      _nextIndent -= _format.getIndentAmount();
         if ( _nextIndent < 0 )
           _nextIndent = 0;
         // If there is no current line and we're de-identing then
         // this indentation level is actually the next level.
         if ( ( _line.length() + _spaces + _text.length() ) == 0 )
           _thisIndent = _nextIndent;
  +      // System.out.print("-"+_nextIndent);
       }
   
   
  
  
  
  1.2       +5 -5      
xml-xalan/java/src/org/apache/xml/serialize/transition/Printer.java
  
  Index: Printer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serialize/transition/Printer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Printer.java      2000/10/02 02:43:13     1.1
  +++ Printer.java      2000/10/02 23:41:45     1.2
  @@ -71,7 +71,7 @@
    * [EMAIL PROTECTED] IndentPrinter} supports indentation and line wrapping by
    * extending this class.
    *
  - * @version $Revision: 1.1 $ $Date: 2000/10/02 02:43:13 $
  + * @version $Revision: 1.2 $ $Date: 2000/10/02 23:41:45 $
    * @author <a href="mailto:[EMAIL PROTECTED]">Assaf Arkin</a>
    */
   public class Printer
  @@ -220,7 +220,7 @@
                     breakLine();
                     i++;
                   }
  -                else if('\n' == c)
  +                else if((0x0A == c) || ('\n' == c))
                   {
                     breakLine();
                   }
  @@ -260,7 +260,7 @@
                     breakLine();
                     i++;
                   }
  -                else if('\n' == c)
  +                else if((0x0A == c) || ('\n' == c))
                   {
                     breakLine();
                   }
  @@ -299,7 +299,7 @@
                     breakLine();
                     ++start;
                   }
  -                else if('\n' == c)
  +                else if((0x0A == c) || ('\n' == c))
                   {
                     breakLine();
                   }
  @@ -326,7 +326,7 @@
                   _writer.write( _buffer );
                   _pos = 0;
               }
  -            else if('\n' == ch)
  +            else if((0x0A == ch) || ('\n' == ch))
               {
                 breakLine();
               }
  
  
  

Reply via email to