1 /*
2 * Copyright 2011 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 package com.fatwire.gst.foundation.include;
17
18 import java.util.Date;
19
20 import COM.FutureTense.Interfaces.ICS;
21
22 import com.fatwire.gst.foundation.facade.runtag.render.CallElement;
23 import com.fatwire.gst.foundation.facade.runtag.render.CallElement.Scope;
24
25 /**
26 * Include implementation for CallElement.
27 *
28 * @author Dolf Dijkstra
29 * @since Apr 11, 2011
30 */
31 public class IncludeElement implements Include {
32
33 private final CallElement tag;
34 private final ICS ics;
35
36 /**
37 * @param ics
38 * @param elementname
39 */
40 public IncludeElement(final ICS ics, final String elementname) {
41 tag = new CallElement(elementname);
42 this.ics = ics;
43
44 }
45
46 /*
47 * (non-Javadoc)
48 *
49 * @see
50 * com.fatwire.gst.foundation.include.Include#include(COM.FutureTense.Interfaces
51 * .ICS)
52 */
53 public void include(final ICS ics) {
54 final String s = tag.execute(ics);
55 if (s != null) {
56 ics.StreamText(s);
57 }
58 }
59
60 /**
61 * Adds the name value pair as an argument to the CallElement tag.
62 *
63 * @param name
64 * @param value
65 * @return this
66 */
67 public IncludeElement argument(final String name, final String value) {
68 tag.setArgument(name, value);
69 return this;
70 }
71
72 /**
73 * Adds the name value pair as an argument to the CallElement tag.
74 *
75 * @param name
76 * @param value
77 * @return this
78 */
79 public IncludeElement argument(final String name, final Date value) {
80 tag.set(name, value);
81 return this;
82 }
83
84 /**
85 * Adds the name value pair as an argument to the CallElement tag.
86 *
87 * @param name
88 * @param value
89 * @return this
90 */
91 public IncludeElement argument(final String name, final long value) {
92 tag.set(name, value);
93 return this;
94 }
95
96 /**
97 * Adds the name value pair as an argument to the CallElement tag.
98 *
99 * @param name
100 * @param value
101 * @return this
102 */
103 public IncludeElement argument(final String name, final int value) {
104 tag.set(name, value);
105 return this;
106 }
107
108 /**
109 * Adds the name value pair as an argument to the CallElement tag.
110 *
111 * @param name
112 * @param value
113 * @return this
114 */
115 public IncludeElement argument(final String name, final boolean value) {
116 tag.set(name, value);
117 return this;
118 }
119
120 /**
121 * Adds the name value pair as an argument to the CallElement tag.
122 *
123 * @param name
124 * @param value
125 * @return this
126 */
127 public IncludeElement argument(final String name, final byte[] value) {
128 tag.set(name, value);
129 return this;
130 }
131
132 /**
133 * Copies the ics variables identified by the name array
134 *
135 * @param name
136 * @return this
137 */
138 public IncludeElement copyArguments(final String... name) {
139 if (name == null) {
140 return this;
141 }
142 for (final String n : name) {
143 argument(n, ics.GetVar(n));
144 }
145 return this;
146 }
147
148 /**
149 * @param scope
150 * @see com.fatwire.gst.foundation.facade.runtag.render.CallElement#setScope(com.fatwire.gst.foundation.facade.runtag.render.CallElement.Scope)
151 */
152 public IncludeElement setScope(final Scope scope) {
153 tag.setScope(scope);
154 return this;
155 }
156
157 public IncludeElement global() {
158 tag.setScope(Scope.GLOBAL);
159 return this;
160 }
161
162 public IncludeElement stacked() {
163 tag.setScope(Scope.STACKED);
164 return this;
165 }
166
167 public IncludeElement local() {
168 tag.setScope(Scope.LOCAL);
169 return this;
170 }
171
172 }