|
|||||||||||||||||||
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 | |||||||||||||||
NestedHTMLWriter.java | - | 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 java.io.CharArrayWriter;
|
|
18 |
import java.io.PrintWriter;
|
|
19 |
|
|
20 |
import org.apache.tapestry.IMarkupWriter;
|
|
21 |
|
|
22 |
/**
|
|
23 |
* Subclass of {@link HTMLWriter} that is nested. A nested writer
|
|
24 |
* buffers its output, then inserts it into its parent writer when it is
|
|
25 |
* closed.
|
|
26 |
*
|
|
27 |
* @author Howard Ship
|
|
28 |
*/
|
|
29 |
|
|
30 |
public class NestedHTMLWriter extends HTMLWriter |
|
31 |
{ |
|
32 |
private IMarkupWriter _parent;
|
|
33 |
private CharArrayWriter _internalBuffer;
|
|
34 |
|
|
35 | 280 |
public NestedHTMLWriter(IMarkupWriter parent)
|
36 |
{ |
|
37 | 280 |
super(parent.getContentType());
|
38 |
|
|
39 | 280 |
_parent = parent; |
40 |
|
|
41 | 280 |
_internalBuffer = new CharArrayWriter();
|
42 |
|
|
43 | 280 |
setWriter(new PrintWriter(_internalBuffer));
|
44 |
} |
|
45 |
|
|
46 |
/**
|
|
47 |
* Invokes the {@link HTMLWriter#close() super-class
|
|
48 |
* implementation}, then gets the data accumulated in the
|
|
49 |
* internal buffer and provides it to the containing writer using
|
|
50 |
* {@link IMarkupWriter#printRaw(char[], int, int)}.
|
|
51 |
*
|
|
52 |
*/
|
|
53 |
|
|
54 | 263 |
public void close() |
55 |
{ |
|
56 | 263 |
super.close();
|
57 |
|
|
58 | 263 |
char[] data = _internalBuffer.toCharArray();
|
59 |
|
|
60 | 263 |
_parent.printRaw(data, 0, data.length); |
61 |
|
|
62 | 263 |
_internalBuffer = null;
|
63 | 263 |
_parent = null;
|
64 |
} |
|
65 |
} |
|