01: package de.webman.template.eventhandler;
02:
03: import com.teamkonzept.db.*;
04: import com.teamkonzept.webman.mainint.db.queries.*;
05: import com.teamkonzept.webman.mainint.events.*;
06: import com.teamkonzept.webman.mainint.*;
07: import com.teamkonzept.webman.*;
08: import com.teamkonzept.web.*;
09: import com.teamkonzept.lib.*;
10: import com.teamkonzept.international.LanguageManager;
11: import java.io.*;
12: import java.sql.*;
13:
14: /**
15: * Loeschen eines Templates
16: *
17: * @author $Author: alex $
18: * @version $Revision: 1.4 $
19: */
20: public class TEDeleteHandler extends DefaultEventHandler implements
21: ParameterTypes, FrameConstants {
22: private TEDeleteHandler() {
23: }
24:
25: private static TEDeleteHandler instance = new TEDeleteHandler();
26:
27: public static TEDeleteHandler getInstance() {
28: return instance;
29: }
30:
31: public void handleEvent(TKEvent evt) throws TKException {
32: try {
33: String tmplId = evt.getParameter(PARAMETER, "TEMPLATE_ID");
34: String tmplName = evt.getParameter(PARAMETER,
35: "TEMPLATE_NAME");
36: TKVector references = TEUtils.getDependencies(new Integer(
37: tmplId));
38: // Checken, ob das Template noch in Documenttypen benutzt wird
39: if (references.size() > 0) {
40: TKHTMLTemplate error = evt
41: .getPrepHTMLTemplate("error_message.tmpl");
42: Object[] tmp = new Object[1];
43: tmp[0] = tmplName;
44: String errorText = LanguageManager.getText("templates",
45: "DELETE_DEPENDENCY", tmp);
46:
47: error.set("ERROR_TEXT", errorText);
48: error.setListIterator(new TKStandardPluginIterator(
49: "REFERENCES", null, references, false, error
50: .getListIterator()));
51: evt.finishTemplate(error);
52: return;
53: }
54: // löschen des Templates in der DB
55: TKQuery q = TKDBManager.newQuery(TKDBTmplDelete.class);
56: q.setQueryParams("TEMPLATE_ID", new Integer(tmplId));
57: q.execute();
58: q.fetchResultSet();
59:
60: // löschen des Temp. im Filesystem
61: // TODO: fileNotFound abfangen
62: File datei = new File(evt.getHttpInterface()
63: .getDocumentRoot()
64: + File.separator
65: + TemplateUtils.getGenerationDirectory() + tmplName);
66: datei.delete();
67:
68: TKHTMLTemplate frame = evt.getPrepHTMLTemplate("f_te.tmpl");
69: HTMLUtils.fillFrameSet(frame, LEFT_FRAME_WIDTH_SMALL,
70: "TE_SHOWLIST", "EMPTY");
71: WebManEvent.fillEventsIntoTemplate(evt.getRemoteUser(),
72: frame, ContextConstants.TEMPLATES);
73: evt.finishTemplate(frame);
74: } catch (TKSQLError error) {
75: // entweder allgemeine Probleme, oder aber das Template wird noch gebraucht
76: TKException e = WebmanExceptionHandler.getException(error);
77: if (e.getErrorCode() == FK_CONSTRAINT_VIOLATION)
78: throw new TKUserException("Template wird benutzt",
79: OBJECT_IN_USE, USER_SEVERITY, false, error
80: .getSQLException());
81: throw e;
82: } catch (Throwable t) {
83: throw WebmanExceptionHandler.getException(t);
84: }
85: }
86:
87: public boolean isHandler(TKEvent evt) {
88: return evt.getName().equalsIgnoreCase("TE_DELETE");
89: }
90: }
|