1 17 package org.apache.jasper.compiler; 18 19 import java.util.Stack ; 20 import java.net.URL ; 21 import java.net.MalformedURLException ; 22 import org.apache.jasper.JspCompilationContext; 23 24 29 final class Mark { 30 31 int cursor, line, col; 33 34 String baseDir; 36 37 char[] stream = null; 39 40 private int fileId; 42 43 private String fileName; 45 46 50 private Stack includeStack = null; 51 52 private String encoding = null; 54 55 private JspReader reader; 57 58 private JspCompilationContext ctxt; 59 60 70 Mark(JspReader reader, char[] inStream, int fileId, String name, 71 String inBaseDir, String inEncoding) { 72 73 this.reader = reader; 74 this.ctxt = reader.getJspCompilationContext(); 75 this.stream = inStream; 76 this.cursor = 0; 77 this.line = 1; 78 this.col = 1; 79 this.fileId = fileId; 80 this.fileName = name; 81 this.baseDir = inBaseDir; 82 this.encoding = inEncoding; 83 this.includeStack = new Stack (); 84 } 85 86 87 90 Mark(Mark other) { 91 92 this.reader = other.reader; 93 this.ctxt = other.reader.getJspCompilationContext(); 94 this.stream = other.stream; 95 this.fileId = other.fileId; 96 this.fileName = other.fileName; 97 this.cursor = other.cursor; 98 this.line = other.line; 99 this.col = other.col; 100 this.baseDir = other.baseDir; 101 this.encoding = other.encoding; 102 103 includeStack = new Stack (); 105 for ( int i=0; i < other.includeStack.size(); i++ ) { 106 includeStack.addElement( other.includeStack.elementAt(i) ); 107 } 108 } 109 110 111 114 Mark(JspCompilationContext ctxt, String filename, int line, int col) { 115 116 this.reader = null; 117 this.ctxt = ctxt; 118 this.stream = null; 119 this.cursor = 0; 120 this.line = line; 121 this.col = col; 122 this.fileId = -1; 123 this.fileName = filename; 124 this.baseDir = "le-basedir"; 125 this.encoding = "le-endocing"; 126 this.includeStack = null; 127 } 128 129 130 139 public void pushStream(char[] inStream, int inFileId, String name, 140 String inBaseDir, String inEncoding) 141 { 142 includeStack.push(new IncludeState(cursor, line, col, fileId, 144 fileName, baseDir, 145 encoding, stream) ); 146 147 cursor = 0; 149 line = 1; 150 col = 1; 151 fileId = inFileId; 152 fileName = name; 153 baseDir = inBaseDir; 154 encoding = inEncoding; 155 stream = inStream; 156 } 157 158 159 164 public Mark popStream() { 165 if ( includeStack.size() <= 0 ) { 167 return null; 168 } 169 170 IncludeState state = (IncludeState) includeStack.pop( ); 172 173 cursor = state.cursor; 175 line = state.line; 176 col = state.col; 177 fileId = state.fileId; 178 fileName = state.fileName; 179 baseDir = state.baseDir; 180 stream = state.stream; 181 return this; 182 } 183 184 185 187 public int getLineNumber() { 188 return line; 189 } 190 191 public int getColumnNumber() { 192 return col; 193 } 194 195 public String getSystemId() { 196 return getFile(); 197 } 198 199 public String getPublicId() { 200 return null; 201 } 202 203 public String toString() { 204 return getFile()+"("+line+","+col+")"; 205 } 206 207 public String getFile() { 208 return this.fileName; 209 } 210 211 218 public URL getURL() throws MalformedURLException { 219 return ctxt.getResource(getFile()); 220 } 221 222 public String toShortString() { 223 return "("+line+","+col+")"; 224 } 225 226 public boolean equals(Object other) { 227 if (other instanceof Mark) { 228 Mark m = (Mark) other; 229 return this.reader == m.reader && this.fileId == m.fileId 230 && this.cursor == m.cursor && this.line == m.line 231 && this.col == m.col; 232 } 233 return false; 234 } 235 236 240 public boolean isGreater(Mark other) { 241 242 boolean greater = false; 243 244 if (this.line > other.line) { 245 greater = true; 246 } else if (this.line == other.line && this.col > other.col) { 247 greater = true; 248 } 249 250 return greater; 251 } 252 253 259 class IncludeState { 260 int cursor, line, col; 261 int fileId; 262 String fileName; 263 String baseDir; 264 String encoding; 265 char[] stream = null; 266 267 IncludeState(int inCursor, int inLine, int inCol, int inFileId, 268 String name, String inBaseDir, String inEncoding, 269 char[] inStream) { 270 cursor = inCursor; 271 line = inLine; 272 col = inCol; 273 fileId = inFileId; 274 fileName = name; 275 baseDir = inBaseDir; 276 encoding = inEncoding; 277 stream = inStream; 278 } 279 } 280 281 } 282 283 | Popular Tags |