1 17 package org.apache.jasper.compiler; 18 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.HashSet ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Vector ; 25 26 import org.apache.el.ExpressionFactoryImpl; 27 import org.apache.jasper.Constants; 28 import org.apache.jasper.JasperException; 29 30 import javax.el.ExpressionFactory; 31 import javax.servlet.jsp.tagext.TagLibraryInfo ; 32 33 38 39 class PageInfo { 40 41 private Vector imports; 42 private Vector dependants; 43 44 private BeanRepository beanRepository; 45 private HashMap taglibsMap; 46 private HashMap jspPrefixMapper; 47 private HashMap xmlPrefixMapper; 48 private HashMap nonCustomTagPrefixMap; 49 private String jspFile; 50 private String defaultLanguage = "java"; 51 private String language; 52 private String defaultExtends = Constants.JSP_SERVLET_BASE; 53 private String xtends; 54 private String contentType = null; 55 private String session; 56 private boolean isSession = true; 57 private String bufferValue; 58 private int buffer = 8*1024; private String autoFlush; 60 private boolean isAutoFlush = true; 61 private String isThreadSafeValue; 62 private boolean isThreadSafe = true; 63 private String isErrorPageValue; 64 private boolean isErrorPage = false; 65 private String errorPage = null; 66 private String info; 67 68 private boolean scriptless = false; 69 private boolean scriptingInvalid = false; 70 71 private String isELIgnoredValue; 72 private boolean isELIgnored = false; 73 74 private String deferredSyntaxAllowedAsLiteralValue; 76 private boolean deferredSyntaxAllowedAsLiteral = false; 77 private ExpressionFactory expressionFactory = new ExpressionFactoryImpl(); 78 private String trimDirectiveWhitespacesValue; 79 private boolean trimDirectiveWhitespaces = false; 80 81 private String omitXmlDecl = null; 82 private String doctypeName = null; 83 private String doctypePublic = null; 84 private String doctypeSystem = null; 85 86 private boolean isJspPrefixHijacked; 87 88 private HashSet prefixes; 90 91 private boolean hasJspRoot = false; 92 private Vector includePrelude; 93 private Vector includeCoda; 94 private Vector pluginDcls; 96 97 PageInfo(BeanRepository beanRepository, String jspFile) { 98 99 this.jspFile = jspFile; 100 this.beanRepository = beanRepository; 101 this.taglibsMap = new HashMap (); 102 this.jspPrefixMapper = new HashMap (); 103 this.xmlPrefixMapper = new HashMap (); 104 this.nonCustomTagPrefixMap = new HashMap (); 105 this.imports = new Vector (); 106 this.dependants = new Vector (); 107 this.includePrelude = new Vector (); 108 this.includeCoda = new Vector (); 109 this.pluginDcls = new Vector (); 110 this.prefixes = new HashSet (); 111 112 for(int i = 0; i < Constants.STANDARD_IMPORTS.length; i++) 114 imports.add(Constants.STANDARD_IMPORTS[i]); 115 } 116 117 122 public boolean isPluginDeclared(String id) { 123 if (pluginDcls.contains(id)) 124 return true; 125 pluginDcls.add(id); 126 return false; 127 } 128 129 public void addImports(List imports) { 130 this.imports.addAll(imports); 131 } 132 133 public void addImport(String imp) { 134 this.imports.add(imp); 135 } 136 137 public List getImports() { 138 return imports; 139 } 140 141 public String getJspFile() { 142 return jspFile; 143 } 144 145 public void addDependant(String d) { 146 if (!dependants.contains(d) && !jspFile.equals(d)) 147 dependants.add(d); 148 } 149 150 public List getDependants() { 151 return dependants; 152 } 153 154 public BeanRepository getBeanRepository() { 155 return beanRepository; 156 } 157 158 public void setScriptless(boolean s) { 159 scriptless = s; 160 } 161 162 public boolean isScriptless() { 163 return scriptless; 164 } 165 166 public void setScriptingInvalid(boolean s) { 167 scriptingInvalid = s; 168 } 169 170 public boolean isScriptingInvalid() { 171 return scriptingInvalid; 172 } 173 174 public List getIncludePrelude() { 175 return includePrelude; 176 } 177 178 public void setIncludePrelude(Vector prelude) { 179 includePrelude = prelude; 180 } 181 182 public List getIncludeCoda() { 183 return includeCoda; 184 } 185 186 public void setIncludeCoda(Vector coda) { 187 includeCoda = coda; 188 } 189 190 public void setHasJspRoot(boolean s) { 191 hasJspRoot = s; 192 } 193 194 public boolean hasJspRoot() { 195 return hasJspRoot; 196 } 197 198 public String getOmitXmlDecl() { 199 return omitXmlDecl; 200 } 201 202 public void setOmitXmlDecl(String omit) { 203 omitXmlDecl = omit; 204 } 205 206 public String getDoctypeName() { 207 return doctypeName; 208 } 209 210 public void setDoctypeName(String doctypeName) { 211 this.doctypeName = doctypeName; 212 } 213 214 public String getDoctypeSystem() { 215 return doctypeSystem; 216 } 217 218 public void setDoctypeSystem(String doctypeSystem) { 219 this.doctypeSystem = doctypeSystem; 220 } 221 222 public String getDoctypePublic() { 223 return doctypePublic; 224 } 225 226 public void setDoctypePublic(String doctypePublic) { 227 this.doctypePublic = doctypePublic; 228 } 229 230 231 232 public void setIsJspPrefixHijacked(boolean isHijacked) { 233 isJspPrefixHijacked = isHijacked; 234 } 235 236 public boolean isJspPrefixHijacked() { 237 return isJspPrefixHijacked; 238 } 239 240 245 public void addPrefix(String prefix) { 246 prefixes.add(prefix); 247 } 248 249 257 public boolean containsPrefix(String prefix) { 258 return prefixes.contains(prefix); 259 } 260 261 267 public void addTaglib(String uri, TagLibraryInfo info) { 268 taglibsMap.put(uri, info); 269 } 270 271 276 public TagLibraryInfo getTaglib(String uri) { 277 return (TagLibraryInfo ) taglibsMap.get(uri); 278 } 279 280 285 public Collection getTaglibs() { 286 return taglibsMap.values(); 287 } 288 289 297 public boolean hasTaglib(String uri) { 298 return taglibsMap.containsKey(uri); 299 } 300 301 307 public void addPrefixMapping(String prefix, String uri) { 308 jspPrefixMapper.put(prefix, uri); 309 } 310 311 318 public void pushPrefixMapping(String prefix, String uri) { 319 LinkedList stack = (LinkedList ) xmlPrefixMapper.get(prefix); 320 if (stack == null) { 321 stack = new LinkedList (); 322 xmlPrefixMapper.put(prefix, stack); 323 } 324 stack.addFirst(uri); 325 } 326 327 333 public void popPrefixMapping(String prefix) { 334 LinkedList stack = (LinkedList ) xmlPrefixMapper.get(prefix); 335 if (stack == null || stack.size() == 0) { 336 } 338 stack.removeFirst(); 339 } 340 341 348 public String getURI(String prefix) { 349 350 String uri = null; 351 352 LinkedList stack = (LinkedList ) xmlPrefixMapper.get(prefix); 353 if (stack == null || stack.size() == 0) { 354 uri = (String ) jspPrefixMapper.get(prefix); 355 } else { 356 uri = (String ) stack.getFirst(); 357 } 358 359 return uri; 360 } 361 362 363 364 365 368 public void setLanguage(String value, Node n, ErrorDispatcher err, 369 boolean pagedir) 370 throws JasperException { 371 372 if (!"java".equalsIgnoreCase(value)) { 373 if (pagedir) 374 err.jspError(n, "jsp.error.page.language.nonjava"); 375 else 376 err.jspError(n, "jsp.error.tag.language.nonjava"); 377 } 378 379 language = value; 380 } 381 382 public String getLanguage(boolean useDefault) { 383 return (language == null && useDefault ? defaultLanguage : language); 384 } 385 386 public String getLanguage() { 387 return getLanguage(true); 388 } 389 390 391 394 public void setExtends(String value, Node.PageDirective n) { 395 396 xtends = value; 397 398 403 if (value.indexOf('.') < 0) 404 n.addImport(value); 405 } 406 407 418 public String getExtends(boolean useDefault) { 419 return (xtends == null && useDefault ? defaultExtends : xtends); 420 } 421 422 429 public String getExtends() { 430 return getExtends(true); 431 } 432 433 434 437 public void setContentType(String value) { 438 contentType = value; 439 } 440 441 public String getContentType() { 442 return contentType; 443 } 444 445 446 449 public void setBufferValue(String value, Node n, ErrorDispatcher err) 450 throws JasperException { 451 452 if ("none".equalsIgnoreCase(value)) 453 buffer = 0; 454 else { 455 if (value == null || !value.endsWith("kb")) 456 err.jspError(n, "jsp.error.page.invalid.buffer"); 457 try { 458 Integer k = new Integer (value.substring(0, value.length()-2)); 459 buffer = k.intValue() * 1024; 460 } catch (NumberFormatException e) { 461 err.jspError(n, "jsp.error.page.invalid.buffer"); 462 } 463 } 464 465 bufferValue = value; 466 } 467 468 public String getBufferValue() { 469 return bufferValue; 470 } 471 472 public int getBuffer() { 473 return buffer; 474 } 475 476 477 480 public void setSession(String value, Node n, ErrorDispatcher err) 481 throws JasperException { 482 483 if ("true".equalsIgnoreCase(value)) 484 isSession = true; 485 else if ("false".equalsIgnoreCase(value)) 486 isSession = false; 487 else 488 err.jspError(n, "jsp.error.page.invalid.session"); 489 490 session = value; 491 } 492 493 public String getSession() { 494 return session; 495 } 496 497 public boolean isSession() { 498 return isSession; 499 } 500 501 502 505 public void setAutoFlush(String value, Node n, ErrorDispatcher err) 506 throws JasperException { 507 508 if ("true".equalsIgnoreCase(value)) 509 isAutoFlush = true; 510 else if ("false".equalsIgnoreCase(value)) 511 isAutoFlush = false; 512 else 513 err.jspError(n, "jsp.error.autoFlush.invalid"); 514 515 autoFlush = value; 516 } 517 518 public String getAutoFlush() { 519 return autoFlush; 520 } 521 522 public boolean isAutoFlush() { 523 return isAutoFlush; 524 } 525 526 527 530 public void setIsThreadSafe(String value, Node n, ErrorDispatcher err) 531 throws JasperException { 532 533 if ("true".equalsIgnoreCase(value)) 534 isThreadSafe = true; 535 else if ("false".equalsIgnoreCase(value)) 536 isThreadSafe = false; 537 else 538 err.jspError(n, "jsp.error.page.invalid.isthreadsafe"); 539 540 isThreadSafeValue = value; 541 } 542 543 public String getIsThreadSafe() { 544 return isThreadSafeValue; 545 } 546 547 public boolean isThreadSafe() { 548 return isThreadSafe; 549 } 550 551 552 555 public void setInfo(String value) { 556 info = value; 557 } 558 559 public String getInfo() { 560 return info; 561 } 562 563 564 567 public void setErrorPage(String value) { 568 errorPage = value; 569 } 570 571 public String getErrorPage() { 572 return errorPage; 573 } 574 575 576 579 public void setIsErrorPage(String value, Node n, ErrorDispatcher err) 580 throws JasperException { 581 582 if ("true".equalsIgnoreCase(value)) 583 isErrorPage = true; 584 else if ("false".equalsIgnoreCase(value)) 585 isErrorPage = false; 586 else 587 err.jspError(n, "jsp.error.page.invalid.iserrorpage"); 588 589 isErrorPageValue = value; 590 } 591 592 public String getIsErrorPage() { 593 return isErrorPageValue; 594 } 595 596 public boolean isErrorPage() { 597 return isErrorPage; 598 } 599 600 601 604 public void setIsELIgnored(String value, Node n, ErrorDispatcher err, 605 boolean pagedir) 606 throws JasperException { 607 608 if ("true".equalsIgnoreCase(value)) 609 isELIgnored = true; 610 else if ("false".equalsIgnoreCase(value)) 611 isELIgnored = false; 612 else { 613 if (pagedir) 614 err.jspError(n, "jsp.error.page.invalid.iselignored"); 615 else 616 err.jspError(n, "jsp.error.tag.invalid.iselignored"); 617 } 618 619 isELIgnoredValue = value; 620 } 621 622 625 public void setDeferredSyntaxAllowedAsLiteral(String value, Node n, ErrorDispatcher err, 626 boolean pagedir) 627 throws JasperException { 628 629 if ("true".equalsIgnoreCase(value)) 630 deferredSyntaxAllowedAsLiteral = true; 631 else if ("false".equalsIgnoreCase(value)) 632 deferredSyntaxAllowedAsLiteral = false; 633 else { 634 if (pagedir) 635 err.jspError(n, "jsp.error.page.invalid.deferredsyntaxallowedasliteral"); 636 else 637 err.jspError(n, "jsp.error.tag.invalid.deferredsyntaxallowedasliteral"); 638 } 639 640 deferredSyntaxAllowedAsLiteralValue = value; 641 } 642 643 646 public void setTrimDirectiveWhitespaces(String value, Node n, ErrorDispatcher err, 647 boolean pagedir) 648 throws JasperException { 649 650 if ("true".equalsIgnoreCase(value)) 651 trimDirectiveWhitespaces = true; 652 else if ("false".equalsIgnoreCase(value)) 653 trimDirectiveWhitespaces = false; 654 else { 655 if (pagedir) 656 err.jspError(n, "jsp.error.page.invalid.trimdirectivewhitespaces"); 657 else 658 err.jspError(n, "jsp.error.tag.invalid.trimdirectivewhitespaces"); 659 } 660 661 trimDirectiveWhitespacesValue = value; 662 } 663 664 public void setELIgnored(boolean s) { 665 isELIgnored = s; 666 } 667 668 public String getIsELIgnored() { 669 return isELIgnoredValue; 670 } 671 672 public boolean isELIgnored() { 673 return isELIgnored; 674 } 675 676 public void putNonCustomTagPrefix(String prefix, Mark where) { 677 nonCustomTagPrefixMap.put(prefix, where); 678 } 679 680 public Mark getNonCustomTagPrefix(String prefix) { 681 return (Mark) nonCustomTagPrefixMap.get(prefix); 682 } 683 684 public String getDeferredSyntaxAllowedAsLiteral() { 685 return deferredSyntaxAllowedAsLiteralValue; 686 } 687 688 public boolean isDeferredSyntaxAllowedAsLiteral() { 689 return deferredSyntaxAllowedAsLiteral; 690 } 691 692 public void setDeferredSyntaxAllowedAsLiteral(boolean isELDeferred) { 693 this.deferredSyntaxAllowedAsLiteral = isELDeferred; 694 } 695 696 public ExpressionFactory getExpressionFactory() { 697 return expressionFactory; 698 } 699 700 public String getTrimDirectiveWhitespaces() { 701 return trimDirectiveWhitespacesValue; 702 } 703 704 public boolean isTrimDirectiveWhitespaces() { 705 return trimDirectiveWhitespaces; 706 } 707 708 public void setTrimDirectiveWhitespaces(boolean trimDirectiveWhitespaces) { 709 this.trimDirectiveWhitespaces = trimDirectiveWhitespaces; 710 } 711 } 712 | Popular Tags |