001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.describe; 016 017 import org.apache.tapestry.IMarkupWriter; 018 import org.apache.tapestry.IRequestCycle; 019 020 /** 021 * Renders an object array as an unordered list; each element is recursively rendered. 022 * 023 * @author Howard M. Lewis Ship 024 * @since 4.0 025 */ 026 public class ObjectArrayRenderStrategy implements RenderStrategy 027 { 028 private RenderStrategy _renderStrategy; 029 030 public void renderObject(Object object, IMarkupWriter writer, IRequestCycle cycle) 031 { 032 Object[] array = (Object[]) object; 033 034 if (array.length == 0) 035 { 036 writer.begin("em"); 037 writer.print("empty list"); 038 writer.end(); 039 return; 040 } 041 042 writer.begin("ul"); 043 044 for (int i = 0; i < array.length; i++) 045 { 046 writer.begin("li"); 047 048 Object item = array[i]; 049 050 if (item == null) 051 { 052 writer.begin("em"); 053 writer.print("<NULL>"); 054 writer.end(); 055 } 056 else 057 _renderStrategy.renderObject(item, writer, cycle); 058 059 writer.end(); 060 061 } 062 063 writer.end(); 064 } 065 066 public void setRenderStrategy(RenderStrategy renderStrategy) 067 { 068 _renderStrategy = renderStrategy; 069 } 070 071 }