KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > content > eventhandler > CEUpdateGroupContentHandler


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.db.*;
14 import com.teamkonzept.publishing.markups.*;
15 import de.webman.content.workflow.*;
16 import java.sql.*;
17 import java.io.*;
18
19 import org.apache.log4j.Category;
20
21 /**
22     Rename eines Contents
23  * @author $Author: alex $
24  * @version $Revision: 1.7 $
25 */

26 public class CEUpdateGroupContentHandler extends DefaultEventHandler implements ParameterTypes, FrameConstants, DatabaseDefaults
27 {
28     /** Logging Category */
29     private static Category cat = Category.getInstance(CEUpdateGroupContentHandler.class);
30
31     /**
32      * Konstruktor private, da Singleton
33      */

34     private CEUpdateGroupContentHandler()
35     {}
36     
37     private static CEUpdateGroupContentHandler instance = new CEUpdateGroupContentHandler();
38     
39     public static CEUpdateGroupContentHandler getInstance()
40     {
41         return instance;
42     }
43     
44     public void handleEvent(TKEvent evt) throws TKException
45     {
46         try
47         {
48             CEUtils.checkEvent(evt);
49             ContentContext ceContext = new ContentContext (evt.getParams());
50
51             // statische Daten der Versionsverwaltung abrufen
52
VersionStatics statics = VersionStatics.setup();
53             // Kennung wird aus Namen eventuell generiert
54
if (ceContext.conNodeShortName == null && ceContext.conNodeName != null)
55             {
56                 ceContext.conNodeShortName = TKUploadField.checkFileName( ceContext.conNodeName);
57             }
58             if (ceContext.conNodeName == null || ceContext.conNodeName.equals(""))
59                 throw new TKUserException("Es muß ein Name angegeben werden", NO_PATHNAME, USER_SEVERITY, true, null);
60             
61             CEUtils.isValidPathname( ceContext.conNodeShortName );
62             if (ceContext.groupConNodeId.intValue() != -1)
63                 CEUtils.checkShortName(ceContext.groupConNodeId, ceContext.conNodeId, ceContext.conNodeShortName);
64             String JavaDoc upBase = CEUtils.getCurrentPath(ceContext.conNodeId);
65             TKQuery q = TKDBManager.newQuery(TKDBContentTreeUpdateNode.class);
66             q.setQueryParams( "CONTENT_NODE_ID", ceContext.conNodeId );
67             q.setQueryParams( "CONTENT_NODE_NAME", ceContext.conNodeName );
68             q.setQueryParams( "CONTENT_NODE_SHORTNAME", ceContext.conNodeShortName );
69             q.setQueryParams( "CONTENT_NODE_TYPE", SINGLE_INTEGER );
70             q.setQueryParams( "CONTENT_FORM", ceContext.formId );
71             q.setQueryParams( "TREE_ID", new Integer JavaDoc(0) );
72             q.setQueryParams( "PROTOTYPE_ID", TKNull.NULL );
73             q.execute();
74
75             String JavaDoc oldName = ceContext.getParam ( "OLD_CONTENT_NODE_NAME");
76             String JavaDoc oldShortName = evt.getParameter(PARAMETER, "OLD_CONTENT_NODE_SHORTNAME");
77
78             // Umbenennen evtl. vorhandener Upload Verzeichnisse
79
if (!oldShortName.equals(ceContext.conNodeShortName))
80             {
81                 // gibt es ein altes Verzeichnis ??
82
String JavaDoc docRoot = evt.getHttpInterface().getDocumentRoot();
83                 String JavaDoc oldDir = docRoot + upBase;
84                 File old = new File(oldDir);
85
86                 if (old.exists())
87                 {
88                     File newDir = new File(old.getParent() + File.separator + ceContext.conNodeShortName);
89
90                     if (newDir.exists())
91                     {
92                         cat.error("Can't rename Asset Directory due to existing directory");
93                     }
94                     else
95                     {
96                         old.renameTo(newDir);
97                     }
98                 }
99             }
100             String JavaDoc Info = "Umbenannt"+(oldName != null ? " von "+oldName : "")+" nach "+ceContext.conNodeName;
101
102             VersionStatus trackingStatus = VersionStatus.lookupRename (statics);
103             if (trackingStatus == null) trackingStatus = VersionStatus.lookupComment (statics);
104
105             if (trackingStatus != null) {
106                 q = TKDBManager.newQuery(TKDBContentNewVersion.class);
107                 q.setQueryParams( "INSTANCE_ID", ceContext.instanceId );
108                 q.setQueryParams( "STATUS_ID", new Integer JavaDoc(trackingStatus.status_id) );
109                 q.setQueryParams( "VERS_INFO", Info );
110                 q.setQueryParams( "VERS_AUTHOR", evt.getRemoteUser() );
111                 q.execute();
112             }
113             // Hier muß der cache nicht aktualisiert werden !!!
114
evt.getParams().put(PARAMETER, "RECALCULATE", "a");
115             CEBrowseHandler.getInstance().handleEvent(evt);
116         }
117         catch (Throwable JavaDoc e)
118         {
119             // TO DO : Analyze Exception !
120
throw WebmanExceptionHandler.getException(e);
121         }
122     }
123     
124     public boolean isHandler(TKEvent evt)
125     {
126         return evt.getName().equalsIgnoreCase("CE_UPDATE_GROUP_CONTENT");
127     }
128 }
129
Popular Tags