1 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 27 39 40 public abstract class InsertText extends AbstractComponent 41 { 42 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 43 { 44 if (cycle.isRewinding()) 45 return; 46 47 String value = getValue(); 48 49 if (value == null) 50 return; 51 52 StringReader reader = null; 53 LineNumberReader lineReader = null; 54 InsertTextMode mode = getMode(); 55 boolean raw = getRaw(); 56 57 try 58 { 59 reader = new StringReader (value); 60 61 lineReader = new LineNumberReader (reader); 62 63 int lineNumber = 0; 64 65 while (true) 66 { 67 String line = lineReader.readLine(); 68 69 71 if (line == null) 72 break; 73 74 mode.writeLine(lineNumber, line, writer, raw); 75 76 lineNumber++; 77 } 78 79 } 80 catch (IOException ex) 81 { 82 throw new ApplicationRuntimeException(HTMLMessages.textConversionError(ex), this, null, 83 ex); 84 } 85 finally 86 { 87 close(lineReader); 88 close(reader); 89 } 90 91 } 92 93 private void close(Reader reader) 94 { 95 if (reader == null) 96 return; 97 98 try 99 { 100 reader.close(); 101 } 102 catch (IOException e) 103 { 104 } 105 } 106 107 108 public abstract InsertTextMode getMode(); 109 110 public abstract void setMode(InsertTextMode mode); 111 112 113 114 public abstract String getValue(); 115 116 117 118 public abstract boolean getRaw(); 119 120 125 protected void finishLoad() 126 { 127 setMode(InsertTextMode.BREAK); 128 } 129 130 } | Popular Tags |