1 package de.webman.content.eventhandler; 2 3 import java.sql.ResultSet ; 4 import com.teamkonzept.db.TKDBManager; 5 import com.teamkonzept.db.TKQuery; 6 import com.teamkonzept.db.QueryConstants; 7 import com.teamkonzept.lib.TKException; 8 import com.teamkonzept.lib.TKVector; 9 import com.teamkonzept.web.TKEvent; 10 import com.teamkonzept.web.TKHTMLTemplate; 11 import com.teamkonzept.web.TKParams; 12 import com.teamkonzept.webman.WebManEvent; 13 import com.teamkonzept.webman.mainint.ContextConstants; 14 import com.teamkonzept.webman.mainint.DatabaseDefaults; 15 import com.teamkonzept.webman.mainint.FrameConstants; 16 import com.teamkonzept.webman.mainint.HTMLUtils; 17 import com.teamkonzept.webman.mainint.TKStandardIterator; 18 import com.teamkonzept.webman.mainint.TreeUtils; 19 import com.teamkonzept.webman.mainint.WebmanExceptionHandler; 20 import com.teamkonzept.webman.mainint.db.queries.TKDBContentTreeIsChild; 21 import com.teamkonzept.webman.mainint.db.queries.content.SelectContentTree; 22 import com.teamkonzept.webman.mainint.events.DefaultEventHandler; 23 import com.teamkonzept.webman.mainint.events.ParameterTypes; 24 import de.webman.content.Content; 25 import de.webman.content.workflow.ContentVersion; 26 import de.webman.content.workflow.VersionCache; 27 28 34 public class CEForwardHandler 35 extends DefaultEventHandler 36 implements ParameterTypes, 37 FrameConstants, 38 DatabaseDefaults 39 { 40 41 44 private static final CEForwardHandler INSTANCE = new CEForwardHandler(); 45 46 49 private CEForwardHandler () 50 { 51 } 53 54 59 public static CEForwardHandler getInstance () 60 { 61 return INSTANCE; 62 } 63 64 70 public void handleEvent (TKEvent event) 71 throws TKException 72 { 73 try 74 { 75 CEUtils.checkEvent(event); 76 77 String target = event.getParameter(PARAMETER, "TARGET_EVENT"); 78 Integer id = new Integer (event.getParameter(PARAMETER, "CONTENT_NODE_ID")); 79 80 ContentContext context = getContentContext(id); 81 TKHTMLTemplate frame = event.getPrepHTMLTemplate("f_ce.tmpl"); 82 83 prepareFrameSet(frame, target, context); 84 85 if (target.equals("CE_GROUP_LIST")) 86 { 87 frame.set("NAVIGATION_CONTEXT", context.calculateNavContext()); 88 } 89 90 if (target.equals("CE_EDIT")) 91 { 92 context.conNodeId = new Integer (event.getParameter(PARAMETER, "CONTENT_NODE_PARENT")); 97 context.conNodeType = DIRECTORY_NODE_INTEGER; 98 99 frame.set("NAVIGATION_CONTEXT", context.calculateNavContext()); 100 } 101 102 event.finishTemplate(frame); 103 } 104 catch (Throwable e) 105 { 106 throw WebmanExceptionHandler.getException(e); 108 } 109 } 110 111 118 public boolean isHandler (TKEvent event) 119 { 120 return event.getName().equalsIgnoreCase("CE_FORWARD"); 121 } 122 123 131 private void prepareFrameSet (TKHTMLTemplate frame, 132 String event, 133 ContentContext context) 134 throws Throwable 135 { 136 HTMLUtils.fillFrameSet(frame, LEFT_FRAME_WIDTH_SMALL, "CE_SHOWLIST", event); 137 138 context.fillIntoTemplate(frame); 139 140 TKVector openNodes = new TKVector(); 141 openNodes.put(0, "-1"); 142 openNodes = TreeUtils.updateOpenNodes(openNodes, 143 context.conNodeId.toString(), 144 "-1", 145 context.conNodeId.toString(), 146 TKDBContentTreeIsChild.class); 147 148 frame.setListIterator(new TKStandardIterator(openNodes, frame.getListIterator(), "OPEN_NODES", "OPEN_NODES")); 149 } 150 151 158 private ContentContext getContentContext (Integer id) 159 throws Throwable 160 { 161 ContentContext context = new ContentContext(new TKParams()); 162 context.conNodeId = id; 163 164 TKQuery query = TKDBManager.newQuery(SelectContentTree.class); 165 query.setQueryParams("ID", id); 166 query.execute(); 167 168 ResultSet result = query.fetchResultSet(); 169 170 if (result.next()) 171 { 172 context.conNodeType = new Integer (result.getInt("CONTENT_NODE_TYPE")); 173 context.formId = new Integer (result.getInt("CONTENT_FORM")); 174 context.conNodeName = result.getString("CONTENT_NODE_NAME"); 175 context.conNodeShortName = result.getString("CONTENT_NODE_SHORTNAME"); 176 } 177 178 if (GROUP_INTEGER.equals(context.conNodeType)) 179 { 180 context.groupConNodeId = context.conNodeId; 181 context.groupConNodeName = context.conNodeName; 182 context.groupConNodeShortName = context.conNodeShortName; 183 } 184 185 if (SINGLE_INTEGER.equals(context.conNodeType)) 186 { 187 Content content = VersionCache.getContentInfo(id); 188 189 context.instanceId = content.getInstanceId(); 190 context.versionId = content.getCurrentVersion().getId(); 191 } 192 193 return context; 194 } 195 196 } 197 | Popular Tags |