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