001: package de.webman.duplication.eventhandler;
002:
003: import com.teamkonzept.web.*;
004: import com.teamkonzept.webman.*;
005: import com.teamkonzept.webman.db.TKWebmanDBManager;
006: import com.teamkonzept.webman.mainint.*;
007: import com.teamkonzept.webman.mainint.db.*;
008:
009: import com.teamkonzept.webman.mainint.db.queries.*;
010: import com.teamkonzept.webman.mainint.db.queries.duplication.*;
011: import com.teamkonzept.webman.mainint.events.*;
012: import com.teamkonzept.lib.*;
013: import com.teamkonzept.db.*;
014:
015: import java.sql.*;
016: import java.io.*;
017:
018: /**
019: * Anzeigen der Maske zum Neuordnen des Contenttree
020: *
021: * @author $Author: alex $
022: * @version $Revision: 1.3 $
023: */
024: public class DUConfirmHandler extends DefaultEventHandler implements
025: ParameterTypes, FrameConstants, DatabaseDefaults,
026: TemplateConstants {
027: private DUConfirmHandler() {
028: }
029:
030: private static DUConfirmHandler instance = new DUConfirmHandler();
031:
032: public static DUConfirmHandler getInstance() {
033: return instance;
034: }
035:
036: public void handleEvent(TKEvent evt) throws TKException {
037: try {
038: TKParams params = evt.getParams();
039:
040: String configureDB = (params.get("PAR", "CONFIGURE_DB")) == null ? ""
041: : params.get("PAR", "CONFIGURE_DB");
042: boolean withNames = !(configureDB.equals("CONFIGURE_DB"));
043: if (!Utils.doDUVerifyParameterSet(withNames, evt)) {
044: Utils.doErrorSide(evt);
045: return;
046: }
047:
048: TKHTMLTemplate t = evt
049: .getPrepHTMLTemplate("du_choose.tmpl");
050:
051: String stSubRootId = null;
052: String stTargetRootId = null;
053:
054: if (params.getClass("PAR") != null) {
055: t.set(params.getClass("PAR"));
056: }
057: String siteTreeFlag = (params.get("PAR", "SITE_TREE_FLAG")) == null ? "OFF"
058: : params.get("PAR", "SITE_TREE_FLAG");
059: String contentTreeFlag = (params.get("PAR", "CONTENT_FLAG")) == null ? "OFF"
060: : params.get("PAR", "CONTENT_FLAG");
061:
062: /* Check if Site-Tree duplication is requested */
063: if (siteTreeFlag.equals("ON")) {
064: /* The followig code is only executed if a Site tree is duplicated */
065:
066: stSubRootId = params.get("PAR", "ST_SUBTREE_ROOT_ID");
067: stTargetRootId = params.get("PAR", "ST_TARGET_ROOT_ID");
068: String newSiteRootName = params.get("PAR",
069: "NEW_SITE_ROOT_NAME") == null ? "" : params
070: .get("PAR", "NEW_SITE_ROOT_NAME");
071: String newSiteRootShortname = params.get("PAR",
072: "NEW_SITE_ROOT_SHORTNAME") == null ? ""
073: : params.get("PAR", "NEW_SITE_ROOT_SHORTNAME");
074:
075: if (((newSiteRootName.equals("") || newSiteRootShortname
076: .equals("")) && !configureDB
077: .equals("CONFIGURE_DB"))
078:
079: || (stSubRootId == null)
080: || (stTargetRootId == null)) {
081: // Missing input parameter
082: Utils.doErrorSide(evt);
083: }
084:
085: TKQuery qSiteSourcePath = TKDBManager
086: .newQuery(TKDBSiteTreeGetParents.class);
087: TKQuery qSiteDestPath = TKDBManager
088: .newQuery(TKDBSiteTreeGetParents.class);
089: qSiteSourcePath.setQueryParams("SITE_NODE_ID",
090: new Integer(Integer.parseInt(stSubRootId)));
091: qSiteDestPath.setQueryParams("SITE_NODE_ID",
092: new Integer(Integer.parseInt(stTargetRootId)));
093: qSiteSourcePath.execute();
094: qSiteDestPath.execute();
095: TKDBResult aSourceResult = new TKDBResult(
096: qSiteSourcePath.fetchResultSet());
097: TKDBResult aDestResult = new TKDBResult(qSiteDestPath
098: .fetchResultSet());
099: TKDBResultIterator iteratorSS = new TKDBResultIterator(
100: aSourceResult, t.getListIterator(),
101: "SITE_SOURCE_PATH");
102: t.setListIterator(iteratorSS);
103:
104: TKDBResultIterator iteratorSD = new TKDBResultIterator(
105: aDestResult, t.getListIterator(),
106: "SITE_DEST_PATH");
107: t.setListIterator(iteratorSD);
108:
109: t.set("NEW_SITE_ROOT_NAME", newSiteRootName);
110: t.set("NEW_SITE_ROOT_SHORTNAME", newSiteRootShortname);
111: t.set("ST_SUBTREE_ROOT_ID", stSubRootId);
112: t.set("ST_TARGET_ROOT_ID", stTargetRootId);
113:
114: }
115:
116: if (contentTreeFlag.equals(ON)) {
117: /* The following is for The Content Tree */
118: String tmplRootId = params.get("PAR",
119: "TEMPLATE_ROOT_ID");
120: String targetRootId = params.get("PAR",
121: "TARGET_ROOT_ID");
122: String newConRootName = params.get("PAR",
123: "NEW_CONTENT_ROOT_NAME") == null ? "" : params
124: .get("PAR", "NEW_CONTENT_ROOT_NAME");
125: String newConRootShortname = params.get("PAR",
126: "NEW_CONTENT_ROOT_SHORTNAME") == null ? ""
127: : params.get("PAR",
128: "NEW_CONTENT_ROOT_SHORTNAME");
129:
130: if (((newConRootName.equals("") || newConRootShortname
131: .equals("")) && !configureDB
132: .equals("CONFIGURE_DB"))
133: || (tmplRootId == null)
134: || (targetRootId == null)) {
135: // Error :missing input parameters
136: Utils.doErrorSide(evt);
137: }
138:
139: TKQuery qContentSourcePath = TKDBManager
140: .newQuery(TKDBContentTreeGetParentsNames.class);
141: TKQuery qContentDestPath = TKDBManager
142: .newQuery(TKDBContentTreeGetParentsNames.class);
143: qContentSourcePath.setQueryParams("CONTENT_NODE_ID",
144: new Integer(Integer.parseInt(tmplRootId)));
145: qContentDestPath.setQueryParams("CONTENT_NODE_ID",
146: new Integer(Integer.parseInt(targetRootId)));
147: qContentSourcePath.execute();
148: qContentDestPath.execute();
149: TKDBResult aSourceResult = new TKDBResult(
150: qContentSourcePath.fetchResultSet());
151: TKDBResult aDestResult = new TKDBResult(
152: qContentDestPath.fetchResultSet());
153: TKDBResultIterator iteratorSS = new TKDBResultIterator(
154: aSourceResult, t.getListIterator(),
155: "CONTENT_SOURCE_PATH");
156: t.setListIterator(iteratorSS);
157:
158: TKDBResultIterator iteratorSD = new TKDBResultIterator(
159: aDestResult, t.getListIterator(),
160: "CONTENT_DEST_PATH");
161: t.setListIterator(iteratorSD);
162:
163: t.set("NEW_CONTENT_ROOT_NAME", newConRootName);
164: t
165: .set("NEW_CONTENT_ROOT_SHORTNAME",
166: newConRootShortname);
167: t.set("TEMPLATE_ROOT_ID", tmplRootId);
168: t.set("TARGET_ROOT_ID", targetRootId);
169:
170: qContentSourcePath.close();
171: qContentDestPath.close();
172: }
173:
174: t.set("CONFIRM", "1");
175: // Number of Copies
176: String currNumber = params.get("PAR", "NUMBER_OF_COPIES");
177: if (currNumber != null) {
178: Integer currNumberInteger = new Integer(currNumber);
179: t.set("NUMBER_OF_COPIES", currNumberInteger);
180: }
181: /* ein fauler hack: */
182: if (params.getClass("MOD_DATE") != null) {
183: t.set(params.getClass("MOD_DATE"));
184: }
185: evt.finishTemplate(t);
186: // return true;
187: return;
188:
189: } catch (Throwable e) {
190: // TO DO : Analyze Exception !
191: throw WebmanExceptionHandler.getException(e);
192: }
193: }
194:
195: public boolean isHandler(TKEvent evt) {
196: return evt.getName().equalsIgnoreCase("DU_CONFIRM");
197: }
198:
199: }
|