001: package de.webman.content.eventhandler;
002:
003: import java.sql.ResultSet;
004: import com.teamkonzept.db.TKDBManager;
005: import com.teamkonzept.db.TKQuery;
006: import com.teamkonzept.db.QueryConstants;
007: import com.teamkonzept.lib.TKException;
008: import com.teamkonzept.lib.TKVector;
009: import com.teamkonzept.web.TKEvent;
010: import com.teamkonzept.web.TKHTMLTemplate;
011: import com.teamkonzept.web.TKParams;
012: import com.teamkonzept.webman.WebManEvent;
013: import com.teamkonzept.webman.mainint.ContextConstants;
014: import com.teamkonzept.webman.mainint.DatabaseDefaults;
015: import com.teamkonzept.webman.mainint.FrameConstants;
016: import com.teamkonzept.webman.mainint.HTMLUtils;
017: import com.teamkonzept.webman.mainint.TKStandardIterator;
018: import com.teamkonzept.webman.mainint.TreeUtils;
019: import com.teamkonzept.webman.mainint.WebmanExceptionHandler;
020: import com.teamkonzept.webman.mainint.db.queries.TKDBContentTreeIsChild;
021: import com.teamkonzept.webman.mainint.db.queries.content.SelectContentTree;
022: import com.teamkonzept.webman.mainint.events.DefaultEventHandler;
023: import com.teamkonzept.webman.mainint.events.ParameterTypes;
024: import de.webman.content.Content;
025: import de.webman.content.workflow.ContentVersion;
026: import de.webman.content.workflow.VersionCache;
027:
028: /**
029: * Forwards content tree related events.
030: *
031: * @author $Author: uli $
032: * @version $Revision: 1.1 $
033: */
034: public class CEForwardHandler extends DefaultEventHandler implements
035: ParameterTypes, FrameConstants, DatabaseDefaults {
036:
037: /**
038: * The singleton instance.
039: */
040: private static final CEForwardHandler INSTANCE = new CEForwardHandler();
041:
042: /**
043: * Avoids outside intstantiation.
044: */
045: private CEForwardHandler() {
046: // NOP
047: }
048:
049: /**
050: * Returns the singleton instance.
051: *
052: * @return the singleton instance.
053: */
054: public static CEForwardHandler getInstance() {
055: return INSTANCE;
056: }
057:
058: /**
059: * Handles the specified event.
060: *
061: * @param event the event to be handled.
062: * @throws TKException if any error occurred during event handling.
063: */
064: public void handleEvent(TKEvent event) throws TKException {
065: try {
066: CEUtils.checkEvent(event);
067:
068: String target = event.getParameter(PARAMETER,
069: "TARGET_EVENT");
070: Integer id = new Integer(event.getParameter(PARAMETER,
071: "CONTENT_NODE_ID"));
072:
073: ContentContext context = getContentContext(id);
074: TKHTMLTemplate frame = event
075: .getPrepHTMLTemplate("f_ce.tmpl");
076:
077: prepareFrameSet(frame, target, context);
078:
079: if (target.equals("CE_GROUP_LIST")) {
080: frame.set("NAVIGATION_CONTEXT", context
081: .calculateNavContext());
082: }
083:
084: if (target.equals("CE_EDIT")) {
085: // Ich verstehe nicht, warum zum korrekten Editieren eines
086: // Single Contents im Template die Id und der Typ des
087: // den Content beinhaltenden Verzeichnisses stehen muß, aber
088: // es funktioniert leider nur so ... [unl/2002-04-17]
089: context.conNodeId = new Integer(event.getParameter(
090: PARAMETER, "CONTENT_NODE_PARENT"));
091: context.conNodeType = DIRECTORY_NODE_INTEGER;
092:
093: frame.set("NAVIGATION_CONTEXT", context
094: .calculateNavContext());
095: }
096:
097: event.finishTemplate(frame);
098: } catch (Throwable e) {
099: // TO DO : Analyze Exception !
100: throw WebmanExceptionHandler.getException(e);
101: }
102: }
103:
104: /**
105: * Checks wether this handler is capable to handle the specified event.
106: *
107: * @param event the event to be handled.
108: * @return <CODE>true</CODE> if this handler is capable to handle the
109: * specified event, otherwise <CODE>false</CODE>.
110: */
111: public boolean isHandler(TKEvent event) {
112: return event.getName().equalsIgnoreCase("CE_FORWARD");
113: }
114:
115: /**
116: * Prepares a frame set for the event to be forwarded.
117: *
118: * @param frame the frame set.
119: * @param event the event to be forwarded.
120: * @param context the content context.
121: * @throws Throwable if an error occurred during preparation.
122: */
123: private void prepareFrameSet(TKHTMLTemplate frame, String event,
124: ContentContext context) throws Throwable {
125: HTMLUtils.fillFrameSet(frame, LEFT_FRAME_WIDTH_SMALL,
126: "CE_SHOWLIST", event);
127:
128: context.fillIntoTemplate(frame);
129:
130: TKVector openNodes = new TKVector();
131: openNodes.put(0, "-1");
132: openNodes = TreeUtils.updateOpenNodes(openNodes,
133: context.conNodeId.toString(), "-1", context.conNodeId
134: .toString(), TKDBContentTreeIsChild.class);
135:
136: frame.setListIterator(new TKStandardIterator(openNodes, frame
137: .getListIterator(), "OPEN_NODES", "OPEN_NODES"));
138: }
139:
140: /**
141: * Returns a context information holder for the specified content.
142: *
143: * @param id the content identifier.
144: * @return a context information holder for the specified content.
145: * @throws Throwable if an error occurred during retrieval.
146: */
147: private ContentContext getContentContext(Integer id)
148: throws Throwable {
149: ContentContext context = new ContentContext(new TKParams());
150: context.conNodeId = id;
151:
152: TKQuery query = TKDBManager.newQuery(SelectContentTree.class);
153: query.setQueryParams("ID", id);
154: query.execute();
155:
156: ResultSet result = query.fetchResultSet();
157:
158: if (result.next()) {
159: context.conNodeType = new Integer(result
160: .getInt("CONTENT_NODE_TYPE"));
161: context.formId = new Integer(result.getInt("CONTENT_FORM"));
162: context.conNodeName = result.getString("CONTENT_NODE_NAME");
163: context.conNodeShortName = result
164: .getString("CONTENT_NODE_SHORTNAME");
165: }
166:
167: if (GROUP_INTEGER.equals(context.conNodeType)) {
168: context.groupConNodeId = context.conNodeId;
169: context.groupConNodeName = context.conNodeName;
170: context.groupConNodeShortName = context.conNodeShortName;
171: }
172:
173: if (SINGLE_INTEGER.equals(context.conNodeType)) {
174: Content content = VersionCache.getContentInfo(id);
175:
176: context.instanceId = content.getInstanceId();
177: context.versionId = content.getCurrentVersion().getId();
178: }
179:
180: return context;
181: }
182:
183: }
|