01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE 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 Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.util.basicapp.helper;
21:
22: import java.io.File;
23:
24: import org.apache.log4j.Logger;
25:
26: /**
27: * Just some utilities for e.g. formatting Strings and
28: * Integers
29: *
30: * @author <a href="mailto:rapude@schlund.de">Ralf Rapude</a>
31: * @version $Id: StringUtils.java 3302 2007-11-30 16:56:16Z jenstl $
32: */
33:
34: public class StringUtils {
35:
36: private static final Logger LOG = Logger
37: .getLogger(StringUtils.class);
38:
39: /**
40: * Checking projectname and language for a valid String.
41: * @return an empty String or the input given to the method
42: * if it is valid
43: */
44: public static String checkString(String input) {
45: String emptyString = "";
46: LOG.debug("Checking the String: " + input);
47:
48: if (input == null || input.length() == 0) {
49: LOG.debug("String is not ok");
50: return emptyString;
51: } else {
52: LOG.debug("String is ok");
53: }
54:
55: return input;
56: }
57:
58: /**
59: * Some basic operations to avoid problems with
60: * not allowed characters
61: * @param The String given by the user
62: * @return The input as a usable String
63: */
64: public static String giveCorrectString(String input) {
65: input.toLowerCase();
66:
67: input = input.replaceAll("ä", "ae");
68: input = input.replaceAll("ü", "ue");
69: input = input.replaceAll("ö", "oe");
70: input = input.replaceAll(" ", "_");
71: input = input.trim();
72:
73: return input;
74: }
75:
76: /**
77: * Check whether the project already exists
78: * @return true if the project exists
79: */
80: public static boolean checkExistingProject(String input) {
81: String[] projectNames = new File(AppValues.BASICPATH).list();
82: boolean exists = false;
83: String tmpName = null;
84:
85: for (int i = 0; i < projectNames.length; i++) {
86: tmpName = projectNames[i];
87:
88: if (tmpName.equals(input)) {
89: exists = true;
90: }
91: }
92:
93: return exists;
94: }
95: }
|