|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InsertTextMode.java | 100% | 100% | 100% | 100% |
|
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.commons.lang.enum.Enum;
|
|
18 |
import org.apache.tapestry.IMarkupWriter;
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Defines a number of ways to format multi-line text for proper
|
|
22 |
* renderring.
|
|
23 |
*
|
|
24 |
* @author Howard Lewis Ship
|
|
25 |
*
|
|
26 |
**/
|
|
27 |
|
|
28 |
public abstract class InsertTextMode extends Enum |
|
29 |
{ |
|
30 |
/**
|
|
31 |
* Mode where each line (after the first) is preceded by a <br> tag.
|
|
32 |
*
|
|
33 |
**/
|
|
34 |
|
|
35 |
public static final InsertTextMode BREAK = new BreakMode(); |
|
36 |
|
|
37 |
/**
|
|
38 |
* Mode where each line is wrapped with a <p> element.
|
|
39 |
*
|
|
40 |
**/
|
|
41 |
|
|
42 |
public static final InsertTextMode PARAGRAPH = new ParagraphMode(); |
|
43 |
|
|
44 | 2 |
protected InsertTextMode(String name)
|
45 |
{ |
|
46 | 2 |
super(name);
|
47 |
} |
|
48 |
|
|
49 |
/**
|
|
50 |
* Invoked by the {@link InsertText} component to write the next line.
|
|
51 |
*
|
|
52 |
* @param lineNumber the line number of the line, starting with 0 for the first line.
|
|
53 |
* @param line the String for the current line.
|
|
54 |
* @param writer the {@link IMarkupWriter} to send output to.
|
|
55 |
**/
|
|
56 |
|
|
57 |
public abstract void writeLine( |
|
58 |
int lineNumber,
|
|
59 |
String line, |
|
60 |
IMarkupWriter writer); |
|
61 |
|
|
62 |
private static class BreakMode extends InsertTextMode |
|
63 |
{ |
|
64 | 1 |
private BreakMode()
|
65 |
{ |
|
66 | 1 |
super("BREAK"); |
67 |
} |
|
68 |
|
|
69 | 4 |
public void writeLine(int lineNumber, String line, IMarkupWriter writer) |
70 |
{ |
|
71 | 4 |
if (lineNumber > 0)
|
72 | 2 |
writer.beginEmpty("br");
|
73 |
|
|
74 | 4 |
writer.print(line); |
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
private static class ParagraphMode extends InsertTextMode |
|
79 |
{ |
|
80 | 1 |
private ParagraphMode()
|
81 |
{ |
|
82 | 1 |
super("PARAGRAPH"); |
83 |
} |
|
84 |
|
|
85 | 3 |
public void writeLine(int lineNumber, String line, IMarkupWriter writer) |
86 |
{ |
|
87 | 3 |
writer.begin("p");
|
88 |
|
|
89 | 3 |
writer.print(line); |
90 |
|
|
91 | 3 |
writer.end(); |
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
} |
|