Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
DefaultAttribute |
|
| 1.5714285714285714;1.571 |
1 | // Copyright 2004, 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 | package org.apache.tapestry.markup; |
|
15 | ||
16 | import java.io.PrintWriter; |
|
17 | ||
18 | ||
19 | /** |
|
20 | * Used to hold markup attribute data for writing in a specific format. |
|
21 | * |
|
22 | * @author jkuhnert |
|
23 | */ |
|
24 | public class DefaultAttribute implements Attribute |
|
25 | { |
|
26 | protected String _value; |
|
27 | protected boolean _raw; |
|
28 | ||
29 | public DefaultAttribute(String value, boolean raw) |
|
30 | 196 | { |
31 | 196 | _value = value; |
32 | 196 | _raw = raw; |
33 | 196 | } |
34 | ||
35 | public Object getValue() |
|
36 | { |
|
37 | 0 | return _value; |
38 | } |
|
39 | ||
40 | void append(Object value) |
|
41 | { |
|
42 | 2 | if (value == null) |
43 | 1 | return; |
44 | ||
45 | 1 | _value += " " + value; |
46 | 1 | } |
47 | ||
48 | void setRaw(boolean raw) |
|
49 | { |
|
50 | 0 | _raw = raw; |
51 | 0 | } |
52 | ||
53 | public boolean isRaw() |
|
54 | { |
|
55 | 0 | return _raw; |
56 | } |
|
57 | ||
58 | void print(String name, PrintWriter writer, MarkupFilter filter) |
|
59 | { |
|
60 | 191 | writer.print(' '); |
61 | 191 | writer.print(name); |
62 | 191 | writer.print("=\""); |
63 | ||
64 | 191 | if (_raw && _value != null) { |
65 | ||
66 | 1 | writer.write(_value); |
67 | ||
68 | 190 | } else if (_value != null) { |
69 | ||
70 | 184 | char[] data = _value.toCharArray(); |
71 | 184 | filter.print(writer, data, 0, data.length, true); |
72 | } |
|
73 | ||
74 | 191 | writer.print('"'); |
75 | 191 | } |
76 | ||
77 | public String toString() |
|
78 | { |
|
79 | 3 | return _value; |
80 | } |
|
81 | } |