You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2005/01/29 11:04:25 UTC
cvs commit: incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/util UnicodeEncoder.java
matzew 2005/01/29 02:04:25
Modified: src/myfaces/org/apache/myfaces/renderkit/html
HtmlResponseWriterImpl.java
Added: src/myfaces/org/apache/myfaces/renderkit/html/util
UnicodeEncoder.java
Log:
MYFACES-91 patch by Jason Hoo. Thanks
Revision Changes Path
1.34 +16 -8 incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java
Index: HtmlResponseWriterImpl.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/HtmlResponseWriterImpl.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- HtmlResponseWriterImpl.java 19 Jan 2005 13:18:04 -0000 1.33
+++ HtmlResponseWriterImpl.java 29 Jan 2005 10:04:25 -0000 1.34
@@ -20,6 +20,7 @@
import org.apache.myfaces.renderkit.html.util.DummyFormUtils;
import org.apache.myfaces.renderkit.html.util.HTMLEncoder;
import org.apache.myfaces.renderkit.html.util.JavascriptUtils;
+import org.apache.myfaces.renderkit.html.util.UnicodeEncoder;
import org.apache.myfaces.renderkit.RendererUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,6 +38,9 @@
* @author Anton Koinov
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.34 2005/01/29 10:04:25 matzew
+ * MYFACES-91 patch by Jason Hoo. Thanks
+ *
* Revision 1.33 2005/01/19 13:18:04 mmarinschek
* better logging of component information
*
@@ -395,7 +399,7 @@
if (isScriptOrStyle())
{
- _writer.write(strValue);
+ _writer.write(UnicodeEncoder.encode(strValue, false, false));
}
else
{
@@ -418,7 +422,8 @@
if (isScriptOrStyle())
{
- _writer.write(cbuf, off, len);
+ String strValue = new String(cbuf, off, len);
+ _writer.write(UnicodeEncoder.encode(strValue, false, false));
}
else if (isTextarea())
{
@@ -475,7 +480,8 @@
public void write(char cbuf[], int off, int len) throws IOException
{
closeStartTagIfNecessary();
- _writer.write(cbuf, off, len);
+ String strValue = new String(cbuf, off, len);
+ _writer.write(UnicodeEncoder.encode(strValue, false, false));
}
public void write(int c) throws IOException
@@ -487,7 +493,8 @@
public void write(char cbuf[]) throws IOException
{
closeStartTagIfNecessary();
- _writer.write(cbuf);
+ String strValue = new String(cbuf);
+ _writer.write(UnicodeEncoder.encode(strValue, false, false));
}
public void write(String str) throws IOException
@@ -497,14 +504,15 @@
// in such case, do not call down the writer chain
if (str.length() > 0)
{
- _writer.write(str);
+ _writer.write(UnicodeEncoder.encode(str, false, false));
}
}
public void write(String str, int off, int len) throws IOException
{
closeStartTagIfNecessary();
- _writer.write(str, off, len);
+ String strValue = str.substring(off, len);
+ _writer.write(UnicodeEncoder.encode(strValue, false, false));
}
// DummyFormResponseWriter support
1.1 incubator-myfaces/src/myfaces/org/apache/myfaces/renderkit/html/util/UnicodeEncoder.java
Index: UnicodeEncoder.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.myfaces.renderkit.html.util;
/**
* Converts Strings so that they can be used within HTML-Code.
*/
public abstract class UnicodeEncoder
{
/**
* Variant of {@link #encode} where encodeNewline is false and encodeNbsp is true.
*/
public static String encode (String string)
{
return encode(string, false, true);
}
/**
* Variant of {@link #encode} where encodeNbsp is true.
*/
public static String encode (String string, boolean encodeNewline)
{
return encode(string, encodeNewline, true);
}
/**
* Encodes the given string, so that it can be used within a html page.
* @param string the string to convert
* @param encodeNewline if true newline characters are converted to <br>'s
* @param encodeSubsequentBlanksToNbsp if true subsequent blanks are converted to &nbsp;'s
*/
public static String encode (String string,
boolean encodeNewline,
boolean encodeSubsequentBlanksToNbsp)
{
if (string == null)
{
return "";
}
StringBuffer sb = new StringBuffer(); //create later on demand
char c;
for (int i = 0; i < string.length (); ++i)
{
c = string.charAt(i);
if (((int)c) >= 0x80)
{
//encode all non basic latin characters
sb.append("&#" + ((int)c) + ";");
}
else
{
sb.append(c);
}
}
return sb.toString();
}
}