Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 80   Methods: 4
NCLOC: 33   Classes: 1
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
NestedMarkupWriterImpl.java 100% 100% 100% 100%
coverage
 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  248
     public String getBuffer()
 40   
     {
 41  248
         return _charArrayWriter.toString();
 42   
     }
 43   
 
 44  264
     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  264
         this(parent, new CharArrayWriter(), filter);
 51   
     }
 52   
 
 53  264
     private NestedMarkupWriterImpl(IMarkupWriter parent, CharArrayWriter writer, MarkupFilter filter)
 54   
     {
 55  264
         super(parent.getContentType(), new PrintWriter(writer), filter);
 56   
 
 57  264
         _parent = parent;
 58  264
         _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  244
     public void close()
 68   
     {
 69  244
         if (_closed)
 70  1
             throw new IllegalStateException(MarkupMessages.closeOnce());
 71   
 
 72  243
         _closed = true;
 73   
 
 74  243
         super.close();
 75   
 
 76  243
         String content = getBuffer();
 77   
 
 78  243
         _parent.printRaw(content);
 79   
     }
 80   
 }