KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > minilang > method > envops > StringToList


1 /*
2  * $Id: StringToList.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.minilang.method.envops;
25
26 import java.text.*;
27 import java.util.*;
28
29 import org.w3c.dom.*;
30
31 import org.ofbiz.base.util.*;
32 import org.ofbiz.minilang.*;
33 import org.ofbiz.minilang.method.*;
34
35 /**
36  * Appends the specified String to a List
37  *
38  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
39  * @version $Rev: 5462 $
40  * @since 2.0
41  */

42 public class StringToList extends MethodOperation {
43     
44     public static final String JavaDoc module = StringToList.class.getName();
45     
46     String JavaDoc string;
47     ContextAccessor listAcsr;
48     ContextAccessor argListAcsr;
49     String JavaDoc messageFieldName;
50
51     public StringToList(Element element, SimpleMethod simpleMethod) {
52         super(element, simpleMethod);
53         string = element.getAttribute("string");
54         listAcsr = new ContextAccessor(element.getAttribute("list-name"));
55         argListAcsr = new ContextAccessor(element.getAttribute("arg-list-name"));
56         messageFieldName = element.getAttribute("message-field-name");
57     }
58
59     public boolean exec(MethodContext methodContext) {
60         String JavaDoc valueStr = methodContext.expandString(string);
61         if (!argListAcsr.isEmpty()) {
62             List argList = (List) argListAcsr.get(methodContext);
63             if (argList != null && argList.size() > 0) {
64                 valueStr = MessageFormat.format(valueStr, argList.toArray());
65             }
66         }
67
68         Object JavaDoc value;
69         if (this.messageFieldName != null && this.messageFieldName.length() > 0) {
70             value = new MessageString(valueStr, this.messageFieldName, true);
71         } else {
72             value = valueStr;
73         }
74
75         List toList = (List) listAcsr.get(methodContext);
76         if (toList == null) {
77             if (Debug.verboseOn()) Debug.logVerbose("List not found with name " + listAcsr + ", creating new List", module);
78             toList = new LinkedList();
79             listAcsr.put(methodContext, toList);
80         }
81         toList.add(value);
82
83         return true;
84     }
85
86     public String JavaDoc rawString() {
87         // TODO: something more than the empty tag
88
return "<string-to-list string=\"" + this.string + "\" list-name=\"" + this.listAcsr + "\"/>";
89     }
90     public String JavaDoc expandedString(MethodContext methodContext) {
91         // TODO: something more than a stub/dummy
92
return this.rawString();
93     }
94 }
95
Popular Tags