Author: ivaynberg
Date: Sun Jul 13 08:21:27 2008
New Revision: 676341
URL: http://svn.apache.org/viewvc?rev=676341&view=rev
Log:
WICKET-1704
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringBufferResourceStream.java
Sun Jul 13 08:21:27 2008
@@ -17,6 +17,7 @@
package org.apache.wicket.util.resource;
import org.apache.wicket.util.string.AppendingStringBuffer;
+import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.time.Time;
/**
@@ -109,6 +110,6 @@
*/
public long length()
{
- return buffer.length();
+ return Strings.lengthInBytes(getString(), getCharset());
}
}
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/resource/StringResourceStream.java
Sun Jul 13 08:21:27 2008
@@ -16,9 +16,7 @@
*/
package org.apache.wicket.util.resource;
-import java.io.UnsupportedEncodingException;
-
-import org.apache.wicket.WicketRuntimeException;
+import org.apache.wicket.util.string.Strings;
/**
@@ -89,24 +87,8 @@
*/
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;
- }
+ return Strings.lengthInBytes(getString(), getCharset());
+
}
}
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/Strings.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/string/Strings.java
Sun Jul 13 08:21:27 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;
@@ -281,7 +283,7 @@
* @return The escaped string
*/
public static CharSequence escapeMarkup(final String s, final boolean
escapeSpaces,
- final boolean convertToHtmlUnicodeEscapes)
+ final boolean convertToHtmlUnicodeEscapes)
{
if (s == null)
{
@@ -592,13 +594,13 @@
}
if (s.equalsIgnoreCase("on") ||
s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") ||
- s.equalsIgnoreCase("1"))
+ s.equalsIgnoreCase("1"))
{
return true;
}
if (s.equalsIgnoreCase("off") ||
s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") ||
- s.equalsIgnoreCase("0"))
+ s.equalsIgnoreCase("0"))
{
return false;
}
@@ -707,7 +709,7 @@
* @return The resulting string with searchFor replaced with replaceWith
*/
public static CharSequence replaceAll(final CharSequence s, final
CharSequence searchFor,
- CharSequence replaceWith)
+ CharSequence replaceWith)
{
if (s == null)
{
@@ -942,7 +944,7 @@
else
{
throw new
StringValueConversionException("Expected single character, not \"" + s +
- "\"");
+ "\"");
}
}
@@ -1093,9 +1095,9 @@
}
/**
- * Converts the given object to a string. Does special conversion for
- * [EMAIL PROTECTED] Throwable throwables} and String arrays of length
1 (in which case it just returns to
- * string in that array, as this is a common thing to have in the
Servlet API).
+ * Converts the given object to a string. Does special conversion for
[EMAIL PROTECTED] Throwable
+ * throwables} and String arrays of length 1 (in which case it just
returns to string in that
+ * array, as this is a common thing to have in the Servlet API).
*
* @param object
* The object
@@ -1156,8 +1158,8 @@
// differentiator for the message (e.g. "component foo was
***added***"
// or "component foo was ***created***")
AppendingStringBuffer sb = new AppendingStringBuffer("The " +
componentType.toLowerCase() +
- " with id '" + component.getId() + "' that
failed to render was " +
- location.getMessage() + "\n");
+ " with id '" + component.getId() + "' that failed to
render was " +
+ location.getMessage() + "\n");
// a list of stacktrace elements that need to be skipped in the
location
// stack trace
@@ -1287,7 +1289,7 @@
* @param stopAtWicketServlet
*/
private static void outputThrowable(Throwable cause,
AppendingStringBuffer sb,
- boolean stopAtWicketServlet)
+ boolean stopAtWicketServlet)
{
sb.append(cause);
sb.append("\n");
@@ -1301,8 +1303,7 @@
sb.append(traceString);
sb.append("\n");
if (stopAtWicketServlet &&
-
(traceString.startsWith("org.apache.wicket.protocol.http.WicketServlet") ||
traceString
-
.startsWith("org.apache.wicket.protocol.http.WicketFilter")))
+
(traceString.startsWith("org.apache.wicket.protocol.http.WicketServlet") ||
traceString.startsWith("org.apache.wicket.protocol.http.WicketFilter")))
{
return;
}
@@ -1344,6 +1345,38 @@
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/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/PackagedTextTemplate.java
Sun Jul 13 08:21:27 2008
@@ -29,6 +29,7 @@
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
import org.apache.wicket.util.resource.locator.ResourceStreamLocator;
import org.apache.wicket.util.string.JavascriptStripper;
+import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -249,6 +250,6 @@
*/
public final long length()
{
- return buffer.length();
+ return Strings.lengthInBytes(getString(), getCharset());
}
}
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateDecorator.java
Sun Jul 13 08:21:27 2008
@@ -23,6 +23,7 @@
import java.util.Map;
import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+import org.apache.wicket.util.string.Strings;
import org.apache.wicket.util.time.Time;
@@ -173,7 +174,7 @@
*/
public long length()
{
- return decorated.length();
+ return Strings.lengthInBytes(getString(), getCharset());
}
/**
Modified:
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
URL:
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java?rev=676341&r1=676340&r2=676341&view=diff
==============================================================================
---
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
(original)
+++
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/util/template/TextTemplateSharedResourceFactory.java
Sun Jul 13 08:21:27 2008
@@ -26,6 +26,7 @@
import org.apache.wicket.SharedResources;
import org.apache.wicket.util.resource.AbstractStringResourceStream;
import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.string.Strings;
/**
@@ -38,8 +39,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 +97,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 variables)
{
@@ -127,7 +128,7 @@
public long length()
{
- return
templateValue.length();
+ return
Strings.lengthInBytes(getString(), getCharset());
}
};
}
@@ -160,7 +161,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