You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sb...@locus.apache.org on 2000/12/06 06:37:11 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/serialize/helpers HTMLOutputFormat.java TextOutputFormat.java XHTMLOutputFormat.java XMLOutputFormat.java package.html

sboag       00/12/05 21:37:11

  Modified:    java/src/org/apache/xalan/serialize ElemDesc.java
                        EncodingInfo.java Encodings.java
                        FormatterToHTML.java FormatterToText.java
                        FormatterToXML.java Method.java Serializer.java
                        SerializerFactory.java serializer.properties
  Added:       java/src/org/apache/xalan/serialize CharInfo.java
                        HTMLEntities.res XMLEntities.res
  Removed:     java/src/org/apache/xalan/serialize OutputFormat.java
               java/src/org/apache/xalan/serialize/helpers
                        HTMLOutputFormat.java TextOutputFormat.java
                        XHTMLOutputFormat.java XMLOutputFormat.java
                        package.html
  Log:
  Deleted OutputFormat and OutputFormatExtended in favor of new
  OutputProperties class.  Default properties are now resource based.
  Serializers should be pluggable, though this hasn't been tested.
  Entity references are now specified through resources, and a bitmap
  is built for fast test to determine special status of character.
  indent-amount and URI character escaping can now be controled
  via xalan attributes on xsl:output.
  
  Revision  Changes    Path
  1.2       +47 -56    xml-xalan/java/src/org/apache/xalan/serialize/ElemDesc.java
  
  Index: ElemDesc.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/ElemDesc.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ElemDesc.java	2000/10/30 18:56:50	1.1
  +++ ElemDesc.java	2000/12/06 05:37:08	1.2
  @@ -56,7 +56,7 @@
    */
   package org.apache.xalan.serialize;
   
  -import java.util.Hashtable;
  +import org.apache.xml.utils.StringToIntTable;
   
   /**
    * <meta name="usage" content="internal"/>
  @@ -66,89 +66,92 @@
   class ElemDesc
   {
   
  -  /** NEEDSDOC Field m_flags          */
  +  /** Bit flags to tell about this element type. */
     int m_flags;
   
  -  /** NEEDSDOC Field m_attrs          */
  -  Hashtable m_attrs = null;
  +  /**
  +   * Table of attribute names to integers, which contain bit flags telling about
  +   *  the attributes.
  +   */
  +  StringToIntTable m_attrs = null;
   
  -  /** NEEDSDOC Field EMPTY          */
  +  /** Bit position if this element type is empty. */
     static final int EMPTY = (1 << 1);
   
  -  /** NEEDSDOC Field FLOW          */
  +  /** Bit position if this element type is a flow. */
     static final int FLOW = (1 << 2);
   
  -  /** NEEDSDOC Field BLOCK          */
  +  /** Bit position if this element type is a block. */
     static final int BLOCK = (1 << 3);
   
  -  /** NEEDSDOC Field BLOCKFORM          */
  +  /** Bit position if this element type is a block form. */
     static final int BLOCKFORM = (1 << 4);
   
  -  /** NEEDSDOC Field BLOCKFORMFIELDSET          */
  +  /** Bit position if this element type is a block form field set (?? -sb). */
     static final int BLOCKFORMFIELDSET = (1 << 5);
   
  -  /** NEEDSDOC Field CDATA          */
  +  /** Bit position if this element type is CDATA. */
     static final int CDATA = (1 << 6);
   
  -  /** NEEDSDOC Field PCDATA          */
  +  /** Bit position if this element type is PCDATA. */
     static final int PCDATA = (1 << 7);
   
  -  /** NEEDSDOC Field RAW          */
  +  /** Bit position if this element type is should be raw characters. */
     static final int RAW = (1 << 8);
   
  -  /** NEEDSDOC Field INLINE          */
  +  /** Bit position if this element type should be inlined. */
     static final int INLINE = (1 << 9);
   
  -  /** NEEDSDOC Field INLINEA          */
  +  /** Bit position if this element type is INLINEA (?? -sb). */
     static final int INLINEA = (1 << 10);
   
  -  /** NEEDSDOC Field INLINELABEL          */
  +  /** Bit position if this element type is an inline label. */
     static final int INLINELABEL = (1 << 11);
   
  -  /** NEEDSDOC Field FONTSTYLE          */
  +  /** Bit position if this element type is a font style. */
     static final int FONTSTYLE = (1 << 12);
   
  -  /** NEEDSDOC Field PHRASE          */
  +  /** Bit position if this element type is a phrase. */
     static final int PHRASE = (1 << 13);
   
  -  /** NEEDSDOC Field FORMCTRL          */
  +  /** Bit position if this element type is a form control. */
     static final int FORMCTRL = (1 << 14);
   
  -  /** NEEDSDOC Field SPECIAL          */
  +  /** Bit position if this element type is ???. */
     static final int SPECIAL = (1 << 15);
   
  -  /** NEEDSDOC Field ASPECIAL          */
  +  /** Bit position if this element type is ???. */
     static final int ASPECIAL = (1 << 16);
   
  -  /** NEEDSDOC Field HEADMISC          */
  +  /** Bit position if this element type is an odd header element. */
     static final int HEADMISC = (1 << 17);
   
  -  /** NEEDSDOC Field HEAD          */
  +  /** Bit position if this element type is a head element (i.e. H1, H2, etc.) */
     static final int HEAD = (1 << 18);
   
  -  /** NEEDSDOC Field LIST          */
  +  /** Bit position if this element type is a list. */
     static final int LIST = (1 << 19);
   
  -  /** NEEDSDOC Field PREFORMATTED          */
  +  /** Bit position if this element type is a preformatted type. */
     static final int PREFORMATTED = (1 << 20);
   
  -  /** NEEDSDOC Field WHITESPACESENSITIVE          */
  +  /** Bit position if this element type is whitespace sensitive. */
     static final int WHITESPACESENSITIVE = (1 << 21);
   
  -  /** NEEDSDOC Field HEADELEM          */
  +  /** Bit position if this element type is a header element (i.e. HEAD). */
     static final int HEADELEM = (1 << 22);
   
  -  /** NEEDSDOC Field ATTRURL          */
  +  /** Bit position if this attribute type is a URL. */
     static final int ATTRURL = (1 << 1);
   
  -  /** NEEDSDOC Field ATTREMPTY          */
  +  /** Bit position if this attribute type is an empty type. */
     static final int ATTREMPTY = (1 << 2);
   
     /**
  -   * Constructor ElemDesc
  +   * Construct an ElemDesc from a set of bit flags.
      *
      *
  -   * NEEDSDOC @param flags
  +   * @param flags Bit flags that describe the basic properties of this element type.
      */
     ElemDesc(int flags)
     {
  @@ -156,12 +159,12 @@
     }
   
     /**
  -   * NEEDSDOC Method is 
  -   *
  +   * Tell if this element type has the basic bit properties that are passed
  +   * as an argument.
      *
  -   * NEEDSDOC @param flags
  +   * @param flags Bit flags that describe the basic properties of interest.
      *
  -   * NEEDSDOC (is) @return
  +   * @return true if any of the flag bits are true.
      */
     boolean is(int flags)
     {
  @@ -171,43 +174,31 @@
     }
   
     /**
  -   * NEEDSDOC Method setAttr 
  +   * Set an attribute name and it's bit properties.
      *
      *
  -   * NEEDSDOC @param name
  -   * NEEDSDOC @param flags
  +   * @param name non-null name of attribute, in upper case.
  +   * @param flags flag bits.
      */
     void setAttr(String name, int flags)
     {
   
       if (null == m_attrs)
  -      m_attrs = new Hashtable();
  +      m_attrs = new StringToIntTable();
   
  -    m_attrs.put(name, new Integer(flags));
  +    m_attrs.put(name, flags);
     }
   
     /**
  -   * NEEDSDOC Method isAttrFlagSet 
  +   * Tell if any of the bits of interest are set for a named attribute type.
      *
  +   * @param name non-null reference to attribute name, in any case.
  +   * @param flags flag mask.
      *
  -   * NEEDSDOC @param name
  -   * NEEDSDOC @param flags
  -   *
  -   * NEEDSDOC (isAttrFlagSet) @return
  +   * @return true if any of the flags are set for the named attribute.
      */
     boolean isAttrFlagSet(String name, int flags)
     {
  -
  -    if (null != m_attrs)
  -    {
  -      Integer _flags = (Integer) m_attrs.get(name);
  -
  -      if (null != _flags)
  -      {
  -        return (_flags.intValue() & flags) != 0;
  -      }
  -    }
  -
  -    return false;
  +    return (null != m_attrs) ? ((m_attrs.getIgnoreCase(name) & flags) != 0) : false;
     }
   }
  
  
  
  1.2       +5 -5      xml-xalan/java/src/org/apache/xalan/serialize/EncodingInfo.java
  
  Index: EncodingInfo.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/EncodingInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EncodingInfo.java	2000/10/30 18:56:50	1.1
  +++ EncodingInfo.java	2000/12/06 05:37:08	1.2
  @@ -78,12 +78,12 @@
     final int lastPrintable;
   
     /**
  -   * Constructor EncodingInfo
  +   * Create an EncodingInfo object based on the name, java name, and the 
  +   * max character size.
      *
  -   *
  -   * NEEDSDOC @param name
  -   * NEEDSDOC @param javaName
  -   * NEEDSDOC @param lastPrintable
  +   * @param name non-null reference to the ISO name.
  +   * @param javaName non-null reference to the Java encoding name.
  +   * @param lastPrintable The maximum character that can be written.
      */
     public EncodingInfo(String name, String javaName, int lastPrintable)
     {
  
  
  
  1.2       +11 -13    xml-xalan/java/src/org/apache/xalan/serialize/Encodings.java
  
  Index: Encodings.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/Encodings.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Encodings.java	2000/10/30 18:56:50	1.1
  +++ Encodings.java	2000/12/06 05:37:08	1.2
  @@ -67,19 +67,16 @@
    * to override encoding names and provide the last printable character
    * for each encoding.
    *
  - * @version $Revision: 1.1 $ $Date: 2000/10/30 18:56:50 $
  + * @version $Revision: 1.2 $ $Date: 2000/12/06 05:37:08 $
    * @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
    */
   public class Encodings extends Object
   {
   
  -  /** NEEDSDOC Field m_shouldNormalizeLinebreaks          */
  -  public static boolean m_shouldNormalizeLinebreaks = true;
  -
     /**
      * The last printable character for unknown encodings.
      */
  -  static final int DefaultLastPrintable = 0x7F;
  +  static final int m_defaultLastPrintable = 0x7F;
   
     /**
      * Returns a writer for the specified encoding based on
  @@ -131,21 +128,21 @@
           return _encodings[i].lastPrintable;
       }
   
  -    return DefaultLastPrintable;
  +    return m_defaultLastPrintable;
     }
   
     /**
      * Returns the last printable character for an unspecified
      * encoding.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return the default size
      */
     public static int getLastPrintable()
     {
  -    return DefaultLastPrintable;
  +    return m_defaultLastPrintable;
     }
   
  -  /** NEEDSDOC Field DEFAULT_MIME_ENCODING          */
  +  /** The default encoding, ISO style, ISO style.   */
     public static final String DEFAULT_MIME_ENCODING = "UTF-8";
   
     /**
  @@ -159,9 +156,10 @@
      * [XML]. If no encoding attribute is specified, then the XSLT processor should
      * use either UTF-8 or UTF-16."
      *
  -   * NEEDSDOC @param encoding
  +   * @param encoding Reference to java-style encoding string, which may be null, 
  +   * in which case a default will be found.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return The ISO-style encoding string, or null if failure.
      */
     public static String getMimeEncoding(String encoding)
     {
  @@ -215,9 +213,9 @@
     /**
      * Try the best we can to convert a Java encoding to a XML-style encoding.
      *
  -   * NEEDSDOC @param encoding
  +   * @param encoding non-null reference to encoding string, java style.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return ISO-style encoding string.
      */
     public static String convertJava2MimeEncoding(String encoding)
     {
  
  
  
  1.7       +146 -586  xml-xalan/java/src/org/apache/xalan/serialize/FormatterToHTML.java
  
  Index: FormatterToHTML.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/FormatterToHTML.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FormatterToHTML.java	2000/11/23 04:57:35	1.6
  +++ FormatterToHTML.java	2000/12/06 05:37:08	1.7
  @@ -63,6 +63,7 @@
   
   import java.util.Hashtable;
   import java.util.Vector;
  +import java.util.Properties;
   
   import org.xml.sax.*;
   
  @@ -70,11 +71,11 @@
   import org.apache.xml.utils.Trie;
   import org.apache.xalan.res.XSLMessages;
   import org.apache.xpath.res.XPATHErrorResources;
  -import org.apache.xalan.serialize.OutputFormat;
  -import org.apache.xalan.serialize.Method;
  -import org.apache.xalan.serialize.helpers.HTMLOutputFormat;
   import org.apache.xml.utils.StringToIntTable;
  +import org.apache.xalan.templates.OutputProperties;
   
  +import javax.xml.transform.OutputKeys;
  +import javax.xml.transform.Result;
   
   /**
    * <meta name="usage" content="general"/>
  @@ -83,73 +84,23 @@
    */
   public class FormatterToHTML extends FormatterToXML
   {
  -  // StringVector m_parents = new StringVector();
   
  -  /** NEEDSDOC Field m_isRawStack          */
  -  BoolStack m_isRawStack = new BoolStack();
  +  /** State stack to keep track of if the current element has output 
  +   *  escaping disabled. */
  +  private BoolStack m_isRawStack = new BoolStack();
   
  -  /** NEEDSDOC Field m_inBlockElem          */
  -  boolean m_inBlockElem = false;
  +  /** True if the current element is a block element.  (seems like 
  +   *  this needs to be a stack. -sb). */
  +  private boolean m_inBlockElem = false;
   
  -  /** NEEDSDOC Field s_HTMLlat1          */
  -  static String[] s_HTMLlat1 = { "nbsp", "iexcl", "cent", "pound", "curren",
  -                                 "yen", "brvbar", "sect", "uml", "copy",
  -                                 "ordf", "laquo", "not", "shy", "reg", "macr",
  -                                 "deg", "plusmn", "sup2", "sup3", "acute",
  -                                 "micro", "para", "middot", "cedil", "sup1",
  -                                 "ordm", "raquo", "frac14", "frac12",
  -                                 "frac34", "iquest", "Agrave", "Aacute",
  -                                 "Acirc", "Atilde", "Auml", "Aring", "AElig",
  -                                 "Ccedil", "Egrave", "Eacute", "Ecirc",
  -                                 "Euml", "Igrave", "Iacute", "Icirc", "Iuml",
  -                                 "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc",
  -                                 "Otilde", "Ouml", "times", "Oslash",
  -                                 "Ugrave", "Uacute", "Ucirc", "Uuml",
  -                                 "Yacute", "THORN", "szlig", "agrave",
  -                                 "aacute", "acirc", "atilde", "auml", "aring",
  -                                 "aelig", "ccedil", "egrave", "eacute",
  -                                 "ecirc", "euml", "igrave", "iacute", "icirc",
  -                                 "iuml", "eth", "ntilde", "ograve", "oacute",
  -                                 "ocirc", "otilde", "ouml", "divide",
  -                                 "oslash", "ugrave", "uacute", "ucirc",
  -                                 "uuml", "yacute", "thorn", "yuml" };
  -
  -  /** NEEDSDOC Field HTMLsymbol1          */
  -  static String[] HTMLsymbol1 = { "Alpha", "Beta", "Gamma", "Delta",
  -                                  "Epsilon", "Zeta", "Eta", "Theta", "Iota",
  -                                  "Kappa", "Lambda", "Mu", "Nu", "Xi",
  -                                  "Omicron", "Pi", "Rho", "", "Sigma", "Tau",
  -                                  "Upsilon", "Phi", "Chi", "Psi", "Omega" };
  -
  -  /** NEEDSDOC Field HTMLsymbol2          */
  -  static String[] HTMLsymbol2 = { "alpha", "beta", "gamma", "delta",
  -                                  "epsilon", "zeta", "eta", "theta", "iota",
  -                                  "kappa", "lambda", "mu", "nu", "xi",
  -                                  "omicron", "pi", "rho", "sigmaf", "sigma",
  -                                  "tau", "upsilon", "phi", "chi", "psi",
  -                                  "omega", "thetasym", "upsih", "piv" };
  -
  -  // "fnof",
  -  // static   String[]  HTMLsymbol2 =    {"bull",    "hellip",    
  -  //                                     "prime",    "Prime",    "oline",    "frasl",    
  -  //                                     "weierp",    "image",    "real",    "trade",    
  -  //                                     "alefsym",    "larr",    "uarr",    "rarr",    
  -  //                                     "darr",    "harr",    "crarr",    "lArr",    
  -  //                                     "uArr",    "rArr",    "dArr",    "hArr",    
  -  //                                     "forall",    "part",    "exist",    "empty",    
  -  //                                     "nabla",    "isin",    "notin",    "ni",    
  -  //                                     "prod",    "sum",    "minus",    "lowast",    
  -  //                                     "radic",    "prop",    "infin",    "ang",    
  -  //                                     "and",    "or",    "cap",    "cup",    "int",    
  -  //                                     "there4",    "sim",    "cong",    "asymp",    
  -  //                                     "ne",    "equiv",    "le",    "ge",    "sub",    
  -  //                                     "sup",    "nsub",    "sube",    "supe",    
  -  //                                     "oplus",    "otimes",    "perp",    "sdot",    
  -  //                                     "lceil",    "rceil",    "lfloor",    "rfloor",    
  -  //                                     "lang",    "rang",    "loz",    "spades",    
  -  //                                      "clubs",    "hearts",    "diams"};
  +  /**
  +   * Map that tells which XML characters should have special treatment, and it
  +   *  provides character to entity name lookup.
  +   */
  +  protected static CharInfo m_htmlcharInfo =
  +    new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
   
  -  /** NEEDSDOC Field m_elementFlags          */
  +  /** A digital search trie for fast, case insensitive lookup of ElemDesc objects. */
     static Trie m_elementFlags = new Trie();
   
     static
  @@ -315,7 +266,7 @@
                          new ElemDesc(0 | ElemDesc.BLOCK | ElemDesc.BLOCKFORM
                                       | ElemDesc.BLOCKFORMFIELDSET));
       m_elementFlags.put("HTML", new ElemDesc(0 | ElemDesc.BLOCK));
  -    
  +
       // From "John Ky" <hand@syd.speednet.com.au
       // Transitional Document Type Definition ()
       // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/sgml/loosedtd.html#basefont
  @@ -324,7 +275,7 @@
       // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/present/graphics.html#edef-STRIKE
       m_elementFlags.put("S", new ElemDesc(0 | ElemDesc.FONTSTYLE));
       m_elementFlags.put("STRIKE", new ElemDesc(0 | ElemDesc.FONTSTYLE));
  -    
  +
       // file:///C:/Documents%20and%20Settings/sboag.BOAG600E/My%20Documents/html/present/graphics.html#edef-U
       m_elementFlags.put("U", new ElemDesc(0 | ElemDesc.FONTSTYLE));
   
  @@ -427,13 +378,13 @@
      */
     static private ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);
   
  -  /** NEEDSDOC Field m_specialEscapeURLs          */
  +  /** True if URLs should be specially escaped with the %xx form. */
     private boolean m_specialEscapeURLs = true;
   
     /**
      * Tells if the formatter should use special URL escaping.
      *
  -   * NEEDSDOC @param bool
  +   * @param bool True if URLs should be specially escaped with the %xx form.
      */
     public void setSpecialEscapeURLs(boolean bool)
     {
  @@ -441,9 +392,28 @@
     }
   
     /**
  +   * Specifies an output format for this serializer. It the
  +   * serializer has already been associated with an output format,
  +   * it will switch to the new format. This method should not be
  +   * called while the serializer is in the process of serializing
  +   * a document.
  +   *
  +   * @param format The output format to use
  +   */
  +  public void setOutputFormat(Properties format)
  +  {
  +
  +    m_specialEscapeURLs =
  +      OutputProperties.getBooleanProperty(OutputProperties.S_USE_URL_ESCAPING,
  +                                          format);
  +
  +    super.setOutputFormat(format);
  +  }
  +
  +  /**
      * Tells if the formatter should use special URL escaping.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return True if URLs should be specially escaped with the %xx form.
      */
     public boolean getSpecialEscapeURLs()
     {
  @@ -453,9 +423,10 @@
     /**
      * Get a description of the given element.
      *
  -   * NEEDSDOC @param name
  +   * @param name non-null name of element, case insensitive.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return non-null reference to ElemDesc, which may be m_dummy if no 
  +   *         element description matches the given name.
      */
     ElemDesc getElemDesc(String name)
     {
  @@ -476,121 +447,14 @@
      */
     public FormatterToHTML()
     {
  -    super();
  -  }
  -
  -  /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  -   */
  -  public FormatterToHTML(Writer writer)
  -  {
  -    super(writer);
  -  }
  -
  -  /**
  -   * Constructor using an output stream, and a simple OutputFormat.
  -   * @param writer        The character output stream to use.
  -   *
  -   * NEEDSDOC @param os
  -   *
  -   * @throws java.io.UnsupportedEncodingException
  -   */
  -  public FormatterToHTML(java.io.OutputStream os)
  -          throws java.io.UnsupportedEncodingException
  -  {
  -
  -    OutputFormat of = new HTMLOutputFormat("UTF-8");
   
  -    this.init(os, of);
  -  }
  -
  -  /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  -   *
  -   * NEEDSDOC @param xmlListener
  -   */
  -  public FormatterToHTML(FormatterToXML xmlListener)
  -  {
  -
  -    super(xmlListener);
  -
  -    m_doIndent = true;  // TODO: But what if the user wants to set it???
  -  }
  -
  -  /**
  -   * Set the attribute characters what will require special mapping.
  -   */
  -  protected void initAttrCharsMap()
  -  {
  -
  -    super.initAttrCharsMap();
  -
  -    m_attrCharsMap[(int) '\n'] = 'S';
  -
  -    // XSLT Spec: The html output method should not 
  -    // escape < characters occurring in attribute values.
  -    m_attrCharsMap[(int) '<'] = '\0';
  -    m_attrCharsMap[(int) '>'] = '\0';
  -    m_attrCharsMap[0x0A] = 'S';
  -    m_attrCharsMap[0x0D] = 'S';
  -
  -    int n = (255 > SPECIALSSIZE) ? 255 : SPECIALSSIZE;
  -
  -    for (int i = 160; i < n; i++)
  -    {
  -      m_attrCharsMap[i] = 'S';
  -    }
  -  }
  -
  -  /**
  -   * Set the characters what will require special mapping.
  -   */
  -  protected void initCharsMap()
  -  {
  -
  -    initAttrCharsMap();
  -
  -    int n = (m_maxCharacter > SPECIALSSIZE) ? SPECIALSSIZE : m_maxCharacter;
  -
  -    for (int i = 0; i < n; i++)
  -    {
  -      m_charsMap[i] = '\0';
  -    }
  -
  -    m_charsMap[(int) '\n'] = 'S';
  -    m_charsMap[(int) '<'] = 'S';
  -    m_charsMap[(int) '>'] = 'S';
  -    m_charsMap[(int) '&'] = 'S';
  -
  -    for (int i = 0; i < 10; i++)
  -    {
  -      m_charsMap[i] = 'S';
  -    }
  -
  -    m_charsMap[0x0A] = 'S';
  -    m_charsMap[0x0D] = 'S';
  -    n = (255 > SPECIALSSIZE) ? 255 : SPECIALSSIZE;
  -
  -    for (int i = 160; i < n; i++)
  -    {
  -      m_charsMap[i] = 'S';
  -    }
  +    super();
   
  -    for (int i = m_maxCharacter; i < SPECIALSSIZE; i++)
  -    {
  -      m_charsMap[i] = 'S';
  -    }
  +    m_charInfo = m_htmlcharInfo;
     }
  -
  -  /** NEEDSDOC Field m_currentElementName          */
  -  String m_currentElementName = null;
   
  -  // protected boolean shouldIndent()
  -  // {
  -  //   return (!m_ispreserve && !m_isprevtext);
  -  // }
  +  /** The name of the current element. */
  +  private String m_currentElementName = null;
   
     /**
      * Receive notification of the beginning of a document.
  @@ -641,35 +505,40 @@
   
     /**
      *  Receive notification of the beginning of an element.
  -   * 
  +   *
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  +   *  @param namespaceURI
  +   *  @param localName
      *  @param name The element type name.
      *  @param atts The attributes attached to the element, if any.
  -   *  @exception org.xml.sax.SAXException Any SAX exception, possibly
  +   *  @throws org.xml.sax.SAXException Any SAX exception, possibly
      *             wrapping another exception.
      *  @see #endElement
      *  @see org.xml.sax.AttributeList
  -   *
  -   * @throws org.xml.sax.SAXException
      */
     public void startElement(
             String namespaceURI, String localName, String name, Attributes atts)
               throws org.xml.sax.SAXException
     {
   
  +    if (null != namespaceURI && namespaceURI.length() > 0)
  +    {
  +      super.startElement(namespaceURI, localName, name, atts);
  +
  +      return;
  +    }
  +
       boolean savedDoIndent = m_doIndent;
       boolean noLineBreak;
   
       writeParentTagEnd();
  -    pushState(namespaceURI, localName, m_format.getCDataElements(),
  -              m_cdataSectionStates);
  -    pushState(namespaceURI, localName, m_format.getNonEscapingElements(),
  -              m_disableOutputEscapingStates);
  -
  -    String nameUpper = name.toUpperCase();
  -    ElemDesc elemDesc = getElemDesc(nameUpper);
  +    pushState(
  +      namespaceURI, localName,
  +      m_cdataSectionNames, m_cdataSectionStates);
  +
  +    // pushState(namespaceURI, localName, m_format.getNonEscapingElements(),
  +    //          m_disableOutputEscapingStates);
  +    ElemDesc elemDesc = getElemDesc(name);
   
       // ElemDesc parentElemDesc = getElemDesc(m_currentElementName);
       boolean isBlockElement = elemDesc.is(ElemDesc.BLOCK);
  @@ -693,7 +562,7 @@
   
       m_isRawStack.push(elemDesc.is(ElemDesc.RAW));
   
  -    m_currentElementName = nameUpper;
  +    m_currentElementName = name;
   
       // m_parents.push(m_currentElementName);
       this.accum('<');
  @@ -709,7 +578,7 @@
       // Flag the current element as not yet having any children.
       openElementForChildren();
   
  -    m_currentIndent += this.indent;
  +    m_currentIndent += this.m_indentAmount;
       m_isprevtext = false;
       m_doIndent = savedDoIndent;
   
  @@ -733,31 +602,34 @@
   
     /**
      *  Receive notification of the end of an element.
  -   * 
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  +   *
  +   *  @param namespaceURI
  +   *  @param localName
      *  @param name The element type name
  -   *  @exception org.xml.sax.SAXException Any SAX exception, possibly
  +   *  @throws org.xml.sax.SAXException Any SAX exception, possibly
      *             wrapping another exception.
  -   *
  -   * @throws org.xml.sax.SAXException
      */
     public void endElement(String namespaceURI, String localName, String name)
             throws org.xml.sax.SAXException
     {
   
  -    m_currentIndent -= this.indent;
  +    if (null != namespaceURI && namespaceURI.length() > 0)
  +    {
  +      super.endElement(namespaceURI, localName, name);
   
  -    // name = name.toUpperCase();
  +      return;
  +    }
  +
  +    m_currentIndent -= this.m_indentAmount;
  +
       boolean hasChildNodes = childNodesWereAdded();
   
       // System.out.println(m_currentElementName);
       // m_parents.pop();
       m_isRawStack.pop();
   
  -    String nameUpper = name.toUpperCase();
  -    ElemDesc elemDesc = getElemDesc(nameUpper);
  +    ElemDesc elemDesc = getElemDesc(name);
   
       // ElemDesc parentElemDesc = getElemDesc(m_currentElementName);
       boolean isBlockElement = elemDesc.is(ElemDesc.BLOCK);
  @@ -819,28 +691,27 @@
   
       m_isprevtext = false;
   
  -    m_disableOutputEscapingStates.pop();
  +    // m_disableOutputEscapingStates.pop();
       m_cdataSectionStates.pop();
     }
   
     /**
      * Process an attribute.
      * @param   name   The name of the attribute.
  -   * NEEDSDOC @param elemDesc
  +   * @param elemDesc non-null reference to the owning element description.
      * @param   value   The value of the attribute.
      *
      * @throws org.xml.sax.SAXException
      */
     protected void processAttribute(
  -          String name, ElemDesc elemDesc, String value) throws org.xml.sax.SAXException
  +          String name, ElemDesc elemDesc, String value)
  +            throws org.xml.sax.SAXException
     {
   
  -    String nameUpper = name.toUpperCase();
  -
       this.accum(' ');
   
  -    if (elemDesc.isAttrFlagSet(nameUpper, ElemDesc.ATTREMPTY)
  -            && ((value.length() == 0) || value.equalsIgnoreCase(name)))
  +    if (((value.length() == 0) || value.equalsIgnoreCase(name))
  +            && elemDesc.isAttrFlagSet(name, ElemDesc.ATTREMPTY))
       {
         this.accum(name);
       }
  @@ -850,8 +721,7 @@
         this.accum('=');
         this.accum('\"');
   
  -      if (m_specialEscapeURLs
  -              && elemDesc.isAttrFlagSet(nameUpper, ElemDesc.ATTRURL))
  +      if (elemDesc.isAttrFlagSet(name, ElemDesc.ATTRURL))
           writeAttrURI(value, this.m_encoding);
         else
           writeAttrString(value, this.m_encoding);
  @@ -860,10 +730,10 @@
       }
     }
   
  -  /** NEEDSDOC Field MASK1          */
  +  /** Mask for high byte. */
     static final int MASK1 = 0xFF00;
   
  -  /** NEEDSDOC Field MASK2          */
  +  /** Mask for low byte. */
     static final int MASK2 = 0x00FF;
   
     /**
  @@ -877,7 +747,8 @@
      *
      * @throws org.xml.sax.SAXException
      */
  -  public void writeAttrURI(String string, String encoding) throws org.xml.sax.SAXException
  +  public void writeAttrURI(String string, String encoding)
  +          throws org.xml.sax.SAXException
     {
   
       char[] stringArray = string.toCharArray();
  @@ -891,17 +762,30 @@
         if ((ch < 9) || (ch > 127)
                 || /*(ch == '"') || -sb, as per #PDIK4L9LZY */ (ch == ' '))
         {
  -        int b1 = (int) ((((int) ch) & MASK1) >> 8);
  -        int b2 = (int) (((int) ch) & MASK2);
  -
  -        if (b1 != 0)
  +        if (m_specialEscapeURLs)
           {
  +          int b1 = (int) ((((int) ch) & MASK1) >> 8);
  +          int b2 = (int) (((int) ch) & MASK2);
  +
  +          if (b1 != 0)
  +          {
  +            accum("%");
  +            accum(Integer.toHexString(b1));
  +          }
  +
             accum("%");
  -          accum(Integer.toHexString(b1));
  +          accum(Integer.toHexString(b2));
           }
  -
  -        accum("%");
  -        accum(Integer.toHexString(b2));
  +        else if (ch < m_maxCharacter)
  +        {
  +          accum(ch);
  +        }
  +        else
  +        {
  +          accum("&#");
  +          accum(Integer.toString(ch));
  +          accum(';');
  +        }
         }
         else if (ch == '"')
         {
  @@ -944,10 +828,14 @@
         // System.out.println("ch: "+(int)ch);
         // System.out.println("m_maxCharacter: "+(int)m_maxCharacter);
         // System.out.println("m_attrCharsMap[ch]: "+(int)m_attrCharsMap[ch]);
  -      if ((ch < SPECIALSSIZE) && (m_attrCharsMap[ch] != 'S'))
  +      if ((ch < m_maxCharacter) && (!m_charInfo.isSpecial(ch)))
         {
           accum(ch);
         }
  +      else if ('<' == ch || '>' == ch)
  +      {
  +        accum(ch);  // no escaping in this case, as specified in 15.2
  +      }
         else if (('&' == ch) && ((i + 1) < strLen) && ('{' == chars[i + 1]))
         {
           accum(ch);  // no escaping in this case, as specified in 15.2
  @@ -1005,52 +893,23 @@
   
             // The next is kind of a hack to keep from escaping in the case 
             // of Shift_JIS and the like.
  +
             /*
             else if ((ch < m_maxCharacter) && (m_maxCharacter == 0xFFFF)
             && (ch != 160))
             {
             accum(ch);  // no escaping in this case
             }
  -          else 
  +          else
             */
  -          if ((ch >= 160) && (ch <= 255))
  -          {
  -            accum('&');
  -            accum(s_HTMLlat1[((int) ch) - 160]);
  -            accum(';');
  -          }
  -          else if ((ch >= 913) && (ch <= 937) && (ch != 930))
  -          {
  -            accum('&');
  -            accum(HTMLsymbol1[((int) ch) - 913]);
  -            accum(';');
  -          }
  -          else if ((ch >= 945) && (ch <= 969))
  -          {
  -            accum('&');
  -            accum(HTMLsymbol2[((int) ch) - 945]);
  -            accum(';');
  -          }
  -          else if ((ch >= 977) && (ch <= 978))
  -          {
  -            accum('&');
  +          String entityName = m_charInfo.getEntityNameForChar(ch);
   
  -            // substracting the number of unused characters
  -            accum(HTMLsymbol2[((int) ch) - 945 - 7]);
  -            accum(';');
  -          }
  -          else if ((ch == 982))
  +          if (null != entityName)
             {
               accum('&');
  -
  -            // substracting the number of unused characters
  -            accum(HTMLsymbol2[((int) ch) - 945 - 10]);
  +            accum(entityName);
               accum(';');
             }
  -          else if (402 == ch)
  -          {
  -            accum("&fnof;");
  -          }
             else if (ch < m_maxCharacter)
             {
               accum(ch);  // no escaping in this case
  @@ -1074,17 +933,17 @@
     }
   
     /**
  -   * NEEDSDOC Method copyEntityIntoBuf 
  +   * Copy an entity into the accumulation buffer.
      *
  +   * @param s The name of the entity.
  +   * @param pos unused.
      *
  -   * NEEDSDOC @param s
  -   * NEEDSDOC @param pos
  +   * @return The pos argument.
      *
  -   * NEEDSDOC (copyEntityIntoBuf) @return
  -   *
      * @throws org.xml.sax.SAXException
      */
  -  private int copyEntityIntoBuf(String s, int pos) throws org.xml.sax.SAXException
  +  private int copyEntityIntoBuf(String s, int pos)
  +          throws org.xml.sax.SAXException
     {
   
       int l = s.length();
  @@ -1132,25 +991,8 @@
             throws org.xml.sax.SAXException
     {
   
  -    if (0 == length)
  -      return;
  -
  -    if (m_inCData)
  +    if (m_isRawStack.peekOrFalse())
       {
  -      cdata(chars, start, length);
  -
  -      return;
  -    }
  -
  -    if (isEscapingDisabled())
  -    {
  -      charactersRaw(chars, start, length);
  -
  -      return;
  -    }
  -
  -    if (!m_isRawStack.isEmpty() && m_isRawStack.peek())
  -    {
         try
         {
           writeParentTagEnd();
  @@ -1174,316 +1016,29 @@
             XPATHErrorResources.ER_OIERROR, null), ioe);  //"IO error", ioe);
         }
       }
  -
  -    writeParentTagEnd();
  -
  -    m_ispreserve = true;
  -
  -    int pos = 0;
  -    int end = start + length;
  -    int startClean = start;
  -    int lengthClean = 0;
  -
  -    for (int i = start; i < end; i++)
  -    {
  -      char ch = chars[i];
  -
  -      if ((ch < SPECIALSSIZE) && (m_charsMap[ch] != 'S'))
  -      {
  -
  -        // accum(ch);
  -        lengthClean++;
  -
  -        continue;
  -      }
  -      else if ((0x0A == ch) && ((i + 1) < end) && (0x0D == chars[i + 1]))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 2;
  -
  -        outputLineSep();
  -
  -        i++;
  -      }
  -
  -      if ((0x0D == ch) && ((i + 1) < end) && (0x0A == chars[i + 1]))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 2;
  -
  -        outputLineSep();
  -
  -        i++;
  -      }
  -      else if (0x0D == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 2;
  -
  -        outputLineSep();
  -
  -        i++;
  -      }
  -      else if ('\n' == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -
  -        outputLineSep();
  -      }
  -      else if ('<' == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf("lt", pos);
  -      }
  -      else if ('>' == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf("gt", pos);
  -      }
  -      else if ('&' == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf("amp", pos);
  -      }
  -      else if ((ch >= 9) && (ch <= 126))
  -      {
  -        lengthClean++;
  -
  -        // accum(ch);
  -      }
  -      else if ((ch >= 160) && (ch <= 255))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf(s_HTMLlat1[((int) ch) - 160], pos);
  -      }
  -      else if ((ch >= 913) && (ch <= 937) && (ch != 930))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf(HTMLsymbol1[((int) ch) - 913], pos);
  -      }
  -      else if ((ch >= 945) && (ch <= 969))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf(HTMLsymbol2[((int) ch) - 945], pos);
  -      }
  -      else if ((ch >= 977) && (ch <= 978))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -
  -        // subtract the unused characters 
  -        pos = copyEntityIntoBuf(HTMLsymbol2[((int) ch) - 945 - 7], pos);
  -      }
  -      else if ((ch == 982))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -
  -        // subtract the unused characters
  -        pos = copyEntityIntoBuf(HTMLsymbol2[((int) ch) - 945 - 10], pos);
  -      }
  -      else if (402 == ch)
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -        pos = copyEntityIntoBuf("fnof", pos);
  -      }
  -      else if (m_isUTF8 && (0xd800 <= ch && ch < 0xdc00))
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        // UTF-16 surrogate
  -        int next;
  -
  -        if (i + 1 >= length)
  -        {
  -          throw new org.xml.sax.SAXException(
  -            XSLMessages.createXPATHMessage(
  -              XPATHErrorResources.ER_INVALID_UTF16_SURROGATE,
  -              new Object[]{ Integer.toHexString(ch) }));  //"Invalid UTF-16 surrogate detected: "
  -
  -          //+Integer.toHexString(ch)+ " ?");
  -        }
  -        else
  -        {
  -          next = chars[++i];
  -
  -          if (!(0xdc00 <= next && next < 0xe000))
  -            throw new org.xml.sax.SAXException(
  -              XSLMessages.createXPATHMessage(
  -                XPATHErrorResources.ER_INVALID_UTF16_SURROGATE,
  -                new Object[]{
  -                  Integer.toHexString(ch) + " "
  -                  + Integer.toHexString(next) }));  //"Invalid UTF-16 surrogate detected: "
  -
  -          //+Integer.toHexString(ch)+" "+Integer.toHexString(next));
  -          next = ((ch - 0xd800) << 10) + next - 0xdc00 + 0x00010000;
  -        }
  -
  -        accum('&');
  -        accum('#');
  -
  -        String intStr = Integer.toString(next);
  -        int nIntStr = intStr.length();
  -
  -        for (int k = 0; k < nIntStr; k++)
  -        {
  -          accum(intStr.charAt(k));
  -        }
  -
  -        accum(';');
  -
  -        startClean = i + 1;
  -      }
  -      else if ((ch >= '\u007F') && (ch <= m_maxCharacter))
  -      {
  -
  -        // Hope this is right...
  -        lengthClean++;
  -
  -        // accum(ch);
  -      }
  -      else
  -      {
  -        if (lengthClean > 0)
  -        {
  -          accum(chars, startClean, lengthClean);
  -
  -          lengthClean = 0;
  -        }
  -
  -        startClean = i + 1;
  -
  -        accum('&');
  -        accum('#');
  -
  -        String intStr = Integer.toString(ch);
  -        int nIntStr = intStr.length();
  -
  -        for (int k = 0; k < nIntStr; k++)
  -        {
  -          accum(intStr.charAt(k));
  -        }
  -
  -        accum(';');
  -      }
  -    }
  -
  -    if (lengthClean > 0)
  +    else
       {
  -      accum(chars, startClean, lengthClean);
  +      super.characters(chars, start, length);
       }
  -
  -    m_isprevtext = true;
     }
   
     /**
      *  Receive notification of cdata.
  -   * 
  +   *
      *  <p>The Parser will call this method to report each chunk of
      *  character data.  SAX parsers may return all contiguous character
      *  data in a single chunk, or they may split it into several
      *  chunks; however, all of the characters in any single event
      *  must come from the same external entity, so that the Locator
      *  provides useful information.</p>
  -   * 
  +   *
      *  <p>The application must not attempt to read from the array
      *  outside of the specified range.</p>
  -   * 
  +   *
      *  <p>Note that some parsers will report whitespace using the
      *  ignorableWhitespace() method rather than this one (validating
      *  parsers must do so).</p>
  -   * 
  +   *
      *  @param ch The characters from the XML document.
      *  @param start The start position in the array.
      *  @param length The number of characters to read from the array.
  @@ -1494,7 +1049,8 @@
      *
      * @throws org.xml.sax.SAXException
      */
  -  public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException
  +  public void cdata(char ch[], int start, int length)
  +          throws org.xml.sax.SAXException
     {
   
       if ((null != m_currentElementName)
  @@ -1548,7 +1104,7 @@
   
     /**
      *  Receive notification of a processing instruction.
  -   * 
  +   *
      *  @param target The processing instruction target.
      *  @param data The processing instruction data, or null if
      *         none was supplied.
  @@ -1563,9 +1119,13 @@
   
       // Use a fairly nasty hack to tell if the next node is supposed to be 
       // unescaped text.
  -    if (target.equals(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING))
  +    if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
  +    {
  +      startNonEscaping();
  +    }
  +    else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
       {
  -      m_disableOutputEscapingStates.setTop(true);
  +      endNonEscaping();
       }
       else
       {
  @@ -1588,7 +1148,7 @@
     /**
      * Receive notivication of a entityReference.
      *
  -   * NEEDSDOC @param name
  +   * @param name non-null reference to entity name string.
      *
      * @throws org.xml.sax.SAXException
      */
  
  
  
  1.3       +68 -65    xml-xalan/java/src/org/apache/xalan/serialize/FormatterToText.java
  
  Index: FormatterToText.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/FormatterToText.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FormatterToText.java	2000/11/13 16:27:02	1.2
  +++ FormatterToText.java	2000/12/06 05:37:09	1.3
  @@ -64,9 +64,10 @@
   
   import org.apache.xpath.res.XPATHErrorResources;
   import org.apache.xalan.res.XSLMessages;
  -import org.apache.xalan.serialize.OutputFormat;
  -import org.apache.xalan.serialize.helpers.TextOutputFormat;
  +import org.apache.xalan.templates.OutputProperties;
   
  +import javax.xml.transform.OutputKeys;
  +
   /**
    * <meta name="usage" content="general"/>
    * This class takes SAX events (in addition to some extra events
  @@ -83,48 +84,8 @@
     {
       super();
     }
  -
  -  /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  -   */
  -  public FormatterToText(Writer writer)
  -  {
  -    super(writer);
  -  }
  -
  -  /**
  -   * Constructor using an output stream, and a simple OutputFormat.
  -   * @param writer        The character output stream to use.
  -   *
  -   * NEEDSDOC @param os
  -   *
  -   * @throws java.io.UnsupportedEncodingException
  -   */
  -  public FormatterToText(java.io.OutputStream os)
  -          throws java.io.UnsupportedEncodingException
  -  {
  -
  -    OutputFormat of = new TextOutputFormat("UTF-8");
  -
  -    this.init(os, of);
  -  }
  -
  -  /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  -   *
  -   * NEEDSDOC @param xmlListener
  -   */
  -  public FormatterToText(FormatterToXML xmlListener)
  -  {
   
  -    super(xmlListener);
  -
  -    m_doIndent = true;  // TODO: But what if the user wants to set it???
  -  }
  -
  -  /**
  +   /**
      * Receive an object for locating the origin of SAX document events.
      *
      * <p>SAX parsers are strongly encouraged (though not absolutely
  @@ -209,9 +170,14 @@
      * defaulted): #IMPLIED attributes will be omitted.</p>
      *
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  -   * @param name The element type name.
  +   * @param namespaceURI The Namespace URI, or the empty string if the
  +   *        element has no Namespace URI or if Namespace
  +   *        processing is not being performed.
  +   * @param localName The local name (without prefix), or the
  +   *        empty string if Namespace processing is not being
  +   *        performed.
  +   * @param name The qualified name (with prefix), or the
  +   *        empty string if qualified names are not available.
      * @param atts The attributes attached to the element, if any.
      * @exception org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
  @@ -240,8 +206,14 @@
      * still be attached to the name.</p>
      *
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  +   * @param namespaceURI The Namespace URI, or the empty string if the
  +   *        element has no Namespace URI or if Namespace
  +   *        processing is not being performed.
  +   * @param localName The local name (without prefix), or the
  +   *        empty string if Namespace processing is not being
  +   *        performed.
  +   * @param name The qualified name (with prefix), or the
  +   *        empty string if qualified names are not available.
      * @param name The element type name
      * @exception org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
  @@ -275,17 +247,24 @@
      * @param ch The characters from the XML document.
      * @param start The start position in the array.
      * @param length The number of characters to read from the array.
  -   * @exception org.xml.sax.SAXException Any SAX exception, possibly
  +   * @throws org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
      * @see #ignorableWhitespace
      * @see org.xml.sax.Locator
  -   *
  -   * @throws org.xml.sax.SAXException
      */
  -  public void characters(char ch[], int start, int length) throws org.xml.sax.SAXException
  +  public void characters(char ch[], int start, int length)
  +          throws org.xml.sax.SAXException
     {
   
  -    this.accum(ch, start, length);
  +    // this.accum(ch, start, length);
  +    try
  +    {
  +      writeNormalizedChars(ch, start, length, false);
  +    }
  +    catch(IOException ioe)
  +    {
  +      throw new SAXException(ioe);
  +    }
       this.flush();
   
       // flushWriter();
  @@ -295,17 +274,26 @@
      * If available, when the disable-output-escaping attribute is used,
      * output raw text without escaping.
      *
  -   * NEEDSDOC @param ch
  -   * NEEDSDOC @param start
  -   * NEEDSDOC @param length
  +   * @param ch The characters from the XML document.
  +   * @param start The start position in the array.
  +   * @param length The number of characters to read from the array.
      *
  -   * @throws org.xml.sax.SAXException
  +   * @throws org.xml.sax.SAXException Any SAX exception, possibly
  +   *            wrapping another exception.
      */
     public void charactersRaw(char ch[], int start, int length)
             throws org.xml.sax.SAXException
     {
   
  -    accum(ch, start, length);
  +    // accum(ch, start, length);
  +    try
  +    {
  +      writeNormalizedChars(ch, start, length, false);
  +    }
  +    catch(IOException ioe)
  +    {
  +      throw new SAXException(ioe);
  +    }
       flush();
   
       // flushWriter();
  @@ -331,17 +319,24 @@
      * @param ch The characters from the XML document.
      * @param start The start position in the array.
      * @param length The number of characters to read from the array.
  -   * @exception org.xml.sax.SAXException Any SAX exception, possibly
  +   * @throws org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
      * @see #ignorableWhitespace
      * @see org.xml.sax.Locator
  -   *
  -   * @throws org.xml.sax.SAXException
      */
  -  public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException
  +  public void cdata(char ch[], int start, int length)
  +          throws org.xml.sax.SAXException
     {
   
  -    accum(ch, start, length);
  +    // accum(ch, start, length);
  +    try
  +    {
  +      writeNormalizedChars(ch, start, length, false);
  +    }
  +    catch(IOException ioe)
  +    {
  +      throw new SAXException(ioe);
  +    }
       flush();
   
       // flushWriter();
  @@ -377,7 +372,15 @@
             throws org.xml.sax.SAXException
     {
   
  -    // No action for the moment.
  +    try
  +    {
  +      writeNormalizedChars(ch, start, length, false);
  +    }
  +    catch(IOException ioe)
  +    {
  +      throw new SAXException(ioe);
  +    }
  +    flush();
     }
   
     /**
  @@ -423,7 +426,7 @@
     /**
      * Receive notivication of a entityReference.
      *
  -   * NEEDSDOC @param name
  +   * @param name non-null reference to the name of the entity.
      *
      * @throws org.xml.sax.SAXException
      */
  
  
  
  1.7       +232 -365  xml-xalan/java/src/org/apache/xalan/serialize/FormatterToXML.java
  
  Index: FormatterToXML.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/FormatterToXML.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FormatterToXML.java	2000/11/23 05:56:49	1.6
  +++ FormatterToXML.java	2000/12/06 05:37:09	1.7
  @@ -66,35 +66,34 @@
   import java.util.Stack;
   import java.util.Vector;
   import java.util.Hashtable;
  +import java.util.Properties;
   
   import org.xml.sax.*;
   import org.xml.sax.ext.LexicalHandler;
   
   import org.w3c.dom.Node;
   
  -import org.apache.xalan.serialize.OutputFormat;
  -import org.apache.xalan.serialize.helpers.XMLOutputFormat;
   import org.apache.xalan.serialize.Serializer;
  -import org.apache.xalan.serialize.OutputFormat;
   import org.apache.xalan.serialize.DOMSerializer;
   import org.apache.xml.utils.QName;
  -
  +import org.apache.xalan.templates.OutputProperties;
   import org.apache.xml.utils.BoolStack;
   import org.apache.xml.utils.TreeWalker;
   import org.apache.xml.utils.WrappedRuntimeException;
  -
   import org.apache.xalan.res.XSLTErrorResources;
   import org.apache.xalan.res.XSLMessages;
   import org.apache.xpath.res.XPATHErrorResources;
   
  +import javax.xml.transform.Result;
  +import javax.xml.transform.OutputKeys;
  +
   /**
    * <meta name="usage" content="general"/>
    * FormatterToXML formats SAX-style events into XML.
    * Warning: this class will be replaced by the Xerces Serializer classes.
    */
   public class FormatterToXML
  -        implements ContentHandler, LexicalHandler, 
  -                   Serializer, DOMSerializer
  +        implements ContentHandler, LexicalHandler, Serializer, DOMSerializer
   {
   
     /**
  @@ -102,13 +101,13 @@
      */
     protected Writer m_writer = null;
   
  -  /** NEEDSDOC Field m_shouldFlush          */
  +  /** True if we control the buffer, and we should flush the output on endDocument. */
     boolean m_shouldFlush = true;
   
  -  /** NEEDSDOC Field m_outputStream          */
  +  /** The output stream where the result stream is written. */
     protected OutputStream m_outputStream = System.out;
   
  -  /** NEEDSDOC Field m_bytesEqualChars          */
  +  /** True if no encoding has to take place, if we're not writting to a Writer. */
     private boolean m_bytesEqualChars = false;
   
     /**
  @@ -137,17 +136,22 @@
      */
     protected BoolStack m_elemStack = new BoolStack();
   
  -  /** NEEDSDOC Field m_disableOutputEscapingStates          */
  +  /** Stack to keep track of disabling output escaping. */
     protected BoolStack m_disableOutputEscapingStates = new BoolStack();
   
  -  /** NEEDSDOC Field m_cdataSectionStates          */
  +  /** True will be pushed, if characters should be in CDATA section blocks. */
     protected BoolStack m_cdataSectionStates = new BoolStack();
   
  +  /** List of QNames obtained from the xsl:output properties. */
  +  protected Vector m_cdataSectionNames = null;
  +
  +  /** True if the current characters should be in CDATA blocks. */
  +  protected boolean m_inCData = false;
  +
     /**
  -   * NEEDSDOC Method isEscapingDisabled 
  +   * Tell if the character escaping should be disabled for the current state.
      *
  -   *
  -   * NEEDSDOC (isEscapingDisabled) @return
  +   * @return true if the character escaping should be disabled.
      */
     protected boolean isEscapingDisabled()
     {
  @@ -155,14 +159,15 @@
     }
   
     /**
  -   * NEEDSDOC Method isCDataSection 
  -   *
  +   * Tell if the characters in the current state should be put in
  +   * cdata section blocks.
      *
  -   * NEEDSDOC (isCDataSection) @return
  +   * @return true if the characters in the current state should be put in
  +   * cdata section blocks.
      */
     protected boolean isCDataSection()
     {
  -    return m_cdataSectionStates.peekOrFalse();
  +    return m_inCData || m_cdataSectionStates.peekOrFalse();
     }
   
     /**
  @@ -221,7 +226,7 @@
     /**
      * Amount to indent.
      */
  -  public int indent = 0;
  +  public int m_indentAmount = 0;
   
     /**
      * Current level of indent.
  @@ -256,6 +261,11 @@
     boolean m_standalone = false;
   
     /**
  +   * True if standalone was specified.
  +   */
  +  boolean m_standaloneWasSpecified = false;
  +
  +  /**
      * The mediatype.  Not used right now.
      */
     String m_mediatype;
  @@ -266,86 +276,19 @@
     protected boolean m_inEntityRef = false;
   
     /**
  -   * These are characters that will be escaped in the output.
  +   * Map that tells which XML characters should have special treatment, and it
  +   *  provides character to entity name lookup.
      */
  +  protected static CharInfo m_xmlcharInfo =
  +    new CharInfo(CharInfo.XML_ENTITIES_RESOURCE);
   
  -  // public char[] m_attrSpecialChars = {'<', '>', '&', '\"', '\r', '\n'};
  -  public char[] m_attrSpecialChars = { '<', '>', '&', '\"' };
  -
  -  /** NEEDSDOC Field SPECIALSSIZE          */
  -  static final int SPECIALSSIZE = 256;
  -
  -  /** NEEDSDOC Field m_attrCharsMap          */
  -  public char[] m_attrCharsMap = new char[SPECIALSSIZE];
  -
  -  /** NEEDSDOC Field m_charsMap          */
  -  public char[] m_charsMap = new char[SPECIALSSIZE];
  -
     /**
  -   * Set the attribute characters what will require special mapping.
  +   * Map that tells which characters should have special treatment, and it
  +   *  provides character to entity name lookup.
      */
  -  protected void initAttrCharsMap()
  -  {
  -
  -    int n = (m_maxCharacter > SPECIALSSIZE) ? SPECIALSSIZE : m_maxCharacter;
  -
  -    for (int i = 0; i < n; i++)
  -    {
  -      m_attrCharsMap[i] = '\0';
  -    }
  +  protected static CharInfo m_charInfo;
   
  -    int nSpecials = m_attrSpecialChars.length;
  -
  -    for (int i = 0; i < nSpecials; i++)
  -    {
  -      m_attrCharsMap[(int) m_attrSpecialChars[i]] = 'S';
  -    }
  -
  -    m_attrCharsMap[0x0A] = 'S';
  -    m_attrCharsMap[0x0D] = 'S';
  -
  -    for (int i = m_maxCharacter; i < SPECIALSSIZE; i++)
  -    {
  -      m_attrCharsMap[i] = 'S';
  -    }
  -  }
  -
     /**
  -   * Set the characters what will require special mapping.
  -   */
  -  protected void initCharsMap()
  -  {
  -
  -    initAttrCharsMap();
  -
  -    int n = (m_maxCharacter > SPECIALSSIZE) ? SPECIALSSIZE : m_maxCharacter;
  -
  -    for (int i = 0; i < n; i++)
  -    {
  -      m_charsMap[i] = '\0';
  -    }
  -
  -    m_charsMap[(int) '\n'] = 'S';
  -    m_charsMap[(int) '<'] = 'S';
  -    m_charsMap[(int) '>'] = 'S';
  -    m_charsMap[(int) '&'] = 'S';
  -
  -    for (int i = 0; i < 20; i++)
  -    {
  -      m_charsMap[i] = 'S';
  -    }
  -
  -    m_charsMap[0x0A] = 'S';
  -    m_charsMap[0x0D] = 'S';
  -    m_charsMap[9] = '\0';
  -
  -    for (int i = m_maxCharacter; i < SPECIALSSIZE; i++)
  -    {
  -      m_charsMap[i] = 'S';
  -    }
  -  }
  -
  -  /**
      * Flag to quickly tell if the encoding is UTF8.
      */
     boolean m_isUTF8;
  @@ -361,51 +304,23 @@
      */
     public boolean m_spaceBeforeClose = false;
   
  -  /** NEEDSDOC Field DEFAULT_MIME_ENCODING          */
  -  static final String DEFAULT_MIME_ENCODING = "UTF-8";
  +  /** The xsl:output properties. */
  +  protected Properties m_format;
   
  -  /** NEEDSDOC Field m_format          */
  -  protected OutputFormat m_format;
  -
     /**
      * Default constructor.
  -   */
  -  public FormatterToXML(){}
  -
  -  /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  -   */
  -  public FormatterToXML(Writer writer)
  -  {
  -    m_shouldFlush = false;
  -    m_writer = writer;
  -  }
  -
  -  /**
  -   * Constructor using an output stream, and a simple OutputFormat.
  -   * @param writer        The character output stream to use.
  -   *
  -   * NEEDSDOC @param os
  -   *
  -   * @throws UnsupportedEncodingException
      */
  -  public FormatterToXML(java.io.OutputStream os)
  -          throws UnsupportedEncodingException
  +  public FormatterToXML()
     {
  -
  -    OutputFormat of = new XMLOutputFormat();
  -
  -    init(os, of);
  +    m_charInfo = m_xmlcharInfo;
     }
   
     /**
  -   * Constructor using a writer.
  -   * @param writer        The character output stream to use.
  +   * Copy properties from another FormatterToXML.
      *
  -   * NEEDSDOC @param xmlListener
  +   * @param xmlListener non-null reference to a FormatterToXML object.
      */
  -  public FormatterToXML(FormatterToXML xmlListener)
  +  public void CopyFrom(FormatterToXML xmlListener)
     {
   
       m_writer = xmlListener.m_writer;
  @@ -424,7 +339,7 @@
       m_isprevtext = xmlListener.m_isprevtext;
       m_doIndent = xmlListener.m_doIndent;
       m_currentIndent = xmlListener.m_currentIndent;
  -    indent = xmlListener.indent;
  +    m_indentAmount = xmlListener.m_indentAmount;
       level = xmlListener.level;
       m_startNewLine = xmlListener.m_startNewLine;
       m_needToOutputDocTypeDecl = xmlListener.m_needToOutputDocTypeDecl;
  @@ -432,9 +347,6 @@
       m_doctypePublic = xmlListener.m_doctypePublic;
       m_standalone = xmlListener.m_standalone;
       m_mediatype = xmlListener.m_mediatype;
  -    m_attrSpecialChars = xmlListener.m_attrSpecialChars;
  -    m_attrCharsMap = xmlListener.m_attrCharsMap;
  -    m_charsMap = xmlListener.m_charsMap;
       m_maxCharacter = xmlListener.m_maxCharacter;
       m_spaceBeforeClose = xmlListener.m_spaceBeforeClose;
       m_inCData = xmlListener.m_inCData;
  @@ -443,8 +355,6 @@
   
       // m_pos = xmlListener.m_pos;
       m_pos = 0;
  -
  -    initCharsMap();
     }
   
     /**
  @@ -454,7 +364,7 @@
      * @param writer The writer to use
      * @param format The output format
      */
  -  public synchronized void init(Writer writer, OutputFormat format)
  +  public synchronized void init(Writer writer, Properties format)
     {
       init(writer, format, false);
     }
  @@ -465,27 +375,32 @@
      *
      * @param writer The writer to use
      * @param format The output format
  -   * NEEDSDOC @param shouldFlush
  +   * @param shouldFlush True if the writer should be flushed at EndDocument.
      */
  -  private synchronized void init(Writer writer, OutputFormat format,
  +  private synchronized void init(Writer writer, Properties format,
                                    boolean shouldFlush)
     {
   
       m_shouldFlush = shouldFlush;
       m_writer = writer;
       m_format = format;
  -
  -    // This is to get around differences between Xalan and Xerces.
  -    // Xalan uses -1 as default for no indenting, Xerces uses 0.
  -    // So we just adjust the indent value here because we bumped it
  -    // up previously ( in StylesheetRoot);
  -    indent = format.getIndentAmount() - 1;
  -    m_doIndent = format.getIndent();
  -    m_shouldNotWriteXMLHeader = format.getOmitXMLDeclaration();
  -    m_doctypeSystem = format.getDoctypeSystemId();
  -    m_doctypePublic = format.getDoctypePublicId();
  -    m_standalone = format.getStandalone();
  -    m_mediatype = format.getMediaType();
  +    m_cdataSectionNames =
  +      OutputProperties.getQNameProperties(OutputKeys.CDATA_SECTION_ELEMENTS,
  +                                          format);
  +    m_indentAmount =
  +      OutputProperties.getIntProperty(OutputProperties.S_KEY_INDENT_AMOUNT,
  +                                      format);
  +    m_doIndent = OutputProperties.getBooleanProperty(OutputKeys.INDENT,
  +            format);
  +    m_shouldNotWriteXMLHeader =
  +      OutputProperties.getBooleanProperty(OutputKeys.OMIT_XML_DECLARATION,
  +                                          format);
  +    m_doctypeSystem = format.getProperty(OutputKeys.DOCTYPE_SYSTEM);
  +    m_doctypePublic = format.getProperty(OutputKeys.DOCTYPE_PUBLIC);
  +    m_standaloneWasSpecified = (null != format.get(OutputKeys.STANDALONE));
  +    m_standalone = OutputProperties.getBooleanProperty(OutputKeys.STANDALONE,
  +            format);
  +    m_mediatype = format.getProperty(OutputKeys.MEDIA_TYPE);
   
       if (null != m_doctypePublic)
       {
  @@ -495,12 +410,11 @@
   
       // initCharsMap();
       if (null == m_encoding)
  -      m_encoding = Encodings.getMimeEncoding(format.getEncoding());
  +      m_encoding =
  +        Encodings.getMimeEncoding(format.getProperty(OutputKeys.ENCODING));
   
  -    m_isUTF8 = m_encoding.equals(DEFAULT_MIME_ENCODING);
  +    m_isUTF8 = m_encoding.equals(Encodings.DEFAULT_MIME_ENCODING);
       m_maxCharacter = Encodings.getLastPrintable(m_encoding);
  -
  -    initCharsMap();
     }
   
     /**
  @@ -512,15 +426,20 @@
      * @throws UnsupportedEncodingException The encoding specified
      *   in the output format is not supported
      */
  -  public synchronized void init(OutputStream output, OutputFormat format)
  +  public synchronized void init(OutputStream output, Properties format)
             throws UnsupportedEncodingException
     {
  -    if(null == format)
  +
  +    if (null == format)
       {
  -      format = new org.apache.xalan.serialize.helpers.XMLOutputFormat();
  +      OutputProperties op = new OutputProperties(Method.XML);
  +
  +      format = op.getProperties();
       }
  -    m_encoding = Encodings.getMimeEncoding(format.getEncoding());
   
  +    m_encoding =
  +      Encodings.getMimeEncoding(format.getProperty(OutputKeys.ENCODING));
  +
       if (m_encoding.equals("WINDOWS-1250") || m_encoding.equals("US-ASCII")
               || m_encoding.equals("ASCII"))
       {
  @@ -569,7 +488,7 @@
     /**
      * Output the doc type declaration.
      *
  -   * NEEDSDOC @param name
  +   * @param name non-null reference to document type name.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -617,7 +536,16 @@
       {
         String encoding = Encodings.getMimeEncoding(m_encoding);
         String version = (null == m_version) ? "1.0" : m_version;
  -      String standalone = (m_standalone) ? " standalone=\"yes\"" : "";
  +      String standalone;
  +
  +      if (m_standaloneWasSpecified)
  +      {
  +        standalone = " standalone=\"" + (m_standalone ? "yes" : "no") + "\"";
  +      }
  +      else
  +      {
  +        standalone = "";
  +      }
   
         accum("<?xml version=\"" + version + "\" encoding=\"" + encoding + "\""
               + standalone + "?>");
  @@ -681,35 +609,35 @@
     }
   
     /**
  -   * NEEDSDOC Method startPrefixMapping 
  +   * Begin the scope of a prefix-URI Namespace mapping.
  +   * @see {@line org.xml.sax.ContentHandler#startPrefixMapping}.
      *
  -   *
  -   * NEEDSDOC @param prefix
  -   * NEEDSDOC @param uri
  -   *
  -   * @throws org.xml.sax.SAXException
  +   * @param prefix The Namespace prefix being declared.
  +   * @param uri The Namespace URI the prefix is mapped to.
  +   * @exception org.xml.sax.SAXException The client may throw
  +   *            an exception during processing.
      */
     public void startPrefixMapping(String prefix, String uri)
             throws org.xml.sax.SAXException{}
   
     /**
  -   * NEEDSDOC Method endPrefixMapping 
  -   *
  -   *
  -   * NEEDSDOC @param prefix
  +   * End the scope of a prefix-URI Namespace mapping.
  +   * @see {@line org.xml.sax.ContentHandler#endPrefixMapping}.
      *
  -   * @throws org.xml.sax.SAXException
  +   * @param prefix The prefix that was being mapping.
  +   * @exception org.xml.sax.SAXException The client may throw
  +   *            an exception during processing.
      */
  -  public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException{}
  +  public void endPrefixMapping(String prefix)
  +          throws org.xml.sax.SAXException{}
   
     /**
  -   * NEEDSDOC Method subPartMatch 
  -   *
  +   * Tell if two strings are equal, without worry if the first string is null.
      *
  -   * NEEDSDOC @param p
  -   * NEEDSDOC @param t
  +   * @param p String reference, which may be null.
  +   * @param t String reference, which may be null.
      *
  -   * NEEDSDOC (subPartMatch) @return
  +   * @return true if strings are equal.
      */
     protected static final boolean subPartMatch(String p, String t)
     {
  @@ -721,13 +649,15 @@
      * is found in the list of qnames.  A state is always pushed,
      * one way or the other.
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  -   * NEEDSDOC @param qnames
  -   * NEEDSDOC @param state
  +   * @param namespaceURI Should be a non-null reference to the namespace URL
  +   *        of the element that owns the state, or empty string.
  +   * @param localName Should be a non-null reference to the local name
  +   *        of the element that owns the state.
  +   * @param qnames Vector of qualified names of elements, or null.
  +   * @param state The stack where the state should be pushed.
      */
     protected void pushState(String namespaceURI, String localName,
  -                           QName[] qnames, BoolStack state)
  +                           Vector qnames, BoolStack state)
     {
   
       boolean b;
  @@ -739,17 +669,16 @@
         if ((null != namespaceURI) && namespaceURI.length() == 0)
           namespaceURI = null;
   
  -      int nElems = qnames.length;
  +      int nElems = qnames.size();
   
         for (int i = 0; i < nElems; i++)
         {
  -        QName q = qnames[i];
  +        QName q = (QName) qnames.elementAt(i);
   
           if (q.getLocalName().equals(localName)
                   && subPartMatch(namespaceURI, q.getNamespaceURI()))
           {
             b = true;
  -          ;
   
             break;
           }
  @@ -767,13 +696,18 @@
      * Receive notification of the beginning of an element.
      *
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  +   * @param namespaceURI The Namespace URI, or the empty string if the
  +   *        element has no Namespace URI or if Namespace
  +   *        processing is not being performed.
  +   * @param localName The local name (without prefix), or the
  +   *        empty string if Namespace processing is not being
  +   *        performed.
      * @param name The element type name.
      * @param atts The attributes attached to the element, if any.
      * @exception org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
  -   * @see #endElement
  +   * @see org.xml.sax.ContentHandler#startElement
  +   * @see org.xml.sax.ContentHandler#endElement
      * @see org.xml.sax.AttributeList
      *
      * @throws org.xml.sax.SAXException
  @@ -794,11 +728,11 @@
       m_needToOutputDocTypeDecl = false;
   
       writeParentTagEnd();
  -    pushState(namespaceURI, localName, m_format.getCDataElements(),
  +    pushState(namespaceURI, localName, m_cdataSectionNames,
                 m_cdataSectionStates);
  -    pushState(namespaceURI, localName, m_format.getNonEscapingElements(),
  -              m_disableOutputEscapingStates);
   
  +    // pushState(namespaceURI, localName, m_format.getNonEscapingElements(),
  +    //          m_disableOutputEscapingStates);
       m_ispreserve = false;
   
       //  System.out.println(name+": m_doIndent = "+m_doIndent+", m_ispreserve = "+m_ispreserve+", m_isprevtext = "+m_isprevtext);
  @@ -822,7 +756,7 @@
       // Flag the current element as not yet having any children.
       openElementForChildren();
   
  -    m_currentIndent += indent;
  +    m_currentIndent += m_indentAmount;
       m_isprevtext = false;
     }
   
  @@ -867,7 +801,7 @@
      * Tell if child nodes have been added to the current
      * element.  Must be called in balance with openElementForChildren().
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return true if child nodes were added.
      */
     protected boolean childNodesWereAdded()
     {
  @@ -878,8 +812,12 @@
      * Receive notification of the end of an element.
      *
      *
  -   * NEEDSDOC @param namespaceURI
  -   * NEEDSDOC @param localName
  +   * @param namespaceURI The Namespace URI, or the empty string if the
  +   *        element has no Namespace URI or if Namespace
  +   *        processing is not being performed.
  +   * @param localName The local name (without prefix), or the
  +   *        empty string if Namespace processing is not being
  +   *        performed.
      * @param name The element type name
      * @exception org.xml.sax.SAXException Any SAX exception, possibly
      *            wrapping another exception.
  @@ -893,7 +831,7 @@
       if (m_inEntityRef)
         return;
   
  -    m_currentIndent -= indent;
  +    m_currentIndent -= m_indentAmount;
   
       boolean hasChildNodes = childNodesWereAdded();
   
  @@ -922,7 +860,7 @@
   
       m_isprevtext = false;
   
  -    m_disableOutputEscapingStates.pop();
  +    // m_disableOutputEscapingStates.pop();
       m_cdataSectionStates.pop();
     }
   
  @@ -1025,11 +963,11 @@
       if (m_inEntityRef)
         return;
   
  -    if (target.equals(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING))
  +    if (target.equals(Result.PI_DISABLE_OUTPUT_ESCAPING))
       {
         startNonEscaping();
       }
  -    else if (target.equals(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING))
  +    else if (target.equals(Result.PI_ENABLE_OUTPUT_ESCAPING))
       {
         endNonEscaping();
       }
  @@ -1067,7 +1005,8 @@
      * @param length The number of characters to use from the array.
      * @exception org.xml.sax.SAXException The application may raise an exception.
      */
  -  public void comment(char ch[], int start, int length) throws org.xml.sax.SAXException
  +  public void comment(char ch[], int start, int length)
  +          throws org.xml.sax.SAXException
     {
   
       if (m_inEntityRef)
  @@ -1085,9 +1024,6 @@
       m_startNewLine = true;
     }
   
  -  /** NEEDSDOC Field m_inCData          */
  -  protected boolean m_inCData = false;
  -
     /**
      * Report the start of a CDATA section.
      *
  @@ -1137,7 +1073,8 @@
      *
      * @throws org.xml.sax.SAXException
      */
  -  public void cdata(char ch[], int start, int length) throws org.xml.sax.SAXException
  +  public void cdata(char ch[], int start, int length)
  +          throws org.xml.sax.SAXException
     {
   
       try
  @@ -1178,25 +1115,28 @@
       }
     }
   
  -  /** NEEDSDOC Field MAXCHARBUF          */
  +  /** The maximum character buffer, set to 4K to match most servers. */
     static final int MAXCHARBUF = (4 * 1024);
   
  -  /** NEEDSDOC Field NUMBERBYTESTOWRITEDIRECT          */
  +  /**
  +   * If a character event is greater than this number, don't bother with
  +   *  the local buffer. 
  +   */
     static final int NUMBERBYTESTOWRITEDIRECT = (1024);
   
  -  /** NEEDSDOC Field m_charBuf          */
  +  /** Character buffer if characters need to be encoded. */
     protected char[] m_charBuf = new char[MAXCHARBUF];
   
  -  /** NEEDSDOC Field m_byteBuf          */
  +  /** Byte buffer if characters do not need to be encoded. */
     protected byte[] m_byteBuf = new byte[MAXCHARBUF];
   
  -  /** NEEDSDOC Field m_pos          */
  +  /** The current position in the m_charBuf or m_byteBuf. */
     protected int m_pos = 0;
   
     /**
      * Append a byte to the buffer.
      *
  -   * NEEDSDOC @param b
  +   * @param b Byte to be written.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1222,7 +1162,7 @@
     /**
      * Append a character to the buffer.
      *
  -   * NEEDSDOC @param b
  +   * @param b byte to be written to result stream.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1248,9 +1188,9 @@
     /**
      * Append a character to the buffer.
      *
  -   * NEEDSDOC @param chars
  -   * NEEDSDOC @param start
  -   * NEEDSDOC @param length
  +   * @param chars non-null reference to character array.
  +   * @param start Start of characters to be written.
  +   * @param length Number of characters to be written.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1304,7 +1244,7 @@
     /**
      * Append a character to the buffer.
      *
  -   * NEEDSDOC @param s
  +   * @param s non-null reference to string to be written to the character buffer.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1357,9 +1297,8 @@
     }
   
     /**
  -   * NEEDSDOC Method flushBytes 
  +   * Flush all accumulated bytes to the result stream, without encoding.
      *
  -   *
      * @throws org.xml.sax.SAXException
      */
     private final void flushBytes() throws org.xml.sax.SAXException
  @@ -1399,8 +1338,7 @@
     }
   
     /**
  -   * NEEDSDOC Method flushChars 
  -   *
  +   * Flush all accumulated characters to the result stream.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1420,8 +1358,7 @@
     }
   
     /**
  -   * NEEDSDOC Method flush 
  -   *
  +   * Flush all accumulated characters or bytes to the result stream.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1468,6 +1405,7 @@
     public void characters(char chars[], int start, int length)
             throws org.xml.sax.SAXException
     {
  +
       if (m_inEntityRef)
         return;
   
  @@ -1500,22 +1438,26 @@
       for (int i = start; i < end; i++)
       {
         char ch = chars[i];
  -      
  -      if(checkWhite)
  +
  +      if (checkWhite)
         {
  -        if(!Character.isWhitespace(ch))
  +        if (!Character.isWhitespace(ch))
           {
             m_ispreserve = true;
             checkWhite = false;
           }
         }
   
  -      if ((ch < SPECIALSSIZE) && (m_charsMap[ch] != 'S'))
  +      if ((ch < m_maxCharacter) && (!m_charInfo.isSpecial(ch)))
         {
   
           // accum(ch);
           lengthClean++;
         }
  +      else if ('"' == ch)
  +      {
  +        lengthClean++;  // don't escape quote here
  +      }
         else
         {
           if (lengthClean > 0)
  @@ -1534,6 +1476,7 @@
       {
         accum(chars, startClean, lengthClean);
       }
  +
       m_isprevtext = true;
     }
   
  @@ -1541,9 +1484,9 @@
      * If available, when the disable-output-escaping attribute is used,
      * output raw text without escaping.
      *
  -   * NEEDSDOC @param ch
  -   * NEEDSDOC @param start
  -   * NEEDSDOC @param length
  +   * @param ch The characters from the XML document.
  +   * @param start The start position in the array.
  +   * @param length The number of characters to read from the array.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1564,10 +1507,10 @@
     /**
      * Normalize the characters, but don't escape.
      *
  -   * NEEDSDOC @param ch
  -   * NEEDSDOC @param start
  -   * NEEDSDOC @param length
  -   * NEEDSDOC @param isCData
  +   * @param ch The characters from the XML document.
  +   * @param start The start position in the array.
  +   * @param length The number of characters to read from the array.
  +   * @param isCData true if a CDATA block should be built around the characters.
      *
      * @throws IOException
      * @throws org.xml.sax.SAXException
  @@ -1581,20 +1524,8 @@
       for (int i = start; i < end; i++)
       {
         char c = ch[i];
  -
  -      if ((0x0D == c) && ((i + 1) < end) && (0x0A == ch[i + 1]))
  -      {
  -        outputLineSep();
  -
  -        i++;
  -      }
  -      else if ((0x0A == c) && ((i + 1) < end) && (0x0D == ch[i + 1]))
  -      {
  -        outputLineSep();
   
  -        i++;
  -      }
  -      else if ('\n' == c)
  +      if (CharInfo.S_LINEFEED == c)
         {
           outputLineSep();
         }
  @@ -1744,12 +1675,15 @@
     }
   
     /**
  -   * NEEDSDOC Method skippedEntity 
  -   *
  +   * Receive notification of a skipped entity.
  +   * @see {@link org.xml.sax.ContentHandler#skippedEntity}.
      *
  -   * NEEDSDOC @param name
  -   *
  -   * @throws org.xml.sax.SAXException
  +   * @param name The name of the skipped entity.  If it is a
  +   *        parameter entity, the name will begin with '%', and if
  +   *        it is the external DTD subset, it will be the string
  +   *        "[dtd]".
  +   * @throws org.xml.sax.SAXException Any SAX exception, possibly
  +   *            wrapping another exception.
      */
     public void skippedEntity(String name) throws org.xml.sax.SAXException
     {
  @@ -1795,7 +1729,7 @@
     /**
      * Receive notivication of a entityReference.
      *
  -   * NEEDSDOC @param name
  +   * @param name The name of the entity.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1816,13 +1750,13 @@
      * Handle one of the default entities, return false if it
      * is not a default entity.
      *
  -   * NEEDSDOC @param ch
  -   * NEEDSDOC @param i
  -   * NEEDSDOC @param chars
  -   * NEEDSDOC @param len
  -   * NEEDSDOC @param escLF
  +   * @param ch character to be escaped.
  +   * @param i index into character array.
  +   * @param chars non-null reference to character array.
  +   * @param len length of chars.
  +   * @param escLF true if the linefeed should be escaped.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return i+1 if the character was written, else i.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1831,72 +1765,27 @@
               throws org.xml.sax.SAXException
     {
   
  -    if (!escLF && (0x0D == ch) && ((i + 1) < len) && (0x0A == chars[i + 1]))
  +    if (!escLF && CharInfo.S_LINEFEED == ch)
       {
         outputLineSep();
  -
  -      i++;
       }
  -    else if (!escLF && (0x0A == ch) && ((i + 1) < len)
  -             && (0x0D == chars[i + 1]))
  -    {
  -      outputLineSep();
  -
  -      i++;
  -    }
  -    else if (!escLF && 0x0D == ch)
  -    {
  -      outputLineSep();
  -
  -      i++;
  -    }
  -    else if (!escLF && '\n' == ch)
  -    {
  -      outputLineSep();
  -    }
  -    else if ('<' == ch)
  -    {
  -      accum('&');
  -      accum('l');
  -      accum('t');
  -      accum(';');
  -    }
  -    else if ('>' == ch)
  -    {
  -      accum('&');
  -      accum('g');
  -      accum('t');
  -      accum(';');
  -    }
  -    else if ('&' == ch)
  -    {
  -      accum('&');
  -      accum('a');
  -      accum('m');
  -      accum('p');
  -      accum(';');
  -    }
  -    else if ('"' == ch)
  -    {
  -      accum('&');
  -      accum('q');
  -      accum('u');
  -      accum('o');
  -      accum('t');
  -      accum(';');
  -    }
  -    else if ('\'' == ch)
  -    {
  -      accum('&');
  -      accum('a');
  -      accum('p');
  -      accum('o');
  -      accum('s');
  -      accum(';');
  -    }
       else
       {
  -      return i;
  +      if (m_charInfo.isSpecial(ch))
  +      {
  +        String entityRef = m_charInfo.getEntityNameForChar(ch);
  +
  +        if (null != entityRef)
  +        {
  +          accum('&');
  +          accum(entityRef);
  +          accum(';');
  +        }
  +        else
  +          return i;
  +      }
  +      else
  +        return i;
       }
   
       return i + 1;
  @@ -1905,13 +1794,13 @@
     /**
      * Escape and accum a character.
      *
  -   * NEEDSDOC @param ch
  -   * NEEDSDOC @param i
  -   * NEEDSDOC @param chars
  -   * NEEDSDOC @param len
  -   * NEEDSDOC @param escLF
  +   * @param ch character to be escaped.
  +   * @param i index into character array.
  +   * @param chars non-null reference to character array.
  +   * @param len length of chars.
  +   * @param escLF true if the linefeed should be escaped.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return i+1 if the character was written, else i.
      *
      * @throws org.xml.sax.SAXException
      */
  @@ -1968,8 +1857,7 @@
         }
         else
         {
  -        if (ch > m_maxCharacter
  -                || ((ch < SPECIALSSIZE) && (m_attrCharsMap[ch] == 'S')))
  +        if (ch > m_maxCharacter || (m_charInfo.isSpecial(ch)))
           {
             accum("&#");
             accum(Integer.toString(ch));
  @@ -1990,9 +1878,7 @@
      * and UTF-16 surrogates for chracter references <CODE>&amp;#xnn</CODE>.
      *
      * @param   string      String to convert to XML format.
  -   * @param   specials    Chracters, should be represeted in chracter referenfces.
      * @param   encoding    CURRENTLY NOT IMPLEMENTED.
  -   * @return              XML-formatted string.
      * @see #backReference
      *
      * @throws org.xml.sax.SAXException
  @@ -2008,7 +1894,7 @@
       {
         char ch = stringChars[i];
   
  -      if ((ch < SPECIALSSIZE) && (m_attrCharsMap[ch] != 'S'))
  +      if ((ch < m_maxCharacter) && (!m_charInfo.isSpecial(ch)))
           accum(ch);
         else
           accumDefaultEscape(ch, i, stringChars, len, true);
  @@ -2016,10 +1902,10 @@
     }
   
     /**
  -   * NEEDSDOC Method shouldIndent 
  -   *
  +   * Tell if, based on space preservation constraints and the doIndent property,
  +   * if an indent should occur.
      *
  -   * NEEDSDOC (shouldIndent) @return
  +   * @return True if an indent should occur.
      */
     protected boolean shouldIndent()
     {
  @@ -2068,7 +1954,7 @@
      * serialized. This method should not be called while the
      * serializer is in the process of serializing a document.
      * <p>
  -   * The encoding specified in the {@link OutputFormat} is used, or
  +   * The encoding specified in the output properties is used, or
      * if no encoding was specified, the default for the selected
      * output method.
      *
  @@ -2089,10 +1975,10 @@
     }
   
     /**
  -   * NEEDSDOC Method getOutputStream 
  +   * Get the output stream where the events will be serialized to.
      *
  -   *
  -   * NEEDSDOC (getOutputStream) @return
  +   * @return reference to the result stream, or null of only a writer was
  +   * set.
      */
     public OutputStream getOutputStream()
     {
  @@ -2103,9 +1989,6 @@
      * Specifies a writer to which the document should be serialized.
      * This method should not be called while the serializer is in
      * the process of serializing a document.
  -   * <p>
  -   * The encoding specified for the {@link OutputFormat} must be
  -   * identical to the output format used with the writer.
      *
      * @param writer The output writer stream
      */
  @@ -2115,10 +1998,9 @@
     }
   
     /**
  -   * NEEDSDOC Method getWriter 
  -   *
  +   * Get the character stream where the events will be serialized to.
      *
  -   * NEEDSDOC (getWriter) @return
  +   * @return Reference to the result Writer, or null.
      */
     public Writer getWriter()
     {
  @@ -2134,7 +2016,7 @@
      *
      * @param format The output format to use
      */
  -  public void setOutputFormat(OutputFormat format)
  +  public void setOutputFormat(Properties format)
     {
   
       boolean shouldFlush = m_shouldFlush;
  @@ -2149,26 +2031,12 @@
      *
      * @return The output format in use
      */
  -  public OutputFormat getOutputFormat()
  +  public Properties getOutputFormat()
     {
       return m_format;
     }
   
     /**
  -   * Return a {@link DocumentHandler} interface into this serializer.
  -   * If the serializer does not support the {@link DocumentHandler}
  -   * interface, it should return null.
  -   *
  -   * @return A {@link DocumentHandler} interface into this serializer,
  -   *  or null if the serializer is not SAX 1 capable
  -   * @throws IOException An I/O exception occured
  -   */
  -  public DocumentHandler asDocumentHandler() throws IOException
  -  {
  -    return null;  // at least for now
  -  }
  -
  -  /**
      * Return a {@link ContentHandler} interface into this serializer.
      * If the serializer does not support the {@link ContentHandler}
      * interface, it should return null.
  @@ -2209,30 +2077,29 @@
     {
       return false;
     }
  -  
  +
     /**
      * Serializes the DOM node. Throws an exception only if an I/O
      * exception occured while serializing.
      *
      * @param elem The element to serialize
  +   *
  +   * @param node Node to serialize.
      * @throws IOException An I/O exception occured while serializing
      */
     public void serialize(Node node) throws IOException
     {
  +
       try
       {
         TreeWalker walker = new TreeWalker(this);
  +
         walker.traverse(node);
       }
  -    catch(org.xml.sax.SAXException se)
  +    catch (org.xml.sax.SAXException se)
       {
         throw new WrappedRuntimeException(se);
       }
     }
  -
   }  //ToXMLStringVisitor
  -
  -
  -
  -
   
  
  
  
  1.2       +0 -1      xml-xalan/java/src/org/apache/xalan/serialize/Method.java
  
  Index: Method.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/Method.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Method.java	2000/11/13 16:27:02	1.1
  +++ Method.java	2000/12/06 05:37:09	1.2
  @@ -65,7 +65,6 @@
    *
    * @version Alpha
    * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
  - * @see OutputFormat
    */
   public final class Method
   {
  
  
  
  1.2       +10 -22    xml-xalan/java/src/org/apache/xalan/serialize/Serializer.java
  
  Index: Serializer.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/Serializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Serializer.java	2000/11/13 16:27:02	1.1
  +++ Serializer.java	2000/12/06 05:37:09	1.2
  @@ -59,8 +59,8 @@
   import java.io.Writer;
   import java.io.OutputStream;
   import java.io.IOException;
  +import java.util.Properties;
   
  -import org.xml.sax.DocumentHandler;
   import org.xml.sax.ContentHandler;
   
   /**
  @@ -120,7 +120,7 @@
      * serialized. This method should not be called while the
      * serializer is in the process of serializing a document.
      * <p>
  -   * The encoding specified in the {@link OutputFormat} is used, or
  +   * The encoding specified in the output {@link Properties} is used, or
      * if no encoding was specified, the default for the selected
      * output method.
      *
  @@ -129,10 +129,10 @@
     public void setOutputStream(OutputStream output);
   
     /**
  -   * NEEDSDOC Method getOutputStream 
  +   * Get the output stream where the events will be serialized to.
      *
  -   *
  -   * NEEDSDOC (getOutputStream) @return
  +   * @return reference to the result stream, or null of only a writer was
  +   * set.
      */
     public OutputStream getOutputStream();
   
  @@ -141,7 +141,7 @@
      * This method should not be called while the serializer is in
      * the process of serializing a document.
      * <p>
  -   * The encoding specified for the {@link OutputFormat} must be
  +   * The encoding specified for the output {@link Properties} must be
      * identical to the output format used with the writer.
      *
      * @param writer The output writer stream
  @@ -149,10 +149,9 @@
     public void setWriter(Writer writer);
   
     /**
  -   * NEEDSDOC Method getWriter 
  -   *
  +   * Get the character stream where the events will be serialized to.
      *
  -   * NEEDSDOC (getWriter) @return
  +   * @return Reference to the result Writer, or null.
      */
     public Writer getWriter();
   
  @@ -165,25 +164,14 @@
      *
      * @param format The output format to use
      */
  -  public void setOutputFormat(OutputFormat format);
  +  public void setOutputFormat(Properties format);
   
     /**
      * Returns the output format for this serializer.
      *
      * @return The output format in use
  -   */
  -  public OutputFormat getOutputFormat();
  -
  -  /**
  -   * Return a {@link DocumentHandler} interface into this serializer.
  -   * If the serializer does not support the {@link DocumentHandler}
  -   * interface, it should return null.
  -   *
  -   * @return A {@link DocumentHandler} interface into this serializer,
  -   *  or null if the serializer is not SAX 1 capable
  -   * @throws IOException An I/O exception occured
      */
  -  public DocumentHandler asDocumentHandler() throws IOException;
  +  public Properties getOutputFormat();
   
     /**
      * Return a {@link ContentHandler} interface into this serializer.
  
  
  
  1.2       +36 -243   xml-xalan/java/src/org/apache/xalan/serialize/SerializerFactory.java
  
  Index: SerializerFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/SerializerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SerializerFactory.java	2000/11/13 16:27:02	1.1
  +++ SerializerFactory.java	2000/12/06 05:37:09	1.2
  @@ -56,6 +56,8 @@
    */
   package org.apache.xalan.serialize;
   
  +import javax.xml.transform.OutputKeys;
  +
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Properties;
  @@ -64,70 +66,21 @@
   import java.io.IOException;
   import java.io.InputStream;
   
  +import org.apache.xalan.templates.OutputProperties;
  +import org.apache.xml.utils.WrappedRuntimeException;
  +
   /**
  - * Factory for creating default serializers. An implementation need
  - * only support the default output methods (XML, HTML and Text).
  - * Additional serializers may be constructed directly by the application.
  - * <p>
  - * The factory is used with the default serializers provided by the
  - * implementation and named in the <tt>serializer.properties</tt>
  - * file of the implementation.
  - * <p>
  - * Usage example:
  - * <pre>
  - * Serializer ser;
  - *
  - * ser = SerializerFactory.getSerializer( Method.XML );
  - * </pre>
  - * or,
  - * <pre>
  - * Serializer   ser;
  - * OutputFormat format;
  - *
  - * format = SerializerFactory.getOutputFormat( Method.HTML );
  - * ser = SerializerFactory.getSerializer( format );
  - * </pre>
  - * <p>
  - *
  - *
  - *
  - * @version Alpha
  - * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
  + * Factory for creating serializers.
    */
   public abstract class SerializerFactory
   {
  -
  -  /**
  -   * The name of the properties file listing all the supported
  -   * serializers. (<tt>/org/xml/serilize/serializer.properties</tt>).
  -   */
  -  public static final String PropertiesResource = "serializer.properties";
  -
  -  /**
  -   * The name of the property listing all the supported output
  -   * methods. Contains a comma delimited list of method names.
  -   * (<tt>serialize.methods</tt>).
  -   */
  -  public static final String PropertyMethods = "serialize.methods";
  -
  -  /**
  -   * The prefix of a property supplying the class name for a
  -   * serializer implementing a specific method.
  -   * (<tt>serialize.</tt>).
  -   */
  -  public static final String PropertySerializerPrefix = "serialize.";
   
  -  /**
  -   * The prefix of a property supplying the class name for an
  -   * output format implementing a specific method.
  -   * (<tt>serialize.format.</tt>).
  -   */
  -  public static final String PropertyFormatPrefix = "serialize.format.";
  -
  -  /**
  +  /*
      * Associates output methods to serializer classes.
  +   * (Don't use this right now.  -sb
      */
  -  private static Hashtable _serializers = new Hashtable();
  +
  +  // private static Hashtable _serializers = new Hashtable();
   
     /**
      * Associates output methods to default output formats.
  @@ -140,211 +93,51 @@
      * output method. For a list of the default output methods see
      * {@link Method}.
      *
  -   * @param method The output method
  -   * @return A suitable serializer, or null
  -   */
  -  public static Serializer getSerializer(String method)
  -  {
  -
  -    Serializer ser;
  -    Class cls;
  -
  -    cls = (Class) _serializers.get(method);
  -
  -    if (cls == null)
  -      return null;
  -
  -    try
  -    {
  -      ser = (Serializer) cls.newInstance();
  -    }
  -    catch (Exception except)
  -    {
  -      return null;
  -    }
  -
  -    return ser;
  -  }
  -
  -  /**
  -   * Returns a serializer for the specified output method. Returns
  -   * null if no implementation exists that supports the specified
  -   * output method. For a list of the default output methods see
  -   * {@link Method}.
  -   *
      * @param format The output format
      * @return A suitable serializer, or null
      */
  -  public static Serializer getSerializer(OutputFormat format)
  +  public static Serializer getSerializer(Properties format)
     {
  -
  -    Serializer ser;
  -    Class cls;
  -
  -    if (format.getMethod() == null)
  -      throw new IllegalArgumentException(
  -        "The output format has not method name");
  -
  -    cls = (Class) _serializers.get(format.getMethod());
   
  -    if (cls == null)
  -      return null;
  +    Serializer ser = null;
   
       try
       {
  -      ser = (Serializer) cls.newInstance();
  -    }
  -    catch (Exception except)
  -    {
  -      return null;
  -    }
  -
  -    ser.setOutputFormat(format);
  +      Class cls;
  +      String method = format.getProperty(OutputKeys.METHOD);
   
  -    return ser;
  -  }
  -
  -  /**
  -   * Returns an output format for the specified output method.
  -   * An implementation may extend {@link OutputFormat} to provide
  -   * additional properties.
  -   *
  -   * @param method The output method
  -   * @return A suitable output format
  -   */
  -  public static OutputFormat getOutputFormat(String method)
  -  {
  +      if (method == null)
  +        throw new IllegalArgumentException(
  +          "The output format has not method name");
   
  -    OutputFormat format;
  -    Class cls;
  +      cls = null;  // (Class)_serializers.get(method);
   
  -    cls = (Class) _formats.get(method);
  -
  -    if (cls != null)
  -    {
  -      try
  +      if (cls == null)
         {
  -        format = (OutputFormat) cls.newInstance();
  -
  -        return format;
  -      }
  -      catch (Exception except){}
  -    }
  +        String className =
  +          format.getProperty(OutputProperties.S_KEY_CONTENT_HANDLER);
   
  -    format = new OutputFormat();
  -
  -    format.setMethod(method);
  -
  -    return format;
  -  }
  -
  -  /**
  -   * Returns an enumeration of all the output methods supported by this
  -   * implementation. The enumeration contains the names of all the output
  -   * methods for which this implementation provides a serializer.
  -   *
  -   * @return An enumeration of all output methods
  -   */
  -  public Enumeration listMethods()
  -  {
  -    return _serializers.keys();
  -  }
  -
  -  /**
  -   * Static constructor loads serializers and output formats
  -   * from properties file.
  -   */
  -  static
  -  {
  -    Properties props;
  -    StringTokenizer token;
  -
  -    try
  -    {
  -      props = new Properties();
  -
  -      InputStream is =
  -        SerializerFactory.class.getResourceAsStream(PropertiesResource);
  +        if (null == className)
  +        {
  +          throw new IllegalArgumentException(
  +            "The output format must have a '"
  +            + OutputProperties.S_KEY_CONTENT_HANDLER + "' property!");
  +        }
   
  -      if (null == is)
  -        System.err.println("Can't get serializer property file: "
  -                           + PropertiesResource);
  +        cls = Class.forName(className);
   
  -      props.load(is);
  +        // _serializers.put(method, cls);
  +      }
   
  -      if (props.getProperty(PropertyMethods) == null)
  -        System.err.println("Serializer property file has no "
  -                           + PropertyMethods + " property");
  -      else
  -      {
  -        token = new StringTokenizer(props.getProperty(PropertyMethods), ", ");
  +      ser = (Serializer) cls.newInstance();
   
  -        while (token.hasMoreElements())
  -        {
  -          String method;
  -          String clsName;
  -          Class cls;
  -
  -          method = token.nextToken();
  -
  -          // Get the serializer class that matches this output method
  -          clsName = props.getProperty(PropertySerializerPrefix + method);
  -
  -          if (clsName == null)
  -          {
  -            System.err.println(
  -              "Could not find property for serializer implementing output method "
  -              + method);
  -          }
  -          else
  -          {
  -            try
  -            {
  -              cls = Class.forName(clsName);
  -
  -              // Breaks in jview -sb
  -              // cls = SerializerFactory.class.getClassLoader().loadClass( clsName );
  -              _serializers.put(method, cls);
  -            }
  -            catch (ClassNotFoundException except)
  -            {
  -              System.err.println("Could not locate serializer class "
  -                                 + clsName);
  -            }
  -          }
  -
  -          // Get the output format class that matches this output method
  -          clsName = props.getProperty(PropertyFormatPrefix + method);
  -
  -          if (clsName == null)
  -          {
  -
  -            // Don't complain in this case.  -sb
  -            // System.err.println( "Could not find property for output format implementing output method " + method );
  -          }
  -          else
  -          {
  -            try
  -            {
  -              cls = Class.forName(clsName);
  -
  -              // Breaks in jview -sb
  -              // cls = SerializerFactory.class.getClassLoader().loadClass( clsName );
  -              _formats.put(method, cls);
  -            }
  -            catch (ClassNotFoundException except)
  -            {
  -              System.err.println("Could not locate output format class "
  -                                 + clsName);
  -            }
  -          }
  -        }
  -      }
  +      ser.setOutputFormat(format);
       }
  -    catch (IOException except)
  +    catch (Exception e)
       {
  -      System.err.println("Error loading " + PropertiesResource + ": "
  -                         + except.toString());
  +      throw new org.apache.xml.utils.WrappedRuntimeException(e);
       }
  +
  +    return ser;
     }
   }
  
  
  
  1.2       +0 -30     xml-xalan/java/src/org/apache/xalan/serialize/serializer.properties
  
  Index: serializer.properties
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/serialize/serializer.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- serializer.properties	2000/11/13 16:27:02	1.1
  +++ serializer.properties	2000/12/06 05:37:09	1.2
  @@ -1,31 +1 @@
   #
  -# $Revision: 1.1 $ $Date: 2000/11/13 16:27:02 $
  -#
  -# Note: This properties file is provided for illustrative purposes
  -#       only and is not part of the interface definition.
  -#       This properties file is located in the implementation JAR
  -#       and different implementations will specify different
  -#       implementation classes and output methods.
  -#
  -
  -#
  -# Lis the methods supported by this implementation
  -#
  -serialize.methods=xml,html,xhtml,text
  -
  -#
  -# Use the transition serializer implementations for the default methods
  -#
  -serialize.xml=org.apache.xalan.serialize.FormatterToXML
  -serialize.html=org.apache.xalan.serialize.FormatterToHTML
  -serialize.text=org.apache.xalan.serialize.FormatterToText
  -serialize.xhtml=org.apache.xalan.serialize.FormatterToXML
  -# serialize.wml:wml=org.apache.xml.serialize.transition.WMLSerializer
  -
  -#
  -# Use the helper output formats for the default methods
  -#
  -serialize.format.xml=org.apache.xalan.serialize.helpers.XMLOutputFormat
  -serialize.format.html=org.apache.xalan.serialize.helpers.HTMLOutputFormat
  -serialize.format.xhtml=org.apache.xalan.serialize.helpers.XHTMLOutputFormat
  -serialize.format.text=org.apache.xalan.serialize.helpers.TextOutputFormat
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xalan/serialize/CharInfo.java
  
  Index: CharInfo.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.serialize;
  
  import java.util.BitSet;
  
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.BufferedReader;
  
  import java.util.Hashtable;
  
  /**
   * This class provides services that tell if a character should have
   * special treatement, such as entity reference substitution or normalization
   * of a newline character.  It also provides character to entity reference
   * lookup.
   */
  public class CharInfo
  {
  
    /** Bit map that tells if a given character should have special treatment. */
    private BitSet m_specialsMap = new BitSet(65535);
  
    /** Lookup table for characters to entity references. */
    private Hashtable m_charToEntityRef = new Hashtable();
  
    /**
     * The name of the HTML entities file.
     * If specified, the file will be resource loaded with the default class loader.
     */
    public static String HTML_ENTITIES_RESOURCE = "HTMLEntities.res";
  
    /**
     * The name of the XML entities file.
     * If specified, the file will be resource loaded with the default class loader.
     */
    public static String XML_ENTITIES_RESOURCE = "XMLEntities.res";
  
    /** The linefeed character, which the parser should always normalize. */
    public static char S_LINEFEED = 0x0A;
  
    /**
     * Constructor that reads in a resource file that describes the mapping of
     * characters to entity references.
     *
     * @param entitiesResource Name of entities resource file that should
     * be loaded, which describes that mapping of characters to entity references.
     */
    public CharInfo(String entitiesResource)
    {
  
      InputStream is = null;
      BufferedReader reader = null;
      int index;
      String name;
      String value;
      int code;
      String line;
  
      try
      {
        is = CharInfo.class.getResourceAsStream(entitiesResource);
  
        if (is == null)
          throw new RuntimeException("The resource [" + entitiesResource
                                     + "] could not be found.\n"
                                     + entitiesResource);
  
        reader = new BufferedReader(new InputStreamReader(is));
        line = reader.readLine();
  
        while (line != null)
        {
          if (line.length() == 0 || line.charAt(0) == '#')
          {
            line = reader.readLine();
  
            continue;
          }
  
          index = line.indexOf(' ');
  
          if (index > 1)
          {
            name = line.substring(0, index);
  
            ++index;
  
            if (index < line.length())
            {
              value = line.substring(index);
              index = value.indexOf(' ');
  
              if (index > 0)
                value = value.substring(0, index);
  
              code = Integer.parseInt(value);
  
              defineEntity(name, (char) code);
            }
          }
  
          line = reader.readLine();
        }
  
        is.close();
        m_specialsMap.set(S_LINEFEED);
      }
      catch (Exception except)
      {
        throw new RuntimeException("The resource [" + entitiesResource
                                   + "] could not load: " + except.toString()
                                   + "\n" + entitiesResource + "\t"
                                   + except.toString());
      }
      finally
      {
        if (is != null)
        {
          try
          {
            is.close();
          }
          catch (Exception except){}
        }
      }
    }
  
    /**
     * Defines a new character reference. The reference's name and value are
     * supplied. Nothing happens if the character reference is already defined.
     * <p>Unlike internal entities, character references are a string to single
     * character mapping. They are used to map non-ASCII characters both on
     * parsing and printing, primarily for HTML documents. '&lt;amp;' is an
     * example of a character reference.</p>
     *
     * @param name The entity's name
     * @param value The entity's value
     */
    protected void defineEntity(String name, char value)
    {
  
      Character character = new Character(value);
  
      m_charToEntityRef.put(character, name);
      m_specialsMap.set(value);
    }
  
    /**
     * Resolve a character to an entity reference name.
     *
     * @param value character value that should be resolved to a name.
     *
     * @return name of character entity, or null if not found.
     */
    public String getEntityNameForChar(char value)
    {
      return (String) m_charToEntityRef.get(new Character(value));
    }
  
    /**
     * Tell if the character argument should have special treatment.
     *
     * @param value character value.
     *
     * @return true if the character should have any special treatment.
     */
    public boolean isSpecial(char value)
    {
      return m_specialsMap.get(value);
    }
  }
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xalan/serialize/HTMLEntities.res
  
  Index: HTMLEntities.res
  ===================================================================
  # $Id: HTMLEntities.res,v 1.1 2000/12/06 05:37:09 sboag Exp $
  #
  # @version $Revision: 1.1 $ $Date: 2000/12/06 05:37:09 $
  # @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
  #
  # Character entity references for markup-significant
  #
  quot 34
  amp 38
  lt 60
  gt 62
  nbsp 160
  #
  # Character entity references for ISO 8859-1 characters
  #
  iexcl 161
  cent 162
  pound 163
  curren 164
  yen 165
  brvbar 166
  sect 167
  uml 168
  copy 169
  ordf 170
  laquo 171
  not 172
  shy 173
  reg 174
  macr 175
  deg 176
  plusmn 177
  sup2 178
  sup3 179
  acute 180
  micro 181
  para 182
  middot 183
  cedil 184
  sup1 185
  ordm 186
  raquo 187
  frac14 188
  frac12 189
  frac34 190
  iquest 191
  Agrave 192
  Aacute 193
  Acirc 194
  Atilde 195
  Auml 196
  Aring 197
  AElig 198
  Ccedil 199
  Egrave 200
  Eacute 201
  Ecirc 202
  Euml 203
  Igrave 204
  Iacute 205
  Icirc 206
  Iuml 207
  ETH 208
  Ntilde 209
  Ograve 210
  Oacute 211
  Ocirc 212
  Otilde 213
  Ouml 214
  times 215
  Oslash 216
  Ugrave 217
  Uacute 218
  Ucirc 219
  Uuml 220
  Yacute 221
  THORN 222
  szlig 223
  agrave 224
  aacute 225
  acirc 226
  atilde 227
  auml 228
  aring 229
  aelig 230
  ccedil 231
  egrave 232
  eacute 233
  ecirc 234
  euml 235
  igrave 236
  iacute 237
  icirc 238
  iuml 239
  eth 240
  ntilde 241
  ograve 242
  oacute 243
  ocirc 244
  otilde 245
  ouml 246
  divide 247
  oslash 248
  ugrave 249
  uacute 250
  ucirc 251
  uuml 252
  yacute 253
  thorn 254
  yuml 255
  #
  # Character entity references for symbols, mathematical symbols, and Greek letters
  #
  # Latin Extended
  fnof 402
  #
  # Greek
  Alpha 913
  Beta 914
  Gamma 915
  Delta 916
  Epsilon 917
  Zeta 918
  Eta 919
  Theta 920
  Iota 921
  Kappa 922
  Lambda 923
  Mu 924
  Nu 925
  Xi 926
  Omicron 927
  Pi 928
  Rho 929
  Sigma 931
  Tau 932
  Upsilon 933
  Phi 934
  Chi 935
  Psi 936
  Omega 937
  alpha 945
  beta 946
  gamma 947
  delta 948
  epsilon 949
  zeta 950
  eta 951
  theta 952
  iota 953
  kappa 954
  lambda 955
  mu 956
  nu 957
  xi 958
  omicron 959
  pi 960
  rho 961
  sigmaf 962
  sigma 963
  tau 964
  upsilon 965
  phi 966
  chi 967
  psi 968
  omega 969
  thetasym 977
  upsih 978
  piv 982
  #
  # General Punctuation
  bull 8226
  hellip 8230
  prime 8242
  Prime 8243
  oline 8254
  frasl 8260
  #
  # Letterlike Symbols
  weierp 8472
  image 8465
  real 8476
  trade 8482
  alefsym 8501
  #
  # Arrows
  larr 8592
  uarr 8593
  rarr 8594
  darr 8595
  harr 8596
  crarr 8629
  lArr 8656
  uArr 8657
  rArr 8658
  dArr 8659
  hArr 8660
  #
  # Mathematical Operators
  forall 8704
  part 8706
  exist 8707
  empty 8709
  nabla 8711
  isin 8712
  notin 8713
  ni 8715
  prod 8719
  sum 8721
  minus 8722
  lowast 8727
  radic 8730
  prop 8733
  infin 8734
  ang 8736
  and 8743
  or 8744
  cap 8745
  cup 8746
  int 8747
  there4 8756
  sim 8764
  cong 8773
  asymp 8776
  ne 8800
  equiv 8801
  le 8804
  ge 8805
  sub 8834
  sup 8835
  nsub 8836
  sube 8838
  supe 8839
  oplus 8853
  otimes 8855
  perp 8869
  sdot 8901
  #
  # Miscellaneous Technical
  lceil 8968
  rceil 8969
  lfloor 8970
  rfloor 8971
  lang 9001
  rang 9002
  #
  # Geometric Shapes
  loz 9674
  #
  # Miscellaneous Symbols
  spades 9824
  clubs 9827
  hearts 9829
  diams 9830
  #
  # Character entity references for internationalization characters
  #
  # Latin Extended-A
  OElig 338
  oelig 339
  #-- Commented out. NN 4.7 does not seem to support these --
  #Scaron 352
  #scaron 353
  Yuml 376
  #
  # Spacing Modifier Letters
  circ 710
  tilde 732
  #
  # General Punctuation
  ensp 8194
  emsp 8195
  thinsp 8201
  zwnj 8204
  zwj 8205
  lrm 8206
  rlm 8207
  ndash 8211
  mdash 8212
  lsquo 8216
  rsquo 8217
  sbquo 8218
  ldquo 8220
  rdquo 8221
  bdquo 8222
  dagger 8224
  Dagger 8225
  permil 8240
  lsaquo 8249
  rsaquo 8250
  euro 8364
  
  
  
  1.1                  xml-xalan/java/src/org/apache/xalan/serialize/XMLEntities.res
  
  Index: XMLEntities.res
  ===================================================================
  # $Id: XMLEntities.res,v 1.1 2000/12/06 05:37:09 sboag Exp $
  #
  # @version $Revision: 1.1 $ $Date: 2000/12/06 05:37:09 $
  # @author <a href="mailto:arkin@intalio.com">Assaf Arkin</a>
  #
  # Character entity references for markup-significant
  #
  quot 34
  amp 38
  lt 60
  gt 62