|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NestedMarkupWriterImpl.java | 100% | 100% | 100% | 100% |
|
1 | // Copyright 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.markup; | |
16 | ||
17 | import java.io.CharArrayWriter; | |
18 | import java.io.PrintWriter; | |
19 | ||
20 | import org.apache.tapestry.IMarkupWriter; | |
21 | import org.apache.tapestry.NestedMarkupWriter; | |
22 | ||
23 | /** | |
24 | * Nested implementation of {@link org.apache.tapestry.IMarkupWriter}. Accumulates content in a | |
25 | * {@link java.io.CharArrayWriter}, and prints the buffered content (raw) on {@link #close()}. | |
26 | * | |
27 | * @author Howard M. Lewis Ship | |
28 | * @since 4.0 | |
29 | * @see org.apache.tapestry.IMarkupWriter#getNestedWriter() | |
30 | */ | |
31 | public class NestedMarkupWriterImpl extends MarkupWriterImpl implements NestedMarkupWriter | |
32 | { | |
33 | private final IMarkupWriter _parent; | |
34 | ||
35 | private final CharArrayWriter _charArrayWriter; | |
36 | ||
37 | private boolean _closed; | |
38 | ||
39 | 211 | public String getBuffer() |
40 | { | |
41 | 211 | return _charArrayWriter.toString(); |
42 | } | |
43 | ||
44 | 226 | public NestedMarkupWriterImpl(IMarkupWriter parent, MarkupFilter filter) |
45 | { | |
46 | // Need to do this awkward double constructor because we want | |
47 | // to create an object and pass it to the parent constructor. | |
48 | // Java language rules get in the way here. | |
49 | ||
50 | 226 | this(parent, new CharArrayWriter(), filter); |
51 | } | |
52 | ||
53 | 226 | private NestedMarkupWriterImpl(IMarkupWriter parent, CharArrayWriter writer, MarkupFilter filter) |
54 | { | |
55 | 226 | super(parent.getContentType(), new PrintWriter(writer), filter); |
56 | ||
57 | 226 | _parent = parent; |
58 | 226 | _charArrayWriter = writer; |
59 | } | |
60 | ||
61 | /** | |
62 | * Closes the internal {@link CharArrayWriter}, then captures its content and invokes | |
63 | * {@link org.apache.tapestry.IMarkupWriter#printRaw(String)} on the parent markup writer | |
64 | * (the writer that created this writer). | |
65 | */ | |
66 | ||
67 | 212 | public void close() |
68 | { | |
69 | 212 | if (_closed) |
70 | 1 | throw new IllegalStateException(MarkupMessages.closeOnce()); |
71 | ||
72 | 211 | _closed = true; |
73 | ||
74 | 211 | super.close(); |
75 | ||
76 | 211 | String content = getBuffer(); |
77 | ||
78 | 211 | _parent.printRaw(content); |
79 | } | |
80 | } |
|