X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FStringUtil.java;h=93d4c6b24332ba1311295e2c15af114aa72fb2d5;hb=e5dc7e8c6534276337eeb0f4cbc7e636b0ffc660;hp=b4dccd1cf7c5ded5d2bec9c5b4f58e17c23ce2ba;hpb=4129038fcef5255505f62afe7679cacc81352cee;p=mir.git
diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java
index b4dccd1c..93d4c6b2 100755
--- a/source/mir/misc/StringUtil.java
+++ b/source/mir/misc/StringUtil.java
@@ -1,20 +1,56 @@
/*
- * 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 the com.oreilly.servlet library, 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 java.text.NumberFormat;
import gnu.regexp.*;
/**
* Statische Hilfsmethoden zur Stringbehandlung
*
- * @version 29.6.99
- * @author RK
+ * @version $Revision: 1.23.2.1 $ $Date: 2002/09/01 21:31:40 $
+ * @author $Author: mh $
+ *
+ * $Log: StringUtil.java,v $
+ * Revision 1.23.2.1 2002/09/01 21:31:40 mh
+ * Mir goes GPL
+ *
+ * Revision 1.23 2002/06/28 20:39:37 mh
+ * added numberformat helper. make webdbDate2readableDate use webdb_create instead. make the order and appearance of it more consistent. cvs macros. and finally code tidying
+ *
+ *
*/
public final class StringUtil {
@@ -36,6 +72,17 @@ public final class StringUtil {
}
}
+ /**
+ * 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)
@@ -68,7 +115,7 @@ public final class StringUtil {
}
/**
- * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyymmddThhmmssTZ)
+ * Return a http://www.w3.org/TR/NOTE-datetime formatted date (yyyy-mm-ddThh:mm:ssTZ)
* @param theDate
* @return w3approved datetime
*/
@@ -76,13 +123,17 @@ public final class StringUtil {
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)));
+ 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....
+ //assumes you are an hour-multiple away from UTC....
int offset=(theDate.get(Calendar.ZONE_OFFSET)/(60*60*1000));
if (offset < 0){
webdbDate.append("-");
@@ -91,7 +142,7 @@ public final class StringUtil {
webdbDate.append("+");
}
webdbDate.append(pad2(Math.abs(offset)));
- webdbDate.append("00");
+ webdbDate.append(":00");
return webdbDate.toString();
}
@@ -135,13 +186,13 @@ public final class StringUtil {
* wandelt Calendar in dd.mm.yyyy um
*
* @param theDate
- * @return String mit dd.mm.yyyy
+ * @return String mit yyyy.mm.dd
*/
public static final String webdbDate2readableDate (String webdbDate) {
String date = "";
- date += webdbDate.substring(6, 8);
- date += "." + webdbDate.substring(4, 6);
- date += "." + webdbDate.substring(0, 4);
+ date += webdbDate.substring(0, 4);
+ date += "-" + webdbDate.substring(5, 7);
+ date += "-"+webdbDate.substring(8, 10);
return date;
}
@@ -162,23 +213,28 @@ public final class StringUtil {
return returnDate.toString();
}
- /**
+ /**
* converts string from format: yyyy-mm-dd__hh:mm:ss.dddddd+TZ
- * to yyyymmddThhmmss+TZ:00 (w3 format for Dublin Core)
+ * to yyyy-mm-ddThh:mm:ss+TZ:00 (w3 format for Dublin Core)
*/
public static String webdbdateToDCDate(String date) {
StringBuffer returnDate = new StringBuffer();
if (date!=null) {
+ returnDate.append(date.substring(0,10));
+ returnDate.append("T");
+ returnDate.append(date.substring(11,19));
+ //String tzInfo=date.substring(26,29);
+ //if (tzInfo.equals("+00")){
+ //UTC gets a special code in w3 dates
+ // returnDate.append("Z");
+ //}
+ //else{
+ //need to see what a newfoundland postgres
+ //timestamp looks like before making this robust
+ // returnDate.append(tzInfo);
+ // returnDate.append(":00");
+ //}
- returnDate.append(date.substring(0,4));
- returnDate.append(date.substring(5,7));
- returnDate.append(date.substring(8,10));
- returnDate.append("T");
- returnDate.append(date.substring(11,13));
- returnDate.append(date.substring(14,16));
- returnDate.append(date.substring(17,19));
- returnDate.append(date.substring(20,22));
- returnDate.append(":00");
}
return returnDate.toString();
}
@@ -236,7 +292,7 @@ public final class StringUtil {
}
/**
- * Splits the provided CSV text into a list. stolen wholesale from
+ * Splits the provided CSV text into a list. stolen wholesale from
* from Jakarta Turbine StrinUtils.java -mh
*
* @param text The CSV list of values to split apart.
@@ -300,7 +356,20 @@ public final class StringUtil {
*/
public static String quote(String s)
{
- String s2 = quote(s, '\'');
+ //String s2 = quote(s, '\'');
+ //Quickhack ÊÊ Ê Ê Ê Ê Ê Ê
+ //Because of '?-Bug in Postgresql-JDBC-Driver
+ StringBuffer temp = new StringBuffer();
+ for(int i=0;i