X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FStringUtil.java;h=7f08337f4657cf221c609b9cca05231616b47c57;hb=ed9932a980050bd1a8c3ffda8d8dff36ead479cc;hp=bcbc06a1f73c305bd77cb14ae973032dc967f5de;hpb=96449227f77b9f1203b2ec1d8d5491b793a2cfa5;p=mir.git diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index bcbc06a1..7f08337f 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -1,439 +1,236 @@ -/* - * 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.text.NumberFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.TimeZone; - -import gnu.regexp.RE; -import gnu.regexp.REException; - -/** - * Statische Hilfsmethoden zur Stringbehandlung - * - * @version $Id: StringUtil.java,v 1.33.2.4 2003/08/10 00:16:53 zapata 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 - * @return 8-ziffriger String (yyyymmdd) - */ - - public static final String date2webdbDate (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))); - return webdbDate.toString(); - } - - /** - * 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) - */ - public static String date2readableDateTime (GregorianCalendar theDate) { - String readable = ""; - int hour; - readable += pad2(theDate.get(Calendar.DATE)); - readable += "." + pad2(theDate.get(Calendar.MONTH) + 1); - readable += "." + String.valueOf(theDate.get(Calendar.YEAR)); - hour = theDate.get(Calendar.HOUR); - if (theDate.get(Calendar.AM_PM) == Calendar.PM) - hour += 12; - readable += " / " + pad2(hour); - readable += ":" + pad2(theDate.get(Calendar.MINUTE)); - return readable; - } - - /** - * deleteForbiddenTags - * this method deletes all