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.envops;
19:
20: import java.util.*;
21:
22: import org.w3c.dom.*;
23: import org.ofbiz.base.util.*;
24: import org.ofbiz.minilang.*;
25: import org.ofbiz.minilang.method.*;
26:
27: /**
28: * Get the first entry from the list
29: */
30: public class FirstFromList extends MethodOperation {
31:
32: public static final String module = FirstFromList.class.getName();
33:
34: ContextAccessor entryAcsr;
35: ContextAccessor listAcsr;
36:
37: public FirstFromList(Element element, SimpleMethod simpleMethod) {
38: super (element, simpleMethod);
39: this .entryAcsr = new ContextAccessor(element
40: .getAttribute("entry-name"));
41: this .listAcsr = new ContextAccessor(element
42: .getAttribute("list-name"));
43: }
44:
45: public boolean exec(MethodContext methodContext) {
46:
47: if (listAcsr.isEmpty()) {
48: Debug
49: .logWarning(
50: "No list-name specified in iterate tag, doing nothing",
51: module);
52: return true;
53: }
54:
55: List theList = (List) listAcsr.get(methodContext);
56:
57: if (theList == null) {
58: if (Debug.infoOn())
59: Debug.logInfo("List not found with name " + listAcsr
60: + ", doing nothing", module);
61: return true;
62: }
63: if (theList.size() == 0) {
64: if (Debug.verboseOn())
65: Debug.logVerbose("List with name " + listAcsr
66: + " has zero entries, doing nothing", module);
67: return true;
68: }
69:
70: entryAcsr.put(methodContext, theList.get(0));
71: return true;
72: }
73:
74: public String rawString() {
75: return "<first-from-list list-name=\"" + this .listAcsr
76: + "\" entry-name=\"" + this .entryAcsr + "\"/>";
77: }
78:
79: public String expandedString(MethodContext methodContext) {
80: // TODO: something more than a stub/dummy
81: return this.rawString();
82: }
83: }
|