Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
InsertTextMode |
|
| 1.1428571428571428;1.143 | ||||
InsertTextMode$1 |
|
| 1.1428571428571428;1.143 | ||||
InsertTextMode$BreakMode |
|
| 1.1428571428571428;1.143 | ||||
InsertTextMode$ParagraphMode |
|
| 1.1428571428571428;1.143 |
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.html; | |
16 | ||
17 | import org.apache.tapestry.IMarkupWriter; | |
18 | ||
19 | /** | |
20 | * Defines a number of ways to format multi-line text for proper renderring. | |
21 | * | |
22 | * @author Howard Lewis Ship | |
23 | */ | |
24 | ||
25 | public abstract class InsertTextMode | |
26 | { | |
27 | ||
28 | /** | |
29 | * Mode where each line (after the first) is preceded by a <br> tag. | |
30 | */ | |
31 | ||
32 | 0 | public static final InsertTextMode BREAK = new BreakMode(); |
33 | ||
34 | /** | |
35 | * Mode where each line is wrapped with a <p> element. | |
36 | */ | |
37 | ||
38 | 0 | public static final InsertTextMode PARAGRAPH = new ParagraphMode(); |
39 | ||
40 | private final String _name; | |
41 | ||
42 | protected InsertTextMode(String name) | |
43 | 0 | { |
44 | 0 | _name = name; |
45 | 0 | } |
46 | ||
47 | public String toString() | |
48 | { | |
49 | 0 | return "InsertTextMode[" + _name + "]"; |
50 | } | |
51 | ||
52 | /** | |
53 | * Invoked by the {@link InsertText} component to write the next line. | |
54 | * | |
55 | * @param lineNumber | |
56 | * the line number of the line, starting with 0 for the first | |
57 | * line. | |
58 | * @param line | |
59 | * the String for the current line. | |
60 | * @param writer | |
61 | * the {@link IMarkupWriter} to send output to. | |
62 | * @param raw | |
63 | * if true, then the output should be unfiltered | |
64 | */ | |
65 | ||
66 | public abstract void writeLine(int lineNumber, String line, | |
67 | IMarkupWriter writer, boolean raw); | |
68 | ||
69 | /** | |
70 | * | |
71 | * @author hls | |
72 | */ | |
73 | 0 | private static final class BreakMode extends InsertTextMode |
74 | { | |
75 | ||
76 | private BreakMode() | |
77 | { | |
78 | 0 | super("BREAK"); |
79 | 0 | } |
80 | ||
81 | public void writeLine(int lineNumber, String line, | |
82 | IMarkupWriter writer, boolean raw) | |
83 | { | |
84 | 0 | if (lineNumber > 0) writer.beginEmpty("br"); |
85 | ||
86 | 0 | writer.print(line, raw); |
87 | 0 | } |
88 | } | |
89 | ||
90 | /** | |
91 | * | |
92 | * @author hls | |
93 | */ | |
94 | 0 | private static final class ParagraphMode extends InsertTextMode |
95 | { | |
96 | ||
97 | private ParagraphMode() | |
98 | { | |
99 | 0 | super("PARAGRAPH"); |
100 | 0 | } |
101 | ||
102 | public void writeLine(int lineNumber, String line, | |
103 | IMarkupWriter writer, boolean raw) | |
104 | { | |
105 | 0 | writer.begin("p"); |
106 | ||
107 | 0 | writer.print(line, raw); |
108 | ||
109 | 0 | writer.end(); |
110 | 0 | } |
111 | } | |
112 | ||
113 | } |