Author: ivaynberg
Date: Sun Jul 13 08:13:28 2008
New Revision: 676340

URL: http://svn.apache.org/viewvc?rev=676340&view=rev
Log:
WICKET-1704

Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
    wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/AbstractStringResourceStream.java
 Sun Jul 13 08:13:28 2008
@@ -21,6 +21,7 @@
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 
+import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.time.Time;
 
 
@@ -71,6 +72,7 @@
        /**
         * @see org.apache.wicket.util.resource.IResourceStream#getContentType()
         */
+       @Override
        public String getContentType()
        {
                return contentType;
@@ -103,6 +105,7 @@
        /**
         * @see org.apache.wicket.util.watch.IModifiable#lastModifiedTime()
         */
+       @Override
        public Time lastModifiedTime()
        {
                return lastModified;
@@ -121,4 +124,10 @@
         * @return The string resource
         */
        protected abstract String getString();
+
+       @Override
+       public final long length()
+       {
+               return Strings.lengthInBytes(getString(), getCharset());
+       }
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
 Sun Jul 13 08:13:28 2008
@@ -91,24 +91,9 @@
        /**
         * @see 
org.apache.wicket.util.resource.AbstractStringResourceStream#getString()
         */
+       @Override
        protected String getString()
        {
                return buffer.toString();
        }
-
-       /**
-        * @see 
org.apache.wicket.util.resource.AbstractResourceStream#asString()
-        */
-       public String asString()
-       {
-               return getString();
-       }
-
-       /**
-        * @see org.apache.wicket.util.resource.IResourceStream#length()
-        */
-       public long length()
-       {
-               return buffer.length();
-       }
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
 Sun Jul 13 08:13:28 2008
@@ -16,9 +16,6 @@
  */
 package org.apache.wicket.util.resource;
 
-import java.io.UnsupportedEncodingException;
-
-import org.apache.wicket.WicketRuntimeException;
 
 
 /**
@@ -86,31 +83,4 @@
        {
                return getString();
        }
-
-       /**
-        * @see org.apache.wicket.util.resource.IResourceStream#length()
-        */
-       @Override
-       public long length()
-       {
-               // WICKET-1705: we cannot use string.length() because we need 
number of bytes rather then
-               // number of characters
-               if (getCharset() != null)
-               {
-                       try
-                       {
-                               return 
getString().getBytes(getCharset().name()).length;
-                       }
-                       catch (UnsupportedEncodingException e)
-                       {
-                               throw new WicketRuntimeException(
-                                       "StringResourceStream created with 
unsupported charset: " + getCharset().name());
-                       }
-               }
-               else
-               {
-                       return getString().getBytes().length;
-               }
-       }
-
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java 
(original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/string/Strings.java 
Sun Jul 13 08:13:28 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.util.string;
 
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -1343,6 +1345,39 @@
                return hexDigit[(nibble & 0xF)];
        }
 
+       /**
+        * Calculates the length of string in bytes, uses specified 
<code>charset</code> if provided.
+        * 
+        * @param string
+        * @param charset
+        *            (optional) character set to use when converting string to 
bytes
+        * @return length of string in bytes
+        */
+       public static int lengthInBytes(String string, Charset charset)
+       {
+               if (string == null)
+               {
+                       throw new NullPointerException("Argument `string` 
cannot be null");
+               }
+               if (charset != null)
+               {
+                       try
+                       {
+                               return string.getBytes(charset.name()).length;
+                       }
+                       catch (UnsupportedEncodingException e)
+                       {
+                               throw new WicketRuntimeException(
+                                       "StringResourceStream created with 
unsupported charset: " + charset.name());
+                       }
+               }
+               else
+               {
+                       return string.getBytes().length;
+               }
+
+       }
+
 
        /**
         * Private constructor prevents construction.

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
 Sun Jul 13 08:13:28 2008
@@ -246,12 +246,5 @@
                return this;
        }
 
-       /**
-        * @see org.apache.wicket.util.resource.IResourceStream#length()
-        */
-       @Override
-       public final long length()
-       {
-               return buffer.length();
-       }
+
 }

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
 Sun Jul 13 08:13:28 2008
@@ -178,15 +178,6 @@
        }
 
        /**
-        * @see org.apache.wicket.util.resource.IResourceStream#length()
-        */
-       @Override
-       public long length()
-       {
-               return decorated.length();
-       }
-
-       /**
         * @see 
org.apache.wicket.util.resource.AbstractResourceStream#setCharset(java.nio.charset.Charset)
         */
        @Override

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java?rev=676340&r1=676339&r2=676340&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
 Sun Jul 13 08:13:28 2008
@@ -38,8 +38,8 @@
  * <p>
  * You may use resources created by this factory directly by calling
  * <code>resourceReference(Map)</code> to get a resource reference to the 
given shared resource
- * interpolation represented by the variables in the <code>Map</code>. Or, for 
convenience, you
- * can use <code>TextTemplateLink</code> to link to resources created by this 
factory.
+ * interpolation represented by the variables in the <code>Map</code>. Or, for 
convenience, you can
+ * use <code>TextTemplateLink</code> to link to resources created by this 
factory.
  * <p>
  * In many cases, it will be useful to extend this class and override
  * <code>sharedResourceName(Map)</code> in order to provide a unique name for 
resources created by
@@ -96,8 +96,8 @@
         * 
         * @param variables
         *            the variables to interpolate into the template
-        * @return a <code>ResourceReference</code> to the template encoded as 
a resource with the
-        *         given variables interpolated
+        * @return a <code>ResourceReference</code> to the template encoded as 
a resource with the given
+        *         variables interpolated
         */
        public ResourceReference resourceReference(final Map<String, Object> 
variables)
        {
@@ -127,11 +127,6 @@
                                                        return templateValue;
                                                }
 
-                                               @Override
-                                               public long length()
-                                               {
-                                                       return 
templateValue.length();
-                                               }
                                        };
                                }
                        };
@@ -163,7 +158,8 @@
        }
 
        /**
-        * Simple encoder for key values. Letters and digits are unchanged. All 
others are encoded as %<hexcode>.
+        * Simple encoder for key values. Letters and digits are unchanged. All 
others are encoded as
+        * %<hexcode>.
         * 
         * @param value
         *            a value


Reply via email to