001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.unifiedGui;
032:
033: import java.io.*;
034: import java.util.*;
035:
036: import javax.servlet.http.*;
037:
038: import de.ug2t.channel.markup.generic.*;
039: import de.ug2t.extTools.httpFileUpLoad.*;
040: import de.ug2t.kernel.*;
041: import de.ug2t.unifiedGui.interfaces.*;
042:
043: /**
044: * @author Dirk
045: *
046: * date: 03.04.2004 project: WiSer-Framework
047: *
048: * <p>
049: * This class maps the widget values from the transport layer to the widget
050: * objects. Normally it is not necessary to use it.
051: * </p>
052: */
053: public final class UnPeerValueMapper {
054: private ArrayList pem_mappingListener = null;
055:
056: public UnPeerValueMapper() {
057: return;
058: }
059:
060: public void pcmf_addMappingListener(IUnMappingEventListener xListen) {
061: if (this .pem_mappingListener == null)
062: this .pem_mappingListener = new ArrayList();
063:
064: this .pem_mappingListener.add(xListen);
065: }
066:
067: public void pcmf_removeMappingListener(
068: IUnMappingEventListener xListen) {
069: if (this .pem_mappingListener == null)
070: return;
071:
072: this .pem_mappingListener.remove(xListen);
073:
074: if (this .pem_mappingListener.size() == 0)
075: this .pem_mappingListener = null;
076: }
077:
078: private KeTreeElement pcmf_testOrphan(KeTreeElement xObj) {
079: KeTreeElement l_ret = xObj;
080:
081: if (l_ret instanceof IUnApplication)
082: return (null);
083:
084: while (true) {
085: l_ret = l_ret.pcmf_getParentNode();
086: if (l_ret == null)
087: return (xObj);
088:
089: xObj = l_ret;
090:
091: if (l_ret instanceof IUnApplication)
092: return (null);
093: }
094: }
095:
096: public boolean pcmf_execMapping(HttpServletRequest xReq,
097: UnComponent xCheckNode, ArrayList xDispList,
098: boolean xStrict, boolean xUseMultiPart, boolean xBubble)
099: throws Exception {
100: Enumeration l_enu = null;
101: UnComponent l_guiObj = null;
102: String l_guiObjName = null;
103: Object l_objValues[] = null;
104: Object l_oldValue = null;
105: HashMap l_chkBoxes = new HashMap();
106: Hashtable l_parameters = null;
107: boolean l_ret = true;
108: int l_cnt = 0;
109:
110: ArrayList l_orphans = new ArrayList();
111:
112: if (KeLog.pcmf_testLog(KeLog.TRACE))
113: KeLog.pcmf_log("ug2t", "entering (pcmf_execMapping)", this ,
114: KeLog.TRACE);
115:
116: if (xUseMultiPart && FileUpload.isMultipartContent(xReq)) {
117: DiskFileUpload l_upload = new DiskFileUpload();
118:
119: l_upload.setSizeThreshold(2000000);
120: l_upload.setSizeMax(-1);
121: l_upload.setRepositoryPath(KeEnvironment
122: .pcmf_getSessionTmpDir());
123:
124: List l_items = l_upload.parseRequest(xReq);
125: Iterator l_it = l_items.iterator();
126: l_parameters = new Hashtable();
127:
128: while (l_it.hasNext()) {
129: FileItem l_item = (FileItem) l_it.next();
130: if (l_item.isFormField()) {
131: String l_iname = l_item.getFieldName();
132: String l_ival = l_item.getString();
133:
134: ArrayList l_parSet = (ArrayList) l_parameters
135: .get(l_iname);
136: if (l_parSet == null) {
137: ArrayList l_new = new ArrayList();
138: l_new.add(l_ival);
139: l_parameters.put(l_iname, l_new);
140: } else
141: l_parSet.add(l_ival);
142: } else {
143: if (l_item.getName().trim().equals("") == false) {
144: String l_fname = KeEnvironment
145: .pcmf_getSessionTmpDir()
146: + new File(l_item.getName()).getName();
147: KeLog.pcmf_log("ug2t", "received file: "
148: + l_fname, this , KeLog.MESSAGE);
149: l_item.write(new File(l_fname));
150: } else
151: KeLog.pcmf_log("ug2t", "no file received",
152: this , KeLog.MESSAGE);
153: }
154: }
155: l_enu = l_parameters.keys();
156: } else
157: l_enu = xReq.getParameterNames();
158:
159: String l_mval = xReq
160: .getParameter(MuGenericApplication.MY_META_KEY);
161: KeRegisteredObject l_mobj = (KeRegisteredObject) KeRegisteredObject
162: .pcmf_getObjByName(MuGenericApplication.MY_META_KEY);
163: if (l_mval != null) {
164: if (this .pem_mappingListener != null) {
165: Iterator l_mit = this .pem_mappingListener.iterator();
166: while (l_mit.hasNext()) {
167: IUnMappingEventListener l_ml = (IUnMappingEventListener) l_mit
168: .next();
169: l_ml.pcmf_mapped(l_mobj, l_mobj.pcmf_getValue(),
170: l_mval);
171: }
172: }
173:
174: if (KeLog.pcmf_testLog(KeLog.DEBUG))
175: KeLog.pcmf_log("ug2t", "mapping value@object: "
176: + l_mval + "@"
177: + MuGenericApplication.MY_META_KEY, this ,
178: KeLog.DEBUG);
179:
180: l_mobj.pcmf_setValue(l_mval);
181: }
182:
183: while (l_enu.hasMoreElements()) {
184: l_guiObjName = (String) l_enu.nextElement();
185: if (l_guiObjName.equals(MuGenericApplication.MY_META_KEY))
186: continue;
187:
188: if (l_parameters == null)
189: l_objValues = xReq.getParameterValues(l_guiObjName);
190: else
191: l_objValues = ((ArrayList) l_parameters
192: .get(l_guiObjName)).toArray();
193:
194: for (l_cnt = 0; l_cnt < l_objValues.length; l_cnt++) {
195: try {
196: l_guiObj = (UnComponent) KeRegisteredObject
197: .pcmf_getObjByName(l_guiObjName);
198: if (l_guiObj == null) {
199: if (KeLog.pcmf_testLog(KeLog.DEBUG))
200: KeLog.pcmf_log("ug2t", "object not found: "
201: + l_guiObjName, this , KeLog.DEBUG);
202:
203: continue;
204: }
205: } catch (ClassCastException e) {
206: if (KeLog.pcmf_testLog(KeLog.DEBUG))
207: KeLog.pcmf_log("ug2t",
208: "object no valid gui object: "
209: + l_guiObjName, this ,
210: KeLog.DEBUG);
211:
212: continue;
213: }
214:
215: pcmf_handleDispatchList(xDispList, xBubble, l_guiObj,
216: l_orphans);
217:
218: l_oldValue = l_guiObj.pcmf_getValue();
219:
220: // So wird in jedem Fall die zugeordnete Seite oder das Cluster gefunden
221: // (appl->seite oder Cluster->sonstwas->...)
222: // Es werden nur die Mappings der aktuellen Seite ausgeführt !
223: // Ausnahme Globals
224: if (xStrict == true) {
225: KeTreeElement l_owningPage = l_guiObj
226: .pcmf_getParentGeneration(l_guiObj
227: .pcmf_getParentNodeCount() - 1);
228: if (l_owningPage != xCheckNode
229: && l_guiObj.pcmf_getGlobal() == false
230: && xCheckNode.pcmf_getGlobal() == false) {
231: KeLog.pcmf_log("ug2t",
232: "object not in context: "
233: + l_guiObj.pcmf_getName()
234: + " owning page: "
235: + l_owningPage.pcmf_getName()
236: + " active page: "
237: + xCheckNode.pcmf_getName(),
238: this , KeLog.ERROR);
239: l_ret = false;
240: }
241: ;
242: }
243: ;
244: if (l_guiObj instanceof IUnCheckBox) {
245: l_chkBoxes.put(l_guiObj, l_objValues[l_cnt]);
246: } else {
247: if (l_objValues[l_cnt].equals(l_oldValue) == false
248: || l_guiObj.pdm_eventOnChange) {
249: if (l_guiObj instanceof IUnButton == false) {
250: if (l_guiObj instanceof MuGenericComponent
251: && ((MuGenericComponent) l_guiObj)
252: .pcmf_getDifferentialRepaint())
253: ((MuGenericComponent) l_guiObj)
254: .pcmf_refreshValue(l_objValues[l_cnt]);
255: else {
256: l_guiObj
257: .pcmf_setValue(l_objValues[l_cnt]);
258: if (l_guiObj instanceof IUnEventChannel)
259: l_guiObj.pcmf_setPropChanged(true);
260: }
261:
262: }
263: l_guiObj.pcmf_setRefresh();
264: }
265: ;
266: }
267: ;
268:
269: if (this .pem_mappingListener != null) {
270: Iterator l_mit = this .pem_mappingListener
271: .iterator();
272: while (l_mit.hasNext()) {
273: IUnMappingEventListener l_ml = (IUnMappingEventListener) l_mit
274: .next();
275: l_ml.pcmf_mapped(l_guiObj, l_oldValue,
276: l_objValues[l_cnt]);
277: }
278: }
279: if (KeLog.pcmf_testLog(KeLog.DEBUG))
280: KeLog.pcmf_log("ug2t", "mapping value@object: "
281: + l_objValues[l_cnt] + "@"
282: + l_guiObj.pcmf_getObjName(), this ,
283: KeLog.DEBUG);
284: }
285: ;
286: }
287: ;
288:
289: if (l_chkBoxes.size() > 0) {
290: UnComponent l_obj = null;
291: Object l_value = null;
292:
293: Iterator l_it = l_chkBoxes.keySet().iterator();
294: while (l_it.hasNext()) {
295: l_obj = (UnComponent) l_it.next();
296: l_value = l_chkBoxes.get(l_obj);
297: if (l_obj.pcmf_getValue().equals(l_value) == false) {
298: if (this .pem_mappingListener != null) {
299: Iterator l_mit = this .pem_mappingListener
300: .iterator();
301: while (l_mit.hasNext()) {
302: IUnMappingEventListener l_ml = (IUnMappingEventListener) l_mit
303: .next();
304: l_ml.pcmf_mapped(l_obj, l_obj
305: .pcmf_getValue(), l_value);
306: }
307: }
308:
309: l_obj.pcmf_setValue(l_value);
310: l_obj.pcmf_setRefresh();
311: }
312: }
313: }
314: if (KeLog.pcmf_testLog(KeLog.TRACE))
315: KeLog.pcmf_log("ug2t", "leaving (pcmf_execMapping)", this ,
316: KeLog.TRACE);
317:
318: xDispList.addAll(0, l_orphans);
319:
320: return (l_ret);
321: };
322:
323: public boolean pcmf_execMapping(Map xParameter,
324: UnComponent xCheckNode, ArrayList xDispList,
325: boolean xStrict, boolean xBubble) throws Exception {
326: Iterator l_enu = xParameter.keySet().iterator();
327: UnComponent l_guiObj = null;
328: String l_guiObjName = null;
329: Object l_objValue = null;
330: Object l_oldValue = null;
331: boolean l_ret = true;
332:
333: ArrayList l_orphans = new ArrayList();
334:
335: if (KeLog.pcmf_testLog(KeLog.TRACE))
336: KeLog.pcmf_log("ug2t", "entering (pcmf_execMapping)", this ,
337: KeLog.TRACE);
338:
339: while (l_enu.hasNext()) {
340: l_guiObjName = (String) l_enu.next();
341: l_objValue = xParameter.get(l_guiObjName);
342:
343: try {
344: l_guiObj = (UnComponent) KeRegisteredObject
345: .pcmf_getObjByName(l_guiObjName);
346: if (l_guiObj == null) {
347: if (KeLog.pcmf_testLog(KeLog.DEBUG))
348: KeLog.pcmf_log("ug2t", "object not found: "
349: + l_guiObjName, this , KeLog.DEBUG);
350:
351: continue;
352: }
353: } catch (ClassCastException e) {
354: if (KeLog.pcmf_testLog(KeLog.DEBUG))
355: KeLog.pcmf_log("ug2t",
356: "object no valid gui object: "
357: + l_guiObjName, this , KeLog.DEBUG);
358:
359: continue;
360: }
361:
362: pcmf_handleDispatchList(xDispList, xBubble, l_guiObj,
363: l_orphans);
364:
365: l_oldValue = l_guiObj.pcmf_getValue();
366:
367: // So wird in jedem Fall die zugeordnete Seite oder das Cluster gefunden
368: // (appl->seite oder Cluster->sonstwas->...)
369: // Es werden nur die Mappings der aktuellen Seite ausgeführt !
370: // Ausnahme Globals
371: if (xStrict == true) {
372: KeTreeElement l_owningPage = l_guiObj
373: .pcmf_getParentGeneration(l_guiObj
374: .pcmf_getParentNodeCount() - 1);
375: if (l_owningPage != xCheckNode
376: && l_guiObj.pcmf_getGlobal() == false
377: && xCheckNode.pcmf_getGlobal() == false) {
378: KeLog.pcmf_log("ug2t", "object not in context: "
379: + l_guiObj.pcmf_getName()
380: + " owning page: "
381: + l_owningPage.pcmf_getName()
382: + " active page: "
383: + xCheckNode.pcmf_getName(), this ,
384: KeLog.ERROR);
385: l_ret = false;
386: }
387: ;
388: }
389:
390: if (l_objValue.equals(l_oldValue) == false
391: || l_guiObj.pdm_eventOnChange) {
392: if (l_guiObj instanceof IUnButton == false)
393: l_guiObj.pcmf_setLocalValue(l_objValue);
394:
395: l_guiObj.pcmf_setRefresh();
396: }
397: ;
398:
399: if (l_guiObj.pcmf_isDeleted()) {
400: l_ret = false;
401: KeLog
402: .pcmf_log(
403: "ug2t",
404: "found deleted object in mapping request (session seems to be closed), dispatch deactivated for request",
405: this , KeLog.MESSAGE);
406: continue;
407: }
408: ;
409:
410: if (l_guiObj.pcmf_getAppl().pcmf_getSession()
411: .pcmf_doAutoEcho()
412: && l_guiObj.pcmf_doAutoEcho())
413: l_guiObj.pcmf_echoValue(l_objValue);
414:
415: if (this .pem_mappingListener != null) {
416: Iterator l_mit = this .pem_mappingListener.iterator();
417: while (l_mit.hasNext()) {
418: IUnMappingEventListener l_ml = (IUnMappingEventListener) l_mit
419: .next();
420: l_ml.pcmf_mapped(l_guiObj, l_oldValue, l_objValue);
421: }
422: }
423:
424: if (KeLog.pcmf_testLog(KeLog.DEBUG))
425: KeLog.pcmf_log("ug2t",
426: "mapping value@object: " + l_objValue + "@"
427: + l_guiObj.pcmf_getObjName(), this ,
428: KeLog.DEBUG);
429: }
430: ;
431:
432: if (KeLog.pcmf_testLog(KeLog.TRACE))
433: KeLog.pcmf_log("ug2t", "leaving (pcmf_execMapping)", this ,
434: KeLog.TRACE);
435:
436: xDispList.addAll(0, l_orphans);
437:
438: return (l_ret);
439: }
440:
441: private void pcmf_handleDispatchList(ArrayList xDispList,
442: boolean xBubble, UnComponent xGuiObj, ArrayList xOrphans) {
443: if (xBubble) {
444: UnComponent l_evParent = (UnComponent) this
445: .pcmf_testOrphan(xGuiObj);
446: if (l_evParent != null)
447: xDispList.add(l_evParent);
448:
449: if (xGuiObj instanceof IUnEventChannel) {
450: if (((IUnEventChannel) xGuiObj).pcmf_isRefreshParent()) {
451: UnComponent l_p = (UnComponent) xGuiObj
452: .pcmf_getParentNode();
453: l_p.pcmf_setRefresh();
454: l_p.pcmf_setPropChanged(true);
455: }
456: }
457: } else {
458: if (xGuiObj instanceof IUnEventChannel) {
459: if (((IUnEventChannel) xGuiObj).pcmf_isRefreshParent()) {
460: UnComponent l_p = (UnComponent) xGuiObj
461: .pcmf_getParentNode();
462: if (l_p != null)
463: xDispList.add(l_p);
464:
465: l_p.pcmf_setRefresh();
466: l_p.pcmf_setPropChanged(true);
467: }
468: }
469:
470: UnComponent l_evParent = (UnComponent) this
471: .pcmf_testOrphan(xGuiObj);
472: if (l_evParent != null)
473: xOrphans.add(xGuiObj);
474: else
475: xDispList.add(xGuiObj);
476: }
477: }
478: }
|