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 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 e) 45 { 46 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 { 57 return doDuDuplicate(true, evt); 58 } 59 60 61 public boolean doDuDuplicate(boolean log, TKEvent evt ) throws Throwable { 62 return doDuDuplicate(log, new Integer [2] , null, null, null, null, evt); 63 } 64 65 public boolean doDuDuplicate(boolean log, Integer [] newRootIDs, TKEvent evt) throws Throwable { 66 return doDuDuplicate(log, newRootIDs, null, null, null, null, evt); 67 } 68 74 public boolean doDuDuplicate(boolean log, Integer [] newRootIDs,String newConRootName, String newConRootShortname, String newSiteRootName, String newSiteRootShortname, TKEvent evt) throws Throwable 75 { 76 TKParams params = evt.getParams(); 77 78 String stSubRootId = null ; 79 String stTargetRootId = null; 80 81 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 if( ! Utils.doDUVerifyParameterSet(true, evt)){ 95 return Utils.doErrorSide(evt); 96 } 97 98 99 TKQuery q = TKDBManager.newQuery( TKDBDuplicateQuery.class ); 100 101 102 String siteDupFlag = params.get( "PAR", "SITE_TREE_FLAG" ) != null ? params.get( "PAR", "SITE_TREE_FLAG" ) : ""; 103 if(siteDupFlag.equals( "ON")){ 104 105 106 107 q.setQueryParams( "SITE_TREE_FLAG", new Integer ( 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 return Utils.doErrorSide(evt); 117 } 118 q.setQueryParams( "ST_SUBTREE_ROOT_ID", new Integer ( Integer.parseInt( stSubRootId ) ) ); 119 q.setQueryParams( "ST_TARGET_ROOT_ID", new Integer ( 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 131 String tmplRootId = params.get( "PAR", "TEMPLATE_ROOT_ID" ); 132 String 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 138 String contentDupFlag = params.get( "PAR", "CONTENT_FLAG" ); 139 if(contentDupFlag.equals( "ON")){ 140 if( newConRootName.equals("") || newConRootShortname.equals("") 141 || (tmplRootId == null) 142 || (targetRootId== null)){ 143 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 ( Integer.parseInt( tmplRootId ) ) ); 150 q.setQueryParams( "TARGET_ROOT_ID", new Integer ( Integer.parseInt( targetRootId ) ) ); 151 } 152 153 154 159 160 161 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 (newContentRootID); 179 } 180 181 newSiteRootID = rsNewIDs.getInt("NEW_SITE_ROOT_ID"); 182 if(!rsNewIDs.wasNull()){ 183 newRootIDs[1] = new Integer (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 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 |