X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FStringUtil.java;h=f9c996a731e0f301df0baaad0b1df11099fb6294;hb=29da699109ce8842d02b60abcdb0dfdc4aa4f0db;hp=9bfb152069ce41927a347e76d45734303a620331;hpb=84722c0556b2100ebf0fd7e769cf89d3fb628ba8;p=mir.git diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 9bfb1520..f9c996a7 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -1,23 +1,85 @@ /* - * put your module comment here + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. */ - - package mir.misc; -import java.io.*; -import java.lang.*; -import java.util.*; -import gnu.regexp.*; +import gnu.regexp.RE; +import gnu.regexp.REException; + +import java.text.NumberFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.TimeZone; /** * Statische Hilfsmethoden zur Stringbehandlung * - * @version 29.6.99 - * @author RK + * @version $Id: StringUtil.java,v 1.33.2.5 2003/10/23 14:55:28 rk Exp $ + * @author mir-coders group + * */ public final class StringUtil { + private static RE re_newline2br, re_brbr2p, re_mail, re_url, re_tags, + re_tables, re_forbiddenTags; + + private StringUtil() { } // this avoids contruction + + static { + try { + //precompile regex + re_newline2br = new RE("(\r?\n){1}"); + re_brbr2p = new RE("(
\r?\n
){1,}"); + re_mail = new RE("\\b([a-zA-Z0-9_.-]+)@([a-zA-Z0-9_-]+)\\.([a-zA-Z0-9_.-]+)\\b"); + re_url = new RE("((https://)|(http://)|(ftp://)){1}([a-zA-Z0-9_-]+).([a-zA-Z0-9_.:-]+)/?([^ \t\r\n<>\\)\\]]+[^ \t\r\n.,<>\\)\\]])"); + 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) + { + NumberFormat numberFormat = NumberFormat.getInstance(); + numberFormat.setMinimumIntegerDigits(minDigits); + numberFormat.setMaximumIntegerDigits(maxDigits); + return numberFormat.format(value); + } + /** * Wandelt Datum in einen 8-ziffrigen String um (yyyymmdd) * @param theDate @@ -33,6 +95,54 @@ public final class StringUtil { } /** + * Wandelt Calendar in einen 12-ziffrigen String um (yyyymmddhhmm) + * @param theDate + * @return 12-ziffriger String (yyyymmdd) + */ + + public static final String date2webdbDateTime (GregorianCalendar theDate) { + StringBuffer webdbDate = new StringBuffer(); + webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); + webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); + webdbDate.append(pad2(theDate.get(Calendar.DATE))); + webdbDate.append(pad2(theDate.get(Calendar.HOUR))); + webdbDate.append(pad2(theDate.get(Calendar.MINUTE))); + return webdbDate.toString(); + } + + /** + * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ) + * @param theDate + * @return w3approved datetime + */ + + public static final String date2w3DateTime (GregorianCalendar theDate) { + StringBuffer webdbDate = new StringBuffer(); + webdbDate.append(String.valueOf(theDate.get(Calendar.YEAR))); + webdbDate.append("-"); + webdbDate.append(pad2(theDate.get(Calendar.MONTH) + 1)); + webdbDate.append("-"); + webdbDate.append(pad2(theDate.get(Calendar.DATE))); + webdbDate.append("T"); + webdbDate.append(pad2(theDate.get(Calendar.HOUR_OF_DAY))); + webdbDate.append(":"); + webdbDate.append(pad2(theDate.get(Calendar.MINUTE))); + webdbDate.append(":"); + webdbDate.append(pad2(theDate.get(Calendar.SECOND))); + //assumes you are an hour-multiple away from UTC.... + int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000)); + if (offset < 0){ + webdbDate.append("-"); + } + else{ + webdbDate.append("+"); + } + webdbDate.append(pad2(Math.abs(offset))); + webdbDate.append(":00"); + return webdbDate.toString(); + } + + /** * wandelt Calendar in dd.mm.yyyy / hh.mm um * @param theDate * @return String mit (dd.mm.yyyy / hh.mm um) @@ -52,6 +162,22 @@ public final class StringUtil { } /** + * deleteForbiddenTags + * this method deletes all