1 17 package org.apache.jasper.compiler; 18 19 import java.io.IOException ; 20 import java.io.PrintWriter ; 21 22 28 public class ServletWriter { 29 public static int TAB_WIDTH = 2; 30 public static String SPACES = " "; 31 32 private int indent = 0; 34 private int virtual_indent = 0; 35 36 PrintWriter writer; 38 39 private int javaLine = 1; 41 42 43 public ServletWriter(PrintWriter writer) { 44 this.writer = writer; 45 } 46 47 public void close() throws IOException { 48 writer.close(); 49 } 50 51 52 54 public int getJavaLine() { 55 return javaLine; 56 } 57 58 59 61 public void pushIndent() { 62 virtual_indent += TAB_WIDTH; 63 if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) 64 indent = virtual_indent; 65 } 66 67 public void popIndent() { 68 virtual_indent -= TAB_WIDTH; 69 if (virtual_indent >= 0 && virtual_indent <= SPACES.length()) 70 indent = virtual_indent; 71 } 72 73 78 public void printComment(Mark start, Mark stop, char[] chars) { 79 if (start != null && stop != null) { 80 println("// from="+start); 81 println("// to="+stop); 82 } 83 84 if (chars != null) 85 for(int i = 0; i < chars.length;) { 86 printin(); 87 print("// "); 88 while (chars[i] != '\n' && i < chars.length) 89 writer.print(chars[i++]); 90 } 91 } 92 93 96 public void println(String s) { 97 javaLine++; 98 writer.println(s); 99 } 100 101 104 public void println() { 105 javaLine++; 106 writer.println(""); 107 } 108 109 112 public void printin() { 113 writer.print(SPACES.substring(0, indent)); 114 } 115 116 119 public void printin(String s) { 120 writer.print(SPACES.substring(0, indent)); 121 writer.print(s); 122 } 123 124 127 public void printil(String s) { 128 javaLine++; 129 writer.print(SPACES.substring(0, indent)); 130 writer.println(s); 131 } 132 133 138 public void print(char c) { 139 writer.print(c); 140 } 141 142 145 public void print(int i) { 146 writer.print(i); 147 } 148 149 155 public void print(String s) { 156 writer.print(s); 157 } 158 159 165 public void printMultiLn(String s) { 166 int index = 0; 167 168 while ((index=s.indexOf('\n',index)) > -1 ) { 170 javaLine++; 171 index++; 172 } 173 174 writer.print(s); 175 } 176 } 177 | Popular Tags |