1 | /* |
2 | * Copyright 2005-2006 The RbUtils Project |
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 | */ |
17 | |
18 | // $Id: StringTools.java,v 1.1 2006/08/24 21:31:48 redfish Exp $ |
19 | |
20 | package org.ktc.rbutils.api; |
21 | |
22 | import org.apache.commons.lang.StringEscapeUtils; |
23 | import org.apache.commons.lang.StringUtils; |
24 | |
25 | /** |
26 | * Provides String utilities for escaping characters. |
27 | * @since RbUtils 0.4 |
28 | * @version $Revision: 1.1 $ |
29 | * @author redfish |
30 | */ |
31 | public class StringTools extends StringEscapeUtils { |
32 | /** The html space character. */ |
33 | public static final String HTML_NBSP = " "; |
34 | |
35 | /** |
36 | * Dummy constructor. This must not be instanciated. |
37 | */ |
38 | protected StringTools() { |
39 | // prevents calls from subclass |
40 | throw new UnsupportedOperationException(); |
41 | } |
42 | |
43 | /** |
44 | * Escapes characteres as super class except if the argument is null or the empty String; in |
45 | * this case, {@link #HTML_NBSP} is returned. |
46 | * <p> |
47 | * {@inheritDoc} |
48 | */ |
49 | public static String escapeHtml(final String aValue) { |
50 | final String escapedString; |
51 | if (aValue == null || StringUtils.EMPTY.equals(aValue)) { |
52 | escapedString = HTML_NBSP; |
53 | } |
54 | else { |
55 | escapedString = StringEscapeUtils.escapeHtml(aValue); |
56 | } |
57 | return escapedString; |
58 | } |
59 | |
60 | } |