KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > common > StringTools


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.syncclient.common;
19
20 /**
21  * Utility class that groups string manipulation functions.
22  *
23  * @author Stefano Fornari
24  * @version $Id: StringTools.java,v 1.2 2005/01/19 10:58:31 fabius Exp $
25  */

26 public class StringTools {
27
28     /**
29      * <p>Escapes the characters in a <code>String</code> using XML entities.</p>
30      *
31      *
32      * <p>Supports only the four basic XML entities (gt, lt, quot, amp).
33      * Does not support DTDs or external entities.</p>
34      *
35      * @param str the <code>String</code> to escape, may be null
36      * @return a new escaped <code>String</code>, <code>null</code> if null string input
37      * @see #unescapeXml(java.lang.String)
38      **/

39     public static String JavaDoc escapeXml(String JavaDoc str) {
40         if (str == null) {
41             return null;
42         }
43         return Entities.XML.escape(str);
44     }
45
46     /**
47      * <p>Unescapes a string containing XML entity escapes to a string
48      * containing the actual Unicode characters corresponding to the
49      * escapes.</p>
50      *
51      * <p>Supports only the four basic XML entities (gt, lt, quot, amp).
52      * Does not support DTDs or external entities.</p>
53      *
54      * @param str the <code>String</code> to unescape, may be null
55      * @return a new unescaped <code>String</code>, <code>null</code> if null string input
56      * @see #escapeXml(String)
57      **/

58     public static String JavaDoc unescapeXml(String JavaDoc str) {
59         if (str == null) {
60             return null;
61         }
62         return Entities.XML.unescape(str);
63     }
64
65
66 }
Popular Tags