01: package com.xoetrope.sql;
02:
03: /**
04: * String utilities for use with SQL queries
05: *
06: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
07: * the GNU Public License (GPL), please see license.txt for more details. If
08: * you make commercial use of this software you must purchase a commercial
09: * license from Xoetrope.</p>
10: * <p> $Revision: 1.4 $</p>
11: */
12: public class StringUtilities {
13: /**
14: * Check to see if a string is null or blank
15: * @return true if the string is null or zero length, otherwise false is rturned
16: * @param s the stringto check
17: */
18: public static boolean isBlankOrNull(String s) {
19: if (s == null)
20: return true;
21: else if (s.compareTo("") == 0)
22: return true;
23: else
24: return false;
25: }
26:
27: /**
28: * Return a blank/empty if the argument is null
29: * @param s the string to check
30: * @return the string or a blank
31: */
32: public static String getBlankString(String s) {
33: if (s == null)
34: return "";
35: else
36: return s;
37: }
38:
39: /**
40: * Escape special characters in preparation for use in SQL statements
41: * @param s the string to check
42: * @return the escaped string
43: */
44: public static String escape(String s) {
45: int pos = s.indexOf("'");
46: String x = s;
47: while (pos >= 0) {
48: x = s.substring(0, pos) + "\"" + s.substring(pos + 1);
49: s = x;
50: pos = s.indexOf("'");
51: }
52:
53: return x;
54: }
55: }
|