View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *    http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package tools.gsf.facade.runtag.xlat;
18  
19  import COM.FutureTense.Interfaces.ICS;
20  import tools.gsf.facade.runtag.AbstractTagRunner;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * Wrapper around the XLAT.STREAM xml tag
27   *
28   * @author Mike Field
29   * @since August 15, 2008
30   */
31  public final class Stream extends AbstractTagRunner {
32      // Default Constructor
33      public Stream() {
34          super("XLAT.STREAM");
35      }
36  
37      /**
38       * Sets key to the value of <code>s</code>
39       *
40       * @param s The key of the db entry to return
41       */
42      public void setKey(String s) {
43          // validate first
44          if (s == null || s.length() == 0) {
45              throw new IllegalArgumentException("Invalid key string: " + s);
46          }
47          this.set("KEY", s);
48      }
49  
50      /**
51       * Sets locale to the value of <code>s</code>
52       *
53       * @param s The locale of the db entry
54       */
55      public void setLocale(String s) {
56          // validate first
57          if (s == null || s.length() == 0) {
58              throw new IllegalArgumentException("Invalid locale string: " + s);
59          }
60          this.set("LOCALE", s);
61      }
62  
63      /**
64       * Sets encode to the value of <code>s</code>
65       *
66       * @param s true or false (case sensitive)
67       */
68      public void setEncode(String s) {
69          // validate first
70          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
71              throw new IllegalArgumentException("Invalid encode string: " + s);
72          }
73          this.set("ENCODE", s);
74      }
75  
76      /**
77       * Sets escape to the value of <code>s</code>
78       *
79       * @param s true or false (case sensitive)
80       */
81      public void setEscape(String s) {
82          // validate first
83          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
84              throw new IllegalArgumentException("Invalid escape string: " + s);
85          }
86          this.set("ESCAPE", s);
87      }
88  
89      /**
90       * Sets evalall to the value of <code>s</code>
91       *
92       * @param s true or false (case sensitive)
93       */
94      public void setEvalAll(String s) {
95          // validate first
96          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
97              throw new IllegalArgumentException("Invalid evalall string: " + s);
98          }
99          this.set("EVALALL", s);
100     }
101 
102     /**
103      * Sets the name and value of a custome argument to
104      * <code>argname=argvalue</code>
105      *
106      * @param argname  The name of the argument
107      * @param argvalue The name of the value
108      */
109     public void setArgument(String argname, String argvalue) {
110         // validate first
111         if (argname == null || argname.length() == 0) {
112             throw new IllegalArgumentException("Invalid argname string: " + argname);
113         }
114         if (argvalue == null || argvalue.length() == 0) {
115             throw new IllegalArgumentException("Invalid argvalue string: " + argvalue);
116         }
117         this.set(argname, argvalue);
118     }
119 
120     protected void preExecute(ICS ics) {
121         // work around a bug in the tag where a variable needs to exist for the
122         // mapping to work
123         super.preExecute(ics);
124 
125         List<String> newVars = new ArrayList<String>();
126         for (Object oKey : list.keySet()) {
127             String sKey = (String) oKey;
128             if (ics.GetVar(sKey) == null) {
129                 newVars.add(sKey);
130                 ics.SetVar(sKey, list.getValString(sKey));
131             }
132         }
133         ics.SetObj("NewVars", newVars);
134     }
135 
136     @SuppressWarnings("unchecked")
137     protected void postExecute(ICS ics) {
138         super.postExecute(ics);
139         List<String> newVars = (List<String>) ics.GetObj("NewVars");
140         for (String toRemove : newVars) {
141             ics.RemoveVar(toRemove);
142         }
143         ics.SetObj("NewVars", null);
144     }
145 
146 }