reintroduced StringUtil.regexpReplace
[mir.git] / source / mir / misc / StringUtil.java
index a468697..6bdeac7 100755 (executable)
  */
 package  mir.misc;
 
-import gnu.regexp.RE;
-import gnu.regexp.REException;
+import org.apache.oro.text.regex.Pattern;
+import org.apache.oro.text.regex.Perl5Matcher;
+import org.apache.oro.text.regex.Perl5Substitution;
+import org.apache.oro.text.regex.Util;
 
 import java.text.NumberFormat;
 import java.util.Calendar;
@@ -40,27 +42,14 @@ import java.util.TimeZone;
 public final class StringUtil {
 
   private static TimeZone UTC = TimeZone.getTimeZone("UTC");
-  private static RE   re_tags, re_tables, re_forbiddenTags;
 
   private StringUtil() { }  // this avoids contruction
 
-  static {
-    try {
-      //precompile regex
-      re_tags       = new RE("<[^>]*>",RE.REG_ICASE);
-      re_tables = new RE("<[ \t\r\n/]*(table|td|tr)[ \t\r\n]*>",RE.REG_ICASE);
-      re_forbiddenTags = new RE("<[ \t\r\n/]*(html|meta|body|head|script)[ \t\r\n]*>",RE.REG_ICASE);
-    }
-    catch (REException e){
-      System.err.println("FATAL: StringUtil: could not precompile REGEX: "+e.toString());
-    }
-  }
-
   /**
    * Formats a number with the specified minimum and maximum number of digits.
    **/
   public static synchronized String zeroPaddingNumber(long value, int minDigits,
-      int maxDigits)
+                                                      int maxDigits)
   {
     NumberFormat numberFormat = NumberFormat.getInstance();
     numberFormat.setMinimumIntegerDigits(minDigits);
@@ -74,7 +63,7 @@ public final class StringUtil {
    * @return 8-ziffriger String (yyyymmdd)
    */
 
-  public static final String date2webdbDate (GregorianCalendar theDate) {
+  public static String date2webdbDate (GregorianCalendar theDate) {
     StringBuffer webdbDate = new StringBuffer();
     webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
     webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1));
@@ -89,7 +78,7 @@ public final class StringUtil {
    * @return w3approved datetime
    */
 
-  public static final String date2w3DateTime (GregorianCalendar theDate) {
+  public static String date2w3DateTime (GregorianCalendar theDate) {
     StringBuffer webdbDate = new StringBuffer();
     webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR)));
     webdbDate.append("-");
@@ -141,7 +130,7 @@ public final class StringUtil {
    * @param webdbDate
    * @return String mit <code>/yyyy/mm/dd</code>
    */
-  public static final String webdbDate2path (String webdbDate) {
+  public static String webdbDate2path (String webdbDate) {
     StringBuffer path = new StringBuffer();
     path.append("/").append(webdbDate.substring(0, 4));
     path.append("/").append(webdbDate.substring(4, 6));
@@ -156,7 +145,7 @@ public final class StringUtil {
    * @param path
    * @return String ohne <code>/</code> am Ende
    */
-  public static final String removeSlash (String path) {
+  public static String removeSlash (String path) {
     return  path.length() > 1 && path.endsWith("/") ? path.substring(0, path.length()
         - 1) : path;
   }
@@ -231,5 +220,16 @@ public final class StringUtil {
     return calendar.getTime();
   }
 
+  public String regexpReplace(String anInput, Pattern anExpression, String aReplacement) {
+    Perl5Matcher matcher = new Perl5Matcher();
+
+    return Util.substitute(
+      matcher, anExpression,
+      new Perl5Substitution(aReplacement), anInput,
+      Util.SUBSTITUTE_ALL);
+  }
+
+
+
 }