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 de.webman.content.db.queries.*;
014: import com.teamkonzept.db.*;
015: import com.teamkonzept.publishing.markups.*;
016: import de.webman.content.workflow.*;
017:
018: import java.sql.*;
019: import java.io.*;
020:
021: /**
022: * Auflisten aller Attribute eines Contents:
023: *
024: * @author $Author: sebastian $
025: * @version $Revision: 1.10 $
026: */
027: public class CEContentAttributesHandler extends DefaultEventHandler
028: implements ParameterTypes, FrameConstants, DatabaseDefaults {
029: private CEContentAttributesHandler() {
030: }
031:
032: private static CEContentAttributesHandler instance = new CEContentAttributesHandler();
033:
034: public static CEContentAttributesHandler getInstance() {
035: return instance;
036: }
037:
038: private static String getAttributeValue(TKEvent evt, int pos) {
039: String help = "ATTRIBUTES." + Integer.toString(pos);
040: if (Integer.parseInt(evt
041: .getParameter(PARAMETER, help + ".TYPE")) == 3) {
042: String back;
043:
044: back = evt.getParameter(PARAMETER, help + ".DAY");
045: back = back + '.'
046: + evt.getParameter(PARAMETER, help + ".MONTH");
047: back = back + '.'
048: + evt.getParameter(PARAMETER, help + ".YEAR");
049: back = back + ' '
050: + evt.getParameter(PARAMETER, help + ".HOUR");
051: back = back + ':'
052: + evt.getParameter(PARAMETER, help + ".MINUTE");
053: back = back + ":00";
054:
055: return back;
056: } else
057: return evt.getParameter(PARAMETER, help
058: + ".ATTRIBUTE_VALUE");
059: }
060:
061: public void handleEvent(TKEvent evt) throws TKException {
062: try {
063:
064: CEUtils.checkEvent(evt);
065:
066: TKHTMLTemplate t = evt
067: .getPrepHTMLTemplate("ce_conAttrList.tmpl");
068:
069: ContentContext ceContext = new ContentContext(evt
070: .getParams(), evt.toString());
071:
072: if (ceContext.instanceId == null)
073: throw new Exception(
074: "doCEContentAttributes: No Content Instance");
075:
076: String event = evt.getName();
077: String action = event == null ? null : evt.getParameter(
078: ACTION, event);
079:
080: TKContentDBData cdata = new TKContentDBData(
081: ceContext.instanceId.intValue(),
082: ceContext.versionId.intValue());
083: TKContentDBInterface.Get(cdata);
084:
085: if (action == null || action.length() == 0
086: || action.equalsIgnoreCase("GET")) {
087: t.setListIterator(new TKContentIterator(t, cdata, t
088: .getListIterator()));
089: ceContext.fillIntoTemplate(t);
090:
091: evt.finishTemplate(t);
092: return;
093: }
094:
095: if (action.equalsIgnoreCase("SAVE")
096: || action.equalsIgnoreCase("NEW_ATTR")
097: || action.equalsIgnoreCase("DELETE_ATTRIBUTE")
098: || action.equalsIgnoreCase("SAVE_AND_CLOSE")) {
099: // packe neue Contentattribute in cdata
100: int i = 0;
101: while (cdata.content_attribute != null
102: && cdata.content_attribute.size() > i) {
103:
104: TKContentAttributeTableData table = (TKContentAttributeTableData) cdata.content_attribute
105: .elementAt(i);
106: int r;
107: for (r = 0; r < cdata.content_attribute.size(); r++) {
108: if (Integer.parseInt(evt.getParameter(
109: PARAMETER, "ATTRIBUTES."
110: + Integer.toString(r)
111: + ".VALUE_ID")) == table.value_id)
112: break;
113: }
114:
115: String value = getAttributeValue(evt, r);
116:
117: if (!(table.value.equals(value))) {
118: table.value = value;
119:
120: TKQuery q = TKDBManager
121: .newQuery(TKDBContentAttributeUpdate.class);
122: table.insertIntoQuery(q);
123: q.execute();
124: }
125: i++;
126: }
127: }
128:
129: if (action.equalsIgnoreCase("DELETE_ATTRIBUTE")) {
130: TKQuery q = TKDBManager
131: .newQuery(TKDBContentAttributeDelete.class);
132: q.setQueryParams("VALUE_ID", new Integer(Integer
133: .parseInt(evt.getParameter("VALUE_ID", evt
134: .getName()))));
135: q.execute();
136:
137: for (int i = 0; i < cdata.content_attribute.size(); i++) {
138: if (((TKContentAttributeTableData) cdata.content_attribute
139: .elementAt(i)).value_id == Integer
140: .parseInt(evt.getParameter("VALUE_ID", evt
141: .getName()))) {
142: cdata.content_attribute.remove(i);
143: break;
144: }
145: }
146:
147: t.setListIterator(new TKContentIterator(t, cdata, t
148: .getListIterator()));
149: ceContext.fillIntoTemplate(t);
150:
151: evt.finishTemplate(t);
152: return;
153:
154: }
155: if (action.equalsIgnoreCase("NEW_ATTR")) {
156: String new_attr_id = evt.getParameter(PARAMETER,
157: "NEW_ATTRIBUTE_ID");
158: System.out.println("new_attr_id : " + new_attr_id);
159: if (new_attr_id != null && new_attr_id.length() != 0
160: && Integer.parseInt(new_attr_id) != -1) {
161: // erzeuge neues attributtable
162: TKContentAttributeTableData table = new TKContentAttributeTableData(
163: cdata.content_id, Integer
164: .parseInt(new_attr_id), "");
165:
166: TKQuery q = TKDBManager
167: .newQuery(TKDBContentAttributePut.class);
168: table.insertIntoQuery(q);
169: q.execute();
170: if (cdata.content_attribute == null)
171: cdata.content_attribute = new TKVector();
172: ResultSet rs = q.fetchResultSet();
173: rs.next();
174: cdata.content_attribute
175: .add(new TKContentAttributeTableData(rs));
176:
177: t.setListIterator(new TKContentIterator(t, cdata, t
178: .getListIterator()));
179: ceContext.fillIntoTemplate(t);
180:
181: evt.finishTemplate(t);
182: return;
183:
184: } else {
185: throw new TKUserException(
186: "Please chose an attribute-type first.",
187: UserCodes.CHOSE_CONTENT_ATTRIBUTE,
188: ErrorCodes.USER_SEVERITY, true, null);
189: }
190: }
191: if (action.equalsIgnoreCase("SAVE_AND_CLOSE")
192: || action.equalsIgnoreCase("CLOSE")) {
193: CEBrowseHandler.getInstance().handleEvent(evt);
194: return;
195: }
196:
197: t.setListIterator(new TKContentIterator(t, cdata, t
198: .getListIterator()));
199: ceContext.fillIntoTemplate(t);
200:
201: evt.finishTemplate(t);
202: } catch (Throwable e) {
203: // TO DO : Analyze Exception !
204: throw WebmanExceptionHandler.getException(e);
205: }
206: }
207:
208: public boolean isHandler(TKEvent evt) {
209: return evt.getName().equalsIgnoreCase("CE_CONTENT_ATTRIBUTES");
210: }
211: }
|