myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r729966 - in /myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago: util/HtmlWriterUtil.java util/ResponseWriterBuffer.java util/XmlUtils.java webapp/TobagoResponseWriterImpl.java
Date Mon, 29 Dec 2008 18:56:11 GMT
Author: bommel
Date: Mon Dec 29 10:56:11 2008
New Revision: 729966

URL: http://svn.apache.org/viewvc?rev=729966&view=rev
Log:
(TOBAGO-731) Minor performance improvements for TobagoReponseWriter, XmlUtils, HtmlWriterUtil
and ResponseWriterBuffer

Modified:
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/HtmlWriterUtil.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ResponseWriterBuffer.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
    myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/HtmlWriterUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/HtmlWriterUtil.java?rev=729966&r1=729965&r2=729966&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/HtmlWriterUtil.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/HtmlWriterUtil.java
Mon Dec 29 10:56:11 2008
@@ -44,7 +44,7 @@
 
   private final boolean utf8;
 
-  public HtmlWriterUtil(Writer out, String characterEncoding) {
+  public HtmlWriterUtil(final Writer out, final String characterEncoding) {
     this.out = out;
     utf8 = "utf-8".equalsIgnoreCase(characterEncoding);
     buffer = new ResponseWriterBuffer(out);
@@ -52,18 +52,11 @@
 
   public void writeAttributeValue(final String text)
       throws IOException {
-    writeAttributeValue(text.toCharArray(), 0, text.length());
+    writeEncodedValue(text.toCharArray(), 0, text.length(), true);
   }
 
-  private void writeAttributeValue(
-      final char[] text, final int start, final int length)
-      throws IOException {
-    writeEncodedValue(text, start, length, true);
-  }
-
-
   public void writeText(final String text) throws IOException {
-    writeText(text.toCharArray(), 0, text.length());
+    writeEncodedValue(text.toCharArray(), 0, text.length(), false);
   }
 
   public void writeText(final char[] text, final int start, final int length)
@@ -103,9 +96,7 @@
             // an open brace don't get escaped
             buffer.addToBuffer('&');
           } else if (CHARS_TO_ESCAPE[ch] != null) {
-            for (char cha : CHARS_TO_ESCAPE[ch]) {
-              buffer.addToBuffer(cha);
-            }
+            buffer.addToBuffer(CHARS_TO_ESCAPE[ch]);
           } else {
             buffer.addToBuffer(ch);
           }
@@ -116,11 +107,8 @@
           buffer.flushBuffer();
 
           out.write('&');
-//          FIXME? write(String) sets the startStillOpen=false
-//          out.write(sISO8859_1_Entities[ch - 0xA0]);
-          for (char c : ISO8859_1_ENTITIES[ch - 0xA0].toCharArray()) {
-            out.write(c);
-          }
+          char[] chars = ISO8859_1_ENTITIES[ch - 0xA0];
+          out.write(chars, 0, chars.length);
           out.write(';');
         } else {
           buffer.flushBuffer();
@@ -220,102 +208,102 @@
   //
   // Entities from HTML 4.0, section 24.2.1; character codes 0xA0 to 0xFF
   //
-  private static final String[] ISO8859_1_ENTITIES = new String[]{
-      "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"
+  private static final char [][] ISO8859_1_ENTITIES = new char [][]{
+      "nbsp".toCharArray(),
+      "iexcl".toCharArray(),
+      "cent".toCharArray(),
+      "pound".toCharArray(),
+      "curren".toCharArray(),
+      "yen".toCharArray(),
+      "brvbar".toCharArray(),
+      "sect".toCharArray(),
+      "uml".toCharArray(),
+      "copy".toCharArray(),
+      "ordf".toCharArray(),
+      "laquo".toCharArray(),
+      "not".toCharArray(),
+      "shy".toCharArray(),
+      "reg".toCharArray(),
+      "macr".toCharArray(),
+      "deg".toCharArray(),
+      "plusmn".toCharArray(),
+      "sup2".toCharArray(),
+      "sup3".toCharArray(),
+      "acute".toCharArray(),
+      "micro".toCharArray(),
+      "para".toCharArray(),
+      "middot".toCharArray(),
+      "cedil".toCharArray(),
+      "sup1".toCharArray(),
+      "ordm".toCharArray(),
+      "raquo".toCharArray(),
+      "frac14".toCharArray(),
+      "frac12".toCharArray(),
+      "frac34".toCharArray(),
+      "iquest".toCharArray(),
+      "Agrave".toCharArray(),
+      "Aacute".toCharArray(),
+      "Acirc".toCharArray(),
+      "Atilde".toCharArray(),
+      "Auml".toCharArray(),
+      "Aring".toCharArray(),
+      "AElig".toCharArray(),
+      "Ccedil".toCharArray(),
+      "Egrave".toCharArray(),
+      "Eacute".toCharArray(),
+      "Ecirc".toCharArray(),
+      "Euml".toCharArray(),
+      "Igrave".toCharArray(),
+      "Iacute".toCharArray(),
+      "Icirc".toCharArray(),
+      "Iuml".toCharArray(),
+      "ETH".toCharArray(),
+      "Ntilde".toCharArray(),
+      "Ograve".toCharArray(),
+      "Oacute".toCharArray(),
+      "Ocirc".toCharArray(),
+      "Otilde".toCharArray(),
+      "Ouml".toCharArray(),
+      "times".toCharArray(),
+      "Oslash".toCharArray(),
+      "Ugrave".toCharArray(),
+      "Uacute".toCharArray(),
+      "Ucirc".toCharArray(),
+      "Uuml".toCharArray(),
+      "Yacute".toCharArray(),
+      "THORN".toCharArray(),
+      "szlig".toCharArray(),
+      "agrave".toCharArray(),
+      "aacute".toCharArray(),
+      "acirc".toCharArray(),
+      "atilde".toCharArray(),
+      "auml".toCharArray(),
+      "aring".toCharArray(),
+      "aelig".toCharArray(),
+      "ccedil".toCharArray(),
+      "egrave".toCharArray(),
+      "eacute".toCharArray(),
+      "ecirc".toCharArray(),
+      "euml".toCharArray(),
+      "igrave".toCharArray(),
+      "iacute".toCharArray(),
+      "icirc".toCharArray(),
+      "iuml".toCharArray(),
+      "eth".toCharArray(),
+      "ntilde".toCharArray(),
+      "ograve".toCharArray(),
+      "oacute".toCharArray(),
+      "ocirc".toCharArray(),
+      "otilde".toCharArray(),
+      "ouml".toCharArray(),
+      "divide".toCharArray(),
+      "oslash".toCharArray(),
+      "ugrave".toCharArray(),
+      "uacute".toCharArray(),
+      "ucirc".toCharArray(),
+      "uuml".toCharArray(),
+      "yacute".toCharArray(),
+      "thorn".toCharArray(),
+      "yuml".toCharArray()
   };
 }

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ResponseWriterBuffer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ResponseWriterBuffer.java?rev=729966&r1=729965&r2=729966&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ResponseWriterBuffer.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/ResponseWriterBuffer.java
Mon Dec 29 10:56:11 2008
@@ -44,20 +44,19 @@
 
   private static final int BUFFER_SIZE = 64;
 
-  private final char[] buff;
+  private final char[] buff = new char[BUFFER_SIZE];
 
   private int bufferIndex;
 
-  private Writer writer;
+  private final Writer writer;
 
-  public ResponseWriterBuffer(Writer writer) {
-    buff = new char[BUFFER_SIZE];
+  public ResponseWriterBuffer(final Writer writer) {
     this.writer = writer;
   }
 
   /**
    * Add a character to the buffer, flushing the buffer if the buffer is
-   * full, and returning the new buffer index
+   * full
    */
   public void addToBuffer(final char ch) throws IOException {
     if (bufferIndex >= BUFFER_SIZE) {
@@ -68,6 +67,16 @@
     buff[bufferIndex++] = ch;
   }
 
+  public void addToBuffer(final char[] ch) throws IOException {
+    if (bufferIndex + ch.length >= BUFFER_SIZE) {
+      writer.write(buff, 0, bufferIndex);
+      bufferIndex = 0;
+    }
+
+    System.arraycopy(ch, 0, buff, bufferIndex, ch.length);
+    bufferIndex += ch.length;
+  }
+
   /**
    * Flush the contents of the buffer to the output stream
    * and return the reset buffer index

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java?rev=729966&r1=729965&r2=729966&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/util/XmlUtils.java
Mon Dec 29 10:56:11 2008
@@ -33,13 +33,13 @@
 import java.io.StringReader;
 import java.util.Properties;
 
-public class XmlUtils {
+public final class XmlUtils {
 
-  public static String escape(String s) {
+  public static String escape(final String s) {
     return escape(s, true);
   }
 
-  public static String escape(String s, boolean isAttributeValue) {
+  public static String escape(final String s, final boolean isAttributeValue) {
     if (null == s) {
       return "";
     }
@@ -51,8 +51,19 @@
     return buffer.toString();
   }
 
-  private static void appendEntityRef(StringBuilder buffer, char ch,
-      boolean isAttributeValue) {
+  public static String escape(final char[] chars, final int offset, final int length, final
boolean isAttributeValue) {
+    if (null == chars) {
+      return "";
+    }
+    StringBuilder buffer = new StringBuilder(length);
+    for (int i = offset; i < length; i++) {
+      appendEntityRef(buffer, chars[i], isAttributeValue);
+    }
+    return buffer.toString();
+  }
+
+  private static void appendEntityRef(final StringBuilder buffer, final char ch,
+      final boolean isAttributeValue) {
     // Encode special XML characters into the equivalent character references.
     // These five are defined by default for all XML documents.
     switch (ch) {
@@ -84,7 +95,7 @@
     }
   }
 
-  public static void load(Properties properties, InputStream stream)
+  public static void load(final Properties properties, final InputStream stream)
       throws IOException {
     Document document;
     try {
@@ -97,7 +108,7 @@
     importProperties(properties, propertiesElement);
   }
 
-  private static Document createDocument(InputStream stream)
+  private static Document createDocument(final InputStream stream)
       throws SAXException, IOException {
     DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     factory.setIgnoringElementContentWhitespace(true);
@@ -114,7 +125,7 @@
     }
   }
 
-  static void importProperties(Properties properties, Element propertiesElement) {
+  static void importProperties(final Properties properties, final Element propertiesElement)
{
     NodeList entries = propertiesElement.getChildNodes();
     int numEntries = entries.getLength();
     int start = numEntries > 0
@@ -134,7 +145,7 @@
 
   private static class Resolver implements EntityResolver {
 
-    public InputSource resolveEntity(String publicId, String systemId)
+    public InputSource resolveEntity(final String publicId, final String systemId)
         throws SAXException {
       String dtd = "<!ELEMENT properties (comment?, entry*)>"
           + "<!ATTLIST properties version CDATA #FIXED '1.0'>"

Modified: myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java?rev=729966&r1=729965&r2=729966&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
(original)
+++ myfaces/tobago/branches/tobago-1.0.x/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriterImpl.java
Mon Dec 29 10:56:11 2008
@@ -190,8 +190,7 @@
       throws IOException {
     closeOpenTag();
     if (xml) {
-      writer.write(XmlUtils.escape(String.valueOf(text)).toCharArray(), offset, length);
-// FIXME: not nice:     XmlUtils.escape(text.toString()).toCharArray()
+      writer.write(XmlUtils.escape(text, offset, length, true));
     } else {
       helper.writeText(text, offset, length);
     }



Mime
View raw message