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: 128   Methods: 3
NCLOC: 67   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
InsertText.java 83.3% 91.7% 100% 90.9%
coverage coverage
 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.IOException;
 18   
 import java.io.LineNumberReader;
 19   
 import java.io.Reader;
 20   
 import java.io.StringReader;
 21   
 
 22   
 import org.apache.hivemind.ApplicationRuntimeException;
 23   
 import org.apache.tapestry.AbstractComponent;
 24   
 import org.apache.tapestry.IMarkupWriter;
 25   
 import org.apache.tapestry.IRequestCycle;
 26   
 import org.apache.tapestry.Tapestry;
 27   
 
 28   
 /**
 29   
  *  Inserts formatted text (possibly collected using a {@link org.apache.tapestry.form.TextArea} 
 30   
  *  component.
 31   
  * 
 32   
  *  [<a href="../../../../../ComponentReference/InsertText.html">Component Reference</a>]
 33   
  *
 34   
  *  <p>To maintain the line breaks provided originally, this component will
 35   
  *  break the input into individual lines and insert additional
 36   
  *  HTML to make each line seperate.
 37   
  *
 38   
  *  <p>This can be down more simply, using the &lt;pre&gt; HTML element, but
 39   
  *  that usually renders the text in a non-proportional font.
 40   
  *
 41   
  * @author Howard Lewis Ship
 42   
  * 
 43   
  **/
 44   
 
 45   
 public abstract class InsertText extends AbstractComponent
 46   
 {
 47  5
     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
 48   
     {
 49  5
         String value = getValue();
 50   
 
 51  5
         if (value == null)
 52  2
             return;
 53   
 
 54  3
         StringReader reader = null;
 55  3
         LineNumberReader lineReader = null;
 56  3
         InsertTextMode mode = getMode();
 57   
 
 58  3
         try
 59   
         {
 60  3
             reader = new StringReader(value);
 61   
 
 62  3
             lineReader = new LineNumberReader(reader);
 63   
 
 64  3
             int lineNumber = 0;
 65   
 
 66  3
             while (true)
 67   
             {
 68  10
                 String line = lineReader.readLine();
 69   
 
 70   
                 // Exit loop at end of file.
 71   
 
 72  10
                 if (line == null)
 73  3
                     break;
 74   
 
 75  7
                 mode.writeLine(lineNumber, line, writer);
 76   
 
 77  7
                 lineNumber++;
 78   
             }
 79   
 
 80   
         }
 81   
         catch (IOException ex)
 82   
         {
 83  0
             throw new ApplicationRuntimeException(
 84   
                 Tapestry.getMessage("InsertText.conversion-error"),
 85   
                 this,
 86   
                 null,
 87   
                 ex);
 88   
         }
 89   
         finally
 90   
         {
 91  3
             close(lineReader);
 92  3
             close(reader);
 93   
         }
 94   
 
 95   
     }
 96   
 
 97  6
     private void close(Reader reader)
 98   
     {
 99  6
         if (reader == null)
 100  0
             return;
 101   
 
 102  6
         try
 103   
         {
 104  6
             reader.close();
 105   
         }
 106   
         catch (IOException e)
 107   
         {
 108   
         }
 109   
     }
 110   
 
 111   
     public abstract InsertTextMode getMode();
 112   
 
 113   
     public abstract void setMode(InsertTextMode mode);
 114   
 
 115   
     public abstract String getValue();
 116   
 
 117   
     /**
 118   
      * Sets the mode parameter property to its default,
 119   
      * {@link InsertTextMode#BREAK}.
 120   
      * 
 121   
      * @since 3.0
 122   
      */
 123  1
     protected void finishLoad()
 124   
     {
 125  1
         setMode(InsertTextMode.BREAK);
 126   
     }
 127   
 
 128   
 }