01: /*
02: * $Id: FilterListByDate.java,v 1.1 2003/08/17 06:06:11 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.entityops;
25:
26: import java.util.List;
27:
28: import org.ofbiz.base.util.UtilDateTime;
29: import org.ofbiz.base.util.UtilValidate;
30: import org.ofbiz.entity.util.EntityUtil;
31: import org.ofbiz.minilang.SimpleMethod;
32: import org.ofbiz.minilang.method.ContextAccessor;
33: import org.ofbiz.minilang.method.MethodContext;
34: import org.ofbiz.minilang.method.MethodOperation;
35: import org.w3c.dom.Element;
36:
37: /**
38: * Uses the delegator to find entity values by anding the map fields
39: *
40: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
41: * @version $Revision: 1.1 $
42: * @since 2.0
43: */
44: public class FilterListByDate extends MethodOperation {
45:
46: ContextAccessor listAcsr;
47: ContextAccessor toListAcsr;
48: ContextAccessor validDateAcsr;
49: String fromFieldName;
50: String thruFieldName;
51: String allSameStr;
52:
53: public FilterListByDate(Element element, SimpleMethod simpleMethod) {
54: super (element, simpleMethod);
55: listAcsr = new ContextAccessor(element
56: .getAttribute("list-name"));
57: toListAcsr = new ContextAccessor(element
58: .getAttribute("to-list-name"), element
59: .getAttribute("list-name"));
60: validDateAcsr = new ContextAccessor(element
61: .getAttribute("valid-date-name"));
62:
63: fromFieldName = element.getAttribute("from-field-name");
64: if (UtilValidate.isEmpty(fromFieldName))
65: fromFieldName = "fromDate";
66: thruFieldName = element.getAttribute("thru-field-name");
67: if (UtilValidate.isEmpty(thruFieldName))
68: thruFieldName = "thruDate";
69:
70: allSameStr = element.getAttribute("all-same");
71: }
72:
73: public boolean exec(MethodContext methodContext) {
74: String fromFieldName = methodContext
75: .expandString(this .fromFieldName);
76: String thruFieldName = methodContext
77: .expandString(this .thruFieldName);
78: String allSameStr = methodContext.expandString(this .allSameStr);
79:
80: boolean allSame = !"false".equals(allSameStr);
81:
82: if (!validDateAcsr.isEmpty()) {
83: toListAcsr.put(methodContext, EntityUtil.filterByDate(
84: (List) listAcsr.get(methodContext),
85: (java.sql.Timestamp) validDateAcsr
86: .get(methodContext), fromFieldName,
87: thruFieldName, true));
88: } else {
89: toListAcsr.put(methodContext, EntityUtil.filterByDate(
90: (List) listAcsr.get(methodContext), UtilDateTime
91: .nowTimestamp(), fromFieldName,
92: thruFieldName, true));
93: }
94: return true;
95: }
96: }
|