1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry; |
16 |
| |
17 |
| import java.util.ArrayList; |
18 |
| import java.util.List; |
19 |
| |
20 |
| import org.apache.hivemind.ApplicationRuntimeException; |
21 |
| import org.apache.hivemind.HiveMind; |
22 |
| import org.apache.hivemind.util.Defense; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| public class TapestryUtils |
31 |
| { |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
149
| public static void storeUniqueAttribute(IRequestCycle cycle, String key, Object object)
|
47 |
| { |
48 |
149
| Defense.notNull(cycle, "cycle");
|
49 |
149
| Defense.notNull(key, "key");
|
50 |
149
| Defense.notNull(object, "object");
|
51 |
| |
52 |
149
| Object existing = cycle.getAttribute(key);
|
53 |
149
| if (existing != null)
|
54 |
1
| throw new IllegalStateException(TapestryMessages.nonUniqueAttribute(
|
55 |
| object, |
56 |
| key, |
57 |
| existing)); |
58 |
| |
59 |
148
| cycle.setAttribute(key, object);
|
60 |
| } |
61 |
| |
62 |
| public static final String PAGE_RENDER_SUPPORT_ATTRIBUTE = "org.apache.tapestry.PageRenderSupport"; |
63 |
| |
64 |
| public static final String FORM_ATTRIBUTE = "org.apache.tapestry.Form"; |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
76
| public static void storePageRenderSupport(IRequestCycle cycle, PageRenderSupport support)
|
71 |
| { |
72 |
76
| storeUniqueAttribute(cycle, PAGE_RENDER_SUPPORT_ATTRIBUTE, support);
|
73 |
| } |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
71
| public static void storeForm(IRequestCycle cycle, IForm form)
|
80 |
| { |
81 |
71
| storeUniqueAttribute(cycle, FORM_ATTRIBUTE, form);
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
12
| public static PageRenderSupport getPageRenderSupport(IRequestCycle cycle, IComponent component)
|
96 |
| { |
97 |
12
| Defense.notNull(component, "component");
|
98 |
| |
99 |
12
| PageRenderSupport result = getOptionalPageRenderSupport(cycle);
|
100 |
12
| if (result == null)
|
101 |
2
| throw new ApplicationRuntimeException(TapestryMessages.noPageRenderSupport(component),
|
102 |
| component.getLocation(), null); |
103 |
| |
104 |
10
| return result;
|
105 |
| } |
106 |
| |
107 |
| |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
116
| public static IForm getForm(IRequestCycle cycle, IComponent component)
|
118 |
| { |
119 |
116
| Defense.notNull(cycle, "cycle");
|
120 |
116
| Defense.notNull(component, "component");
|
121 |
| |
122 |
116
| IForm result = (IForm) cycle.getAttribute(FORM_ATTRIBUTE);
|
123 |
| |
124 |
116
| if (result == null)
|
125 |
2
| throw new ApplicationRuntimeException(TapestryMessages.noForm(component), component
|
126 |
| .getLocation(), null); |
127 |
| |
128 |
114
| return result;
|
129 |
| } |
130 |
| |
131 |
77
| public static void removePageRenderSupport(IRequestCycle cycle)
|
132 |
| { |
133 |
77
| cycle.removeAttribute(PAGE_RENDER_SUPPORT_ATTRIBUTE);
|
134 |
| } |
135 |
| |
136 |
72
| public static void removeForm(IRequestCycle cycle)
|
137 |
| { |
138 |
72
| cycle.removeAttribute(FORM_ATTRIBUTE);
|
139 |
| } |
140 |
| |
141 |
| |
142 |
| |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
102
| public static PageRenderSupport getOptionalPageRenderSupport(IRequestCycle cycle)
|
149 |
| { |
150 |
102
| return (PageRenderSupport) cycle.getAttribute(PAGE_RENDER_SUPPORT_ATTRIBUTE);
|
151 |
| } |
152 |
| |
153 |
| |
154 |
| |
155 |
| |
156 |
| |
157 |
214
| public static String[] split(String input)
|
158 |
| { |
159 |
214
| return split(input, ',');
|
160 |
| } |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
268
| public static String[] split(String input, char delimiter)
|
167 |
| { |
168 |
268
| if (HiveMind.isBlank(input))
|
169 |
158
| return new String[0];
|
170 |
| |
171 |
110
| List strings = new ArrayList();
|
172 |
| |
173 |
110
| char[] buffer = input.toCharArray();
|
174 |
| |
175 |
110
| int start = 0;
|
176 |
110
| int length = 0;
|
177 |
| |
178 |
110
| for (int i = 0; i < buffer.length; i++)
|
179 |
| { |
180 |
849
| if (buffer[i] != delimiter)
|
181 |
| { |
182 |
788
| length++;
|
183 |
788
| continue;
|
184 |
| } |
185 |
| |
186 |
| |
187 |
| |
188 |
| |
189 |
61
| String token = new String(buffer, start, length);
|
190 |
61
| strings.add(token);
|
191 |
| |
192 |
61
| start = i + 1;
|
193 |
61
| length = 0;
|
194 |
| } |
195 |
| |
196 |
| |
197 |
| |
198 |
| |
199 |
110
| if (start == 0 && length == buffer.length)
|
200 |
| { |
201 |
80
| return new String[]
|
202 |
| { input }; |
203 |
| } |
204 |
| |
205 |
| |
206 |
30
| String token = new String(buffer, start, length);
|
207 |
30
| strings.add(token);
|
208 |
| |
209 |
30
| return (String[]) strings.toArray(new String[strings.size()]);
|
210 |
| } |
211 |
| } |