KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > functions > StringFunctions


1 /*
2  * Copyright 2005 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.taglib.core.functions;
17
18 /**
19  * <p>Contains set of functions to ease the work with strings on the JSP</p>
20  * <p><a HREF="StringFunctions.java.htm"><i>View source</i></a></p>
21  *
22  * @author Roman Puchkovskiy <a HREF="mailto:roman.puchkovskiy@blandware.com">
23  * &lt;roman.puchkovskiy@blandware.com&gt;</a>
24  * @version $Revision: 1.1 $ $Date: 2006/03/07 07:26:05 $
25  */

26 public class StringFunctions {
27     /**
28      * Escapes double-quote symbols with backslash
29      *
30      * @param o object which string representation will be taken
31      * @return string where all double-quotes are escaped with a backslash
32      */

33     public static String JavaDoc escapeDoubleQuotesForJs(Object JavaDoc o) {
34         String JavaDoc str = "";
35         if (o != null) {
36             str = o.toString();
37         }
38         return str.replaceAll("\\\"", "\\\\\"");
39     }
40
41     /**
42      * Replaces all carriage returns with spaces
43      *
44      * @param o object which string representation will be taken
45      * @return string without carriage returns
46      */

47     public static String JavaDoc asSingleLine(Object JavaDoc o) {
48         String JavaDoc str = "";
49         if (o != null) {
50             str = o.toString();
51         }
52         return str.replaceAll("\\r|\\n", " ");
53     }
54 }
55
Popular Tags