|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
RenderString.java | 0% | 22.2% | 33.3% | 23.5% |
|
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. This is primarily | |
25 | * used to present error messages. | |
26 | * | |
27 | * @author Howard Lewis Ship | |
28 | */ | |
29 | ||
30 | public class RenderString implements IRender, Serializable | |
31 | { | |
32 | private static final long serialVersionUID = 6215074338439140780L; | |
33 | ||
34 | private String _string; | |
35 | ||
36 | private boolean _raw = false; | |
37 | ||
38 | 10 | public RenderString(String string) |
39 | { | |
40 | 10 | _string = string; |
41 | } | |
42 | ||
43 | /** | |
44 | * @param string | |
45 | * the string to render | |
46 | * @param raw | |
47 | * if true, the String is rendered as-is, with no filtering. If false (the default), | |
48 | * the String is filtered. | |
49 | */ | |
50 | ||
51 | 0 | public RenderString(String string, boolean raw) |
52 | { | |
53 | 0 | _string = string; |
54 | 0 | _raw = raw; |
55 | } | |
56 | ||
57 | /** | |
58 | * Renders the String to the writer. Does nothing if the string is null. If raw is true, uses | |
59 | * {@link IMarkupWriter#printRaw(String)}, otherwise {@link IMarkupWriter#print(String)}. | |
60 | */ | |
61 | ||
62 | 0 | public void render(IMarkupWriter writer, IRequestCycle cycle) |
63 | { | |
64 | 0 | if (_string == null) |
65 | 0 | return; |
66 | ||
67 | 0 | writer.print(_string, _raw); |
68 | } | |
69 | ||
70 | 7 | public String getString() |
71 | { | |
72 | 7 | return _string; |
73 | } | |
74 | ||
75 | 0 | public boolean isRaw() |
76 | { | |
77 | 0 | return _raw; |
78 | } | |
79 | ||
80 | /** | |
81 | * Returns the string that would be rendered. This is part of the contract for error renderers | |
82 | * used with validation ... must provide a user-presentable toString() that does not include any | |
83 | * markup. | |
84 | */ | |
85 | ||
86 | 0 | public String toString() |
87 | { | |
88 | 0 | return _string; |
89 | } | |
90 | } |
|