misc. fixes
[mir.git] / source / mir / misc / StringUtil.java
index b05c748..11b599f 100755 (executable)
@@ -41,7 +41,7 @@ import java.util.TimeZone;
 /**
  * Statische Hilfsmethoden zur Stringbehandlung
  *
- * @version $Id: StringUtil.java,v 1.33.2.6 2005/02/10 16:22:30 rhindes Exp $
+ * @version $Id: StringUtil.java,v 1.33.2.7 2005/09/18 15:01:27 zapata Exp $
  * @author mir-coders group
  *
  */
@@ -260,7 +260,7 @@ public final class StringUtil {
    *  in den html-tag <p>
    *  nur sinnvoll, wenn text nicht im html-format eingegeben
    */
-  public static String convertNewline2P(String haystack) {
+  private static String convertNewline2P(String haystack) {
     return re_brbr2p.substituteAll(haystack,"\n</p><p>");
   }
 
@@ -269,7 +269,7 @@ public final class StringUtil {
    *  in den html-tag <br>
    *  nur sinnvoll, wenn text nicht im html-format eingegeben
    */
-  public static String convertNewline2Break(String haystack) {
+  private static String convertNewline2Break(String haystack) {
     return re_newline2br.substituteAll(haystack,"$0<br />");
   }
 
@@ -278,7 +278,7 @@ public final class StringUtil {
    *  in einen klickbaren link um
    *  nur sinnvoll, wenn text nicht im html-format eingegeben
    */
-  public static String createMailLinks(String haystack) {
+  private static String createMailLinks(String haystack) {
     return re_mail.substituteAll(haystack,"<a href=\"mailto:$0\">$0</a>");
   }
 
@@ -288,7 +288,7 @@ public final class StringUtil {
    *  in einen klickbaren link um
    *  nur sinnvoll, wenn text nicht im html-format eingegeben
    */
-  public static String createMailLinks(String haystack, String imageRoot, String mailImage) {
+  private static String createMailLinks(String haystack, String imageRoot, String mailImage) {
     return re_mail.substituteAll(haystack,"<img src=\""+imageRoot+"/"+mailImage+"\" border=\"0\"/>&#160;<a href=\"mailto:$0\">$0</a>");
   }
 
@@ -298,7 +298,7 @@ public final class StringUtil {
    *  in einen klickbaren link um
    *  nur sinnvoll, wenn text nicht im html-format eingegeben
    */
-  public static String createURLLinks(String haystack) {
+  private static String createURLLinks(String haystack) {
     return re_url.substituteAll(haystack,"<a href=\"$0\">$0</a>");
   }
 
@@ -311,7 +311,7 @@ public final class StringUtil {
    * @param extImage  the url of the icon to show next to the link
    * @return a String containing the url
    */
-  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
+  private static String createURLLinks(String haystack, String title, String imageRoot,String extImage) {
     if (title == null) {
       return re_url.substituteAll(haystack,"<img src=\""+imageRoot+"/"+extImage+"\" border=\"0\"/>&#160;<a href=\"$0\">$0</a>");
     }
@@ -328,51 +328,17 @@ public final class StringUtil {
    * @param intImage unused
    * @return a String containing the url
    */
-  public static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
+  private static String createURLLinks(String haystack, String title, String imageRoot,String extImage,String intImage) {
     return createURLLinks(haystack, title, imageRoot, extImage);
   }
 
   /**
    * this method deletes all html tags
    */
-  public static final String removeHTMLTags(String haystack){
+  public static String removeHTMLTags(String haystack){
     return re_tags.substituteAll(haystack,"");
   }
 
-  /**
-   * this method deletes all but the approved tags html tags
-   * it also deletes approved tags which contain malicious-looking attributes and doesn't work at all
-   */
-  public static String approveHTMLTags(String haystack){
-    try {
-      String approvedTags="a|img|h1|h2|h3|h4|h5|h6|br|b|i|strong|p";
-      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";
-      String approvedProtocols="rtsp|http|ftp|https|freenet|mailto";
-
-      // kill all the bad tags that have attributes
-      String s = "<\\s*/?\\s*(?!(("+approvedTags+")\\s))\\w+\\s[^>]*>";
-      RE regex = new RE(s,RE.REG_ICASE);
-      haystack = regex.substituteAll(haystack,"");
-
-      // kill all the bad tags that are attributeless
-      regex = new RE("<\\s*/?\\s*(?!(("+approvedTags+")\\s*>))\\w+\\s*>",RE.REG_ICASE);
-      haystack = regex.substituteAll(haystack,"");
-
-      // kill all the tags which have a javascript attribute like onLoad
-      regex = new RE("<[^>]*("+badAttributes+")[^>]*>",RE.REG_ICASE);
-      haystack = regex.substituteAll(haystack,"");
-
-      // kill all the tags which include a url to an unacceptable protocol
-      regex = new RE("<\\s*a\\s+[^>]*href=(?!(\'|\")?("+approvedProtocols+"))[^>]*>",RE.REG_ICASE);
-      haystack = regex.substituteAll(haystack,"");
-
-      return haystack;
-    } catch(REException ex){
-      ex.printStackTrace();
-      return null;
-    }
-  }
-
 
   /**
    *  createHTML ruft alle regex-methoden zum unwandeln eines nicht
@@ -394,8 +360,9 @@ public final class StringUtil {
   public static String createHTML(String content,String producerDocRoot,String mailImage,String extImage,String intImage){
     content=convertNewline2Break(content);
     content=convertNewline2P(content);
-    content=createMailLinks(content,producerDocRoot,mailImage);
-    content=createURLLinks(content,null,producerDocRoot,extImage,intImage);
+    content=createMailLinks(content, producerDocRoot,mailImage);
+    content=createURLLinks(content, null, producerDocRoot, extImage, intImage);
+
     return content;
   }
 
@@ -403,7 +370,6 @@ public final class StringUtil {
    * Converts mir's horrible internal date format (yyyy-MM-dd HH:mm:ss+zz) into a java Date
    *
    * @param anInternalDate
-   * @return
    */
   public static Date convertMirInternalDateToDate(String anInternalDate) {
     Calendar calendar = new GregorianCalendar();