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.text.*;
21: import java.util.*;
22:
23: import org.w3c.dom.*;
24:
25: import org.ofbiz.base.util.*;
26: import org.ofbiz.minilang.*;
27: import org.ofbiz.minilang.method.*;
28:
29: /**
30: * Appends the specified String to a List
31: */
32: public class StringToList extends MethodOperation {
33:
34: public static final String module = StringToList.class.getName();
35:
36: String string;
37: ContextAccessor listAcsr;
38: ContextAccessor argListAcsr;
39: String messageFieldName;
40:
41: public StringToList(Element element, SimpleMethod simpleMethod) {
42: super (element, simpleMethod);
43: string = element.getAttribute("string");
44: listAcsr = new ContextAccessor(element
45: .getAttribute("list-name"));
46: argListAcsr = new ContextAccessor(element
47: .getAttribute("arg-list-name"));
48: messageFieldName = element.getAttribute("message-field-name");
49: }
50:
51: public boolean exec(MethodContext methodContext) {
52: String valueStr = methodContext.expandString(string);
53: if (!argListAcsr.isEmpty()) {
54: List argList = (List) argListAcsr.get(methodContext);
55: if (argList != null && argList.size() > 0) {
56: valueStr = MessageFormat.format(valueStr, argList
57: .toArray());
58: }
59: }
60:
61: Object value;
62: if (this .messageFieldName != null
63: && this .messageFieldName.length() > 0) {
64: value = new MessageString(valueStr, this .messageFieldName,
65: true);
66: } else {
67: value = valueStr;
68: }
69:
70: List toList = (List) listAcsr.get(methodContext);
71: if (toList == null) {
72: if (Debug.verboseOn())
73: Debug.logVerbose("List not found with name " + listAcsr
74: + ", creating new List", module);
75: toList = new LinkedList();
76: listAcsr.put(methodContext, toList);
77: }
78: toList.add(value);
79:
80: return true;
81: }
82:
83: public String rawString() {
84: // TODO: something more than the empty tag
85: return "<string-to-list string=\"" + this .string
86: + "\" list-name=\"" + this .listAcsr + "\"/>";
87: }
88:
89: public String expandedString(MethodContext methodContext) {
90: // TODO: something more than a stub/dummy
91: return this.rawString();
92: }
93: }
|