1 package de.webman.content.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.*; 9 import com.teamkonzept.webman.mainint.events.*; 10 import com.teamkonzept.lib.*; 11 import com.teamkonzept.field.*; 12 import com.teamkonzept.field.db.*; 13 import com.teamkonzept.field.db.queries.*; 14 import com.teamkonzept.db.*; 15 import de.webman.generator.Preview; 16 import java.sql.*; 17 import de.webman.content.workflow.*; 18 import de.webman.content.*; 19 import de.webman.content.db.queries.TKDBContentAttributeGetOldContentId; 20 import de.webman.acl.Policy; 21 import de.webman.util.legacy.Legacy; 22 import org.apache.log4j.Category; 23 24 28 public class CESaveHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults 29 { 30 31 private static Category cat = Category.getInstance(CESaveHandler.class); 32 33 34 private CESaveHandler() 35 {} 36 37 38 private static CESaveHandler instance = new CESaveHandler(); 39 40 41 public static CESaveHandler getInstance() 42 { 43 return instance; 44 } 45 46 52 public void checkUserRights(String user, String event, Integer contentNodeId) throws TKException 53 { 54 try 55 { 56 WebManEvent.checkEvent(user, event, ContextConstants.CONTENT_EDIT, Policy.CONTENT_TREE_ID, contentNodeId == null ? null:contentNodeId); 57 } 58 catch (Throwable t) 59 { 60 throw WebmanExceptionHandler.getException(t); 61 } 62 } 63 64 77 public String getValidName(String shortName, String name, Integer groupId, Integer contentNodeId) throws TKException 78 { 79 try 80 { 81 if (groupId == null) 82 return shortName; String retName = shortName; 84 if (shortName == null && name != null) 86 { 87 retName = TKUploadField.checkFileName( name); 88 } 89 if (name == null || name.equals("")) 90 throw new TKUserException("Es muß ein Name angegeben werden", NO_PATHNAME, USER_SEVERITY, true, null); 91 92 if (groupId.intValue() != -1) 94 CEUtils.checkShortName(contentNodeId, groupId, retName); 95 CEUtils.isValidPathname( retName ); 96 return retName; 97 } 98 catch (Throwable t) 99 { 100 t.printStackTrace(); 101 throw WebmanExceptionHandler.getException(t); 102 } 103 } 104 105 112 public String getContentSaveConflict(Integer contentNodeId, Integer versionId, Integer toStatusId) throws TKException 113 { 114 if (contentNodeId == null) 115 return null; 116 try 117 { 118 Content content = ContentFactory.getInstance().getContent(contentNodeId); 119 return VersionControl.savedAlready(content, versionId, toStatusId); 120 } 121 catch (Throwable t) 122 { 123 t.printStackTrace(); 124 throw WebmanExceptionHandler.getException(t); 125 } 126 } 127 128 141 public Content saveContentVersion(Integer contentId, String author, Integer instanceId, Integer toStatusId, Integer contentNodeType, String name, String shortName, Integer groupId, Integer formId, Integer contentNodeId) throws TKException 142 { 143 try 144 { 145 TKContentDBData cdata = null; 146 if (instanceId == null) 147 instanceId = new Integer (-1); 148 149 if (contentNodeId == null) 150 contentNodeId = new Integer (-1); 151 if (instanceId.intValue() >= 0) 152 { 153 cdata = new TKContentDBData( instanceId.intValue(), 0 ); TKQuery q = TKDBManager.newQuery(TKDBContentAttributeGetOldContentId.class); 156 q.setQueryParams("CONTENT_ID", new Integer (contentId.intValue())); 157 q.setQueryParams("INSTANCE_ID", new Integer (instanceId.intValue())); 158 q.execute(); 159 160 ResultSet rs = q.fetchResultSet(); 161 while (rs.next()) 163 { 164 cdata.content_id = rs.getInt("OLD_CONTENT_ID"); 165 } 166 cdata.setIgnoreTable("CONTENT_NODE", true); 167 cdata.setIgnoreTable("CONTENT_VALUE", true); 168 TKContentDBInterface.Get( cdata ); 169 cdata.setIgnoreTable("CONTENT_NODE", false); 170 cdata.setIgnoreTable("CONTENT_VALUE", false); 171 172 } else 173 { 174 cdata = new TKContentDBData (); 175 } 176 Content content = CEUtils.createContentInstance (instanceId, contentNodeType, name, shortName, groupId, formId, contentNodeId); 178 if (content == null) 179 content = new Content(contentNodeId, name, shortName, instanceId, formId, contentNodeType.intValue() == DIRECTORY_NODE_INTEGER.intValue(), groupId); 180 if (content.getInstanceId() == null) 181 content.setInstanceId(instanceId ); 182 cdata.instance_id = content.getInstanceId().intValue(); 183 cdata.content_id = contentId.intValue(); 184 cdata.version_info = "%WebManThread.doCESave/content"; 186 cdata.version_author = author; 187 cdata.status_id = toStatusId.intValue(); 188 189 TKContentDBInterface.New( cdata ); 191 cdata.setIgnoreTable("CONTENT_NODE", true); 192 cdata.setIgnoreTable("CONTENT_VALUE", true); 193 TKContentDBInterface.Put( cdata ); 194 cdata.setIgnoreTable("CONTENT_NODE", false); 195 cdata.setIgnoreTable("CONTENT_VALUE", false); 196 ContentVersion version = new ContentVersion(new Integer (cdata.version_id), contentId, content.getId(), author, null, null, groupId==null); 198 content.getInterestingVersions().put(toStatusId, version); 199 return content; 200 } 201 catch (Throwable t) 202 { 203 t.printStackTrace(); 204 throw WebmanExceptionHandler.getException(t); 205 } 206 } 207 208 214 public void handleEvent (TKEvent evt) 215 throws TKException 216 { 217 try 218 { 219 if (evt.getName().equalsIgnoreCase("CE_SAVE_AND_PREVIEW") && 220 evt.getParameter(PARAMETER, "DO_PREVIEW") != null) 221 { 222 Preview preview = new Preview(evt); 224 preview.doPreviewIndexPerContent(); 225 226 return; 228 } 229 230 ContentContext ceContext = new ContentContext (evt.getParams(), null); 232 233 WebManEvent.checkEvent(evt.getRemoteUser(), evt.getName(), ContextConstants.CONTENT_EDIT, Policy.CONTENT_TREE_ID, ceContext.conNodeId); 235 236 TKHTMLTemplate t = evt.getPrepHTMLTemplate( "ce_fields.tmpl" ); 237 238 VersionStatics statics = VersionStatics.setup(); 240 ceContext.conNodeShortName = getValidName(ceContext.conNodeShortName, ceContext.conNodeName, ceContext.groupConNodeId, ceContext.conNodeId); 241 String conflictAuthor = null; 243 if (ceContext.instanceId.intValue() >= 0) 244 conflictAuthor = getContentSaveConflict(ceContext.conNodeId, ceContext.versionId, ceContext.toStatusId); 245 246 TKFormDBData data = new TKFormDBData( ceContext.formId.intValue() ); 247 TKFormDBInterface.Get( data ); 248 TKBaseField field = TKFieldRegistry.getFieldFromDB( data ); 249 TKHashtable fieldContext = new TKHashtable(); 250 Object realData = field.compileData( "", evt.getParams().getClass( PARAMETER ), fieldContext ); 251 field.fillIntoTemplate( t, realData, "" ); 252 253 Object diags = field.getFromContext (TKBaseField.DIAGS_KEY,fieldContext); 254 if (diags != null && (diags instanceof TKVector)) 255 { 256 ceContext.fillIntoTemplate (t); 258 TKVector hints = new TKVector (); 259 hints.addElement ("Sicherung wurde NICHT durchgeführt, siehe Meldungen"); 260 TKStandardIterator it1 = new TKStandardIterator( hints, t.getListIterator(), "HINTS", "HINT" ); 261 262 if (diags != null) 263 { 264 TKListIterator it2 = new TKStandardPluginIterator 265 ("DIAGNOSTICS","DIAGNOSTIC",(TKVector) diags, false, it1); 266 t.setListIterator( it2 ); 267 } 268 269 t.set( "HAS_DIAGNOSTICS", new Boolean (true) ); 270 t.set( "HAS_HINTS", new Boolean (true) ); 271 cat.warn("Sicherung wurde nicht duchgeführt -> "); 272 WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ContextConstants.CONTENT_EDIT, Policy.CONTENT_TREE_ID, ceContext.conNodeId); 273 evt.finishTemplate(t); 274 return; 275 } 276 boolean checked = evt.getParameter(PARAMETER, "CHECKED") != null; 279 if (conflictAuthor != null && !checked) 280 { 281 ceContext.fillIntoTemplate (t); 283 t.set( "HAS_CONFLICT", new Boolean (true) ); 284 t.set( "CONFLICT_AUTHOR" , conflictAuthor); 285 cat.warn("Konflikt bei Speicherung! "); 286 WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(), t, ContextConstants.CONTENT_EDIT, Policy.CONTENT_TREE_ID, ceContext.conNodeId); 287 evt.finishTemplate(t); 288 return; 289 } 290 291 292 TKContentDBData testConDB = new TKContentDBData (); 293 field.insertDataIntoDB( testConDB, realData ); 294 field.getDataFromDB( testConDB ); 295 296 297 300 303 TKContentDBData cdata = null; 304 305 308 if (ceContext.instanceId.intValue() >= 0) 309 { 310 311 314 cdata = new TKContentDBData( ceContext.instanceId.intValue(), 0 ); 315 316 cdata.setIgnoreTable ("CONTENT_VALUE",true); 317 cdata.setIgnoreTable ("CONTENT_NODE",true); 318 TKContentDBInterface.Get (cdata); 319 cdata.setIgnoreTable ("CONTENT_VALUE",false); 320 cdata.setIgnoreTable ("CONTENT_NODE",false); 321 322 } else cdata = new TKContentDBData (); 323 Content content = CEUtils.createContentInstance (ceContext.instanceId, ceContext.conNodeType, ceContext.conNodeName, ceContext.conNodeShortName, ceContext.groupConNodeId, ceContext.formId, ceContext.conNodeId); 325 326 if (content != null) 327 { 328 if (content.getInstanceId() == null) 329 content.setInstanceId(ceContext.instanceId ); 330 else 331 ceContext.instanceId = content.getInstanceId(); 332 if (content.getId() != null) 333 ceContext.conNodeId = content.getId(); 334 } 335 338 cdata.version_info = "%WebManThread.doCESave/content"; 340 cdata.version_author = evt.getRemoteUser(); 341 cdata.status_id = ceContext.toStatusId.intValue(); 342 cdata.instance_id = ceContext.instanceId.intValue(); 343 344 TKContentDBInterface.New( cdata ); 346 347 field.insertDataIntoDB( cdata, realData ); 348 TKContentDBInterface.Put( cdata ); 349 350 ceContext.versionId = new Integer (cdata.version_id); 352 CEUtils.getVersionInfo (ceContext,t,statics); 353 ceContext.mode = null; 354 ceContext.fillIntoTemplate (t); 355 if (ceContext.getNavigationContext() != null) 356 evt.getParams().put(PARAMETER, "RECALCULATE", "a"); 357 359 361 if (evt.getName().equalsIgnoreCase("CE_SAVE")) { 363 CEBrowseHandler.getInstance().handleEvent(evt); 364 } 365 else 366 { 367 if (evt.getName().equalsIgnoreCase("CE_SAVE_AND_PREVIEW")) { 369 evt.getParams().put(PARAMETER, "DO_PREVIEW", Boolean.TRUE); 370 } 371 372 evt.getParams().put(PARAMETER, "VERSION_ID", ceContext.versionId); 374 375 if (ceContext.instanceId.intValue() != -1) 377 { 378 evt.getParams().put(PARAMETER, "INSTANCE_ID", ceContext.instanceId); 379 evt.getParams().put(PARAMETER, "CONTENT_NODE_ID", ceContext.conNodeId); 380 } 381 382 CEEditHandler.getInstance().handleEvent(evt); 383 384 } 404 } 405 catch (Throwable e) 406 { 407 throw WebmanExceptionHandler.getException(e); 408 } 409 } 410 411 public boolean isHandler(TKEvent evt) 412 { 413 return ( evt.getName().equalsIgnoreCase("CE_SAVE") || evt.getName().equalsIgnoreCase("CE_SAVE_TO_DB") || evt.getName().equalsIgnoreCase("CE_SAVE_AND_PREVIEW") ); 417 } 418 } 419 | Popular Tags |