|
|||||||||||||||||||
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 | |||||||||||||||
HTMLWriter.java | - | 57.1% | 57.1% | 57.1% |
|
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 java.io.OutputStream;
|
|
18 |
import java.io.PrintWriter;
|
|
19 |
|
|
20 |
import org.apache.tapestry.AbstractMarkupWriter;
|
|
21 |
import org.apache.tapestry.IMarkupWriter;
|
|
22 |
import org.apache.tapestry.util.text.DefaultCharacterTranslatorSource;
|
|
23 |
import org.apache.tapestry.util.text.ICharacterTranslatorSource;
|
|
24 |
|
|
25 |
/**
|
|
26 |
* This class is used to create HTML output.
|
|
27 |
*
|
|
28 |
* <p>The <code>HTMLWriter</code> handles the necessary escaping
|
|
29 |
* of invalid characters.
|
|
30 |
* Specifically, the '<', '>' and '&' characters are properly
|
|
31 |
* converted to their HTML entities by the <code>print()</code> methods.
|
|
32 |
* Similar measures are taken by the {@link #attribute(String, String)} method.
|
|
33 |
* Other invalid characters are converted to their numeric entity equivalent.
|
|
34 |
*
|
|
35 |
* @author Howard Lewis Ship
|
|
36 |
**/
|
|
37 |
|
|
38 |
public class HTMLWriter extends AbstractMarkupWriter |
|
39 |
{ |
|
40 |
private static final ICharacterTranslatorSource TRANSLATOR_SOURCE = |
|
41 |
new DefaultCharacterTranslatorSource();
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Creates a new markup writer around the {@link PrintWriter}.
|
|
45 |
* The writer will not be closed when the markup writer closes.
|
|
46 |
* The content type is currently hard-wired to
|
|
47 |
* <code>text/html</code>.
|
|
48 |
*
|
|
49 |
* @since 3.0
|
|
50 |
*
|
|
51 |
**/
|
|
52 |
|
|
53 | 0 |
public HTMLWriter(PrintWriter writer)
|
54 |
{ |
|
55 | 0 |
super(TRANSLATOR_SOURCE, "text/html", writer); |
56 |
} |
|
57 |
|
|
58 | 0 |
public HTMLWriter(String contentType, OutputStream outputStream)
|
59 |
{ |
|
60 | 0 |
super(TRANSLATOR_SOURCE, contentType, outputStream);
|
61 |
} |
|
62 |
|
|
63 | 175 |
public HTMLWriter(String contentType, String encoding, OutputStream outputStream)
|
64 |
{ |
|
65 | 175 |
super(TRANSLATOR_SOURCE, contentType, encoding, outputStream);
|
66 |
} |
|
67 |
|
|
68 | 280 |
protected HTMLWriter(String contentType)
|
69 |
{ |
|
70 | 280 |
super(TRANSLATOR_SOURCE, contentType);
|
71 |
} |
|
72 |
|
|
73 |
/**
|
|
74 |
* Creates a default writer for content type "text/html; charset=utf-8".
|
|
75 |
*
|
|
76 |
**/
|
|
77 |
|
|
78 | 0 |
public HTMLWriter(OutputStream outputStream)
|
79 |
{ |
|
80 | 0 |
this(outputStream, "UTF-8"); |
81 |
} |
|
82 |
|
|
83 | 175 |
public HTMLWriter(OutputStream outputStream, String encoding)
|
84 |
{ |
|
85 | 175 |
this("text/html", encoding, outputStream); |
86 |
} |
|
87 |
|
|
88 | 280 |
public IMarkupWriter getNestedWriter()
|
89 |
{ |
|
90 | 280 |
return new NestedHTMLWriter(this); |
91 |
} |
|
92 |
} |
|