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 9 10 import com.teamkonzept.webman.mainint.db.queries.*; 11 import com.teamkonzept.webman.mainint.db.queries.duplication.*; 12 import com.teamkonzept.webman.mainint.events.*; 13 import com.teamkonzept.lib.*; 14 import com.teamkonzept.db.*; 15 16 import java.sql.*; 17 import java.io.*; 18 19 25 public class DUConfirmHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults, TemplateConstants 26 { 27 private DUConfirmHandler() 28 {} 29 30 private static DUConfirmHandler instance = new DUConfirmHandler(); 31 32 public static DUConfirmHandler getInstance() 33 { 34 return instance; 35 } 36 37 public void handleEvent(TKEvent evt) throws TKException 38 { 39 try 40 { 41 TKParams params = evt.getParams(); 42 43 String configureDB = (params.get("PAR", "CONFIGURE_DB")) == null? "":params.get("PAR", "CONFIGURE_DB") ; 44 boolean withNames = !(configureDB.equals("CONFIGURE_DB")); 45 if( ! Utils.doDUVerifyParameterSet(withNames, evt)){ 46 Utils.doErrorSide(evt); 47 return; 48 } 49 50 TKHTMLTemplate t = evt.getPrepHTMLTemplate( "du_choose.tmpl" ); 51 52 String stSubRootId = null ; 53 String stTargetRootId = null; 54 55 if(params.getClass("PAR") != null){ 56 t.set(params.getClass("PAR")); 57 } 58 String siteTreeFlag = (params.get("PAR", "SITE_TREE_FLAG")) == null? "OFF":params.get("PAR", "SITE_TREE_FLAG") ; 59 String contentTreeFlag = (params.get( "PAR", "CONTENT_FLAG" ))==null? "OFF":params.get( "PAR", "CONTENT_FLAG" ); 60 61 62 if(siteTreeFlag.equals( "ON")){ 63 64 65 66 stSubRootId = params.get( "PAR", "ST_SUBTREE_ROOT_ID" ); 67 stTargetRootId = params.get( "PAR", "ST_TARGET_ROOT_ID" ); 68 String newSiteRootName = params.get( "PAR", "NEW_SITE_ROOT_NAME" ) == null? "": params.get( "PAR", "NEW_SITE_ROOT_NAME" ) ; 69 String newSiteRootShortname = params.get( "PAR", "NEW_SITE_ROOT_SHORTNAME" ) == null? "" :params.get( "PAR", "NEW_SITE_ROOT_SHORTNAME" ); 70 71 if( 72 ( 73 ( 74 newSiteRootName.equals("") 75 || 76 newSiteRootShortname.equals("") 77 ) 78 && !configureDB.equals("CONFIGURE_DB") 79 ) 80 81 || (stSubRootId == null) 82 || (stTargetRootId == null) 83 ){ 84 Utils.doErrorSide(evt); 86 } 87 88 TKQuery qSiteSourcePath= TKDBManager.newQuery( TKDBSiteTreeGetParents.class ); 89 TKQuery qSiteDestPath = TKDBManager.newQuery( TKDBSiteTreeGetParents.class ); 90 qSiteSourcePath.setQueryParams( "SITE_NODE_ID", new Integer ( Integer.parseInt( stSubRootId ) ) ); 91 qSiteDestPath.setQueryParams( "SITE_NODE_ID", new Integer ( Integer.parseInt( stTargetRootId ) ) ); 92 qSiteSourcePath.execute(); 93 qSiteDestPath.execute(); 94 TKDBResult aSourceResult = new TKDBResult(qSiteSourcePath.fetchResultSet()); 95 TKDBResult aDestResult = new TKDBResult(qSiteDestPath.fetchResultSet()); 96 TKDBResultIterator iteratorSS = new TKDBResultIterator( aSourceResult, t.getListIterator(), "SITE_SOURCE_PATH"); 97 t.setListIterator( iteratorSS); 98 99 TKDBResultIterator iteratorSD = new TKDBResultIterator( aDestResult, t.getListIterator(), "SITE_DEST_PATH"); 100 t.setListIterator( iteratorSD ); 101 102 103 t.set( "NEW_SITE_ROOT_NAME",newSiteRootName); 104 t.set( "NEW_SITE_ROOT_SHORTNAME", newSiteRootShortname); 105 t.set( "ST_SUBTREE_ROOT_ID" , stSubRootId ); 106 t.set( "ST_TARGET_ROOT_ID" , stTargetRootId ); 107 108 109 } 110 111 112 if(contentTreeFlag.equals(ON)){ 113 114 String tmplRootId = params.get( "PAR", "TEMPLATE_ROOT_ID" ); 115 String targetRootId = params.get( "PAR", "TARGET_ROOT_ID" ); 116 String newConRootName = params.get( "PAR", "NEW_CONTENT_ROOT_NAME" )==null? "":params.get( "PAR", "NEW_CONTENT_ROOT_NAME" ) ; 117 String newConRootShortname = params.get( "PAR", "NEW_CONTENT_ROOT_SHORTNAME" )==null? "":params.get( "PAR", "NEW_CONTENT_ROOT_SHORTNAME" ); 118 119 120 121 if( ((newConRootName.equals("") || newConRootShortname.equals("")) && !configureDB.equals("CONFIGURE_DB")) 122 || (tmplRootId == null) 123 || (targetRootId== null)){ 124 Utils.doErrorSide(evt); 126 } 127 128 129 130 131 TKQuery qContentSourcePath= TKDBManager.newQuery( TKDBContentTreeGetParentsNames.class ); 132 TKQuery qContentDestPath = TKDBManager.newQuery( TKDBContentTreeGetParentsNames.class ); 133 qContentSourcePath.setQueryParams( "CONTENT_NODE_ID", new Integer ( Integer.parseInt( tmplRootId ) ) ); 134 qContentDestPath.setQueryParams( "CONTENT_NODE_ID", new Integer ( Integer.parseInt( targetRootId ) ) ); 135 qContentSourcePath.execute(); 136 qContentDestPath.execute(); 137 TKDBResult aSourceResult = new TKDBResult(qContentSourcePath.fetchResultSet()); 138 TKDBResult aDestResult = new TKDBResult(qContentDestPath.fetchResultSet()); 139 TKDBResultIterator iteratorSS = new TKDBResultIterator( aSourceResult, t.getListIterator(), "CONTENT_SOURCE_PATH"); 140 t.setListIterator( iteratorSS); 141 142 TKDBResultIterator iteratorSD = new TKDBResultIterator( aDestResult, t.getListIterator(), "CONTENT_DEST_PATH"); 143 t.setListIterator( iteratorSD ); 144 145 t.set( "NEW_CONTENT_ROOT_NAME",newConRootName); 146 t.set( "NEW_CONTENT_ROOT_SHORTNAME", newConRootShortname); 147 t.set( "TEMPLATE_ROOT_ID" , tmplRootId ); 148 t.set( "TARGET_ROOT_ID" , targetRootId ); 149 150 qContentSourcePath.close(); 151 qContentDestPath.close(); 152 } 153 154 155 t.set( "CONFIRM", "1" ); 156 String currNumber = params.get( "PAR", "NUMBER_OF_COPIES" ); 158 if(currNumber != null){ 159 Integer currNumberInteger = new Integer (currNumber); 160 t.set( "NUMBER_OF_COPIES",currNumberInteger); 161 } 162 163 if(params.getClass("MOD_DATE")!= null){ 164 t.set(params.getClass("MOD_DATE")); 165 } 166 evt.finishTemplate(t); 167 return; 169 170 171 } 172 catch (Throwable e) 173 { 174 throw WebmanExceptionHandler.getException(e); 176 } 177 } 178 179 public boolean isHandler(TKEvent evt) 180 { 181 return evt.getName().equalsIgnoreCase("DU_CONFIRM"); 182 } 183 184 } 185 | Popular Tags |