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 |
148
| public static void storeUniqueAttribute(IRequestCycle cycle, String key, Object object)
|
47 |
| { |
48 |
148
| Defense.notNull(cycle, "cycle");
|
49 |
148
| Defense.notNull(key, "key");
|
50 |
148
| Defense.notNull(object, "object");
|
51 |
| |
52 |
148
| Object existing = cycle.getAttribute(key);
|
53 |
148
| if (existing != null)
|
54 |
1
| throw new IllegalStateException(TapestryMessages.nonUniqueAttribute(
|
55 |
| object, |
56 |
| key, |
57 |
| existing)); |
58 |
| |
59 |
147
| 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 |
70
| public static void storeForm(IRequestCycle cycle, IForm form)
|
80 |
| { |
81 |
70
| storeUniqueAttribute(cycle, FORM_ATTRIBUTE, form);
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
| |
95 |
15
| public static PageRenderSupport getPageRenderSupport(IRequestCycle cycle, IComponent component)
|
96 |
| { |
97 |
15
| Defense.notNull(cycle, "cycle");
|
98 |
15
| Defense.notNull(component, "component");
|
99 |
| |
100 |
15
| PageRenderSupport result = (PageRenderSupport) cycle
|
101 |
| .getAttribute(PAGE_RENDER_SUPPORT_ATTRIBUTE); |
102 |
| |
103 |
15
| if (result == null)
|
104 |
2
| throw new ApplicationRuntimeException(TapestryMessages.noPageRenderSupport(component),
|
105 |
| component.getLocation(), null); |
106 |
| |
107 |
13
| return result;
|
108 |
| } |
109 |
| |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| |
118 |
| |
119 |
| |
120 |
117
| public static IForm getForm(IRequestCycle cycle, IComponent component)
|
121 |
| { |
122 |
117
| Defense.notNull(cycle, "cycle");
|
123 |
117
| Defense.notNull(component, "component");
|
124 |
| |
125 |
117
| IForm result = (IForm) cycle.getAttribute(FORM_ATTRIBUTE);
|
126 |
| |
127 |
117
| if (result == null)
|
128 |
2
| throw new ApplicationRuntimeException(TapestryMessages.noForm(component), component
|
129 |
| .getLocation(), null); |
130 |
| |
131 |
115
| return result;
|
132 |
| } |
133 |
| |
134 |
77
| public static void removePageRenderSupport(IRequestCycle cycle)
|
135 |
| { |
136 |
77
| cycle.removeAttribute(PAGE_RENDER_SUPPORT_ATTRIBUTE);
|
137 |
| } |
138 |
| |
139 |
71
| public static void removeForm(IRequestCycle cycle)
|
140 |
| { |
141 |
71
| cycle.removeAttribute(FORM_ATTRIBUTE);
|
142 |
| } |
143 |
| |
144 |
| |
145 |
| |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
| |
151 |
51
| public static PageRenderSupport getOptionalPageRenderSupport(IRequestCycle cycle)
|
152 |
| { |
153 |
51
| return (PageRenderSupport) cycle.getAttribute(PAGE_RENDER_SUPPORT_ATTRIBUTE);
|
154 |
| } |
155 |
| |
156 |
| |
157 |
| |
158 |
| |
159 |
| |
160 |
131
| public static String[] split(String input)
|
161 |
| { |
162 |
131
| return split(input, ',');
|
163 |
| } |
164 |
| |
165 |
| |
166 |
| |
167 |
| |
168 |
| |
169 |
184
| public static String[] split(String input, char delimiter)
|
170 |
| { |
171 |
184
| if (HiveMind.isBlank(input))
|
172 |
75
| return new String[0];
|
173 |
| |
174 |
109
| List strings = new ArrayList();
|
175 |
| |
176 |
109
| char[] buffer = input.toCharArray();
|
177 |
| |
178 |
109
| int start = 0;
|
179 |
109
| int length = 0;
|
180 |
| |
181 |
109
| for (int i = 0; i < buffer.length; i++)
|
182 |
| { |
183 |
847
| if (buffer[i] != delimiter)
|
184 |
| { |
185 |
786
| length++;
|
186 |
786
| continue;
|
187 |
| } |
188 |
| |
189 |
| |
190 |
| |
191 |
| |
192 |
61
| String token = new String(buffer, start, length);
|
193 |
61
| strings.add(token);
|
194 |
| |
195 |
61
| start = i + 1;
|
196 |
61
| length = 0;
|
197 |
| } |
198 |
| |
199 |
| |
200 |
| |
201 |
| |
202 |
109
| if (start == 0 && length == buffer.length)
|
203 |
| { |
204 |
79
| return new String[]
|
205 |
| { input }; |
206 |
| } |
207 |
| |
208 |
| |
209 |
30
| String token = new String(buffer, start, length);
|
210 |
30
| strings.add(token);
|
211 |
| |
212 |
30
| return (String[]) strings.toArray(new String[strings.size()]);
|
213 |
| } |
214 |
| } |