dlr         02/02/15 17:54:57

  Modified:    src/java/org/apache/xmlrpc XmlRpc.java
  Log:
  o Optimized XmlWriter through use of constants for XML template text.
  
  o JavaDoc'd Formatter's ctor.
  
  Revision  Changes    Path
  1.12      +39 -19    xml-rpc/src/java/org/apache/xmlrpc/XmlRpc.java
  
  Index: XmlRpc.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/XmlRpc.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -u -r1.11 -r1.12
  --- XmlRpc.java       16 Feb 2002 01:14:06 -0000      1.11
  +++ XmlRpc.java       16 Feb 2002 01:54:57 -0000      1.12
  @@ -677,13 +677,28 @@
        */
       class XmlWriter
       {
  -
  +        protected static final String PROLOG_START =
  +            "<?xml version=\"1.0\" encoding=\"";
  +        protected static final String PROLOG_END = "\"?>";
  +        protected static final String CLOSING_TAG_START = "</";
  +        protected static final String SINGLE_TAG_END = "/>";
  +        protected static final String LESS_THAN_ENTITY = "&lt;";
  +        protected static final String GREATER_THAN_ENTITY = "&gt;";
  +        protected static final String AMPERSAND_ENTITY = "&amp;";
  +
  +        /**
  +         * The buffer to write to.
  +         */
           StringBuffer buf;
  +
  +        /**
  +         * The encoding to use.
  +         */
           String enc;
   
           public XmlWriter (StringBuffer buf)
           {
  -            // The default encoding used for XML-RPC is ISO-8859-1 for pragmatical 
reasons.
  +            // The default encoding used for XML-RPC is ISO-8859-1.
               this (buf, encoding);
           }
   
  @@ -691,9 +706,11 @@
           {
               this.buf = buf;
               this.enc = enc;
  -            // get name of encoding for XML prolog
  -            String encName = encodings.getProperty (enc, enc);
  -            buf.append ("<?xml version=\"1.0\" encoding=\"" + encName + "\"?>");
  +
  +            // Add the XML prolog (which includes the encoding)
  +            buf.append (PROLOG_START);
  +            buf.append (encodings.getProperty (enc, enc));
  +            buf.append (PROLOG_END);
           }
   
           public void startElement (String elem)
  @@ -705,7 +722,7 @@
   
           public void endElement (String elem)
           {
  -            buf.append ("</");
  +            buf.append (CLOSING_TAG_START);
               buf.append (elem);
               buf.append ('>');
           }
  @@ -714,10 +731,9 @@
           {
               buf.append ('<');
               buf.append (elem);
  -            buf.append ("/>");
  +            buf.append (SINGLE_TAG_END);
           }
   
  -
           public void chardata (String text)
           {
               int l = text.length ();
  @@ -726,17 +742,17 @@
                   char c = text.charAt (i);
                   switch (c)
                   {
  -                    case '<' :
  -                        buf.append ("&lt;");
  -                        break;
  -                    case '>' :
  -                        buf.append ("&gt;");
  -                        break;
  -                    case '&' :
  -                        buf.append ("&amp;");
  -                        break;
  -                    default :
  -                        buf.append (c);
  +                case '<' :
  +                    buf.append (LESS_THAN_ENTITY);
  +                    break;
  +                case '>' :
  +                    buf.append (GREATER_THAN_ENTITY);
  +                    break;
  +                case '&' :
  +                    buf.append (AMPERSAND_ENTITY);
  +                    break;
  +                default :
  +                    buf.append (c);
                   }
               }
           }
  @@ -771,6 +787,10 @@
   {
       private DateFormat f;
   
  +    /**
  +     * Uses the <code>DateFormat</code> string
  +     * <code>yyyyMMdd'T'HH:mm:ss</code>.
  +     */
       public Formatter ()
       {
           f = new SimpleDateFormat ("yyyyMMdd'T'HH:mm:ss");
  
  
  


Reply via email to