View Javadoc

1   package net.sf.tacos.markup;
2   
3   import org.apache.tapestry.IMarkupWriter;
4   import org.apache.tapestry.NestedMarkupWriter;
5   import org.apache.tapestry.markup.Attribute;
6   
7   /**
8    * Decorates an existing {@link IMarkupWriter} in order to add
9    * a few shortcut methods.
10   * 
11   * @see #create(String, String...)
12   * @see #createEmpty(String, String...)
13   */
14  public class ExtendedMarkupWriterImpl implements IExtendedMarkupWriter {
15      private IMarkupWriter writer;
16  
17      public ExtendedMarkupWriterImpl(IMarkupWriter writer) {
18          this.writer = writer;
19      }
20  
21      /**
22       * {@inheritDoc}
23       */
24      public IExtendedMarkupWriter createEmpty(String tag, String... attributes) {
25          writer.beginEmpty(tag);
26          writeAttributesAndValues(attributes);
27          return this;
28      }
29  
30      /**
31       * {@inheritDoc}
32       */    
33      public IExtendedMarkupWriter create(String tag, String... attributes) {
34          writer.begin(tag);
35          writeAttributesAndValues(attributes);
36          return this;
37      }
38  
39      private void writeAttributesAndValues(String... attributes) {
40          for (int i=0; i<attributes.length; i+=2) {
41              writer.attribute(attributes[i], attributes[i+1]);
42          }
43      }
44  
45      public void attribute(String name, int value) {
46          writer.attribute(name, value);
47      }
48  
49      public void attribute(String name, boolean value) {
50          writer.attribute(name, value);
51      }
52  
53      public void attribute(String name, String value) {
54          writer.attribute(name, value);
55      }
56  
57      public void attributeRaw(String name, String value) {
58          writer.attributeRaw(name, value);
59      }
60  
61      public void appendAttribute(String name, int value) {
62          writer.appendAttribute(name, value);
63      }
64  
65      public void appendAttribute(String name, boolean value) {
66          writer.appendAttribute(name, value);
67      }
68  
69      public void appendAttribute(String name, String value) {
70          writer.appendAttribute(name, value);
71      }
72  
73      public void appendAttributeRaw(String name, String value) {
74          writer.appendAttributeRaw(name, value);
75      }
76  
77      public boolean hasAttribute(String name) {
78          return writer.hasAttribute(name);
79      }
80  
81      public Attribute getAttribute(String name) {
82          return writer.getAttribute(name);
83      }
84  
85      public Attribute removeAttribute(String name) {
86          return writer.removeAttribute(name);
87      }
88  
89      public void clearAttributes() {
90          writer.clearAttributes();
91      }
92  
93      public void begin(String name) {
94          writer.begin(name);
95      }
96  
97      public void beginEmpty(String name) {
98          writer.beginEmpty(name);
99      }
100 
101     public boolean checkError() {
102         return writer.checkError();
103     }
104 
105     public void close() {
106         writer.close();
107     }
108 
109     public void closeTag() {
110         writer.closeTag();
111     }
112 
113     public void comment(String value) {
114         writer.comment(value);
115     }
116 
117     public void end() {
118         writer.end();
119     }
120 
121     public void end(String name) {
122         writer.end(name);
123     }
124 
125     public void flush() {
126         writer.flush();
127     }
128 
129     public NestedMarkupWriter getNestedWriter() {
130         return writer.getNestedWriter();
131     }
132 
133     public void print(char[] data, int offset, int length) {
134         writer.print(data, offset, length);
135     }
136 
137     public void print(char[] data, int offset, int length, boolean raw) {
138         writer.print(data, offset, length, raw);
139     }
140 
141     public void print(char value) {
142         writer.print(value);
143     }
144 
145     public void print(int value) {
146         writer.print(value);
147     }
148 
149     public void print(String value) {
150         writer.print(value);
151     }
152 
153     public void print(String value, boolean raw) {
154         writer.print(value, raw);
155     }
156 
157     public void println() {
158         writer.println();
159     }
160 
161     public void printRaw(char[] buffer, int offset, int length) {
162         writer.printRaw(buffer, offset, length);
163     }
164 
165     public void printRaw(String value) {
166         writer.printRaw(value);
167     }
168 
169     public String getContentType() {
170         return writer.getContentType();
171     }
172 }
173