Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
RenderString |
|
| 1.3333333333333333;1.333 |
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 | ||
15 | package org.apache.tapestry.valid; |
|
16 | ||
17 | import java.io.Serializable; |
|
18 | ||
19 | import org.apache.tapestry.IMarkupWriter; |
|
20 | import org.apache.tapestry.IRender; |
|
21 | import org.apache.tapestry.IRequestCycle; |
|
22 | ||
23 | /** |
|
24 | * A wrapper around {@link String} that allows the String to be renderred. |
|
25 | * This is primarily used to present error messages. |
|
26 | * |
|
27 | * @author Howard Lewis Ship |
|
28 | */ |
|
29 | ||
30 | public class RenderString implements IRender, Serializable |
|
31 | { |
|
32 | ||
33 | private static final long serialVersionUID = 6215074338439140780L; |
|
34 | ||
35 | private String _string; |
|
36 | ||
37 | 12 | private boolean _raw = false; |
38 | ||
39 | public RenderString(String string) |
|
40 | 12 | { |
41 | 12 | _string = string; |
42 | 12 | } |
43 | ||
44 | /** |
|
45 | * @param string |
|
46 | * the string to render |
|
47 | * @param raw |
|
48 | * if true, the String is rendered as-is, with no filtering. If |
|
49 | * false (the default), the String is filtered. |
|
50 | */ |
|
51 | ||
52 | public RenderString(String string, boolean raw) |
|
53 | 0 | { |
54 | 0 | _string = string; |
55 | 0 | _raw = raw; |
56 | 0 | } |
57 | ||
58 | /** |
|
59 | * Renders the String to the writer. Does nothing if the string is null. If |
|
60 | * raw is true, uses {@link IMarkupWriter#printRaw(String)}, otherwise |
|
61 | * {@link IMarkupWriter#print(String)}. |
|
62 | */ |
|
63 | ||
64 | public void render(IMarkupWriter writer, IRequestCycle cycle) |
|
65 | { |
|
66 | 0 | if (_string == null) return; |
67 | ||
68 | 0 | writer.print(_string, _raw); |
69 | 0 | } |
70 | ||
71 | public String getString() |
|
72 | { |
|
73 | 7 | return _string; |
74 | } |
|
75 | ||
76 | public boolean isRaw() |
|
77 | { |
|
78 | 0 | return _raw; |
79 | } |
|
80 | ||
81 | /** |
|
82 | * Returns the string that would be rendered. This is part of the contract |
|
83 | * for error renderers used with validation ... must provide a |
|
84 | * user-presentable toString() that does not include any markup. |
|
85 | */ |
|
86 | ||
87 | public String toString() |
|
88 | { |
|
89 | 2 | return _string; |
90 | } |
|
91 | } |