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