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.operation;
19:
20: import java.util.*;
21:
22: import org.w3c.dom.*;
23: import org.ofbiz.base.util.*;
24:
25: /**
26: * A complete string process for a given field; contains multiple string operations
27: */
28: public class SimpleMapProcess {
29:
30: public static final String module = SimpleMapProcess.class
31: .getName();
32:
33: List simpleMapOperations = new LinkedList();
34: String field = "";
35:
36: public SimpleMapProcess(Element simpleMapProcessElement) {
37: this .field = simpleMapProcessElement.getAttribute("field");
38: readOperations(simpleMapProcessElement);
39: }
40:
41: public String getFieldName() {
42: return field;
43: }
44:
45: public void exec(Map inMap, Map results, List messages,
46: Locale locale, ClassLoader loader) {
47: Iterator strOpsIter = simpleMapOperations.iterator();
48:
49: while (strOpsIter.hasNext()) {
50: SimpleMapOperation simpleMapOperation = (SimpleMapOperation) strOpsIter
51: .next();
52:
53: simpleMapOperation.exec(inMap, results, messages, locale,
54: loader);
55: }
56: }
57:
58: void readOperations(Element simpleMapProcessElement) {
59: List operationElements = UtilXml
60: .childElementList(simpleMapProcessElement);
61:
62: if (operationElements != null && operationElements.size() > 0) {
63: Iterator operElemIter = operationElements.iterator();
64:
65: while (operElemIter.hasNext()) {
66: Element curOperElem = (Element) operElemIter.next();
67: String nodeName = curOperElem.getNodeName();
68:
69: if ("validate-method".equals(nodeName)) {
70: simpleMapOperations.add(new ValidateMethod(
71: curOperElem, this ));
72: } else if ("compare".equals(nodeName)) {
73: simpleMapOperations.add(new Compare(curOperElem,
74: this ));
75: } else if ("compare-field".equals(nodeName)) {
76: simpleMapOperations.add(new CompareField(
77: curOperElem, this ));
78: } else if ("regexp".equals(nodeName)) {
79: simpleMapOperations.add(new Regexp(curOperElem,
80: this ));
81: } else if ("not-empty".equals(nodeName)) {
82: simpleMapOperations.add(new NotEmpty(curOperElem,
83: this ));
84: } else if ("copy".equals(nodeName)) {
85: simpleMapOperations
86: .add(new Copy(curOperElem, this ));
87: } else if ("convert".equals(nodeName)) {
88: simpleMapOperations.add(new Convert(curOperElem,
89: this ));
90: } else {
91: Debug.logWarning(
92: "[SimpleMapProcessor.SimpleMapProcess.readOperations] Operation element \""
93: + nodeName + "\" not recognized",
94: module);
95: }
96: }
97: }
98: }
99: }
|