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 com.fatwire.gst.foundation.facade.runtag.xlat;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import COM.FutureTense.Interfaces.ICS;
23  
24  import com.fatwire.gst.foundation.facade.runtag.AbstractTagRunner;
25  
26  /**
27   * Wrapper around the XLAT.STREAM xml tag
28   * 
29   * @author Mike Field
30   * @since August 15, 2008
31   */
32  public final class Stream extends AbstractTagRunner {
33      // Default Constructor
34      public Stream() {
35          super("XLAT.STREAM");
36      }
37  
38      /**
39       * Sets key to the value of <code>s</code>
40       * 
41       * @param s The key of the db entry to return
42       */
43      public void setKey(String s) {
44          // validate first
45          if (s == null || s.length() == 0) {
46              throw new IllegalArgumentException("Invalid key string: " + s);
47          }
48          this.set("KEY", s);
49      }
50  
51      /**
52       * Sets locale to the value of <code>s</code>
53       * 
54       * @param s The locale of the db entry
55       */
56      public void setLocale(String s) {
57          // validate first
58          if (s == null || s.length() == 0) {
59              throw new IllegalArgumentException("Invalid locale string: " + s);
60          }
61          this.set("LOCALE", s);
62      }
63  
64      /**
65       * Sets encode to the value of <code>s</code>
66       * 
67       * @param s true or false (case sensitive)
68       */
69      public void setEncode(String s) {
70          // validate first
71          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
72              throw new IllegalArgumentException("Invalid encode string: " + s);
73          }
74          this.set("ENCODE", s);
75      }
76  
77      /**
78       * Sets escape to the value of <code>s</code>
79       * 
80       * @param s true or false (case sensitive)
81       */
82      public void setEscape(String s) {
83          // validate first
84          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
85              throw new IllegalArgumentException("Invalid escape string: " + s);
86          }
87          this.set("ESCAPE", s);
88      }
89  
90      /**
91       * Sets evalall to the value of <code>s</code>
92       * 
93       * @param s true or false (case sensitive)
94       */
95      public void setEvalAll(String s) {
96          // validate first
97          if (s == null || s.length() == 0 || !s.equals("true") && !s.equals("false")) {
98              throw new IllegalArgumentException("Invalid evalall string: " + s);
99          }
100         this.set("EVALALL", s);
101     }
102 
103     /**
104      * Sets the name and value of a custome argument to
105      * <code>argname=argvalue</code>
106      * 
107      * @param argname The name of the argument
108      * @param argvalue The name of the value
109      */
110     public void setArgument(String argname, String argvalue) {
111         // validate first
112         if (argname == null || argname.length() == 0) {
113             throw new IllegalArgumentException("Invalid argname string: " + argname);
114         }
115         if (argvalue == null || argvalue.length() == 0) {
116             throw new IllegalArgumentException("Invalid argvalue string: " + argvalue);
117         }
118         this.set(argname, argvalue);
119     }
120 
121     protected void preExecute(ICS ics) {
122         // work around a bug in the tag where a variable needs to exist for the
123         // mapping to work
124         super.preExecute(ics);
125 
126         List<String> newVars = new ArrayList<String>();
127         for (Object oKey : list.keySet()) {
128             String sKey = (String) oKey;
129             if (ics.GetVar(sKey) == null) {
130                 newVars.add(sKey);
131                 ics.SetVar(sKey, list.getValString(sKey));
132             }
133         }
134         ics.SetObj("NewVars", newVars);
135     }
136 
137     @SuppressWarnings("unchecked")
138     protected void postExecute(ICS ics) {
139         super.postExecute(ics);
140         List<String> newVars = (List<String>) ics.GetObj("NewVars");
141         for (String toRemove : newVars) {
142             ics.RemoveVar(toRemove);
143         }
144         ics.SetObj("NewVars", null);
145     }
146 
147 }