KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > duplication > eventhandler > CounterNameModifier


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 /**
21  * @author $Author: mischa $
22  * @version $Revision: 1.1 $
23 */

24 public class CounterNameModifier extends NameModifier
25 {
26     private static Category cat = Category.getInstance(CounterNameModifier.class);
27     
28     //String MyClassIdentifier = "MOD_COUNTER";
29
String JavaDoc MyClassIdentifier = "PAR";
30     
31
32     int mode;
33     boolean reverse;
34     String JavaDoc numberOfCopiesString;
35     String JavaDoc numberingDirection;
36     int firstCounter;
37     
38     CounterNameModifier(){
39         classIdentifier = MyClassIdentifier;
40     }
41
42     void localInit(){
43     
44         //extModeStr = (String)myParams.get( "NAME_EXTENSION" );
45
numberOfCopiesString = (String JavaDoc)myParams.get( "NUMBER_OF_COPIES" );
46         numberingDirection = (String JavaDoc)myParams.get( "NUM_DIRECTION" );
47         String JavaDoc stringShape = (String JavaDoc)myParams.get( "STRING_SHAPE") ;
48         reverse = (numberingDirection != null && numberingDirection.equals("REVERSE") );
49         try{
50             mode = (new Integer JavaDoc(stringShape)).intValue();
51         }
52         catch(NumberFormatException JavaDoc e){
53             mode = 0;
54         }
55         try{
56             firstCounter = (new Integer JavaDoc((String JavaDoc)myParams.get( "FIRST_COUNTER" ))).intValue();
57         }
58         catch(NumberFormatException JavaDoc e)
59         {
60             // normal error
61
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 JavaDoc modify(int copyNrInt, String JavaDoc oldName)
71     {
72         cat.debug("CounterNameModifier.modify() called with mode = "+ mode);
73         String JavaDoc newName;
74         StringBuffer JavaDoc stringBuffer;
75         Integer JavaDoc copyNr = new Integer JavaDoc(copyNrInt + firstCounter);
76         boolean front = true;
77         String JavaDoc copyStr = reverse ? new String JavaDoc(new Integer JavaDoc(nrOfCopies - copyNr.intValue() +1 ).toString()) : copyNr.toString();
78         if (mode == 0){
79             newName = front? copyStr + "_" : "_" + copyStr;
80         }
81         else if (mode == 1){// String mit Nullen auffuellen
82
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){ // _ hinten
86
stringBuffer = new StringBuffer JavaDoc( copyStr + "_");
87                 for (int i = 0; i < diff ; i++){
88                     stringBuffer.insert(0,'0');
89                 }
90             }
91             else{// _ vorne
92
stringBuffer = new StringBuffer JavaDoc( copyStr );
93                 for (int i = 0; i < diff ; i++){
94                     stringBuffer.insert(0,'0');
95                 }
96                 stringBuffer.insert(0,'_');
97             }
98             newName = new String JavaDoc( stringBuffer);
99         }
100         else if (mode == 2){
101             newName = new String JavaDoc( "_" + copyStr);
102         }
103         else{
104             newName = "";
105         }
106         return newName;
107     }
108 }
109
110
Popular Tags