1 19 20 package org.netbeans.modules.web.jsps.parserapi; 21 22 import java.beans.PropertyChangeListener ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.net.URLClassLoader ; 26 import java.util.Map ; 27 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileSystem; 30 31 import org.netbeans.modules.web.jspparser.ContextUtil; 32 33 38 public interface JspParserAPI { 39 40 public static abstract class WebModule { 41 42 47 public static final String PROP_LIBRARIES = "libraries"; 49 54 public static final String PROP_PACKAGE_ROOTS = "package_roots"; 56 60 public abstract FileObject getDocumentBase(); 61 62 63 68 public abstract File [] getExtraClasspathEntries(); 69 70 73 public abstract java.io.InputStream getEditorInputStream (FileObject fo); 74 75 public abstract void addPropertyChangeListener(PropertyChangeListener l); 76 77 public abstract void removePropertyChangeListener(PropertyChangeListener l); 78 } 79 80 81 public static final int ERROR_IGNORE = 1; 82 84 public static final int ERROR_REPORT_ANY = 2; 85 87 public static final int ERROR_REPORT_ACCURATE = 3; 88 89 public static final String TAG_MIME_TYPE = "text/x-tag"; 91 98 public JspOpenInfo getJspOpenInfo(FileObject jspFile, WebModule wm, boolean useEditor); 99 100 109 public JspParserAPI.ParseResult analyzePage(FileObject jspFile, WebModule wm, 110 int errorReportingMode); 111 112 113 116 public URLClassLoader getModuleClassLoader(WebModule wm); 117 118 119 121 131 public Map getTaglibMap(WebModule wm) throws IOException ; 132 133 137 public static class ParseResult { 138 139 protected PageInfo pageInfo; 140 protected Node.Nodes nodes; 141 protected JspParserAPI.ErrorDescriptor[] errors; 142 protected boolean parsedOK; 143 144 148 public ParseResult(PageInfo pageInfo, Node.Nodes nodes) { 149 this (pageInfo, nodes, null); 150 } 151 152 155 public ParseResult(JspParserAPI.ErrorDescriptor[] errors) { 156 this (null, null, errors); 157 } 158 159 165 public ParseResult(PageInfo pageInfo, Node.Nodes nodes, JspParserAPI.ErrorDescriptor[] errors) { 166 this.pageInfo = pageInfo; 167 this.nodes = nodes; 168 this.errors = errors; 169 this.parsedOK = ((errors == null) || (errors.length == 0)); 170 } 171 172 174 public boolean isParsingSuccess() { 175 return parsedOK; 176 } 177 178 181 public PageInfo getPageInfo() { 182 return pageInfo; 183 } 184 185 188 public Node.Nodes getNodes() { 189 return nodes; 190 } 191 192 195 public JspParserAPI.ErrorDescriptor[] getErrors() { 196 if (!(parsedOK)) { 197 return errors; 198 } 199 throw new IllegalStateException (); 200 } 201 202 public String toString() { 203 StringBuffer result = new StringBuffer (); 204 result.append("--------- JspParserAPI.parseResult(), success: "); 205 result.append(isParsingSuccess()); 206 result.append("\n"); 207 if (pageInfo != null) { 208 result.append(" ---- PAGEINFO\n"); 209 result.append(pageInfo.toString()); 210 } 211 if (nodes != null) { 212 result.append("\n ---- NODES\n"); 213 result.append(nodes.toString()); 214 result.append("\n"); 215 } 216 if (!isParsingSuccess()) { 217 result.append("\n ---- ERRORS\n"); 218 for (int i = 0; i < errors.length; i++) { 219 result.append(errors[i].toString()); 220 } 221 } 222 return result.toString(); 223 } 224 225 } 226 227 231 public static class JspOpenInfo { 232 233 private boolean isXml; 234 private String encoding; 235 236 public JspOpenInfo(boolean isXml, String encoding) { 237 this.isXml = isXml; 238 this.encoding = encoding; 239 } 240 241 public boolean isXmlSyntax() { 242 return isXml; 243 } 244 245 public String getEncoding() { 246 return encoding; 247 } 248 249 public boolean equals(Object o) { 250 if (o instanceof JspOpenInfo) { 251 JspOpenInfo openInfo2 = (JspOpenInfo)o; 252 return (getEncoding().equals(openInfo2.getEncoding()) && 253 isXmlSyntax() == openInfo2.isXmlSyntax()); 254 } 255 else { 256 return false; 257 } 258 } 259 260 public int hashCode() { 261 return encoding.hashCode() + (isXml ? 1 : 0); 262 } 263 264 public String toString() { 265 return super.toString() + " [isXml: " + isXml + ", encoding: " + encoding + "]"; 266 } 267 268 } 269 270 272 public static class ErrorDescriptor { 273 274 protected FileObject wmRoot; 275 protected FileObject source; 276 protected int line; 277 protected int column; 278 protected String errorMessage; 279 protected String referenceText; 280 281 290 public ErrorDescriptor(FileObject wmRoot, FileObject source, int line, 291 int column, String errorMessage, String referenceText) { 292 this.wmRoot = wmRoot; 293 this.source = source; 294 this.line = line; 295 this.column = column; 296 this.errorMessage = errorMessage; 297 this.referenceText = referenceText; 298 } 299 300 301 public FileObject getSource() { 302 return source; 303 } 304 305 306 public int getLine() { 307 return line; 308 } 309 310 311 public int getColumn() { 312 return column; 313 } 314 315 316 public String getErrorMessage() { 317 return errorMessage; 318 } 319 320 321 public String getReferenceText() { 322 return referenceText; 323 } 324 325 public String toString() { 326 StringBuffer result = new StringBuffer (); 327 result.append("ERROR in ") 328 .append(getSourcePath()) 329 .append(" at [") 330 .append(getLine()) 331 .append(", ") 332 .append(getColumn()) 333 .append("] ") 334 .append(getErrorMessage()) 335 .append("\n") 336 .append(getReferenceText()) 337 .append("\n"); 338 return result.toString(); 339 } 340 341 private String getSourcePath() { 342 if (wmRoot == null) { 343 return getSource().getNameExt(); 344 } 345 else { 346 return ContextUtil.findRelativeContextPath(wmRoot, getSource()); 347 } 348 } 349 } 350 351 352 } 353 | Popular Tags |