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 | 3 | public class ObjectArrayRenderStrategy implements RenderStrategy |
27 | { |
|
28 | private RenderStrategy _renderStrategy; |
|
29 | ||
30 | public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle) |
|
31 | { |
|
32 | 3 | Object[] array = (Object[]) object; |
33 | ||
34 | 3 | if (array.length == 0) |
35 | { |
|
36 | 1 | writer.begin("em"); |
37 | 1 | writer.print("empty list"); |
38 | 1 | writer.end(); |
39 | 1 | return; |
40 | } |
|
41 | ||
42 | 2 | writer.begin("ul"); |
43 | ||
44 | 5 | for (int i = 0; i < array.length; i++) |
45 | { |
|
46 | 3 | writer.begin("li"); |
47 | ||
48 | 3 | Object item = array[i]; |
49 | ||
50 | 3 | if (item == null) |
51 | { |
|
52 | 1 | writer.begin("em"); |
53 | 1 | writer.print("<NULL>"); |
54 | 1 | writer.end(); |
55 | } |
|
56 | else |
|
57 | 2 | _renderStrategy.renderObject(item, writer, cycle); |
58 | ||
59 | 3 | writer.end(); |
60 | ||
61 | } |
|
62 | ||
63 | 2 | writer.end(); |
64 | 2 | } |
65 | ||
66 | public void setRenderStrategy(RenderStrategy renderStrategy) |
|
67 | { |
|
68 | 1 | _renderStrategy = renderStrategy; |
69 | 1 | } |
70 | ||
71 | } |