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 single operation, does the specified operation on the given field
27: */
28: public abstract class SimpleMapOperation {
29:
30: String message = null;
31: String propertyResource = null;
32: boolean isProperty = false;
33: SimpleMapProcess simpleMapProcess;
34: String fieldName;
35:
36: public SimpleMapOperation(Element element,
37: SimpleMapProcess simpleMapProcess) {
38: Element failMessage = UtilXml.firstChildElement(element,
39: "fail-message");
40: Element failProperty = UtilXml.firstChildElement(element,
41: "fail-property");
42:
43: if (failMessage != null) {
44: this .message = failMessage.getAttribute("message");
45: this .isProperty = false;
46: } else if (failProperty != null) {
47: this .propertyResource = failProperty
48: .getAttribute("resource");
49: this .message = failProperty.getAttribute("property");
50: this .isProperty = true;
51: }
52:
53: this .simpleMapProcess = simpleMapProcess;
54: this .fieldName = simpleMapProcess.getFieldName();
55: }
56:
57: public abstract void exec(Map inMap, Map results, List messages,
58: Locale locale, ClassLoader loader);
59:
60: public void addMessage(List messages, ClassLoader loader,
61: Locale locale) {
62: if (!isProperty && message != null) {
63: messages.add(new MessageString(message, fieldName, true));
64: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding message: " + message, module);
65: } else if (isProperty && propertyResource != null
66: && message != null) {
67: // this one doesn't do the proper i18n: String propMsg = UtilProperties.getPropertyValue(UtilURL.fromResource(propertyResource, loader), message);
68: String propMsg = UtilProperties.getMessage(
69: propertyResource, message, locale);
70: if (propMsg == null || propMsg.length() == 0) {
71: messages
72: .add(new MessageString(
73: "Simple Map Processing error occurred, but no message was found, sorry.",
74: fieldName, propertyResource, message,
75: locale, true));
76: } else {
77: messages.add(new MessageString(propMsg, fieldName,
78: propertyResource, message, locale, true));
79: }
80: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] Adding property message: " + propMsg, module);
81: } else {
82: messages
83: .add(new MessageString(
84: "Simple Map Processing error occurred, but no message was found, sorry.",
85: fieldName, true));
86: // if (Debug.infoOn()) Debug.logInfo("[SimpleMapOperation.addMessage] ERROR: No message found", module);
87: }
88: }
89: }
|