View Javadoc

1   package org.weda.tapestry.renderer.impl;
2   
3   import org.apache.hivemind.ApplicationRuntimeException;
4   import org.apache.tapestry.IMarkupWriter;
5   import org.apache.tapestry.IRequestCycle;
6   import org.weda.property.PropertyDescriptor;
7   import org.weda.converter.ValueTypeConverter;
8   import org.weda.converter.ValueTypeConverterException;
9   
10  /**
11   *
12   * @author Mikhail Titov
13   */
14  public class InplaceRenderer extends AbstractRenderer {
15      public void render(
16              IMarkupWriter writer, IRequestCycle cycle
17              , PropertyDescriptor propertyDescriptor
18              , ValueTypeConverter converter, Object value, Object dataId) 
19      {
20          try{
21              writer.begin("p");
22              String style = getStyle(value);
23              if (style!=null)
24                  writer.attribute("style", style);
25              if (   value == null 
26                  || !Number.class.isAssignableFrom(
27                          propertyDescriptor.getPropertyClass()))
28              {
29                  renderContent(
30                      writer
31                      , value==null?" ":
32                          (String)converter.convert(
33                              String.class, value
34                              , propertyDescriptor.getPattern()));
35              }else{
36                  writer.attribute("align", "right");
37                  renderContent(
38                      writer
39                      , (String)converter.convert(
40                              String.class, value
41                              , propertyDescriptor.getPattern()));
42              }
43              writer.end();
44          }catch(ValueTypeConverterException e){
45              throw new ApplicationRuntimeException(e);
46          }
47      }
48      
49      protected void renderContent(IMarkupWriter writer, String content){
50          writer.print(content);
51      }
52      
53      protected String getStyle(Object value){
54          return null;
55      }
56  }