2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
37 import java.text.NumberFormat;
41 * Statische Hilfsmethoden zur Stringbehandlung
43 * @version $Id: StringUtil.java,v 1.27 2002/11/25 19:06:45 zapata Exp $
44 * @author mir-coders group
47 public final class StringUtil {
49 private static RE re_newline2br, re_brbr2p, re_mail, re_url, re_tags;
51 private StringUtil() { } // this avoids contruction
56 re_newline2br = new RE("(\r?\n){1}");
57 re_brbr2p = new RE("(<br>\r?\n<br>){1,}");
58 re_mail = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");
59 re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");
60 re_tags = new RE("<[^>]*>",RE.REG_ICASE);
62 catch (REException e){
63 System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
68 * Formats a number with the specified minimum and maximum number of digits.
70 public static synchronized String zeroPaddingNumber(long value, int minDigits,
73 NumberFormat numberFormat = NumberFormat.getInstance();
74 numberFormat.setMinimumIntegerDigits(minDigits);
75 numberFormat.setMaximumIntegerDigits(maxDigits);
76 return numberFormat.format(value);
80 * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)
82 * @return 8-ziffriger String (yyyymmdd)
85 public static final String date2webdbDate (GregorianCalendar theDate) {
86 StringBuffer webdbDate = new StringBuffer();
87 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
88 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
89 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
90 return webdbDate.toString();
94 * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
96 * @return 12-ziffriger String (yyyymmdd)
99 public static final String date2webdbDateTime (GregorianCalendar theDate) {
100 StringBuffer webdbDate = new StringBuffer();
101 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
102 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
103 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
104 webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
105 webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
106 return webdbDate.toString();
110 * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
112 * @return w3approved datetime
115 public static final String date2w3DateTime (GregorianCalendar theDate) {
116 StringBuffer webdbDate = new StringBuffer();
117 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
118 webdbDate.append("-");
119 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
120 webdbDate.append("-");
121 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
122 webdbDate.append("T");
123 webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
124 webdbDate.append(":");
125 webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
126 webdbDate.append(":");
127 webdbDate.append(pad2(theDate.get(Calendar.SECOND)));
128 //assumes you are an hour-multiple away from UTC....
129 int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
131 webdbDate.append("-");
134 webdbDate.append("+");
136 webdbDate.append(pad2(Math.abs(offset)));
137 webdbDate.append(":00");
138 return webdbDate.toString();
142 * wandelt Calendar in dd.mm.yyyy / hh.mm um
144 * @return String mit (dd.mm.yyyy / hh.mm um)
146 public static String date2readableDateTime (GregorianCalendar theDate) {
147 String readable = "";
149 readable += pad2(theDate.get(Calendar.DATE));
150 readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);
151 readable += "." + String.valueOf(theDate.get(Calendar.YEAR));
152 hour = theDate.get(Calendar.HOUR);
153 if (theDate.get(Calendar.AM_PM) == Calendar.PM)
155 readable += " / " + pad2(hour);
156 readable += ":" + pad2(theDate.get(Calendar.MINUTE));
161 * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>
165 * @return String mit <code>/yyyy/mm/dd</code>
167 public static final String webdbDate2path (String webdbDate) {
168 StringBuffer path = new StringBuffer();
169 path.append("/").append(webdbDate.substring(0, 4));
170 path.append("/").append(webdbDate.substring(4, 6));
173 //path.append("/").append(webdbDate.substring(6, 8));
174 return path.toString();
178 * wandelt Calendar in dd.mm.yyyy um
181 * @return String mit <code>yyyy.mm.dd</code>
183 public static final String webdbDate2readableDate (String webdbDate) {
185 date += webdbDate.substring(0, 4);
186 date += "-" + webdbDate.substring(5, 7);
187 date += "-"+webdbDate.substring(8, 10);
193 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
194 * to dd.mm.yyyy hh:mm
196 public static String dateToReadableDate(String date) {
197 StringBuffer returnDate = new StringBuffer();
200 returnDate.append(date.substring(8,10)).append('.');
201 returnDate.append(date.substring(5,7)).append('.');
202 returnDate.append(date.substring(0,4)).append(' ');
203 returnDate.append(date.substring(11,16));
205 return returnDate.toString();
209 * converts string from format: yyyy-mm-dd__hh:mm:ss.dddddd+TZ
210 * to yyyy-mm-ddThh:mm:ss+TZ:00 (w3 format for Dublin Core)
212 public static String webdbdateToDCDate(String date) {
213 StringBuffer returnDate = new StringBuffer();
215 returnDate.append(date.substring(0,10));
216 returnDate.append("T");
217 returnDate.append(date.substring(11,19));
218 //String tzInfo=date.substring(26,29);
219 //if (tzInfo.equals("+00")){
220 //UTC gets a special code in w3 dates
221 // returnDate.append("Z");
224 //need to see what a newfoundland postgres
225 //timestamp looks like before making this robust
226 // returnDate.append(tzInfo);
227 // returnDate.append(":00");
231 return returnDate.toString();
236 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
239 public static String dateToYear (String date) {
240 StringBuffer returnDate = new StringBuffer();
243 returnDate.append(date.substring(0,4));
245 return returnDate.toString();
249 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
252 public static String dateToMonth (String date) {
253 StringBuffer returnDate = new StringBuffer();
255 if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
256 else returnDate.append(date.substring(6,7));
258 return returnDate.toString();
262 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
265 public static String dateToDayOfMonth (String date) {
266 StringBuffer returnDate = new StringBuffer();
268 if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
269 else returnDate.append(date.substring(9,10));
271 return returnDate.toString();
275 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
278 public static String dateToTime (String date) {
279 StringBuffer returnDate = new StringBuffer();
281 returnDate.append(date.substring(11,16));
283 return returnDate.toString();
287 * Splits the provided CSV text into a list. stolen wholesale from
288 * from Jakarta Turbine StrinUtils.java -mh
290 * @param text The CSV list of values to split apart.
291 * @param separator The separator character.
292 * @return The list of values.
294 public static String[] split(String text, String separator)
296 StringTokenizer st = new StringTokenizer(text, separator);
297 String[] values = new String[st.countTokens()];
299 while (st.hasMoreTokens())
301 values[pos++] = st.nextToken();
307 * Joins the elements of the provided array into a single string
308 * containing a list of CSV elements. Stolen wholesale from Jakarta
309 * Turbine StringUtils.java. -mh
311 * @param list The list of values to join together.
312 * @param separator The separator character.
313 * @return The CSV text.
315 public static String join(String[] list, String separator)
317 StringBuffer csv = new StringBuffer();
318 for (int i = 0; i < list.length; i++)
322 csv.append(separator);
326 return csv.toString();
331 * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
333 * @return gequoteter String
335 public static String quoteIfNecessary(String s) {
336 for (int i = 0; i < s.length(); i++)
337 if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.'))
338 return quote(s, '"');
343 * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
344 * "gefährliche" Zeichen innerhalb des Strings
345 * Quotes special SQL-characters in <code>s</code>
347 * @return geqoteter String
349 public static String quote(String s)
351 //String s2 = quote(s, '\'');
352 //Quickhack ÊÊ Ê Ê Ê Ê Ê Ê
353 //Because of '?-Bug in Postgresql-JDBC-Driver
354 StringBuffer temp = new StringBuffer();
355 for(int i=0;i<s.length();i++){
356 if(s.charAt(i)=='\''){
357 temp.append("'");
359 temp.append(s.charAt(i));
362 String s2 = temp.toString();
365 s2 = quote(s2, '\"');
370 * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
371 * "gefährliche" Zeichen innerhalb des Strings
373 * @param s String, der gequoted werden soll
374 * @param quoteChar zu quotendes Zeichen
375 * @return gequoteter String
377 public static String quote(String s, char quoteChar)
379 StringBuffer buf = new StringBuffer(s.length());
381 while (pos < s.length()) {
382 int i = s.indexOf(quoteChar, pos);
383 if (i < 0) i = s.length();
384 buf.append(s.substring(pos, i));
386 if (pos < s.length()) {
388 buf.append(quoteChar);
392 return buf.toString();
396 * replaces dangerous characters in <code>s</code>
400 public static String unquote(String s)
403 StringBuffer buf = new StringBuffer(s.length());
405 String searchString = "\\"+quoteChar;
406 while (pos < s.length()) {
407 int i = s.indexOf(searchString, pos);
408 if (i < 0) i = s.length();
409 buf.append(s.substring(pos, i));
412 return buf.toString();
416 * Wandelet String in byte[] um.
418 * @return byte[] des String
421 public static byte[] stringToBytes(String s) {
422 String crlf = System.getProperty("line.separator");
423 if (!crlf.equals("\n"))
424 s = replace(s, "\n", crlf);
425 // byte[] buf = new byte[s.length()];
426 byte[] buf = s.getBytes();
431 * Ersetzt in String <code>s</code> das <code>pattern</code> durch <code>substitute</code>
435 * @return String mit den Ersetzungen
437 public static String replace(String s, String pattern, String substitute) {
438 int i = 0, pLen = pattern.length(), sLen = substitute.length();
439 StringBuffer buf = new StringBuffer(s.length());
441 int j = s.indexOf(pattern, i);
443 buf.append(s.substring(i));
446 buf.append(s.substring(i, j));
447 buf.append(substitute);
451 return buf.toString();
455 * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
459 * @return String mit den Ersetzungen
461 public static String regexpReplace(String haystack, String pattern, String substitute) {
463 RE regex = new RE(pattern);
464 return regex.substituteAll(haystack,substitute);
465 } catch(REException ex){
474 * Fügt einen Separator an den Pfad an
476 * @return Pfad mit Separator am Ende
478 public static final String addSeparator (String path) {
479 return path.length() == 0 || path.endsWith(File.separator) ? path : path
480 + File.separatorChar;
484 * Fügt ein <code>/</code> ans ende des Strings and
486 * @return Pfad mit <code>/</code> am Ende
488 public static final String addSlash (String path) {
489 return path.length() == 0 || path.endsWith("/") ? path : path + '/';
493 * Löscht <code>/</code> am Ende des Strings, falls vorhanden
495 * @return String ohne <code>/</code> am Ende
497 public static final String removeSlash (String path) {
498 return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
503 * Checks to see if the path is absolute by looking for a leading file
508 public static boolean isAbsolutePath (String path) {
509 return path.startsWith(File.separator);
513 * Löscht Slash am Anfang des Strings
517 public static String removeFirstSlash (String path) {
518 return path.startsWith("/") ? path.substring(1) : path;
522 * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)
523 * @return zwistellige Zahl
525 public static String pad2 (int number) {
526 return number < 10 ? "0" + number : String.valueOf(number);
530 * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)
532 * @return 3-stellige Zahl
534 public static String pad3 (int number) {
535 return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);
539 * Konvertiert Unix-Linefeeds in Win-Linefeeds
541 * @return Konvertierter String
543 public static String unixLineFeedsToWin(String s) {
546 i = s.indexOf('\n', i+1);
548 if ((i == 0 || s.charAt(i-1) != '\r') &&
549 (i == s.length()-1 || s.charAt(i+1) != '\r')) {
550 s = s.substring(0, i)+'\r'+s.substring(i);
558 * verwandelt einen String in eine gültige Url, konvertiert Sonderzeichen
559 * und Spaces werden zu Underscores
561 * @return gültige Url
564 ML: I don't exactly understand the point of this routine, and I think it isn't
565 being used anymore. (And it sometimes causes locale problems). So I commented
568 public static String convert2url(String s) {
570 StringBuffer buf = new StringBuffer();
571 for(int i = 0; i < s.length(); i++ ) {
572 switch( s.charAt( i ) ) {
574 buf.append( "oe" ); break;
576 buf.append( "ae" ); break;
578 buf.append( "ue" ); break;
580 buf.append( "a" ); break;
583 buf.append( "_" ); break;
585 if( buf.charAt( buf.length() - 1 ) != '_' ) {
590 buf.append( s.charAt( i ) );
593 return buf.toString();
597 public static String decodeHTMLinTags(String s){
598 StringBuffer buffer = new StringBuffer();
599 boolean start = false;
600 boolean stop = false;
605 for(int i=0;i<s.length();i++){
606 if(s.charAt(i)=='<'){
609 } else if(s.charAt(i)=='>'){
614 buffer.append(s.substring(temp,startIndex));
615 buffer.append(replaceQuot(s.substring(startIndex,stopIndex+1)));
616 i= temp= stopIndex+1;
622 buffer.append(s.substring(stopIndex+1));
623 return buffer.toString();
629 public static String replaceQuot(String s) {
630 StringBuffer buffer = new StringBuffer();
631 for(int j = 0; j < s.length();j++){
632 if(s.charAt(j)=='&'){
633 if(s.indexOf( """,j) == j) {
634 buffer.append( "\"" );
638 buffer.append(s.charAt(j));
641 return buffer.toString();
644 /** wandelt Quotes in Sonderzeichen um
647 public static String decodeHtml(String s) {
648 StringBuffer buf = new StringBuffer();
649 for(int i=0;i < s.length(); i++ ) {
650 if( s.indexOf( "ö", i ) == i ) {
651 buf.append( "ö" ); i += 5;
654 if( s.indexOf( "ä", i ) == i ) {
655 buf.append( "ä" ); i += 5;
658 if( s.indexOf( "ü", i ) == i ) {
659 buf.append( "ü" ); i += 5;
662 if( s.indexOf( "Ö", i ) == i ) {
663 buf.append( "Ö" ); i += 5;
666 if( s.indexOf( "Ä", i ) == i ) {
667 buf.append( "Ä" ); i += 5;
670 if( s.indexOf( "Ü", i ) == i ) {
671 buf.append( "Ü" ); i += 5;
674 if( s.indexOf( "ß", i ) == i ) {
675 buf.append( "ß" ); i += 6;
678 if( s.indexOf( """, i ) == i ) {
679 buf.append( "\"" ); i += 5;
682 buf.append( s.charAt(i) );
684 return buf.toString();
689 * schnellere Variante der String.toLowerCase()-Routine
691 * @return String in Kleinbuchsten
693 public static String toLowerCase(String s) {
695 char[] a = new char[l];
696 for (int i = 0; i < l; i++)
697 a[i] = Character.toLowerCase(s.charAt(i));
698 return new String(a);
702 * Findet <code>element</code> im String-Array <code>array</code>
705 * @return Fundstelle als int oder -1
707 public static int indexOf(String[] array, String element) {
709 for (int i = 0; i < array.length; i++)
710 if (array[i].equals(element))
716 * Testet auf Vorkommen von <code>element</code> in <code>array</code>
717 * @param array String-Array
719 * @return true wenn <code>element</code> vorkommt, sonst false
721 public static boolean contains(String[] array, String element) {
722 return indexOf(array, element) >= 0;
726 * Ermittelt CRC-Prüfsumme von String <code>s</code>
728 * @return CRC-Prüfsumme
730 public static int getCRC(String s) {
732 char val[] = s.toCharArray();
733 int len = val.length;
735 for (int i = 0 ; i < len; i++) {
737 h = (((h >> 30) | (h << 1)) ^ (val[i]+i));
740 return (h << 8) | (len & 0xff);
744 * Liefert Default-Wert def zurück, wenn String <code>s</code>
749 * @return geparster int aus s oder def
751 public static int parseInt(String s, int def) {
752 if (s == null) return def;
754 return Integer.parseInt(s);
755 } catch (NumberFormatException e) {
761 * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann.
764 * @return geparster float oder def
766 public static float parseFloat(String s, float def) {
767 if (s == null) return def;
769 return new Float(s).floatValue();
770 } catch (NumberFormatException e) {
776 * Findet Ende eines Satzes in String <code>text</code>
779 * @return index des Satzendes, oder -1
781 public static int findEndOfSentence(String text, int startIndex) {
783 int i = text.indexOf('.', startIndex);
784 if (i < 0) return -1;
785 if (i > 0 && !Character.isDigit(text.charAt(i-1)) &&
786 (i+1 >= text.length()
787 || text.charAt(i+1) == ' '
788 || text.charAt(i+1) == '\n'
789 || text.charAt(i+1) == '\t'))
796 * Findet Wortende in String <code>text</code> ab <code>startIndex</code>
799 * @return Index des Wortendes, oder -1
801 public static int findEndOfWord(String text, int startIndex) {
802 int i = text.indexOf(' ', startIndex),
803 j = text.indexOf('\n', startIndex);
804 if (i < 0) i = text.length();
805 if (j < 0) j = text.length();
806 return Math.min(i, j);
811 * convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)
812 * in den html-tag <p>
813 * nur sinnvoll, wenn text nicht im html-format eingegeben
815 public static String convertNewline2P(String haystack) {
816 return re_brbr2p.substituteAll(haystack,"\n</p><p>");
820 * convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)
821 * in den html-tag <br>
822 * nur sinnvoll, wenn text nicht im html-format eingegeben
824 public static String convertNewline2Break(String haystack) {
825 return re_newline2br.substituteAll(haystack,"$0<br />");
829 * createMailLinks wandelt text im email-adressenformat
830 * in einen klickbaren link um
831 * nur sinnvoll, wenn text nicht im html-format eingegeben
833 public static String createMailLinks(String haystack) {
834 return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
839 * createMailLinks wandelt text im email-adressenformat
840 * in einen klickbaren link um
841 * nur sinnvoll, wenn text nicht im html-format eingegeben
843 public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
844 return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/> <a href=\"mailto:$0\">$0</a>");
849 * createURLLinks wandelt text im url-format
850 * in einen klickbaren link um
851 * nur sinnvoll, wenn text nicht im html-format eingegeben
853 public static String createURLLinks(String haystack) {
854 return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
858 * this routine takes text in url format and makes
859 * a clickaeble "<href>" link removing any "illegal" html tags
860 * @param haystack, the url
861 * @param title, the href link text
862 * @param imagRoot, the place to find icons
863 * @param extImage, the url of the icon to show next to the link
864 * @return a String containing the url
866 public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
868 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");
870 title = removeHTMLTags(title);
871 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");
876 * this routine takes text in url format and makes
877 * a clickaeble "<href>" link removing any "illegal" html tags
878 * @param haystack, the url
879 * @param imageRoot, the place to find icons
880 * @param extImage, the url of the icon to show next to the link
881 * @param intImage, unused
882 * @return a String containing the url
884 public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
885 return createURLLinks(haystack, title, imageRoot, extImage);
889 * deleteForbiddenTags
890 * this method deletes all <script>, <body> and <head>-tags
892 public static final String deleteForbiddenTags(String haystack) {
894 RE regex = new RE("<[ \t\r\n](.*?)script(.*?)/script(.*?)>",RE.REG_ICASE);
895 haystack = regex.substituteAll(haystack,"");
896 regex = new RE("<head>(.*?)</head>");
897 haystack = regex.substituteAll(haystack,"");
898 regex = new RE("<[ \t\r\n/]*body(.*?)>");
899 haystack = regex.substituteAll(haystack,"");
901 } catch(REException ex){
907 * this method deletes all html tags
909 public static final String removeHTMLTags(String haystack){
910 return re_tags.substituteAll(haystack,"");
915 * this method deletes all but the approved tags html tags
916 * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
918 public static String approveHTMLTags(String haystack){
920 String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
921 String badAttributes="onAbort|onBlur|onChange|onClick|onDblClick|onDragDrop|onError|onFocus|onKeyDown|onKeyPress|onKeyUp|onLoad|onMouseDown|onMouseMove|onMouseOut|onMouseOver|onMouseUp|onMove|onReset|onResize|onSelect|onSubmit|onUnload";
922 String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
924 // kill all the bad tags that have attributes
925 String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
926 RE regex = new RE(s,RE.REG_ICASE);
927 haystack = regex.substituteAll(haystack,"");
929 // kill all the bad tags that are attributeless
930 regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
931 haystack = regex.substituteAll(haystack,"");
933 // kill all the tags which have a javascript attribute like onLoad
934 regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
935 haystack = regex.substituteAll(haystack,"");
937 // kill all the tags which include a url to an unacceptable protocol
938 regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
939 haystack = regex.substituteAll(haystack,"");
942 } catch(REException ex){
943 ex.printStackTrace();
950 * createHTML ruft alle regex-methoden zum unwandeln eines nicht
951 * htmlcodierten string auf und returnt einen htmlcodierten String
953 public static String createHTML(String content){
954 content=convertNewline2Break(content);
955 content=convertNewline2P(content);
956 content=createMailLinks(content);
957 content=createURLLinks(content);
963 * createHTML ruft alle regex-methoden zum unwandeln eines nicht
964 * htmlcodierten string auf und returnt einen htmlcodierten String
966 public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
967 content=convertNewline2Break(content);
968 content=convertNewline2P(content);
969 content=createMailLinks(content,producerDocRoot,mailImage);
970 content=createURLLinks(content,null,producerDocRoot,extImage,intImage);