Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 116 |  | Methods: | 9
| NCLOC: | 73 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
ValueTagWriter.java | 66.7% | 89.2% | 100% | 86.2% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     /*
6 |  |
      * Created on 2004/01/04
7 |  |
      */
8 |  |
     package org.asyrinx.brownie.tapestry.util;
9 |  |
10 |  |
     import java.util.HashMap;
11 |  |
     import java.util.Iterator;
12 |  |
     import java.util.Map;
13 |  |
14 |  |
     import org.apache.commons.lang.StringUtils;
15 |  |
     import org.apache.tapestry.IMarkupWriter;
16 |  |
17 |  |
     /**
18 |  |
      * @author akima
19 |  |
      */
20 |  |
     public class ValueTagWriter {
21 |  |
22 |  |
         /**
23 |  |
          *
24 |  |
          */
25 | 2 |
         public ValueTagWriter(IMarkupWriter writer) {
26 | 2 |
             this(writer, "span", new HashMap());
27 |  |
         }
28 |  |
29 |  |
         /**
30 |  |
          *
31 |  |
          */
32 | 7 |
         public ValueTagWriter(IMarkupWriter writer, String tagName,
33 |  |
                 Map extraAttributes) {
34 | 7 |
             super();
35 | 7 |
             this.writer = writer;
36 | 7 |
             this.extraAttributes = extraAttributes;
37 | 7 |
             setTagName(tagName);
38 |  |
         }
39 |  |
40 |  |
         private String tagName = "span";
41 |  |
42 |  |
         private final Map extraAttributes;
43 |  |
44 |  |
         protected final IMarkupWriter writer;
45 |  |
46 | 5 |
         protected void attributes(Map attibutes) {
47 | 5 |
             if (attibutes == null)
48 | 0 |
                 return;
49 | 5 |
             final Iterator iterator = attibutes.keySet().iterator();
50 | 5 |
             while (iterator.hasNext()) {
51 | 0 |
                 final String element = String.valueOf(iterator.next());
52 | 0 |
                 writer.attribute(element, String.valueOf(extraAttributes
53 |  |
                         .get(element)));
54 |  |
             }
55 |  |
         }
56 |  |
57 | 5 |
         public void addProperty(String id, String value) {
58 | 5 |
             if (StringUtils.isEmpty(value))
59 | 0 |
                 return;
60 | 5 |
             writer.begin(getTagName());
61 | 5 |
             writer.attribute("id", id);
62 | 5 |
             attributes(getExtraAttributes());
63 | 5 |
             final IMarkupWriter innerDivWriter = writer.getNestedWriter();
64 | 5 |
             innerDivWriter.printRaw(value);
65 | 5 |
             innerDivWriter.close();
66 | 5 |
             writer.end();
67 |  |
             //writer.println();
68 |  |
         }
69 |  |
70 | 6 |
         public void addProperties(Map properties) {
71 | 6 |
             final Iterator iterator = properties.keySet().iterator();
72 | 6 |
             while (iterator.hasNext()) {
73 | 9 |
                 final String element = String.valueOf(iterator.next());
74 | 9 |
                 final Object value = properties.get(element);
75 | 9 |
                 if (value instanceof Map) {
76 | 5 |
                     final ValueTagWriter nestedWriter = new ValueTagWriter(
77 |  |
                             this.writer.getNestedWriter(), getTagName(),
78 |  |
                             getExtraAttributes());
79 | 5 |
                     writer.begin(getTagName());
80 | 5 |
                     writer.attribute("id", element);
81 | 5 |
                     nestedWriter.addProperties((Map) value);
82 | 5 |
                     nestedWriter.close();
83 | 5 |
                     writer.end();
84 |  |
                 } else {
85 | 4 |
                     if (value != null)
86 | 4 |
                         addProperty(element, String.valueOf(value));
87 |  |
                 }
88 |  |
             }
89 |  |
         }
90 |  |
91 | 5 |
         public void close() {
92 | 5 |
             this.writer.close();
93 |  |
         }
94 |  |
95 |  |
         /**
96 |  |
          * @return
97 |  |
          */
98 | 10 |
         public Map getExtraAttributes() {
99 | 10 |
             return extraAttributes;
100 |  |
         }
101 |  |
102 |  |
         /**
103 |  |
          * @return
104 |  |
          */
105 | 15 |
         public String getTagName() {
106 | 15 |
             return tagName;
107 |  |
         }
108 |  |
109 |  |
         /**
110 |  |
          * @param string
111 |  |
          */
112 | 7 |
         public void setTagName(String string) {
113 | 7 |
             tagName = string;
114 |  |
         }
115 |  |
116 |  |
     }