001: package de.webman.content.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: import com.teamkonzept.webman.mainint.db.queries.*;
009: import com.teamkonzept.webman.mainint.events.*;
010: import com.teamkonzept.lib.*;
011: import com.teamkonzept.field.*;
012: import com.teamkonzept.field.db.*;
013: import com.teamkonzept.db.*;
014: import com.teamkonzept.publishing.markups.*;
015: import de.webman.content.workflow.*;
016: import java.sql.*;
017: import java.io.*;
018:
019: import org.apache.log4j.Category;
020:
021: /**
022: Rename eines Contents
023: * @author $Author: alex $
024: * @version $Revision: 1.7 $
025: */
026: public class CEUpdateGroupContentHandler extends DefaultEventHandler
027: implements ParameterTypes, FrameConstants, DatabaseDefaults {
028: /** Logging Category */
029: private static Category cat = Category
030: .getInstance(CEUpdateGroupContentHandler.class);
031:
032: /**
033: * Konstruktor private, da Singleton
034: */
035: private CEUpdateGroupContentHandler() {
036: }
037:
038: private static CEUpdateGroupContentHandler instance = new CEUpdateGroupContentHandler();
039:
040: public static CEUpdateGroupContentHandler getInstance() {
041: return instance;
042: }
043:
044: public void handleEvent(TKEvent evt) throws TKException {
045: try {
046: CEUtils.checkEvent(evt);
047: ContentContext ceContext = new ContentContext(evt
048: .getParams());
049:
050: // statische Daten der Versionsverwaltung abrufen
051: VersionStatics statics = VersionStatics.setup();
052: // Kennung wird aus Namen eventuell generiert
053: if (ceContext.conNodeShortName == null
054: && ceContext.conNodeName != null) {
055: ceContext.conNodeShortName = TKUploadField
056: .checkFileName(ceContext.conNodeName);
057: }
058: if (ceContext.conNodeName == null
059: || ceContext.conNodeName.equals(""))
060: throw new TKUserException(
061: "Es muß ein Name angegeben werden",
062: NO_PATHNAME, USER_SEVERITY, true, null);
063:
064: CEUtils.isValidPathname(ceContext.conNodeShortName);
065: if (ceContext.groupConNodeId.intValue() != -1)
066: CEUtils
067: .checkShortName(ceContext.groupConNodeId,
068: ceContext.conNodeId,
069: ceContext.conNodeShortName);
070: String upBase = CEUtils.getCurrentPath(ceContext.conNodeId);
071: TKQuery q = TKDBManager
072: .newQuery(TKDBContentTreeUpdateNode.class);
073: q.setQueryParams("CONTENT_NODE_ID", ceContext.conNodeId);
074: q
075: .setQueryParams("CONTENT_NODE_NAME",
076: ceContext.conNodeName);
077: q.setQueryParams("CONTENT_NODE_SHORTNAME",
078: ceContext.conNodeShortName);
079: q.setQueryParams("CONTENT_NODE_TYPE", SINGLE_INTEGER);
080: q.setQueryParams("CONTENT_FORM", ceContext.formId);
081: q.setQueryParams("TREE_ID", new Integer(0));
082: q.setQueryParams("PROTOTYPE_ID", TKNull.NULL);
083: q.execute();
084:
085: String oldName = ceContext
086: .getParam("OLD_CONTENT_NODE_NAME");
087: String oldShortName = evt.getParameter(PARAMETER,
088: "OLD_CONTENT_NODE_SHORTNAME");
089:
090: // Umbenennen evtl. vorhandener Upload Verzeichnisse
091: if (!oldShortName.equals(ceContext.conNodeShortName)) {
092: // gibt es ein altes Verzeichnis ??
093: String docRoot = evt.getHttpInterface()
094: .getDocumentRoot();
095: String oldDir = docRoot + upBase;
096: File old = new File(oldDir);
097:
098: if (old.exists()) {
099: File newDir = new File(old.getParent()
100: + File.separator
101: + ceContext.conNodeShortName);
102:
103: if (newDir.exists()) {
104: cat
105: .error("Can't rename Asset Directory due to existing directory");
106: } else {
107: old.renameTo(newDir);
108: }
109: }
110: }
111: String Info = "Umbenannt"
112: + (oldName != null ? " von " + oldName : "")
113: + " nach " + ceContext.conNodeName;
114:
115: VersionStatus trackingStatus = VersionStatus
116: .lookupRename(statics);
117: if (trackingStatus == null)
118: trackingStatus = VersionStatus.lookupComment(statics);
119:
120: if (trackingStatus != null) {
121: q = TKDBManager.newQuery(TKDBContentNewVersion.class);
122: q.setQueryParams("INSTANCE_ID", ceContext.instanceId);
123: q.setQueryParams("STATUS_ID", new Integer(
124: trackingStatus.status_id));
125: q.setQueryParams("VERS_INFO", Info);
126: q.setQueryParams("VERS_AUTHOR", evt.getRemoteUser());
127: q.execute();
128: }
129: // Hier muß der cache nicht aktualisiert werden !!!
130: evt.getParams().put(PARAMETER, "RECALCULATE", "a");
131: CEBrowseHandler.getInstance().handleEvent(evt);
132: } catch (Throwable e) {
133: // TO DO : Analyze Exception !
134: throw WebmanExceptionHandler.getException(e);
135: }
136: }
137:
138: public boolean isHandler(TKEvent evt) {
139: return evt.getName()
140: .equalsIgnoreCase("CE_UPDATE_GROUP_CONTENT");
141: }
142: }
|