1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.facade.runtag;
18
19 import java.util.Enumeration;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import COM.FutureTense.Interfaces.ICS;
25
26 import com.fatwire.gst.foundation.facade.FTValListFacade;
27
28
29
30
31
32
33
34
35 public abstract class AbstractTagRunner extends FTValListFacade implements TagRunner {
36
37 private static final Log LOG = LogFactory.getLog(AbstractTagRunner.class.getPackage().getName());
38
39 private final String tagName;
40
41
42
43
44 protected AbstractTagRunner(String tagName) {
45 this.tagName = tagName;
46 }
47
48
49
50
51
52
53
54
55
56 protected void bind(ICS ics) {
57
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public String execute(ICS ics) {
76 bind(ics);
77 if (ics.GetErrno() != 0) {
78 ics.ClearErrno();
79 }
80 preExecute(ics);
81
82 if (LOG.isTraceEnabled()) {
83 StringBuffer sb = new StringBuffer("About to execute runTag for tag: " + tagName + ". ");
84 sb.append("\nInput param list:");
85 for (Object k : list.keySet()) {
86 String key = (String) k;
87 sb.append("\n\t").append(key).append("=")
88 .append(isPW(key) ? "<password suppressed>" : list.getValString(key));
89 }
90 sb.append("\nVariables:");
91 Enumeration<?> e = ics.GetVars();
92 while (e.hasMoreElements()) {
93 String key = (String) e.nextElement();
94 sb.append("\n\t").append(key).append("=").append(isPW(key) ? "<password suppressed>" : ics.GetVar(key));
95 }
96 sb.append("\nSession Variables:");
97 e = ics.GetSSVars();
98 while (e.hasMoreElements()) {
99 String key = (String) e.nextElement();
100 sb.append("\n\t").append(key).append("=")
101 .append(isPW(key) ? "<password suppressed>" : ics.GetSSVar(key));
102 }
103 LOG.trace(sb);
104 }
105 String s = ics.runTag(tagName, list);
106 if (LOG.isTraceEnabled()) {
107 StringBuffer sb = new StringBuffer("Just completed execution of runTag for tag: " + tagName + ". ");
108 sb.append("\nInput param list:");
109 for (Object k : list.keySet()) {
110 String key = (String) k;
111 sb.append("\n\t").append(key).append("=")
112 .append(isPW(key) ? "<password suppressed>" : list.getValString(key));
113 }
114 sb.append("\nVariables:");
115 Enumeration<?> e = ics.GetVars();
116 while (e.hasMoreElements()) {
117 String key = (String) e.nextElement();
118 sb.append("\n\t").append(key).append("=").append(isPW(key) ? "<password suppressed>" : ics.GetVar(key));
119 }
120 sb.append("\nSession Variables:");
121 e = ics.GetSSVars();
122 while (e.hasMoreElements()) {
123 String key = (String) e.nextElement();
124 sb.append("\n\t").append(key).append("=")
125 .append(isPW(key) ? "<password suppressed>" : ics.GetSSVar(key));
126 }
127 LOG.trace(sb);
128 }
129 postExecute(ics);
130 if (ics.GetErrno() != 0) {
131 this.handleError(ics);
132 }
133 return s;
134 }
135
136 private static final boolean isPW(String key) {
137 return key != null && key.toLowerCase().contains("password");
138 }
139
140
141
142
143
144
145
146
147
148 protected void preExecute(ICS ics) {
149
150 }
151
152
153
154
155
156
157
158
159 protected void postExecute(ICS ics) {
160
161 }
162
163
164
165
166
167
168
169
170
171
172 protected void handleError(ICS ics) {
173 throw new TagRunnerRuntimeException("ics.runTag(" + tagName + ") returned an errno.", ics.GetErrno(), list,
174 ics.getComplexError(), ics.GetVar("pagename"), ics.ResolveVariables("CS.elementname"));
175
176 }
177 }