01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.entityops;
19:
20: import java.util.List;
21:
22: import org.ofbiz.base.util.UtilDateTime;
23: import org.ofbiz.base.util.UtilValidate;
24: import org.ofbiz.entity.util.EntityUtil;
25: import org.ofbiz.minilang.SimpleMethod;
26: import org.ofbiz.minilang.method.ContextAccessor;
27: import org.ofbiz.minilang.method.MethodContext;
28: import org.ofbiz.minilang.method.MethodOperation;
29: import org.w3c.dom.Element;
30:
31: /**
32: * Uses the delegator to find entity values by anding the map fields
33: */
34: public class FilterListByDate extends MethodOperation {
35:
36: ContextAccessor listAcsr;
37: ContextAccessor toListAcsr;
38: ContextAccessor validDateAcsr;
39: String fromFieldName;
40: String thruFieldName;
41: String allSameStr;
42:
43: public FilterListByDate(Element element, SimpleMethod simpleMethod) {
44: super (element, simpleMethod);
45: listAcsr = new ContextAccessor(element
46: .getAttribute("list-name"));
47: toListAcsr = new ContextAccessor(element
48: .getAttribute("to-list-name"), element
49: .getAttribute("list-name"));
50: validDateAcsr = new ContextAccessor(element
51: .getAttribute("valid-date-name"));
52:
53: fromFieldName = element.getAttribute("from-field-name");
54: if (UtilValidate.isEmpty(fromFieldName))
55: fromFieldName = "fromDate";
56: thruFieldName = element.getAttribute("thru-field-name");
57: if (UtilValidate.isEmpty(thruFieldName))
58: thruFieldName = "thruDate";
59:
60: allSameStr = element.getAttribute("all-same");
61: }
62:
63: public boolean exec(MethodContext methodContext) {
64:
65: if (!validDateAcsr.isEmpty()) {
66: toListAcsr.put(methodContext, EntityUtil.filterByDate(
67: (List) listAcsr.get(methodContext),
68: (java.sql.Timestamp) validDateAcsr
69: .get(methodContext), fromFieldName,
70: thruFieldName, true));
71: } else {
72: toListAcsr.put(methodContext, EntityUtil.filterByDate(
73: (List) listAcsr.get(methodContext), UtilDateTime
74: .nowTimestamp(), fromFieldName,
75: thruFieldName, true));
76: }
77: return true;
78: }
79:
80: public String rawString() {
81: // TODO: something more than the empty tag
82: return "<filter-list-by-date/>";
83: }
84:
85: public String expandedString(MethodContext methodContext) {
86: // TODO: something more than a stub/dummy
87: return this.rawString();
88: }
89: }
|