1 20 package org.enhydra.barracuda.testbed; 21 22 import org.apache.log4j.*; 23 import java.util.*; 24 import java.text.*; 25 26 30 public class TestUtil { 31 32 public static boolean BATCH_MODE = false; 34 public static int DEBUG_LEVEL = 0; 35 36 46 public static void parseParams (String args[]) { 47 if (args!=null) { 49 for (int i=0; i<args.length; i++) { 50 String parm = args[i].toLowerCase(); 51 if (parm.startsWith("batch=")) { 52 BATCH_MODE = (parm.toLowerCase().indexOf("true")>0); 53 } else if (parm.startsWith("debug_level=")) { 54 try {DEBUG_LEVEL = Integer.parseInt(parm.substring(12));} 55 catch (Exception e) {} 56 } 57 } 58 } 59 60 System.out.println ("Setting BATCH_MODE="+TestUtil.BATCH_MODE); 62 System.out.println ("Setting DEBUG_LEVEL="+TestUtil.DEBUG_LEVEL); 63 System.out.println (""); 64 } 65 66 public static String dateStringInDefaultLocaleShortForm(String theYear, String theMonth, String theDay) { 67 Calendar aCalendar = Calendar.getInstance(); 68 aCalendar.clear(); 70 aCalendar.set(2000, 0, 1); 71 72 Date aZeroDate = aCalendar.getTime(); 73 DateFormat aDefaultDateFormat = DateFormat.getDateInstance(DateFormat.SHORT); 74 FieldPosition yearFieldPosn = new FieldPosition(DateFormat.YEAR_FIELD); 75 FieldPosition monthFieldPosn = new FieldPosition(DateFormat.MONTH_FIELD); 76 FieldPosition dayFieldPosn = new FieldPosition(DateFormat.DATE_FIELD); 77 aDefaultDateFormat.format(aZeroDate, new StringBuffer (), yearFieldPosn); 78 aDefaultDateFormat.format(aZeroDate, new StringBuffer (), monthFieldPosn); 79 aDefaultDateFormat.format(aZeroDate, new StringBuffer (), dayFieldPosn); 80 81 ArrayList sortedPositions = new ArrayList(); 83 sortedPositions.add(yearFieldPosn); 84 if (monthFieldPosn.getBeginIndex() > yearFieldPosn.getBeginIndex()) { 85 sortedPositions.add(0, monthFieldPosn); 86 } else { 87 sortedPositions.add(monthFieldPosn); 88 } 89 if (dayFieldPosn.getBeginIndex() > ((FieldPosition)sortedPositions.get(0)).getBeginIndex()) { 90 sortedPositions.add(0, dayFieldPosn); 91 } else if (dayFieldPosn.getBeginIndex() > ((FieldPosition)sortedPositions.get(1)).getBeginIndex()) { 92 sortedPositions.add(1, dayFieldPosn); 93 } else { 94 sortedPositions.add(dayFieldPosn); 95 } 96 97 StringBuffer aStrBuff = new StringBuffer (aDefaultDateFormat.format(aZeroDate)); 99 for (int i = 0; i < sortedPositions.size(); i++) { 100 FieldPosition currFieldPosn = (FieldPosition)sortedPositions.get(i); 101 String currField = theYear; 102 if (currFieldPosn==monthFieldPosn) { 103 currField = theMonth; 104 } else if (currFieldPosn==dayFieldPosn) { 105 currField = theDay; 106 } 107 aStrBuff.replace(currFieldPosn.getBeginIndex(), currFieldPosn.getEndIndex(), currField); 108 } 109 return (aStrBuff.toString()); 110 } 111 } 112 | Popular Tags |