From: idfx Date: Mon, 10 Sep 2001 21:59:10 +0000 (+0000) Subject: webdbdate2path was in format /yyyy/mm/dd/ should be in /yyyy/mm/ X-Git-Tag: prexmlproducerconfig~496 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=84722c0556b2100ebf0fd7e769cf89d3fb628ba8;p=mir.git webdbdate2path was in format /yyyy/mm/dd/ should be in /yyyy/mm/ --- diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 76a323b4..9bfb1520 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -18,107 +18,109 @@ import gnu.regexp.*; */ public final class StringUtil { - /** - * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd) - * @param theDate - * @return 8-ziffriger String (yyyymmdd) - */ - - public static final String date2webdbDate (GregorianCalendar theDate) { - StringBuffer webdbDate = new StringBuffer(); - webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); - webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); - webdbDate.append(pad2(theDate.get(Calendar.DATE))); - return webdbDate.toString(); - } - - /** - * wandelt Calendar in dd.mm.yyyy / hh.mm um - * @param theDate - * @return String mit (dd.mm.yyyy / hh.mm um) - */ - public static String date2readableDateTime (GregorianCalendar theDate) { - String readable = ""; - int hour; - readable += pad2(theDate.get(Calendar.DATE)); - readable += "." + pad2(theDate.get(Calendar.MONTH) + 1); - readable += "." + String.valueOf(theDate.get(Calendar.YEAR)); - hour = theDate.get(Calendar.HOUR); - if (theDate.get(Calendar.AM_PM) == Calendar.PM) - hour += 12; - readable += " / " + pad2(hour); - readable += ":" + pad2(theDate.get(Calendar.MINUTE)); - return readable; - } - - /** - * wandelt eine Datum in einen 8-buchstabigen String, der durch / - * getrennt ist. - * - * @param webdbDate - * @return String mit /yyyy/mm/dd - */ - public static final String webdbDate2path (String webdbDate) { - StringBuffer path = new StringBuffer(); - path.append("/").append(webdbDate.substring(0, 4)); - path.append("/").append(webdbDate.substring(4, 6)); - path.append("/").append(webdbDate.substring(6, 8)); - return path.toString(); - } - - /** - * wandelt Calendar in dd.mm.yyyy um - * - * @param theDate - * @return String mit dd.mm.yyyy - */ - public static final String webdbDate2readableDate (String webdbDate) { - String date = ""; - date += webdbDate.substring(6, 8); - date += "." + webdbDate.substring(4, 6); - date += "." + webdbDate.substring(0, 4); - return date; - } + /** + * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd) + * @param theDate + * @return 8-ziffriger String (yyyymmdd) + */ + + public static final String date2webdbDate (GregorianCalendar theDate) { + StringBuffer webdbDate = new StringBuffer(); + webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); + webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); + webdbDate.append(pad2(theDate.get(Calendar.DATE))); + return webdbDate.toString(); + } + + /** + * wandelt Calendar in dd.mm.yyyy / hh.mm um + * @param theDate + * @return String mit (dd.mm.yyyy / hh.mm um) + */ + public static String date2readableDateTime (GregorianCalendar theDate) { + String readable = ""; + int hour; + readable += pad2(theDate.get(Calendar.DATE)); + readable += "." + pad2(theDate.get(Calendar.MONTH) + 1); + readable += "." + String.valueOf(theDate.get(Calendar.YEAR)); + hour = theDate.get(Calendar.HOUR); + if (theDate.get(Calendar.AM_PM) == Calendar.PM) + hour += 12; + readable += " / " + pad2(hour); + readable += ":" + pad2(theDate.get(Calendar.MINUTE)); + return readable; + } + + /** + * wandelt eine Datum in einen 8-buchstabigen String, der durch / + * getrennt ist. + * + * @param webdbDate + * @return String mit /yyyy/mm/dd + */ + public static final String webdbDate2path (String webdbDate) { + StringBuffer path = new StringBuffer(); + path.append("/").append(webdbDate.substring(0, 4)); + path.append("/").append(webdbDate.substring(4, 6)); + path.append("/"); + //who did this? + //path.append("/").append(webdbDate.substring(6, 8)); + return path.toString(); + } + + /** + * wandelt Calendar in dd.mm.yyyy um + * + * @param theDate + * @return String mit dd.mm.yyyy + */ + public static final String webdbDate2readableDate (String webdbDate) { + String date = ""; + date += webdbDate.substring(6, 8); + date += "." + webdbDate.substring(4, 6); + date += "." + webdbDate.substring(0, 4); + return date; + } /** * 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(); - } - - - /** - * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält - * - * @return gequoteter String - */ - public static String quoteIfNecessary(String s) { - for (int i = 0; i < s.length(); i++) - if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.')) - return quote(s, '"'); - return s; - } - - /** - * schließt s in ' ein und setzt Backslashes vor - * "gefährliche" Zeichen innerhalb des Strings - * Quotes special SQL-characters in s - * - * @return geqoteter String - */ - public static String quote(String s) - { + 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(); + } + + + /** + * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält + * + * @return gequoteter String + */ + public static String quoteIfNecessary(String s) { + for (int i = 0; i < s.length(); i++) + if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.')) + return quote(s, '"'); + return s; + } + + /** + * schließt s in ' ein und setzt Backslashes vor + * "gefährliche" Zeichen innerhalb des Strings + * Quotes special SQL-characters in s + * + * @return geqoteter String + */ + public static String quote(String s) + { //String s2 = quote(s, '\''); //Quickhack @@ -135,383 +137,383 @@ public final class StringUtil { //Quickhack end s2 = quote(s2, '\"'); - return s2; - } - - /** - * schließt s in ' ein und setzt Backslashes vor - * "gefährliche" Zeichen innerhalb des Strings - * - * @param s String, der gequoted werden soll - * @param quoteChar zu quotendes Zeichen - * @return gequoteter String - */ - public static String quote(String s, char quoteChar) - { - StringBuffer buf = new StringBuffer(s.length()); - int pos = 0; - while (pos < s.length()) { - int i = s.indexOf(quoteChar, pos); - if (i < 0) i = s.length(); - buf.append(s.substring(pos, i)); - pos = i; - if (pos < s.length()) { - buf.append('\\'); - buf.append(quoteChar); - pos++; - } - } - return buf.toString(); - } - - /** - * ersetzt gefährliche zeichen in s - * - */ - - public static String unquote(String s) - { - char quoteChar='\''; - StringBuffer buf = new StringBuffer(s.length()); - int pos = 0; - String searchString = "\\"+quoteChar; - while (pos < s.length()) { - int i = s.indexOf(searchString, pos); - if (i < 0) i = s.length(); - buf.append(s.substring(pos, i)); - pos = i+1; - } - return buf.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); + return s2; + } + + /** + * schließt s in ' ein und setzt Backslashes vor + * "gefährliche" Zeichen innerhalb des Strings + * + * @param s String, der gequoted werden soll + * @param quoteChar zu quotendes Zeichen + * @return gequoteter String + */ + public static String quote(String s, char quoteChar) + { + StringBuffer buf = new StringBuffer(s.length()); + int pos = 0; + while (pos < s.length()) { + int i = s.indexOf(quoteChar, pos); + if (i < 0) i = s.length(); + buf.append(s.substring(pos, i)); + pos = i; + if (pos < s.length()) { + buf.append('\\'); + buf.append(quoteChar); + pos++; + } + } + return buf.toString(); + } + + /** + * ersetzt gefährliche zeichen in s + * + */ + + public static String unquote(String s) + { + char quoteChar='\''; + StringBuffer buf = new StringBuffer(s.length()); + int pos = 0; + String searchString = "\\"+quoteChar; + while (pos < s.length()) { + int i = s.indexOf(searchString, pos); + if (i < 0) i = s.length(); + buf.append(s.substring(pos, i)); + pos = i+1; + } + return buf.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 s das pattern durch substitute - * @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(); - } - - - /** - * 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 / ans ende des Strings and - * @param path - * @return Pfad mit / am Ende - */ - public static final String addSlash (String path) { - return path.length() == 0 || path.endsWith("/") ? path : path + '/'; - } - - /** - * Löscht / am Ende des Strings, falls vorhanden - * @param path - * @return String ohne / am Ende - */ - public static final String removeSlash (String path) { - return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length() - - 1) : path; - } - - /** - * Löscht Slash am Anfang des Strings - * @param path - * @return - */ - public static String removeFirstSlash (String path) { - return path.startsWith("/") ? path.substring(1) : path; - } - - /** - * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05) - * @return zwistellige Zahl - */ - public static String pad2 (int number) { - return number < 10 ? "0" + number : String.valueOf(number); - } - - /** - * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007) - * - * @return 3-stellige Zahl - */ - public static String pad3 (int number) { - return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number); - } - - /** - * Konvertiert Unix-Linefeeds in Win-Linefeeds - * @param s - * @return Konvertierter String - */ - public static String unixLineFeedsToWin(String s) { - int i = -1; - while (true) { - i = s.indexOf('\n', i+1); - if (i < 0) break; - if ((i == 0 || s.charAt(i-1) != '\r') && - (i == s.length()-1 || s.charAt(i+1) != '\r')) { - s = s.substring(0, i)+'\r'+s.substring(i); - i++; - } - } - return s; - } - - - /** - * verwandelt einen String in eine gültige Url, konvertiert Sonderzeichen - * und Spaces werden zu Underscores - * - * @return gültige Url - */ - public static String convert2url(String s) { - s = toLowerCase(s); - StringBuffer buf = new StringBuffer(); - for(int i = 0; i < s.length(); i++ ) { - switch( s.charAt( i ) ) { - case 'ö': - buf.append( "oe" ); break; - case 'ä': - buf.append( "ae" ); break; - case 'ü': - buf.append( "ue" ); break; - case 'ã': - buf.append( "a" ); break; - case '´': - case '.': - buf.append( "_" ); break; - case ' ': - if( buf.charAt( buf.length() - 1 ) != '_' ) { - buf.append( "_" ); - } - break; - default: - buf.append( s.charAt( i ) ); - } - } - return buf.toString(); - } - - /** - * wandelt Sonderzeichen in Quotes um - * - * @return Kovertierter String - */ - public static String encodeHtml(String s) { - StringBuffer buf = new StringBuffer(); - for(int i=0;i < s.length(); i++ ) { - - /** @todo looks inefficient */ - if (s.charAt(i)=='&') { - // convert html to xml-parsable representation - if( s.indexOf( "ö", i ) == i ) { - buf.append( "ö" ); i += 5; - continue; - } - if( s.indexOf( "ä", i ) == i ) { - buf.append( "ä" ); i += 5; - continue; - } - if( s.indexOf( "ü", i ) == i ) { - buf.append( "ü" ); i += 5; - continue; - } - if( s.indexOf( "Ö", i ) == i ) { - buf.append( "Ö" ); i += 5; - continue; - } - if( s.indexOf( "Ä", i ) == i ) { - buf.append( "Ä" ); i += 5; - continue; - } - if( s.indexOf( "Ü", i ) == i ) { - buf.append( "Ü" ); i += 5; - continue; - } - if( s.indexOf( "ß", i ) == i ) { - buf.append( "ß" ); i += 6; - continue; - } - - /** @todo should only escape outside of tags */ - - if( s.indexOf( """, i ) == i ) { - buf.append( "ß" ); i += 5; - continue; + return buf; + } + + /** + * Ersetzt in String s das pattern durch substitute + * @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(); + } + + + /** + * 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 / ans ende des Strings and + * @param path + * @return Pfad mit / am Ende + */ + public static final String addSlash (String path) { + return path.length() == 0 || path.endsWith("/") ? path : path + '/'; + } + + /** + * Löscht / am Ende des Strings, falls vorhanden + * @param path + * @return String ohne / am Ende + */ + public static final String removeSlash (String path) { + return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length() + - 1) : path; + } + + /** + * Löscht Slash am Anfang des Strings + * @param path + * @return + */ + public static String removeFirstSlash (String path) { + return path.startsWith("/") ? path.substring(1) : path; + } + + /** + * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05) + * @return zwistellige Zahl + */ + public static String pad2 (int number) { + return number < 10 ? "0" + number : String.valueOf(number); + } + + /** + * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007) + * + * @return 3-stellige Zahl + */ + public static String pad3 (int number) { + return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number); + } + + /** + * Konvertiert Unix-Linefeeds in Win-Linefeeds + * @param s + * @return Konvertierter String + */ + public static String unixLineFeedsToWin(String s) { + int i = -1; + while (true) { + i = s.indexOf('\n', i+1); + if (i < 0) break; + if ((i == 0 || s.charAt(i-1) != '\r') && + (i == s.length()-1 || s.charAt(i+1) != '\r')) { + s = s.substring(0, i)+'\r'+s.substring(i); + i++; + } + } + return s; + } + + + /** + * verwandelt einen String in eine gültige Url, konvertiert Sonderzeichen + * und Spaces werden zu Underscores + * + * @return gültige Url + */ + public static String convert2url(String s) { + s = toLowerCase(s); + StringBuffer buf = new StringBuffer(); + for(int i = 0; i < s.length(); i++ ) { + switch( s.charAt( i ) ) { + case 'ö': + buf.append( "oe" ); break; + case 'ä': + buf.append( "ae" ); break; + case 'ü': + buf.append( "ue" ); break; + case 'ã': + buf.append( "a" ); break; + case '´': + case '.': + buf.append( "_" ); break; + case ' ': + if( buf.charAt( buf.length() - 1 ) != '_' ) { + buf.append( "_" ); + } + break; + default: + buf.append( s.charAt( i ) ); } - if( s.indexOf( "–", i ) == i ) { - buf.append( "–" ); i += 6; - continue; + } + return buf.toString(); + } + + /** + * wandelt Sonderzeichen in Quotes um + * + * @return Kovertierter String + */ + public static String encodeHtml(String s) { + StringBuffer buf = new StringBuffer(); + for(int i=0;i < s.length(); i++ ) { + + /** @todo looks inefficient */ + if (s.charAt(i)=='&') { + // convert html to xml-parsable representation + if( s.indexOf( "ö", i ) == i ) { + buf.append( "ö" ); i += 5; + continue; + } + if( s.indexOf( "ä", i ) == i ) { + buf.append( "ä" ); i += 5; + continue; + } + if( s.indexOf( "ü", i ) == i ) { + buf.append( "ü" ); i += 5; + continue; + } + if( s.indexOf( "Ö", i ) == i ) { + buf.append( "Ö" ); i += 5; + continue; + } + if( s.indexOf( "Ä", i ) == i ) { + buf.append( "Ä" ); i += 5; + continue; + } + if( s.indexOf( "Ü", i ) == i ) { + buf.append( "Ü" ); i += 5; + continue; + } + if( s.indexOf( "ß", i ) == i ) { + buf.append( "ß" ); i += 6; + continue; + } + + /** @todo should only escape outside of tags */ + + if( s.indexOf( """, i ) == i ) { + buf.append( "ß" ); i += 5; + continue; + } + if( s.indexOf( "–", i ) == i ) { + buf.append( "–" ); i += 6; + continue; } if( s.indexOf( "—", i ) == i ) { - buf.append( "—" ); i += 6; - continue; + buf.append( "—" ); i += 6; + continue; } if( s.indexOf( "“", i ) == i ) { - buf.append( "“" ); i += 6; - continue; + buf.append( "“" ); i += 6; + continue; } if( s.indexOf( "”", i ) == i ) { - buf.append( "”" ); i += 6; - continue; + buf.append( "”" ); i += 6; + continue; } if( s.indexOf( "„", i ) == i ) { - buf.append( "„" ); i += 6; - continue; + buf.append( "„" ); i += 6; + continue; } //looks pretty stupid if( s.indexOf( "<", i ) == i ) { - buf.append( "<" ); i += 3; - continue; + buf.append( "<" ); i += 3; + continue; } if( s.indexOf( ">", i ) == i ) { - buf.append( ">" ); i += 3; - continue; + buf.append( ">" ); i += 3; + continue; } if( s.indexOf( "´", i ) == i ) { - buf.append( "´" ); i += 6; - continue; + buf.append( "´" ); i += 6; + continue; } if( s.indexOf( " ", i ) == i ) { - buf.append( " " ); i += 5; - continue; + buf.append( " " ); i += 5; + continue; } //has to be the last if( s.indexOf( "&", i ) == i ) { - buf.append( "&" ); i += 0; - continue; + buf.append( "&" ); i += 0; + continue; } - } - // convert umlauts an other special charakters - switch( s.charAt(i) ) { - case 'ö': buf.append( "ö" ); break; - case 'ä': buf.append( "ä" ); break; - case 'ü': buf.append( "ü" ); break; - case 'Ö': buf.append( "Ö" ); break; - case 'Ä': buf.append( "Ä" ); break; - case 'Ü': buf.append( "Ü" ); break; - case 'ß': buf.append( "ß" ); break; - case 'é': buf.append( "é" ); break; - case 'è': buf.append( "è" ); break; - case 'á': buf.append( "á" ); break; - case 'à': buf.append( "à" ); break; - case 'â': buf.append( "â" ); break; - case 'ã': buf.append( "ã" ); break; - case '¬': buf.append( "¬" ); break; - case '¹': buf.append( "¹" ); break; - case '²': buf.append( "²" ); break; - case '³': buf.append( "³" ); break; - case '¼': buf.append( "¼" ); break; - case '½': buf.append( "½" ); break; - case '¾': buf.append( "¾" ); break; - case '¶': buf.append( "¶" ); break; - case 'æ': buf.append( "æ" ); break; - case 'ð': buf.append( "ð" ); break; - case '|': buf.append( "¦" ); break; - case '·': buf.append( "·" ); break; - case '°': buf.append( "°" ); break; - case '§': buf.append( "§" ); break; - case 'ø': buf.append( "ø" ); break; - case 'ç': buf.append( "ç" ); break; - case '¤': buf.append( "¤" ); break; - case 'ª': buf.append( "ª" ); break; - case 'Ç': buf.append( "Ç" ); break; - case 'Ã': buf.append( "Ã" ); break; - case 'Â': buf.append( "Â" ); break; - case 'Æ': buf.append( "Æ" ); break; - case '©': buf.append( "©" ); break; - case '®': buf.append( "®" ); break; - case '¥': buf.append( "¥" ); break; - case 'Þ': buf.append( "þ" ); break; - case '¯': buf.append( "¯" ); break; - case 'Ð': buf.append( "Ð" ); break; - case 'º': buf.append( "º" ); break; - case '¡': buf.append( "¡" ); break; - case '£': buf.append( "£" ); break; - case '±': buf.append( "±" ); break; - case '¿': buf.append( "¿" ); break; - case 'Ø': buf.append( "Ø" ); break; - case 'Á': buf.append( "À" ); break; - case 'À': buf.append( "Á" ); break; - case 'É': buf.append( "È" ); break; - case 'È': buf.append( "É" ); break; - case 'ù': buf.append( "ú" ); break; - case 'ñ': buf.append( "ñ" ); break; - case 'Ñ': buf.append( "Ñ" ); break; - case 'µ': buf.append( "µ" ); break; - case 'Í': buf.append( "Ì" ); break; - case 'Ì': buf.append( "Í" ); break; - case 'í': buf.append( "ì" ); break; - case 'ì': buf.append( "í" ); break; - case 'î': buf.append( "î" ); break; - case 'Î': buf.append( "Î" ); break; - case 'ó': buf.append( "ó" ); break; - case 'Ó': buf.append( "Ò" ); break; - case 'ò': buf.append( "Î" ); break; - case 'Ò': buf.append( "Ó" ); break; - case 'ô': buf.append( "ô" ); break; - case 'Ô': buf.append( "Ô" ); break; - case 'õ': buf.append( "õ" ); break; - case 'Õ': buf.append( "Õ" ); break; - case 'ý': buf.append( "ý" ); break; - case 'Ý': buf.append( "Ý" ); break; - case 'û': buf.append( "û" ); break; - case 'Û': buf.append( "Û" ); break; - case 'ú': buf.append( "ù" ); break; - case 'Ú': buf.append( "Ù" ); break; - case 'Ù': buf.append( "Ú" ); break; - case 'Ê': buf.append( "Ê" ); break; - case 'ê': buf.append( "ê" ); break; - case 'å': buf.append( "å" ); break; - case 'Å': buf.append( "Å" ); break; - case 'ë': buf.append( "ë" ); break; - case 'Ë': buf.append( "Ë" ); break; - case 'ÿ': buf.append( "ÿ" ); break; - case 'ï': buf.append( "ï" ); break; - case 'Ï': buf.append( "Ï" ); break; - case '«': buf.append( "«" ); break; + } + // convert umlauts an other special charakters + switch( s.charAt(i) ) { + case 'ö': buf.append( "ö" ); break; + case 'ä': buf.append( "ä" ); break; + case 'ü': buf.append( "ü" ); break; + case 'Ö': buf.append( "Ö" ); break; + case 'Ä': buf.append( "Ä" ); break; + case 'Ü': buf.append( "Ü" ); break; + case 'ß': buf.append( "ß" ); break; + case 'é': buf.append( "é" ); break; + case 'è': buf.append( "è" ); break; + case 'á': buf.append( "á" ); break; + case 'à': buf.append( "à" ); break; + case 'â': buf.append( "â" ); break; + case 'ã': buf.append( "ã" ); break; + case '¬': buf.append( "¬" ); break; + case '¹': buf.append( "¹" ); break; + case '²': buf.append( "²" ); break; + case '³': buf.append( "³" ); break; + case '¼': buf.append( "¼" ); break; + case '½': buf.append( "½" ); break; + case '¾': buf.append( "¾" ); break; + case '¶': buf.append( "¶" ); break; + case 'æ': buf.append( "æ" ); break; + case 'ð': buf.append( "ð" ); break; + case '|': buf.append( "¦" ); break; + case '·': buf.append( "·" ); break; + case '°': buf.append( "°" ); break; + case '§': buf.append( "§" ); break; + case 'ø': buf.append( "ø" ); break; + case 'ç': buf.append( "ç" ); break; + case '¤': buf.append( "¤" ); break; + case 'ª': buf.append( "ª" ); break; + case 'Ç': buf.append( "Ç" ); break; + case 'Ã': buf.append( "Ã" ); break; + case 'Â': buf.append( "Â" ); break; + case 'Æ': buf.append( "Æ" ); break; + case '©': buf.append( "©" ); break; + case '®': buf.append( "®" ); break; + case '¥': buf.append( "¥" ); break; + case 'Þ': buf.append( "þ" ); break; + case '¯': buf.append( "¯" ); break; + case 'Ð': buf.append( "Ð" ); break; + case 'º': buf.append( "º" ); break; + case '¡': buf.append( "¡" ); break; + case '£': buf.append( "£" ); break; + case '±': buf.append( "±" ); break; + case '¿': buf.append( "¿" ); break; + case 'Ø': buf.append( "Ø" ); break; + case 'Á': buf.append( "À" ); break; + case 'À': buf.append( "Á" ); break; + case 'É': buf.append( "È" ); break; + case 'È': buf.append( "É" ); break; + case 'ù': buf.append( "ú" ); break; + case 'ñ': buf.append( "ñ" ); break; + case 'Ñ': buf.append( "Ñ" ); break; + case 'µ': buf.append( "µ" ); break; + case 'Í': buf.append( "Ì" ); break; + case 'Ì': buf.append( "Í" ); break; + case 'í': buf.append( "ì" ); break; + case 'ì': buf.append( "í" ); break; + case 'î': buf.append( "î" ); break; + case 'Î': buf.append( "Î" ); break; + case 'ó': buf.append( "ó" ); break; + case 'Ó': buf.append( "Ò" ); break; + case 'ò': buf.append( "Î" ); break; + case 'Ò': buf.append( "Ó" ); break; + case 'ô': buf.append( "ô" ); break; + case 'Ô': buf.append( "Ô" ); break; + case 'õ': buf.append( "õ" ); break; + case 'Õ': buf.append( "Õ" ); break; + case 'ý': buf.append( "ý" ); break; + case 'Ý': buf.append( "Ý" ); break; + case 'û': buf.append( "û" ); break; + case 'Û': buf.append( "Û" ); break; + case 'ú': buf.append( "ù" ); break; + case 'Ú': buf.append( "Ù" ); break; + case 'Ù': buf.append( "Ú" ); break; + case 'Ê': buf.append( "Ê" ); break; + case 'ê': buf.append( "ê" ); break; + case 'å': buf.append( "å" ); break; + case 'Å': buf.append( "Å" ); break; + case 'ë': buf.append( "ë" ); break; + case 'Ë': buf.append( "Ë" ); break; + case 'ÿ': buf.append( "ÿ" ); break; + case 'ï': buf.append( "ï" ); break; + case 'Ï': buf.append( "Ï" ); break; + case '«': buf.append( "«" ); break; case '»': buf.append( "»" ); break; case '\'': buf.append( "´" ); break; case '\"': buf.append( """ ); break; @@ -520,13 +522,13 @@ public final class StringUtil { //case '\u8220': buf.append( "“" ); break; //case '\u8221': buf.append( "”" ); break; //case '\u8222': buf.append( "„" ); break; - //case '\"': buf.append( """ ); break; - default: buf.append( s.charAt(i) ); - } + //case '\"': buf.append( """ ); break; + default: buf.append( s.charAt(i) ); + } - } - return buf.toString(); - } + } + return buf.toString(); + } public static String decodeHTMLinTags(String s){ @@ -572,144 +574,144 @@ public final class StringUtil { return buffer.toString(); } - /** wandelt Quotes in Sonderzeichen um - */ - /** - public static String decodeHtml(String s) { - StringBuffer buf = new StringBuffer(); - for(int i=0;i < s.length(); i++ ) { - if( s.indexOf( "ö", i ) == i ) { - buf.append( "ö" ); i += 5; - continue; - } - if( s.indexOf( "ä", i ) == i ) { - buf.append( "ä" ); i += 5; - continue; - } - if( s.indexOf( "ü", i ) == i ) { - buf.append( "ü" ); i += 5; - continue; - } - if( s.indexOf( "Ö", i ) == i ) { - buf.append( "Ö" ); i += 5; - continue; - } - if( s.indexOf( "Ä", i ) == i ) { - buf.append( "Ä" ); i += 5; - continue; - } - if( s.indexOf( "Ü", i ) == i ) { - buf.append( "Ü" ); i += 5; - continue; - } - if( s.indexOf( "ß", i ) == i ) { - buf.append( "ß" ); i += 6; - continue; - } + /** wandelt Quotes in Sonderzeichen um + */ + /** + public static String decodeHtml(String s) { + StringBuffer buf = new StringBuffer(); + for(int i=0;i < s.length(); i++ ) { + if( s.indexOf( "ö", i ) == i ) { + buf.append( "ö" ); i += 5; + continue; + } + if( s.indexOf( "ä", i ) == i ) { + buf.append( "ä" ); i += 5; + continue; + } + if( s.indexOf( "ü", i ) == i ) { + buf.append( "ü" ); i += 5; + continue; + } + if( s.indexOf( "Ö", i ) == i ) { + buf.append( "Ö" ); i += 5; + continue; + } + if( s.indexOf( "Ä", i ) == i ) { + buf.append( "Ä" ); i += 5; + continue; + } + if( s.indexOf( "Ü", i ) == i ) { + buf.append( "Ü" ); i += 5; + continue; + } + if( s.indexOf( "ß", i ) == i ) { + buf.append( "ß" ); i += 6; + continue; + } if( s.indexOf( """, i ) == i ) { - buf.append( "\"" ); i += 5; - continue; - } - buf.append( s.charAt(i) ); - } - return buf.toString(); - } - */ - - /** - * schnellere Variante der String.toLowerCase()-Routine - * - * @return String in Kleinbuchsten - */ - public static String toLowerCase(String s) { - int l = s.length(); - char[] a = new char[l]; - for (int i = 0; i < l; i++) - a[i] = Character.toLowerCase(s.charAt(i)); - return new String(a); - } - - /** - * Findet element im String-Array array - * @param array - * @param element - * @return Fundstelle als int oder -1 - */ - public static int indexOf(String[] array, String element) { - if (array != null) - for (int i = 0; i < array.length; i++) - if (array[i].equals(element)) - return i; - return -1; - } - - /** - * Testet auf Vorkommen von element in array - * @param array String-Array - * @param element - * @return true wenn element vorkommt, sonst false - */ - public static boolean contains(String[] array, String element) { - return indexOf(array, element) >= 0; - } - - /** - * Ermittelt CRC-Prüfsumme von String s - * @param s - * @return CRC-Prüfsumme - */ + buf.append( "\"" ); i += 5; + continue; + } + buf.append( s.charAt(i) ); + } + return buf.toString(); + } + */ + + /** + * schnellere Variante der String.toLowerCase()-Routine + * + * @return String in Kleinbuchsten + */ + public static String toLowerCase(String s) { + int l = s.length(); + char[] a = new char[l]; + for (int i = 0; i < l; i++) + a[i] = Character.toLowerCase(s.charAt(i)); + return new String(a); + } + + /** + * Findet element im String-Array array + * @param array + * @param element + * @return Fundstelle als int oder -1 + */ + public static int indexOf(String[] array, String element) { + if (array != null) + for (int i = 0; i < array.length; i++) + if (array[i].equals(element)) + return i; + return -1; + } + + /** + * Testet auf Vorkommen von element in array + * @param array String-Array + * @param element + * @return true wenn element vorkommt, sonst false + */ + public static boolean contains(String[] array, String element) { + return indexOf(array, element) >= 0; + } + + /** + * Ermittelt CRC-Prüfsumme von String s + * @param s + * @return CRC-Prüfsumme + */ public static int getCRC(String s) { - int h = 0; - char val[] = s.toCharArray(); - int len = val.length; - - for (int i = 0 ; i < len; i++) { - h &= 0x7fffffff; - h = (((h >> 30) | (h << 1)) ^ (val[i]+i)); - } - - return (h << 8) | (len & 0xff); - } - - /** - * Liefert Default-Wert def zurück, wenn String s - * kein Integer ist. - * - * @param s - * @param def - * @return geparster int aus s oder def - */ - public static int parseInt(String s, int def) { - if (s == null) return def; - try { - return Integer.parseInt(s); - } catch (NumberFormatException e) { - return def; - } - } - - /** - * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann. - * @param s - * @param def - * @return geparster float oder def - */ - public static float parseFloat(String s, float def) { - if (s == null) return def; - try { - return new Float(s).floatValue(); - } catch (NumberFormatException e) { - return def; - } - } - - /** - * Findet Ende eines Satzes in String text - * @param text - * @param startIndex - * @return index des Satzendes, oder -1 - */ - public static int findEndOfSentence(String text, int startIndex) { + int h = 0; + char val[] = s.toCharArray(); + int len = val.length; + + for (int i = 0 ; i < len; i++) { + h &= 0x7fffffff; + h = (((h >> 30) | (h << 1)) ^ (val[i]+i)); + } + + return (h << 8) | (len & 0xff); + } + + /** + * Liefert Default-Wert def zurück, wenn String s + * kein Integer ist. + * + * @param s + * @param def + * @return geparster int aus s oder def + */ + public static int parseInt(String s, int def) { + if (s == null) return def; + try { + return Integer.parseInt(s); + } catch (NumberFormatException e) { + return def; + } + } + + /** + * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann. + * @param s + * @param def + * @return geparster float oder def + */ + public static float parseFloat(String s, float def) { + if (s == null) return def; + try { + return new Float(s).floatValue(); + } catch (NumberFormatException e) { + return def; + } + } + + /** + * Findet Ende eines Satzes in String text + * @param text + * @param startIndex + * @return index des Satzendes, oder -1 + */ + public static int findEndOfSentence(String text, int startIndex) { while (true) { int i = text.indexOf('.', startIndex); if (i < 0) return -1; @@ -723,178 +725,178 @@ public final class StringUtil { } } - /** - * Findet Wortende in String text ab startIndex - * @param text - * @param startIndex - * @return Index des Wortendes, oder -1 - */ - public static int findEndOfWord(String text, int startIndex) { - int i = text.indexOf(' ', startIndex), - j = text.indexOf('\n', startIndex); - if (i < 0) i = text.length(); - if (j < 0) j = text.length(); - return Math.min(i, j); - } - - /** - * Diese Routine macht aus links in reinem text browsbare links - * @param text - * @return Konvertierter String - */ - public static String makeLinks(String text) { - int i = 0; - StringBuffer buf = new StringBuffer(text.length()); - while (true) { - int j = text.indexOf("http://", i); - if (j < 0) { - buf.append(text.substring(i)); - break; - } else { - buf.append(text.substring(i, j)); - int k = findEndOfWord(text,j+7); - String url=""; - if (k<0) url = text.substring(j); - else url = text.substring(j,k); - - buf.append(""+url+""); - //System.out.println("url mark: " + url); - i = j+url.length(); - } - } - return buf.toString(); - - } - - - /** - * convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n) - * in den html-tag

- * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String convertNewline2P(String haystack) { - try { - RE regex = new RE("(
\r?\n
){1,}"); - return regex.substituteAll(haystack,"\n

"); - } catch(REException ex){ - return null; - } - } - - /** - * convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n) - * in den html-tag
- * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String convertNewline2Break(String haystack) { - try { - RE regex = new RE("(\r?\n){1}"); - return regex.substituteAll(haystack,"$0
"); - } catch(REException ex){ - return null; - } - } - - /** - * createMailLinks wandelt text im email-adressenformat - * in einen klickbaren link um - * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String createMailLinks(String haystack) { - try { - RE regex = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+).([a-zA-Z0-9_.-]+)"); - return regex.substituteAll(haystack,"$0"); - } catch(REException ex){ - return null; - } - } - - - /** - * createMailLinks wandelt text im email-adressenformat - * in einen klickbaren link um - * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String createMailLinks(String haystack, String imageRoot, String mailImage) { - try { - RE regex = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+).([a-zA-Z0-9_.-]+)"); - return regex.substituteAll(haystack," $0"); - } catch(REException ex){ - return null; - } - } - - - /** - * createURLLinks wandelt text im url-format - * in einen klickbaren link um - * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String createURLLinks(String haystack) { - try { - //dieser Ausdruck brauch dringend fachliche Beratung - RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/([^ \t\r\n<>]+[^ \t\r\n.,<>])"); - return regex.substituteAll(haystack,"$0"); - } catch(REException ex){ - return null; - } - } - - /** - * createURLLinks wandelt text im url-format - * in einen klickbaren link um - * nur sinnvoll, wenn text nicht im html-format eingegeben - */ - public static String createURLLinks(String haystack,String imageRoot,String extImage,String intImage) { - try { - //dieser Ausdruck brauch dringend fachliche Beratung - RE regex = new RE("((https://)|(http://)|(ftp://))+([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>]+[^ \t\r\n.,<>])"); - return regex.substituteAll(haystack," $0"); - } catch(REException ex){ - return null; - } - } - - /** - * deleteForbiddenTags - * this method deletes all