Author: nbelaevski
Date: 2007-06-11 13:17:50 -0400 (Mon, 11 Jun 2007)
New Revision: 1124
Added:
trunk/richfaces/common/src/main/java/org/richfaces/org/
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/lang/
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java
Removed:
trunk/richfaces/drag-drop/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java
Log:
StringEscapeUtils.java moved to common
Added:
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java
===================================================================
---
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java
(rev 0)
+++
trunk/richfaces/common/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java 2007-06-11
17:17:50 UTC (rev 1124)
@@ -0,0 +1,219 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces 3.0 - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.richfaces.org.apache.commons.lang;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * <p>Escapes and unescapes <code>String</code>s for
+ * Java, Java Script, HTML, XML, and SQL.</p>
+ *
+ * @author Apache Jakarta Turbine
+ * @author GenerationJavaCore library
+ * @author Purple Technology
+ * @author <a href="mailto:bayard@generationjava.com">Henri
Yandell</a>
+ * @author <a href="mailto:alex@purpletech.com">Alexander Day
Chaffee</a>
+ * @author Antony Riley
+ * @author Helge Tesgaard
+ * @author <a href="sean(a)boohai.com">Sean Brown</a>
+ * @author <a href="mailto:ggregory@seagullsw.com">Gary
Gregory</a>
+ * @author Phil Steitz
+ * @author Pete Gieser
+ * @since 2.0
+ * @version $Id: StringEscapeUtils.java,v 1.1 2007/02/09 19:37:06 nick_belaevski Exp $
+ */
+public class StringEscapeUtils {
+
+ /**
+ * <p>Escapes the characters in a <code>String</code> using
JavaScript String rules.</p>
+ * <p>Escapes any values it finds into their JavaScript String form.
+ * Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
</p>
+ *
+ * <p>So a tab becomes the characters <code>'\\'</code>
and
+ * <code>'t'</code>.</p>
+ *
+ * <p>The only difference between Java strings and JavaScript strings
+ * is that in JavaScript, a single quote must be escaped.</p>
+ *
+ * <p>Example:
+ * <pre>
+ * input string: He didn't say, "Stop!"
+ * output string: He didn\'t say, \"Stop!\"
+ * </pre>
+ * </p>
+ *
+ * @param str String to escape values in, may be null
+ * @return String with escaped values, <code>null</code> if null string
input
+ */
+ public static String escapeJavaScript(String str) {
+ return escapeJavaStyleString(str, true);
+ }
+
+ /**
+ * <p>Escapes the characters in a <code>String</code> using
JavaScript String rules
+ * to a <code>Writer</code>.</p>
+ *
+ * <p>A <code>null</code> string input has no effect.</p>
+ *
+ * @see #escapeJavaScript(java.lang.String)
+ * @param out Writer to write escaped string into
+ * @param str String to escape values in, may be null
+ * @throws IllegalArgumentException if the Writer is <code>null</code>
+ * @throws IOException if error occurs on underlying Writer
+ **/
+ public static void escapeJavaScript(Writer out, String str) throws IOException {
+ escapeJavaStyleString(out, str, true);
+ }
+
+ /**
+ * <p>Worker method for the {@link #escapeJavaScript(String)}
method.</p>
+ *
+ * @param str String to escape values in, may be null
+ * @param escapeSingleQuotes escapes single quotes if <code>true</code>
+ * @return the escaped string
+ */
+ private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes)
{
+ if (str == null) {
+ return null;
+ }
+ try {
+ StringWriter writer = new StringWriter(str.length() * 2);
+ escapeJavaStyleString(writer, str, escapeSingleQuotes);
+ return writer.toString();
+ } catch (IOException ioe) {
+ // this should never ever happen while writing to a StringWriter
+ ioe.printStackTrace();
+ return null;
+ }
+ }
+
+ /**
+ * <p>Worker method for the {@link #escapeJavaScript(String)}
method.</p>
+ *
+ * @param out write to receieve the escaped string
+ * @param str String to escape values in, may be null
+ * @param escapeSingleQuote escapes single quotes if <code>true</code>
+ * @throws IOException if an IOException occurs
+ */
+ private static void escapeJavaStyleString(Writer out, String str, boolean
escapeSingleQuote) throws IOException {
+ if (out == null) {
+ throw new IllegalArgumentException("The Writer must not be null");
+ }
+ if (str == null) {
+ return;
+ }
+ int sz;
+ sz = str.length();
+ for (int i = 0; i < sz; i++) {
+ char ch = str.charAt(i);
+
+ // handle unicode
+ if (ch > 0xfff) {
+ out.write("\\u" + hex(ch));
+ } else if (ch > 0xff) {
+ out.write("\\u0" + hex(ch));
+ } else if (ch > 0x7f) {
+ out.write("\\u00" + hex(ch));
+ } else if (ch < 32) {
+ switch (ch) {
+ case '\b':
+ out.write('\\');
+ out.write('b');
+ break;
+ case '\n':
+ out.write('\\');
+ out.write('n');
+ break;
+ case '\t':
+ out.write('\\');
+ out.write('t');
+ break;
+ case '\f':
+ out.write('\\');
+ out.write('f');
+ break;
+ case '\r':
+ out.write('\\');
+ out.write('r');
+ break;
+ default :
+ if (ch > 0xf) {
+ out.write("\\u00" + hex(ch));
+ } else {
+ out.write("\\u000" + hex(ch));
+ }
+ break;
+ }
+ } else {
+ switch (ch) {
+ case '\'':
+ if (escapeSingleQuote) {
+ out.write('\\');
+ }
+ out.write('\'');
+ break;
+ case '"':
+ out.write('\\');
+ out.write('"');
+ break;
+ case '\\':
+ out.write('\\');
+ out.write('\\');
+ break;
+ default :
+ out.write(ch);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * <p>Returns an upper case hexadecimal <code>String</code> for the
given
+ * character.</p>
+ *
+ * @param ch The character to convert.
+ * @return An upper case hexadecimal <code>String</code>
+ */
+ private static String hex(char ch) {
+ return Integer.toHexString(ch).toUpperCase();
+ }
+
+}
Deleted:
trunk/richfaces/drag-drop/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java
===================================================================
---
trunk/richfaces/drag-drop/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java 2007-06-11
16:35:39 UTC (rev 1123)
+++
trunk/richfaces/drag-drop/src/main/java/org/richfaces/org/apache/commons/lang/StringEscapeUtils.java 2007-06-11
17:17:50 UTC (rev 1124)
@@ -1,219 +0,0 @@
-/**
- * License Agreement.
- *
- * JBoss RichFaces 3.0 - Ajax4jsf Component Library
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.richfaces.org.apache.commons.lang;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * <p>Escapes and unescapes <code>String</code>s for
- * Java, Java Script, HTML, XML, and SQL.</p>
- *
- * @author Apache Jakarta Turbine
- * @author GenerationJavaCore library
- * @author Purple Technology
- * @author <a href="mailto:bayard@generationjava.com">Henri
Yandell</a>
- * @author <a href="mailto:alex@purpletech.com">Alexander Day
Chaffee</a>
- * @author Antony Riley
- * @author Helge Tesgaard
- * @author <a href="sean(a)boohai.com">Sean Brown</a>
- * @author <a href="mailto:ggregory@seagullsw.com">Gary
Gregory</a>
- * @author Phil Steitz
- * @author Pete Gieser
- * @since 2.0
- * @version $Id: StringEscapeUtils.java,v 1.1 2007/02/09 19:37:06 nick_belaevski Exp $
- */
-public class StringEscapeUtils {
-
- /**
- * <p>Escapes the characters in a <code>String</code> using
JavaScript String rules.</p>
- * <p>Escapes any values it finds into their JavaScript String form.
- * Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
</p>
- *
- * <p>So a tab becomes the characters <code>'\\'</code>
and
- * <code>'t'</code>.</p>
- *
- * <p>The only difference between Java strings and JavaScript strings
- * is that in JavaScript, a single quote must be escaped.</p>
- *
- * <p>Example:
- * <pre>
- * input string: He didn't say, "Stop!"
- * output string: He didn\'t say, \"Stop!\"
- * </pre>
- * </p>
- *
- * @param str String to escape values in, may be null
- * @return String with escaped values, <code>null</code> if null string
input
- */
- public static String escapeJavaScript(String str) {
- return escapeJavaStyleString(str, true);
- }
-
- /**
- * <p>Escapes the characters in a <code>String</code> using
JavaScript String rules
- * to a <code>Writer</code>.</p>
- *
- * <p>A <code>null</code> string input has no effect.</p>
- *
- * @see #escapeJavaScript(java.lang.String)
- * @param out Writer to write escaped string into
- * @param str String to escape values in, may be null
- * @throws IllegalArgumentException if the Writer is <code>null</code>
- * @throws IOException if error occurs on underlying Writer
- **/
- public static void escapeJavaScript(Writer out, String str) throws IOException {
- escapeJavaStyleString(out, str, true);
- }
-
- /**
- * <p>Worker method for the {@link #escapeJavaScript(String)}
method.</p>
- *
- * @param str String to escape values in, may be null
- * @param escapeSingleQuotes escapes single quotes if <code>true</code>
- * @return the escaped string
- */
- private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes)
{
- if (str == null) {
- return null;
- }
- try {
- StringWriter writer = new StringWriter(str.length() * 2);
- escapeJavaStyleString(writer, str, escapeSingleQuotes);
- return writer.toString();
- } catch (IOException ioe) {
- // this should never ever happen while writing to a StringWriter
- ioe.printStackTrace();
- return null;
- }
- }
-
- /**
- * <p>Worker method for the {@link #escapeJavaScript(String)}
method.</p>
- *
- * @param out write to receieve the escaped string
- * @param str String to escape values in, may be null
- * @param escapeSingleQuote escapes single quotes if <code>true</code>
- * @throws IOException if an IOException occurs
- */
- private static void escapeJavaStyleString(Writer out, String str, boolean
escapeSingleQuote) throws IOException {
- if (out == null) {
- throw new IllegalArgumentException("The Writer must not be null");
- }
- if (str == null) {
- return;
- }
- int sz;
- sz = str.length();
- for (int i = 0; i < sz; i++) {
- char ch = str.charAt(i);
-
- // handle unicode
- if (ch > 0xfff) {
- out.write("\\u" + hex(ch));
- } else if (ch > 0xff) {
- out.write("\\u0" + hex(ch));
- } else if (ch > 0x7f) {
- out.write("\\u00" + hex(ch));
- } else if (ch < 32) {
- switch (ch) {
- case '\b':
- out.write('\\');
- out.write('b');
- break;
- case '\n':
- out.write('\\');
- out.write('n');
- break;
- case '\t':
- out.write('\\');
- out.write('t');
- break;
- case '\f':
- out.write('\\');
- out.write('f');
- break;
- case '\r':
- out.write('\\');
- out.write('r');
- break;
- default :
- if (ch > 0xf) {
- out.write("\\u00" + hex(ch));
- } else {
- out.write("\\u000" + hex(ch));
- }
- break;
- }
- } else {
- switch (ch) {
- case '\'':
- if (escapeSingleQuote) {
- out.write('\\');
- }
- out.write('\'');
- break;
- case '"':
- out.write('\\');
- out.write('"');
- break;
- case '\\':
- out.write('\\');
- out.write('\\');
- break;
- default :
- out.write(ch);
- break;
- }
- }
- }
- }
-
- /**
- * <p>Returns an upper case hexadecimal <code>String</code> for the
given
- * character.</p>
- *
- * @param ch The character to convert.
- * @return An upper case hexadecimal <code>String</code>
- */
- private static String hex(char ch) {
- return Integer.toHexString(ch).toUpperCase();
- }
-
-}