01: /*
02: * $Id: FieldToSession.java,v 1.1 2003/08/17 06:06:13 ajzeneski Exp $
03: *
04: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
24: package org.ofbiz.minilang.method.eventops;
25:
26: import java.util.*;
27:
28: import org.w3c.dom.*;
29: import org.ofbiz.base.util.*;
30: import org.ofbiz.minilang.*;
31: import org.ofbiz.minilang.method.*;
32:
33: /**
34: * Copies a map field to a Servlet session attribute
35: *
36: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
37: * @version $Revision: 1.1 $
38: * @since 2.0
39: */
40: public class FieldToSession extends MethodOperation {
41:
42: public static final String module = FieldToSession.class.getName();
43:
44: ContextAccessor mapAcsr;
45: ContextAccessor fieldAcsr;
46: FlexibleServletAccessor sessionAcsr;
47:
48: public FieldToSession(Element element, SimpleMethod simpleMethod) {
49: super (element, simpleMethod);
50: mapAcsr = new ContextAccessor(element.getAttribute("map-name"));
51: fieldAcsr = new ContextAccessor(element
52: .getAttribute("field-name"));
53: sessionAcsr = new FlexibleServletAccessor(element
54: .getAttribute("session-name"), element
55: .getAttribute("field-name"));
56: }
57:
58: public boolean exec(MethodContext methodContext) {
59: // only run this if it is in an EVENT context
60: if (methodContext.getMethodType() == MethodContext.EVENT) {
61: Object fieldVal = null;
62: if (!mapAcsr.isEmpty()) {
63: Map fromMap = (Map) mapAcsr.get(methodContext);
64: if (fromMap == null) {
65: Debug.logWarning("Map not found with name "
66: + mapAcsr, module);
67: return true;
68: }
69: fieldVal = fieldAcsr.get(fromMap, methodContext);
70: } else {
71: // no map name, try the env
72: fieldVal = fieldAcsr.get(methodContext);
73: }
74:
75: if (fieldVal == null) {
76: Debug.logWarning("Field value not found with name "
77: + fieldAcsr + " in Map with name " + mapAcsr,
78: module);
79: return true;
80: }
81:
82: sessionAcsr.put(methodContext.getRequest().getSession(),
83: fieldVal, methodContext.getEnvMap());
84: }
85: return true;
86: }
87: }
|