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.23.2.5 2002/12/13 05:55:40 mh Exp $
44 * @author rk, mir-coders group
48 public final class StringUtil {
50 private static RE re_newline2br, re_brbr2p, re_mail, re_url, re_tags,
51 re_tables, re_forbiddenTags;
53 private StringUtil() { } // this avoids contruction
58 re_newline2br = new RE("(\r?\n){1}");
59 re_brbr2p = new RE("(<br>\r?\n<br>){1,}");
60 re_mail = new RE("([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)");
61 re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])");
62 re_tags = new RE("<[^>]*>",RE.REG_ICASE);
63 re_tables = new RE("<[ \t\r\n/]*(table|td|tr)[ \t\r\n]*>",RE.REG_ICASE);
64 re_forbiddenTags = new RE("<[ \t\r\n/]*(body|head|script)[ \t\r\n]*>",RE.REG_ICASE);
66 catch (REException e){
67 System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
72 * Formats a number with the specified minimum and maximum number of digits.
74 public static synchronized String zeroPaddingNumber(long value, int minDigits,
77 NumberFormat numberFormat = NumberFormat.getInstance();
78 numberFormat.setMinimumIntegerDigits(minDigits);
79 numberFormat.setMaximumIntegerDigits(maxDigits);
80 return numberFormat.format(value);
84 * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd)
86 * @return 8-ziffriger String (yyyymmdd)
89 public static final String date2webdbDate (GregorianCalendar theDate) {
90 StringBuffer webdbDate = new StringBuffer();
91 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
92 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
93 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
94 return webdbDate.toString();
98 * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm)
100 * @return 12-ziffriger String (yyyymmdd)
103 public static final String date2webdbDateTime (GregorianCalendar theDate) {
104 StringBuffer webdbDate = new StringBuffer();
105 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
106 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
107 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
108 webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
109 webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
110 return webdbDate.toString();
114 * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
116 * @return w3approved datetime
119 public static final String date2w3DateTime (GregorianCalendar theDate) {
120 StringBuffer webdbDate = new StringBuffer();
121 webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
122 webdbDate.append("-");
123 webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
124 webdbDate.append("-");
125 webdbDate.append(pad2(theDate.get(Calendar.DATE)));
126 webdbDate.append("T");
127 webdbDate.append(pad2(theDate.get(Calendar.HOUR)));
128 webdbDate.append(":");
129 webdbDate.append(pad2(theDate.get(Calendar.MINUTE)));
130 webdbDate.append(":");
131 webdbDate.append(pad2(theDate.get(Calendar.SECOND)));
132 //assumes you are an hour-multiple away from UTC....
133 int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
135 webdbDate.append("-");
138 webdbDate.append("+");
140 webdbDate.append(pad2(Math.abs(offset)));
141 webdbDate.append(":00");
142 return webdbDate.toString();
146 * wandelt Calendar in dd.mm.yyyy / hh.mm um
148 * @return String mit (dd.mm.yyyy / hh.mm um)
150 public static String date2readableDateTime (GregorianCalendar theDate) {
151 String readable = "";
153 readable += pad2(theDate.get(Calendar.DATE));
154 readable += "." + pad2(theDate.get(Calendar.MONTH) + 1);
155 readable += "." + String.valueOf(theDate.get(Calendar.YEAR));
156 hour = theDate.get(Calendar.HOUR);
157 if (theDate.get(Calendar.AM_PM) == Calendar.PM)
159 readable += " / " + pad2(hour);
160 readable += ":" + pad2(theDate.get(Calendar.MINUTE));
165 * wandelt eine Datum in einen 8-buchstabigen String, der durch <code>/</code>
169 * @return String mit <code>/yyyy/mm/dd</code>
171 public static final String webdbDate2path (String webdbDate) {
172 StringBuffer path = new StringBuffer();
173 path.append("/").append(webdbDate.substring(0, 4));
174 path.append("/").append(webdbDate.substring(4, 6));
177 //path.append("/").append(webdbDate.substring(6, 8));
178 return path.toString();
182 * wandelt Calendar in dd.mm.yyyy um
185 * @return String mit <code>yyyy.mm.dd</code>
187 public static final String webdbDate2readableDate (String webdbDate) {
189 date += webdbDate.substring(0, 4);
190 date += "-" + webdbDate.substring(5, 7);
191 date += "-"+webdbDate.substring(8, 10);
197 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
198 * to dd.mm.yyyy hh:mm
200 public static String dateToReadableDate(String date) {
201 StringBuffer returnDate = new StringBuffer();
204 returnDate.append(date.substring(8,10)).append('.');
205 returnDate.append(date.substring(5,7)).append('.');
206 returnDate.append(date.substring(0,4)).append(' ');
207 returnDate.append(date.substring(11,16));
209 return returnDate.toString();
213 * converts string from format: yyyy-mm-dd__hh:mm:ss.dddddd+TZ
214 * to yyyy-mm-ddThh:mm:ss+TZ:00 (w3 format for Dublin Core)
216 public static String webdbdateToDCDate(String date) {
217 StringBuffer returnDate = new StringBuffer();
219 returnDate.append(date.substring(0,10));
220 returnDate.append("T");
221 returnDate.append(date.substring(11,19));
222 //String tzInfo=date.substring(26,29);
223 //if (tzInfo.equals("+00")){
224 //UTC gets a special code in w3 dates
225 // returnDate.append("Z");
228 //need to see what a newfoundland postgres
229 //timestamp looks like before making this robust
230 // returnDate.append(tzInfo);
231 // returnDate.append(":00");
235 return returnDate.toString();
240 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
243 public static String dateToYear (String date) {
244 StringBuffer returnDate = new StringBuffer();
247 returnDate.append(date.substring(0,4));
249 return returnDate.toString();
253 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
256 public static String dateToMonth (String date) {
257 StringBuffer returnDate = new StringBuffer();
259 if (!date.substring(5,6).equalsIgnoreCase("0")) returnDate.append(date.substring(5,7));
260 else returnDate.append(date.substring(6,7));
262 return returnDate.toString();
266 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
269 public static String dateToDayOfMonth (String date) {
270 StringBuffer returnDate = new StringBuffer();
272 if (!date.substring(8,9).equalsIgnoreCase("0")) returnDate.append(date.substring(8,10));
273 else returnDate.append(date.substring(9,10));
275 return returnDate.toString();
279 * converts string from format: yyyy-mm-dd__hh:mm:ss.d
282 public static String dateToTime (String date) {
283 StringBuffer returnDate = new StringBuffer();
285 returnDate.append(date.substring(11,16));
287 return returnDate.toString();
291 * Splits the provided CSV text into a list. stolen wholesale from
292 * from Jakarta Turbine StrinUtils.java -mh
294 * @param text The CSV list of values to split apart.
295 * @param separator The separator character.
296 * @return The list of values.
298 public static String[] split(String text, String separator)
300 StringTokenizer st = new StringTokenizer(text, separator);
301 String[] values = new String[st.countTokens()];
303 while (st.hasMoreTokens())
305 values[pos++] = st.nextToken();
311 * Joins the elements of the provided array into a single string
312 * containing a list of CSV elements. Stolen wholesale from Jakarta
313 * Turbine StringUtils.java. -mh
315 * @param list The list of values to join together.
316 * @param separator The separator character.
317 * @return The CSV text.
319 public static String join(String[] list, String separator)
321 StringBuffer csv = new StringBuffer();
322 for (int i = 0; i < list.length; i++)
326 csv.append(separator);
330 return csv.toString();
335 * schließt einen String in Anführungsszeichen ein, falls er Leerzeichen o.ä. enthält
337 * @return gequoteter String
339 public static String quoteIfNecessary(String s) {
340 for (int i = 0; i < s.length(); i++)
341 if (!(Character.isLetterOrDigit(s.charAt(i)) || s.charAt(i) == '.'))
342 return quote(s, '"');
347 * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
348 * "gefährliche" Zeichen innerhalb des Strings
349 * Quotes special SQL-characters in <code>s</code>
351 * @return geqoteter String
353 public static String quote(String s)
355 //String s2 = quote(s, '\'');
356 //Quickhack ÊÊ Ê Ê Ê Ê Ê Ê
357 //Because of '?-Bug in Postgresql-JDBC-Driver
358 StringBuffer temp = new StringBuffer();
359 for(int i=0;i<s.length();i++){
360 if(s.charAt(i)=='\''){
361 temp.append("'");
363 temp.append(s.charAt(i));
366 String s2 = temp.toString();
369 s2 = quote(s2, '\"');
374 * schließt <code>s</code> in <code>'</code> ein und setzt Backslashes vor
375 * "gefährliche" Zeichen innerhalb des Strings
377 * @param s String, der gequoted werden soll
378 * @param quoteChar zu quotendes Zeichen
379 * @return gequoteter String
381 public static String quote(String s, char quoteChar)
383 StringBuffer buf = new StringBuffer(s.length());
385 while (pos < s.length()) {
386 int i = s.indexOf(quoteChar, pos);
387 if (i < 0) i = s.length();
388 buf.append(s.substring(pos, i));
390 if (pos < s.length()) {
392 buf.append(quoteChar);
396 return buf.toString();
400 * replaces dangerous characters in <code>s</code>
404 public static String unquote(String s)
407 StringBuffer buf = new StringBuffer(s.length());
409 String searchString = "\\"+quoteChar;
410 while (pos < s.length()) {
411 int i = s.indexOf(searchString, pos);
412 if (i < 0) i = s.length();
413 buf.append(s.substring(pos, i));
416 return buf.toString();
420 * replaces characters that cannot appera in HTML with escaped equivalents.
422 public static String encodeHTML(String aText) {
423 final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' };
424 final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" };
426 int position, nextPosition;
428 StringBuffer result = new StringBuffer();
433 nextPosition = indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position);
436 nextPosition = aText.length();
438 result.append(aText.substring(position, nextPosition));
440 if (nextPosition<aText.length())
441 for (i=0; i<CHARACTERS_TO_ESCAPE.length; i++) {
442 if (CHARACTERS_TO_ESCAPE[i] == aText.charAt(nextPosition)) {
443 result.append(ESCAPE_CODES[i]);
447 position=nextPosition+1;
449 while (nextPosition<aText.length()) ;
451 return result.toString();
455 * Wandelet String in byte[] um.
457 * @return byte[] des String
460 public static byte[] stringToBytes(String s) {
461 String crlf = System.getProperty("line.separator");
462 if (!crlf.equals("\n"))
463 s = replace(s, "\n", crlf);
464 // byte[] buf = new byte[s.length()];
465 byte[] buf = s.getBytes();
470 * Ersetzt in String <code>s</code> das <code>pattern</code> durch <code>substitute</code>
474 * @return String mit den Ersetzungen
476 public static String replace(String s, String pattern, String substitute) {
477 int i = 0, pLen = pattern.length(), sLen = substitute.length();
478 StringBuffer buf = new StringBuffer(s.length());
480 int j = s.indexOf(pattern, i);
482 buf.append(s.substring(i));
485 buf.append(s.substring(i, j));
486 buf.append(substitute);
490 return buf.toString();
494 * Ersetzt in String <code>s</code> das Regexp <code>pattern</code> durch <code>substitute</code>
498 * @return String mit den Ersetzungen
500 public static String regexpReplace(String haystack, String pattern, String substitute) {
502 RE regex = new RE(pattern);
503 return regex.substituteAll(haystack,substitute);
504 } catch(REException ex){
513 * Fügt einen Separator an den Pfad an
515 * @return Pfad mit Separator am Ende
517 public static final String addSeparator (String path) {
518 return path.length() == 0 || path.endsWith(File.separator) ? path : path
519 + File.separatorChar;
523 * Fügt ein <code>/</code> ans ende des Strings and
525 * @return Pfad mit <code>/</code> am Ende
527 public static final String addSlash (String path) {
528 return path.length() == 0 || path.endsWith("/") ? path : path + '/';
532 * Löscht <code>/</code> am Ende des Strings, falls vorhanden
534 * @return String ohne <code>/</code> am Ende
536 public static final String removeSlash (String path) {
537 return path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
542 * Checks to see if the path is absolute by looking for a leading file
547 public static boolean isAbsolutePath (String path) {
548 return path.startsWith(File.separator);
552 * Löscht Slash am Anfang des Strings
556 public static String removeFirstSlash (String path) {
557 return path.startsWith("/") ? path.substring(1) : path;
561 * formatiert eine Zahl (0-99) zweistellig (z.B. 5 -> 05)
562 * @return zwistellige Zahl
564 public static String pad2 (int number) {
565 return number < 10 ? "0" + number : String.valueOf(number);
569 * formatiert eine Zahl (0-999) dreistellig (z.B. 7 -> 007)
571 * @return 3-stellige Zahl
573 public static String pad3 (int number) {
574 return number < 10 ? "00" + number : number < 100 ? "0" + number : String.valueOf(number);
578 * Konvertiert Unix-Linefeeds in Win-Linefeeds
580 * @return Konvertierter String
582 public static String unixLineFeedsToWin(String s) {
585 i = s.indexOf('\n', i+1);
587 if ((i == 0 || s.charAt(i-1) != '\r') &&
588 (i == s.length()-1 || s.charAt(i+1) != '\r')) {
589 s = s.substring(0, i)+'\r'+s.substring(i);
598 * verwandelt einen String in eine gültige Url, konvertiert Sonderzeichen
599 * und Spaces werden zu Underscores
601 * @return gültige Url
603 public static String convert2url(String s) {
605 StringBuffer buf = new StringBuffer();
606 for(int i = 0; i < s.length(); i++ ) {
607 switch( s.charAt( i ) ) {
609 buf.append( "oe" ); break;
611 buf.append( "ae" ); break;
613 buf.append( "ue" ); break;
615 buf.append( "a" ); break;
618 buf.append( "_" ); break;
620 if( buf.charAt( buf.length() - 1 ) != '_' ) {
625 buf.append( s.charAt( i ) );
628 return buf.toString();
631 public static String replaceQuot(String s) {
632 StringBuffer buffer = new StringBuffer();
633 for(int j = 0; j < s.length();j++){
634 if(s.charAt(j)=='&'){
635 if(s.indexOf( """,j) == j) {
636 buffer.append( "\"" );
640 buffer.append(s.charAt(j));
643 return buffer.toString();
647 * schnellere Variante der String.toLowerCase()-Routine
649 * @return String in Kleinbuchsten
651 public static String toLowerCase(String s) {
653 char[] a = new char[l];
654 for (int i = 0; i < l; i++)
655 a[i] = Character.toLowerCase(s.charAt(i));
656 return new String(a);
660 * Finds <code>element</code> in String-Array <code>array</code>
663 * @return Position where the element was found or -1
665 public static int indexOf(String[] array, String element) {
667 for (int i = 0; i < array.length; i++)
668 if (array[i].equals(element))
674 * Finds position of first in <code>aCharacters</code> array in String
675 * <code>aString</code> starting from position <code>aFrom</code>
680 * @return Position where the element was found or -1
682 public static int indexOfCharacters(String aString, char[] aCharacters, int aFrom) {
687 for (i=0; i<aCharacters.length ; i++) {
688 position = aString.indexOf(aCharacters[i], aFrom);
690 if (position != -1 && ( result == -1 || position < result )) {
700 * Testet auf Vorkommen von <code>element</code> in <code>array</code>
701 * @param array String-Array
703 * @return true wenn <code>element</code> vorkommt, sonst false
705 public static boolean contains(String[] array, String element) {
706 return indexOf(array, element) >= 0;
710 * Ermittelt CRC-Prüfsumme von String <code>s</code>
712 * @return CRC-Prüfsumme
714 public static int getCRC(String s) {
716 char val[] = s.toCharArray();
717 int len = val.length;
719 for (int i = 0 ; i < len; i++) {
721 h = (((h >> 30) | (h << 1)) ^ (val[i]+i));
724 return (h << 8) | (len & 0xff);
728 * Liefert Default-Wert def zurück, wenn String <code>s</code>
733 * @return geparster int aus s oder def
735 public static int parseInt(String s, int def) {
736 if (s == null) return def;
738 return Integer.parseInt(s);
739 } catch (NumberFormatException e) {
744 public static String interpretAsString(Object aValue) throws Exception {
745 if (aValue instanceof String)
746 return (String) aValue;
748 if (aValue instanceof Integer)
749 return ((Integer) aValue).toString();
754 throw new Exception("String expected, "+aValue+" found");
760 * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann.
763 * @return geparster float oder def
765 public static float parseFloat(String s, float def) {
766 if (s == null) return def;
768 return new Float(s).floatValue();
769 } catch (NumberFormatException e) {
775 * Findet Ende eines Satzes in String <code>text</code>
778 * @return index des Satzendes, oder -1
780 public static int findEndOfSentence(String text, int startIndex) {
782 int i = text.indexOf('.', startIndex);
783 if (i < 0) return -1;
784 if (i > 0 && !Character.isDigit(text.charAt(i-1)) &&
785 (i+1 >= text.length()
786 || text.charAt(i+1) == ' '
787 || text.charAt(i+1) == '\n'
788 || text.charAt(i+1) == '\t'))
795 * Findet Wortende in String <code>text</code> ab <code>startIndex</code>
798 * @return Index des Wortendes, oder -1
800 public static int findEndOfWord(String text, int startIndex) {
801 int i = text.indexOf(' ', startIndex),
802 j = text.indexOf('\n', startIndex);
803 if (i < 0) i = text.length();
804 if (j < 0) j = text.length();
805 return Math.min(i, j);
810 * convertNewline2P ist eine regex-routine zum umwandeln von 2 oder mehr newlines (\n)
811 * in den html-tag <p>
812 * nur sinnvoll, wenn text nicht im html-format eingegeben
814 public static String convertNewline2P(String haystack) {
815 return re_brbr2p.substituteAll(haystack,"\n</p><p>");
819 * convertNewline2Break ist eine regex-routine zum umwandeln von 1 newline (\n)
820 * in den html-tag <br>
821 * nur sinnvoll, wenn text nicht im html-format eingegeben
823 public static String convertNewline2Break(String haystack) {
824 return re_newline2br.substituteAll(haystack,"$0<br />");
828 * createMailLinks wandelt text im email-adressenformat
829 * in einen klickbaren link um
830 * nur sinnvoll, wenn text nicht im html-format eingegeben
832 public static String createMailLinks(String haystack) {
833 return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
838 * createMailLinks wandelt text im email-adressenformat
839 * in einen klickbaren link um
840 * nur sinnvoll, wenn text nicht im html-format eingegeben
842 public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
843 return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/> <a href=\"mailto:$0\">$0</a>");
848 * createURLLinks wandelt text im url-format
849 * in einen klickbaren link um
850 * nur sinnvoll, wenn text nicht im html-format eingegeben
852 public static String createURLLinks(String haystack) {
853 return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
857 * this routine takes text in url format and makes
858 * a clickaeble "<href>" link removing any "illegal" html tags
859 * @param haystack, the url
860 * @param title, the href link text
861 * @param imagRoot, the place to find icons
862 * @param extImage, the url of the icon to show next to the link
863 * @return a String containing the url
865 public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
867 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">$0</a>");
869 title = removeHTMLTags(title);
870 return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/> <a href=\"$0\">"+title+"</a>");
875 * this routine takes text in url format and makes
876 * a clickaeble "<href>" link removing any "illegal" html tags
877 * @param haystack, the url
878 * @param imageRoot, the place to find icons
879 * @param extImage, the url of the icon to show next to the link
880 * @param intImage, unused
881 * @return a String containing the url
883 public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
884 return createURLLinks(haystack, title, imageRoot, extImage);
888 * deleteForbiddenTags
889 * this method deletes all <script>, <body> and <head>-tags
891 public static final String deleteForbiddenTags(String haystack) {
892 return re_forbiddenTags.substituteAll(haystack,"");
896 * deleteHTMLTableTags
897 * this method deletes all <table>, <tr> and <td>-tags
899 public static final String deleteHTMLTableTags(String haystack) {
900 return re_tables.substituteAll(haystack,"");
904 * this method deletes all html tags
906 public static final String removeHTMLTags(String haystack){
907 return re_tags.substituteAll(haystack,"");
912 * this method deletes all but the approved tags html tags
913 * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
915 public static String approveHTMLTags(String haystack){
917 String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
918 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";
919 String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
921 // kill all the bad tags that have attributes
922 String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
923 RE regex = new RE(s,RE.REG_ICASE);
924 haystack = regex.substituteAll(haystack,"");
926 // kill all the bad tags that are attributeless
927 regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
928 haystack = regex.substituteAll(haystack,"");
930 // kill all the tags which have a javascript attribute like onLoad
931 regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
932 haystack = regex.substituteAll(haystack,"");
934 // kill all the tags which include a url to an unacceptable protocol
935 regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
936 haystack = regex.substituteAll(haystack,"");
939 } catch(REException ex){
940 ex.printStackTrace();
947 * createHTML ruft alle regex-methoden zum unwandeln eines nicht
948 * htmlcodierten string auf und returnt einen htmlcodierten String
950 public static String createHTML(String content){
951 content=convertNewline2Break(content);
952 content=convertNewline2P(content);
953 content=createMailLinks(content);
954 content=createURLLinks(content);
960 * createHTML ruft alle regex-methoden zum unwandeln eines nicht
961 * htmlcodierten string auf und returnt einen htmlcodierten String
963 public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
964 content=convertNewline2Break(content);
965 content=convertNewline2P(content);
966 content=createMailLinks(content,producerDocRoot,mailImage);
967 content=createURLLinks(content,null,producerDocRoot,extImage,intImage);