Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ObjectArrayRenderStrategy |
|
| 3.0;3 |
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | package org.apache.tapestry.describe; | |
16 | ||
17 | import org.apache.tapestry.IMarkupWriter; | |
18 | import org.apache.tapestry.IRequestCycle; | |
19 | ||
20 | /** | |
21 | * Renders an object array as an unordered list; each element is recursively rendered. | |
22 | * | |
23 | * @author Howard M. Lewis Ship | |
24 | * @since 4.0 | |
25 | */ | |
26 | 0 | public class ObjectArrayRenderStrategy implements RenderStrategy |
27 | { | |
28 | private RenderStrategy _renderStrategy; | |
29 | ||
30 | public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle) | |
31 | { | |
32 | 0 | Object[] array = (Object[]) object; |
33 | ||
34 | 0 | if (array.length == 0) |
35 | { | |
36 | 0 | writer.begin("em"); |
37 | 0 | writer.print("empty list"); |
38 | 0 | writer.end(); |
39 | 0 | return; |
40 | } | |
41 | ||
42 | 0 | writer.begin("ul"); |
43 | ||
44 | 0 | for (int i = 0; i < array.length; i++) |
45 | { | |
46 | 0 | writer.begin("li"); |
47 | ||
48 | 0 | Object item = array[i]; |
49 | ||
50 | 0 | if (item == null) |
51 | { | |
52 | 0 | writer.begin("em"); |
53 | 0 | writer.print("<NULL>"); |
54 | 0 | writer.end(); |
55 | } | |
56 | else | |
57 | 0 | _renderStrategy.renderObject(item, writer, cycle); |
58 | ||
59 | 0 | writer.end(); |
60 | ||
61 | } | |
62 | ||
63 | 0 | writer.end(); |
64 | 0 | } |
65 | ||
66 | public void setRenderStrategy(RenderStrategy renderStrategy) | |
67 | { | |
68 | 0 | _renderStrategy = renderStrategy; |
69 | 0 | } |
70 | ||
71 | } |