*/
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;
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);
* @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));
* @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("-");
* @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));
* @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;
}
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);
+ }
+
+
+
}