1 package de.webman.duplication.eventhandler; 2 3 import com.teamkonzept.web.servlet.*; 4 import com.teamkonzept.webman.mainint.*; 5 import com.teamkonzept.webman.db.*; 6 import com.teamkonzept.web.*; 7 import com.teamkonzept.lib.*; 8 9 import com.teamkonzept.web.oracle.*; 10 import com.teamkonzept.field.*; 11 import com.teamkonzept.db.*; 12 import com.teamkonzept.webman.*; 13 14 import java.io.*; 15 import java.util.*; 16 import java.sql.*; 17 import java.text.*; 18 19 import org.apache.log4j.Category; 20 24 public class CounterNameModifier extends NameModifier 25 { 26 private static Category cat = Category.getInstance(CounterNameModifier.class); 27 28 String MyClassIdentifier = "PAR"; 30 31 32 int mode; 33 boolean reverse; 34 String numberOfCopiesString; 35 String numberingDirection; 36 int firstCounter; 37 38 CounterNameModifier(){ 39 classIdentifier = MyClassIdentifier; 40 } 41 42 void localInit(){ 43 44 numberOfCopiesString = (String )myParams.get( "NUMBER_OF_COPIES" ); 46 numberingDirection = (String )myParams.get( "NUM_DIRECTION" ); 47 String stringShape = (String )myParams.get( "STRING_SHAPE") ; 48 reverse = (numberingDirection != null && numberingDirection.equals("REVERSE") ); 49 try{ 50 mode = (new Integer (stringShape)).intValue(); 51 } 52 catch(NumberFormatException e){ 53 mode = 0; 54 } 55 try{ 56 firstCounter = (new Integer ((String )myParams.get( "FIRST_COUNTER" ))).intValue(); 57 } 58 catch(NumberFormatException e) 59 { 60 cat.debug(" Exception caught by DuplicateServlet.doDuMultiDuplicate() " , e); 62 firstCounter = 1; 63 } 64 } 65 66 public boolean checkParams(){ 67 return true; 68 } 69 70 public String modify(int copyNrInt, String oldName) 71 { 72 cat.debug("CounterNameModifier.modify() called with mode = "+ mode); 73 String newName; 74 StringBuffer stringBuffer; 75 Integer copyNr = new Integer (copyNrInt + firstCounter); 76 boolean front = true; 77 String copyStr = reverse ? new String (new Integer (nrOfCopies - copyNr.intValue() +1 ).toString()) : copyNr.toString(); 78 if (mode == 0){ 79 newName = front? copyStr + "_" : "_" + copyStr; 80 } 81 else if (mode == 1){ int diff = String.valueOf(nrOfCopies + firstCounter).length() - copyStr.toString().length(); 83 cat.debug(" nrOfCopies = " +nrOfCopies +" firstCounter " + firstCounter +" copyStr " + copyStr); 84 cat.debug(" diff = " +diff); 85 if (front){ stringBuffer = new StringBuffer ( copyStr + "_"); 87 for (int i = 0; i < diff ; i++){ 88 stringBuffer.insert(0,'0'); 89 } 90 } 91 else{ stringBuffer = new StringBuffer ( copyStr ); 93 for (int i = 0; i < diff ; i++){ 94 stringBuffer.insert(0,'0'); 95 } 96 stringBuffer.insert(0,'_'); 97 } 98 newName = new String ( stringBuffer); 99 } 100 else if (mode == 2){ 101 newName = new String ( "_" + copyStr); 102 } 103 else{ 104 newName = ""; 105 } 106 return newName; 107 } 108 } 109 110 | Popular Tags |