Source code: com/arranger/jarl/script/jarlsp/SimpleJarlSPBase.java
1 package com.arranger.jarl.script.jarlsp;
2
3 import java.io.IOException;
4 import java.io.Writer;
5 import java.util.Map;
6
7 /**
8 * SimpleISPBase created on Jan 17, 2003
9 */
10 public abstract class SimpleJarlSPBase implements JarlSPBase {
11
12 protected Writer m_out;
13 protected Map m_properties;
14 protected JarlSPRuntime m_runtime;
15
16 /**
17 * Initialize this page
18 */
19 public void init(JarlSPRuntime runtime, Map properties) {
20 m_runtime = runtime;
21 m_out = m_runtime.getWriter();
22 m_properties = properties;
23 }
24
25 /**
26 * Prints the specified primitive.
27 *
28 * @param p Primitive to print
29 */
30 public void print(boolean p) throws IOException {
31 m_out.write(String.valueOf(p));
32 }
33
34 /**
35 * Prints the specified primitive.
36 *
37 * @param p Primitive to print
38 */
39 public void print(byte p) throws IOException {
40 m_out.write(String.valueOf(p));
41 }
42
43 /**
44 * Prints the specified primitive.
45 *
46 * @param p Primitive to print
47 */
48 public void print(char p) throws IOException {
49 m_out.write(String.valueOf(p));
50 }
51
52 /**
53 * Prints the specified primitive.
54 *
55 * @param p Primitive to print
56 */
57 public void print(int p) throws IOException {
58 m_out.write(String.valueOf(p));
59 }
60
61 /**
62 * Prints the specified primitive.
63 *
64 * @param p Primitive to print
65 */
66 public void print(long p) throws IOException {
67 m_out.write(String.valueOf(p));
68 }
69
70 /**
71 * Prints the specified primitive.
72 *
73 * @param p Primitive to print
74 */
75 public void print(float p) throws IOException {
76 m_out.write(String.valueOf(p));
77 }
78
79 /**
80 * Prints the specified primitive.
81 *
82 * @param p Primitive to print
83 */
84 public void print(double p) throws IOException {
85 m_out.write(String.valueOf(p));
86 }
87
88 /**
89 * Prints the specified array.
90 *
91 * @param a Array to print
92 */
93 public void print(byte[] a) throws IOException {
94 m_out.write(new String(a));
95 }
96
97 /**
98 * Prints the specified array.
99 *
100 * @param a Array to print
101 * @param start IndexTask of first item to print.
102 * @param length Length of items to print
103 */
104 public void print(byte[] a, int start, int length) throws IOException {
105 m_out.write(new String(a, start, length));
106 }
107
108 /**
109 * Prints the specified array.
110 *
111 * @param a Array to print
112 */
113 public void print(char[] a) throws IOException {
114 m_out.write(a);
115 }
116
117 /**
118 * Prints the specified array.
119 *
120 * @param a Array to print
121 * @param start IndexTask of first item to print.
122 * @param length Length of items to print
123 */
124 public void print(char[] a, int start, int length) throws IOException {
125 m_out.write(a, start, length);
126 }
127
128 /**
129 * Prints the specified object.
130 *
131 * @param o Object to print
132 */
133 public void print(Object o) throws IOException {
134 if (o != null) {
135 m_out.write(o.toString());
136 }
137 }
138
139 /**
140 * Prints the specified object.
141 *
142 * @param o Object to print
143 */
144 public void print(String o) throws IOException {
145 if (o != null) {
146 m_out.write(o);
147 }
148 }
149
150 /**
151 * Returns specified parameter.
152 * Note, if the param isn't found, it goes first to the runtime, then to the 'value'
153 *
154 * @param name Name of parameter to get.
155 * @return Parameter value or null if not found.
156 */
157 public Object get(String name) {
158 Object result = m_properties.get(name);
159 if (result == null) {
160 result = m_runtime.get(name);
161 }
162 return result;
163 }
164
165 /**
166 * Sets the specified parameter.
167 *
168 * @param name Name of paraeter to set.
169 * @param value Parameter value to be set.
170 */
171 public void set(String name, Object value) {
172 m_properties.put(name, value);
173 }
174
175 /**
176 * Returns string version of specified parameter.
177 *
178 * @param name Name of parameter to get.
179 * @param defaultValue Default value to return if parameter not found
180 * or not a string.
181 *
182 * @return String value of specified parameter or the default vaule if not found.
183 */
184 public String getString(String name, String defaultValue) {
185 Object result = get(name);
186
187 if (result == null || !(result instanceof String)) {
188 return defaultValue;
189 }
190
191 return (String)result;
192 }
193 }