KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.duplication.eventhandler;
2
3 import com.teamkonzept.web.*;
4 import com.teamkonzept.webman.*;
5 import com.teamkonzept.webman.db.TKWebmanDBManager;
6 import com.teamkonzept.webman.mainint.*;
7 import com.teamkonzept.webman.mainint.db.*;
8 import com.teamkonzept.webman.mainint.db.queries.duplication.*;
9
10
11 import com.teamkonzept.webman.mainint.db.queries.*;
12 import com.teamkonzept.webman.mainint.events.*;
13 import com.teamkonzept.lib.*;
14 import com.teamkonzept.db.*;
15
16
17
18 import java.sql.*;
19 import java.io.*;
20
21 /**
22 * Anzeigen der Maske zum Neuordnen des Contenttree
23 *
24  * @author $Author: alex $
25  * @version $Revision: 1.3 $
26 */

27 public class DUDuplicateHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults
28 {
29     private DUDuplicateHandler()
30     {}
31     
32     private static DUDuplicateHandler instance = new DUDuplicateHandler();
33     
34     public static DUDuplicateHandler getInstance()
35     {
36         return instance;
37     }
38     
39     public void handleEvent(TKEvent evt) throws TKException
40     {
41         try{
42             doDuDuplicate(evt);
43         }
44         catch (Throwable JavaDoc e)
45         {
46             // TO DO : Analyze Exception !
47
throw WebmanExceptionHandler.getException(e);
48         }
49     }
50     
51     public boolean isHandler(TKEvent evt)
52     {
53         return evt.getName().equalsIgnoreCase("DU_DUPLICATE");
54     }
55
56     public boolean doDuDuplicate(TKEvent evt) throws Throwable JavaDoc{
57         return doDuDuplicate(true, evt);
58     }
59     
60     
61     public boolean doDuDuplicate(boolean log, TKEvent evt ) throws Throwable JavaDoc{
62         return doDuDuplicate(log, new Integer JavaDoc[2] , null, null, null, null, evt);
63     }
64     
65     public boolean doDuDuplicate(boolean log, Integer JavaDoc[] newRootIDs, TKEvent evt) throws Throwable JavaDoc{
66         return doDuDuplicate(log, newRootIDs, null, null, null, null, evt);
67     }
68     /**
69      * dupliziert teilbaeume und gibt eine Bestaetigungsseite zurueck wenn log == true
70      *
71      *
72      * @param log states if a template is print out
73      */

74     public boolean doDuDuplicate(boolean log, Integer JavaDoc[] newRootIDs,String JavaDoc newConRootName, String JavaDoc newConRootShortname, String JavaDoc newSiteRootName, String JavaDoc newSiteRootShortname, TKEvent evt) throws Throwable JavaDoc
75     {
76         TKParams params = evt.getParams();
77         
78         String JavaDoc stSubRootId = null ;
79         String JavaDoc stTargetRootId = null;
80         
81         /* Variables for Results */
82         int newContentRootID= -1;
83         int newSiteRootID = -1;
84         
85         TKHTMLTemplate t = null;
86         if(log){
87             t= evt.getPrepHTMLTemplate( "du_intro.tmpl" );
88             if(params.getClass("PAR") != null){
89                 t.set(params.getClass("PAR"));
90             }
91         }
92         
93         // Check ParameterSet
94
if( ! Utils.doDUVerifyParameterSet(true, evt)){
95             return Utils.doErrorSide(evt);
96         }
97         
98             
99         TKQuery q = TKDBManager.newQuery( TKDBDuplicateQuery.class );
100        
101         /* Check if Site-Tree duplication is requested */
102         String JavaDoc siteDupFlag = params.get( "PAR", "SITE_TREE_FLAG" ) != null ? params.get( "PAR", "SITE_TREE_FLAG" ) : "";
103         if(siteDupFlag.equals( "ON")){
104         /* The followig code is only executed if a Site tree is duplicated */
105        
106         /* Query flag for execution of Site-Tree copy */
107              q.setQueryParams( "SITE_TREE_FLAG", new Integer JavaDoc( 1 ) );
108              
109              stSubRootId = params.get( "PAR", "ST_SUBTREE_ROOT_ID" );
110              stTargetRootId = params.get( "PAR", "ST_TARGET_ROOT_ID" );
111              newSiteRootName = newSiteRootName != null ? newSiteRootName : params.get( "PAR", "NEW_SITE_ROOT_NAME" );
112              newSiteRootShortname = newSiteRootShortname != null? newSiteRootShortname : params.get( "PAR", "NEW_SITE_ROOT_SHORTNAME" );
113              
114              if(newSiteRootName.equals("") || newSiteRootShortname.equals("") || stSubRootId.equals("") || newSiteRootShortname.equals("")){
115                // Missing input parameter
116
return Utils.doErrorSide(evt);
117              }
118              q.setQueryParams( "ST_SUBTREE_ROOT_ID", new Integer JavaDoc( Integer.parseInt( stSubRootId ) ) );
119              q.setQueryParams( "ST_TARGET_ROOT_ID", new Integer JavaDoc( Integer.parseInt( stTargetRootId ) ) );
120              q.setQueryParams( "NEW_SITE_ROOT_NAME", newSiteRootName );
121              q.setQueryParams( "NEW_SITE_ROOT_SHORTNAME", newSiteRootShortname );
122              if(log){
123                 t.set( "ST_SUBTREE_ROOT_ID" , stSubRootId );
124                 t.set( "ST_TARGET_ROOT_ID" , stTargetRootId );
125              }
126         }
127         
128         
129         
130         /* The following is for The Content Tree */
131         String JavaDoc tmplRootId = params.get( "PAR", "TEMPLATE_ROOT_ID" );
132         String JavaDoc targetRootId = params.get( "PAR", "TARGET_ROOT_ID" );
133         newConRootName = newConRootName != null ? newConRootName :params.get( "PAR", "NEW_CONTENT_ROOT_NAME" );
134         newConRootShortname = newConRootShortname != null ? newConRootShortname : params.get( "PAR", "NEW_CONTENT_ROOT_SHORTNAME" );
135             
136                
137        /* Check if Contenttree duplication is requested */
138         String JavaDoc contentDupFlag = params.get( "PAR", "CONTENT_FLAG" );
139         if(contentDupFlag.equals( "ON")){
140             if( newConRootName.equals("") || newConRootShortname.equals("")
141                 || (tmplRootId == null)
142                 || (targetRootId== null)){
143                // Error :missing input parameters
144
return Utils.doErrorSide(evt);
145             }
146                
147             q.setQueryParams( "NEW_CONTENT_ROOT_NAME", newConRootName );
148             q.setQueryParams( "NEW_CONTENT_ROOT_SHORTNAME", newConRootShortname );
149             q.setQueryParams( "TEMPLATE_ROOT_ID", new Integer JavaDoc( Integer.parseInt( tmplRootId ) ) );
150             q.setQueryParams( "TARGET_ROOT_ID", new Integer JavaDoc( Integer.parseInt( targetRootId ) ) );
151         }
152         
153         
154         /*
155         TKQuery qResults = TKWebmanDBManager.newQuery(SelectDuplicationResults.class);
156         qResults.setQueryParams( "TEMPLATE_ROOT_ID", new Integer( Integer.parseInt( tmplRootId ) ) );
157         qResults.setQueryParams( "ST_SUBTREE_ROOT_ID", new Integer( Integer.parseInt( stSubRootId ) ) );
158         */

159         
160         
161         /* This transaction is ABSOLUTELY REQUIRED.
162             If omitted, the oracle version will not yield the expected results
163         */

164         
165         ResultSet rsNewIDs;
166         
167         TKDBManager.beginTransaction();
168         try{
169             q.execute();
170             rsNewIDs=q.fetchResultSet();
171             
172             TKDBManager.commitTransaction();
173           
174             
175             if(rsNewIDs != null && rsNewIDs.next()){
176                 newContentRootID = rsNewIDs.getInt("NEW_CONT_ROOT_ID");
177                 if(!rsNewIDs.wasNull()){
178                     newRootIDs[0] = new Integer JavaDoc(newContentRootID);
179                 }
180                 
181                 newSiteRootID = rsNewIDs.getInt("NEW_SITE_ROOT_ID");
182                 if(!rsNewIDs.wasNull()){
183                     newRootIDs[1] = new Integer JavaDoc(newSiteRootID);
184                 }
185             }
186
187         q.close();
188                    
189         }
190         catch(SQLException e){
191             TKDBManager.rollbackTransaction();
192             throw e;
193         }
194            
195         if(log){
196             String JavaDoc numberOfCopies = params.get("PAR", "NUMBER_OF_COPIES");
197             if( numberOfCopies != null ){
198                     t.set("NUMBER_OF_COPIES",numberOfCopies);
199             }
200             t.set( "DONE", "1" );
201             evt.finishTemplate(t);
202         }
203         return true;
204     }
205         
206 }
207
Popular Tags