- * converts string from format: yyyy-mm-dd__hh:mm:ss.d
- * to dd.mm.yyyy hh:mm
- */
- public static String dateToReadableDate(String date) {
- StringBuffer returnDate = new StringBuffer();
- if (date!=null) {
-
- returnDate.append(date.substring(8,10)).append('.');
- returnDate.append(date.substring(5,7)).append('.');
- returnDate.append(date.substring(0,4)).append(' ');
- returnDate.append(date.substring(11,16));
- }
- return returnDate.toString();
- }
-
- /**
- * converts string from format: yyyy-mm-dd__hh:mm:ss.d
- * to yyyy
- */
- public static String dateToYear (String date) {
- StringBuffer returnDate = new StringBuffer();
- if (date!=null) {
-
- returnDate.append(date.substring(0,4));
- }
- return returnDate.toString();
- }
-
- /**
- * converts string from format: yyyy-mm-dd__hh:mm:ss.d
- * to [m]m
- */
- public static String dateToMonth (String date) {
- StringBuffer returnDate = new StringBuffer();
- if (date!=null) {
- if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
- else returnDate.append(date.substring(6,7));
- }
- return returnDate.toString();
- }
-
- /**
- * converts string from format: yyyy-mm-dd__hh:mm:ss.d
- * to [d]d
- */
- public static String dateToDayOfMonth (String date) {
- StringBuffer returnDate = new StringBuffer();
- if (date!=null) {
- if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
- else returnDate.append(date.substring(9,10));
- }
- return returnDate.toString();
- }
-
- /**
- * converts string from format: yyyy-mm-dd__hh:mm:ss.d
- * to hh:mm
- */
- public static String dateToTime (String date) {
- StringBuffer returnDate = new StringBuffer();
- if (date!=null) {
- returnDate.append(date.substring(11,16));
- }
- return returnDate.toString();
- }
-
- /**
- * Splits the provided CSV text into a list. stolen wholesale from
- * from Jakarta Turbine StrinUtils.java -mh
- *
- * @param text The CSV list of values to split apart.
- * @param separator The separator character.
- * @return The list of values.
- */
- public static String[] split(String text, String separator)
- {
- StringTokenizer st = new StringTokenizer(text, separator);
- String[] values = new String[st.countTokens()];
- int pos = 0;
- while (st.hasMoreTokens())
- {
- values[pos++] = st.nextToken();
- }
- return values;
- }
-
- /**
- * Joins the elements of the provided array into a single string
- * containing a list of CSV elements. Stolen wholesale from Jakarta
- * Turbine StringUtils.java. -mh
- *
- * @param list The list of values to join together.
- * @param separator The separator character.
- * @return The CSV text.
- */
- public static String join(String[] list, String separator)
- {
- StringBuffer csv = new StringBuffer();
- for (int i = 0; i < list.length; i++)
- {
- if (i > 0)
- {
- csv.append(separator);
- }
- csv.append(list[i]);
- }
- return csv.toString();
- }
-
- /**
- * Wandelet String in byte[] um.
- * @param s
- * @return byte[] des String
- */
-
- public static byte[] stringToBytes(String s) {
- String crlf = System.getProperty("line.separator");
- if (!crlf.equals("\n"))
- s = replace(s, "\n", crlf);
- // byte[] buf = new byte[s.length()];
- byte[] buf = s.getBytes();
- return buf;
- }
-
- /**
- * Ersetzt in String <code>s</code> das <code>pattern</code> durch <code>substitute</code>
- * @param s
- * @param pattern
- * @param substitute
- * @return String mit den Ersetzungen
- */
- public static String replace(String s, String pattern, String substitute) {
- int i = 0, pLen = pattern.length(), sLen = substitute.length();
- StringBuffer buf = new StringBuffer(s.length());
- while (true) {
- int j = s.indexOf(pattern, i);
- if (j < 0) {
- buf.append(s.substring(i));
- break;
- } else {
- buf.append(s.substring(i, j));
- buf.append(substitute);
- i = j+pLen;
- }
- }
- return buf.toString();
- }
-
- /**
- * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
- * @param s
- * @param pattern
- * @param substitute
- * @return String mit den Ersetzungen
- */
- public static String regexpReplace(String haystack, String pattern, String substitute) {
- try {
- RE regex = new RE(pattern);
- return regex.substituteAll(haystack,substitute);
- } catch(REException ex){
- return null;
- }
- }
-
-
-
-
- /**
- * Fügt einen Separator an den Pfad an
- * @param path
- * @return Pfad mit Separator am Ende
- */
- public static final String addSeparator (String path) {
- return path.length() == 0 || path.endsWith(File.separator) ? path : path
- + File.separatorChar;
- }
-
- /**
- * Fügt ein <code>/</code> ans ende des Strings and
- * @param path
- * @return Pfad mit <code>/</code> am Ende
- */
- public static final String addSlash (String path) {
- return path.length() == 0 || path.endsWith("/") ? path : path + '/';
- }
-
- /**
- * Löscht <code>/</code> am Ende des Strings, falls vorhanden