1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ch.oscg.jreleaseinfo;
20
21
22 /***
23 * Utility class for JReleaseInfoAntTask task. All methods are defined static so
24 * they can be called without creating an instance.
25 *
26 * @author Thomas Cotting, Tangarena Engineering AG, Luzern
27 * @version $Revision: 1.4 $ ($Date: 2005/08/06 14:12:36 $ / $Author: tcotting $)
28 */
29 public class JReleaseInfoUtil {
30 /***
31 * Utility method to append slash to pathelement.
32 *
33 * @param pathElement which should be checked
34 *
35 * @return the processed pathelement
36 */
37 public static String getPathElement(String pathElement) {
38 if (pathElement == null) {
39 return "";
40 } else if (pathElement == "") {
41 return "";
42 } else if (pathElement.endsWith("/")) {
43 return pathElement;
44 } else if (pathElement.endsWith("//")) {
45 return pathElement;
46 } else {
47 return pathElement + '/';
48 }
49 }
50
51 /***
52 * Utility method to change the first letter of a string to uppercase.
53 *
54 * @param str String to process
55 *
56 * @return str where first letter is uppercase
57 */
58 public static String upperCaseFirstLetter(String str) {
59 if ((str == null) || (str.length() == 0)) {
60 return str;
61 } else if (str.length() == 1) {
62 return str.toUpperCase();
63 } else {
64
65 return str.substring(0, 1).toUpperCase() + str.substring(1);
66 }
67 }
68
69 /***
70 * Utility method to change the first letter of a string to lowercase.
71 *
72 * @param str String to process
73 *
74 * @return str where first letter is lowercase
75 */
76 public static String lowerCaseFirstLetter(String str) {
77 if ((str == null) || (str.length() == 0)) {
78 return str;
79 } else if (str.length() == 1) {
80 return str.toLowerCase();
81 } else {
82
83 return str.substring(0, 1).toLowerCase() + str.substring(1);
84 }
85 }
86
87 /***
88 * Utility method to check if a String value is a valid boolean value.
89 *
90 * @param val String value expressing a boolean
91 *
92 * @return true if val==true|TRUE|True...
93 */
94 public static boolean checkIsBoolean(String val) {
95 return (val.equalsIgnoreCase("TRUE") || val.equalsIgnoreCase("FALSE"));
96 }
97
98 /***
99 * Utility method to check the validity of string for name. Note: Only some
100 * common mistakes are checked.
101 *
102 * @param name String to check
103 *
104 * @return true when not null and not empty
105 */
106 public static boolean isValidNameString(String name) {
107 return ((name != null) && (name != ""));
108 }
109
110 /***
111 * Utility method to check the validity of string for a class name. Note:
112 * Only some common mistakes are checked.
113 *
114 * @param name String to check
115 *
116 * @return true when valid name string and no dot
117 */
118 public static boolean isValidClassNameString(String name) {
119 return (isValidNameString(name) && (name.indexOf(".") == -1));
120 }
121
122 /***
123 * Utility method to check the validity of string for a package name. Note:
124 * Only some common mistakes are checked.
125 *
126 * @param name String to check (empty string is allowed)
127 *
128 * @return true/false
129 */
130 public static boolean isValidPackageNameString(String name) {
131 return (name == null) ||
132 ((name != "") && (name.indexOf("/") == -1) && (name.indexOf("//") == -1) &&
133 ((name.indexOf(".") == -1) ||
134 ((name.indexOf(".") != 0) && (name.indexOf(".") != (name.length() - 1)))));
135 }
136 }