1 16 package org.jboss.web.tomcat.tc6.jasper; 17 18 import java.util.Properties ; 19 import java.util.Enumeration ; 20 import java.util.ArrayList ; 21 import java.util.Map ; 22 import java.io.File ; 23 24 import javax.servlet.ServletConfig ; 25 import javax.servlet.ServletContext ; 26 27 import org.apache.jasper.Options; 28 import org.apache.jasper.Constants; 29 import org.apache.jasper.xmlparser.ParserUtils; 30 import org.apache.jasper.compiler.TldLocationsCache; 31 import org.apache.jasper.compiler.JspConfig; 32 import org.apache.jasper.compiler.TagPluginManager; 33 import org.apache.jasper.compiler.Localizer; 34 import org.jboss.logging.Logger; 35 36 43 public class JspServletOptions 44 implements Options 45 { 46 static Logger log = Logger.getLogger(JspServletOptions.class); 47 48 private Properties settings = new Properties (); 49 50 53 private boolean development = true; 54 55 59 private boolean displaySourceFragment = true; 60 61 64 public boolean fork = true; 65 66 69 private boolean keepGenerated = true; 70 71 74 private boolean trimSpaces = false; 75 76 79 private boolean isPoolingEnabled = true; 80 81 86 private boolean mappedFile = true; 87 88 93 private boolean sendErrorToClient = false; 94 95 98 private boolean classDebugInfo = true; 99 100 103 private int checkInterval = 0; 104 105 108 private boolean isSmapSuppressed = false; 109 110 113 private boolean isSmapDumped = false; 114 115 118 private boolean genStringAsCharArray = false; 119 120 private boolean errorOnUseBeanInvalidClassAttribute = true; 121 122 125 private File scratchDir; 126 127 132 private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"; 133 134 137 private String classpath = null; 138 139 142 private String compiler = null; 143 144 147 private String compilerClassName = null; 148 149 152 private String compilerTargetVM = "1.4"; 153 154 157 private String compilerSourceVM = "1.4"; 158 159 162 private TldLocationsCache tldLocationsCache = null; 163 164 167 private JspConfig jspConfig = null; 168 169 172 private TagPluginManager tagPluginManager = null; 173 174 177 private String javaEncoding = "UTF8"; 178 179 182 private int modificationTestInterval = 4; 183 184 private boolean ignoreAnnotations; 185 186 187 188 191 private boolean xpoweredBy; 192 193 194 public boolean getIgnoreAnnotations() 195 { 196 return ignoreAnnotations; 197 } 198 199 public void setIgnoreAnnotations(boolean ignoreAnnotations) 200 { 201 this.ignoreAnnotations = ignoreAnnotations; 202 } 203 204 public String getProperty(String name) 205 { 206 return settings.getProperty(name); 207 } 208 209 public void setProperty(String name, String value) 210 { 211 if (name != null && value != null) 212 { 213 settings.setProperty(name, value); 214 } 215 } 216 217 220 public boolean getKeepGenerated() 221 { 222 return keepGenerated; 223 } 224 225 228 public boolean getTrimSpaces() 229 { 230 return trimSpaces; 231 } 232 233 public boolean isPoolingEnabled() 234 { 235 return isPoolingEnabled; 236 } 237 238 241 public boolean getMappedFile() 242 { 243 return mappedFile; 244 } 245 246 249 public boolean getSendErrorToClient() 250 { 251 return sendErrorToClient; 252 } 253 254 257 public boolean getClassDebugInfo() 258 { 259 return classDebugInfo; 260 } 261 262 265 public int getCheckInterval() 266 { 267 return checkInterval; 268 } 269 270 273 public int getModificationTestInterval() 274 { 275 return modificationTestInterval; 276 } 277 278 281 public boolean getDevelopment() 282 { 283 return development; 284 } 285 286 public boolean getDisplaySourceFragment() 287 { 288 return displaySourceFragment; 290 } 291 292 295 public boolean isSmapSuppressed() 296 { 297 return isSmapSuppressed; 298 } 299 300 303 public boolean isSmapDumped() 304 { 305 return isSmapDumped; 306 } 307 308 311 public boolean genStringAsCharArray() 312 { 313 return this.genStringAsCharArray; 314 } 315 316 319 public String getIeClassId() 320 { 321 return ieClassId; 322 } 323 324 327 public File getScratchDir() 328 { 329 return scratchDir; 330 } 331 332 336 public String getClassPath() 337 { 338 return classpath; 339 } 340 341 344 public boolean isXpoweredBy() 345 { 346 return xpoweredBy; 347 } 348 349 352 public String getCompiler() 353 { 354 return compiler; 355 } 356 357 360 public String getCompilerClassName() 361 { 362 return compilerClassName; 363 } 364 365 368 public String getCompilerTargetVM() 369 { 370 return compilerTargetVM; 371 } 372 373 376 public String getCompilerSourceVM() 377 { 378 return compilerSourceVM; 379 } 380 381 public boolean getErrorOnUseBeanInvalidClassAttribute() 382 { 383 return errorOnUseBeanInvalidClassAttribute; 384 } 385 386 public void setErrorOnUseBeanInvalidClassAttribute(boolean b) 387 { 388 errorOnUseBeanInvalidClassAttribute = b; 389 } 390 391 public TldLocationsCache getTldLocationsCache() 392 { 393 return tldLocationsCache; 394 } 395 396 public void setTldLocationsCache(TldLocationsCache tldC) 397 { 398 tldLocationsCache = tldC; 399 } 400 401 public String getJavaEncoding() 402 { 403 return javaEncoding; 404 } 405 406 public boolean getFork() 407 { 408 return fork; 409 } 410 411 public JspConfig getJspConfig() 412 { 413 return jspConfig; 414 } 415 416 public TagPluginManager getTagPluginManager() 417 { 418 return tagPluginManager; 419 } 420 421 424 public boolean isCaching() 425 { 426 return false; 427 } 428 429 436 public Map getCache() 437 { 438 return null; 439 } 440 441 445 public JspServletOptions(ServletConfig config, ServletContext context) 446 { 447 448 Enumeration enumeration = config.getInitParameterNames(); 449 while (enumeration.hasMoreElements()) 450 { 451 String k = (String ) enumeration.nextElement(); 452 String v = config.getInitParameter(k); 453 setProperty(k, v); 454 } 455 456 String validating = config.getInitParameter("validating"); 458 if ("false".equals(validating)) ParserUtils.validating = false; 459 460 String keepgen = config.getInitParameter("keepgenerated"); 461 if (keepgen != null) 462 { 463 if (keepgen.equalsIgnoreCase("true")) 464 { 465 this.keepGenerated = true; 466 } 467 else if (keepgen.equalsIgnoreCase("false")) 468 { 469 this.keepGenerated = false; 470 } 471 else 472 { 473 log.warn(Localizer.getMessage("jsp.warning.keepgen")); 474 } 475 } 476 477 478 String trimsp = config.getInitParameter("trimSpaces"); 479 if (trimsp != null) 480 { 481 if (trimsp.equalsIgnoreCase("true")) 482 { 483 trimSpaces = true; 484 } 485 else if (trimsp.equalsIgnoreCase("false")) 486 { 487 trimSpaces = false; 488 } 489 else 490 { 491 log.warn(Localizer.getMessage("jsp.warning.trimspaces")); 492 } 493 } 494 495 this.isPoolingEnabled = true; 496 String poolingEnabledParam 497 = config.getInitParameter("enablePooling"); 498 if (poolingEnabledParam != null 499 && !poolingEnabledParam.equalsIgnoreCase("true")) 500 { 501 if (poolingEnabledParam.equalsIgnoreCase("false")) 502 { 503 this.isPoolingEnabled = false; 504 } 505 else 506 { 507 log.warn(Localizer.getMessage("jsp.warning.enablePooling")); 508 } 509 } 510 511 String mapFile = config.getInitParameter("mappedfile"); 512 if (mapFile != null) 513 { 514 if (mapFile.equalsIgnoreCase("true")) 515 { 516 this.mappedFile = true; 517 } 518 else if (mapFile.equalsIgnoreCase("false")) 519 { 520 this.mappedFile = false; 521 } 522 else 523 { 524 log.warn(Localizer.getMessage("jsp.warning.mappedFile")); 525 } 526 } 527 528 String senderr = config.getInitParameter("sendErrToClient"); 529 if (senderr != null) 530 { 531 if (senderr.equalsIgnoreCase("true")) 532 { 533 this.sendErrorToClient = true; 534 } 535 else if (senderr.equalsIgnoreCase("false")) 536 { 537 this.sendErrorToClient = false; 538 } 539 else 540 { 541 log.warn(Localizer.getMessage("jsp.warning.sendErrToClient")); 542 } 543 } 544 545 String debugInfo = config.getInitParameter("classdebuginfo"); 546 if (debugInfo != null) 547 { 548 if (debugInfo.equalsIgnoreCase("true")) 549 { 550 this.classDebugInfo = true; 551 } 552 else if (debugInfo.equalsIgnoreCase("false")) 553 { 554 this.classDebugInfo = false; 555 } 556 else 557 { 558 log.warn(Localizer.getMessage("jsp.warning.classDebugInfo")); 559 } 560 } 561 562 String checkInterval = config.getInitParameter("checkInterval"); 563 if (checkInterval != null) 564 { 565 try 566 { 567 this.checkInterval = Integer.parseInt(checkInterval); 568 if (this.checkInterval == 0) 569 { 570 this.checkInterval = 300; 571 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 572 } 573 } 574 catch (NumberFormatException ex) 575 { 576 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 577 } 578 } 579 580 String modificationTestInterval = config.getInitParameter("modificationTestInterval"); 581 if (modificationTestInterval != null) 582 { 583 try 584 { 585 this.modificationTestInterval = Integer.parseInt(modificationTestInterval); 586 } 587 catch (NumberFormatException ex) 588 { 589 log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval")); 590 } 591 } 592 593 String development = config.getInitParameter("development"); 594 if (development != null) 595 { 596 if (development.equalsIgnoreCase("true")) 597 { 598 this.development = true; 599 } 600 else if (development.equalsIgnoreCase("false")) 601 { 602 this.development = false; 603 } 604 else 605 { 606 log.warn(Localizer.getMessage("jsp.warning.development")); 607 } 608 } 609 610 String displaySourceFragment = config.getInitParameter("displaySourceFragment"); 611 if (displaySourceFragment != null) 612 { 613 if (displaySourceFragment.equalsIgnoreCase("true")) 614 { 615 this.displaySourceFragment = true; 616 } 617 else if (displaySourceFragment.equalsIgnoreCase("false")) 618 { 619 this.displaySourceFragment = false; 620 } 621 else 622 { 623 log.warn(Localizer.getMessage("jsp.warning.displaySourceFragment")); 624 } 625 } 626 627 String suppressSmap = config.getInitParameter("suppressSmap"); 628 if (suppressSmap != null) 629 { 630 if (suppressSmap.equalsIgnoreCase("true")) 631 { 632 isSmapSuppressed = true; 633 } 634 else if (suppressSmap.equalsIgnoreCase("false")) 635 { 636 isSmapSuppressed = false; 637 } 638 else 639 { 640 log.warn(Localizer.getMessage("jsp.warning.suppressSmap")); 641 } 642 } 643 644 String dumpSmap = config.getInitParameter("dumpSmap"); 645 if (dumpSmap != null) 646 { 647 if (dumpSmap.equalsIgnoreCase("true")) 648 { 649 isSmapDumped = true; 650 } 651 else if (dumpSmap.equalsIgnoreCase("false")) 652 { 653 isSmapDumped = false; 654 } 655 else 656 { 657 log.warn(Localizer.getMessage("jsp.warning.dumpSmap")); 658 } 659 } 660 661 String genCharArray = config.getInitParameter("genStrAsCharArray"); 662 if (genCharArray != null) 663 { 664 if (genCharArray.equalsIgnoreCase("true")) 665 { 666 genStringAsCharArray = true; 667 } 668 else if (genCharArray.equalsIgnoreCase("false")) 669 { 670 genStringAsCharArray = false; 671 } 672 else 673 { 674 log.warn(Localizer.getMessage("jsp.warning.genchararray")); 675 } 676 } 677 678 String errBeanClass = 679 config.getInitParameter("errorOnUseBeanInvalidClassAttribute"); 680 if (errBeanClass != null) 681 { 682 if (errBeanClass.equalsIgnoreCase("true")) 683 { 684 errorOnUseBeanInvalidClassAttribute = true; 685 } 686 else if (errBeanClass.equalsIgnoreCase("false")) 687 { 688 errorOnUseBeanInvalidClassAttribute = false; 689 } 690 else 691 { 692 log.warn(Localizer.getMessage("jsp.warning.errBean")); 693 } 694 } 695 696 String ieClassId = config.getInitParameter("ieClassId"); 697 if (ieClassId != null) 698 this.ieClassId = ieClassId; 699 700 String classpath = config.getInitParameter("classpath"); 701 if (classpath != null) 702 this.classpath = classpath; 703 704 707 String dir = config.getInitParameter("scratchdir"); 708 if (dir != null) 709 { 710 scratchDir = new File (dir); 711 } 712 else 713 { 714 scratchDir = (File ) context.getAttribute(Constants.TMP_DIR); 716 if (scratchDir == null) 717 { 718 dir = System.getProperty("java.io.tmpdir"); 721 if (dir != null) 722 scratchDir = new File (dir); 723 } 724 } 725 if (this.scratchDir == null) 726 { 727 log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir")); 728 return; 729 } 730 731 if (!(scratchDir.exists() && scratchDir.canRead() && 732 scratchDir.canWrite() && scratchDir.isDirectory())) 733 log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", 734 scratchDir.getAbsolutePath())); 735 736 this.compiler = config.getInitParameter("compiler"); 737 738 String compilerTargetVM = config.getInitParameter("compilerTargetVM"); 739 if (compilerTargetVM != null) 740 { 741 this.compilerTargetVM = compilerTargetVM; 742 } 743 744 String compilerSourceVM = config.getInitParameter("compilerSourceVM"); 745 if (compilerSourceVM != null) 746 { 747 this.compilerSourceVM = compilerSourceVM; 748 } 749 750 String javaEncoding = config.getInitParameter("javaEncoding"); 751 if (javaEncoding != null) 752 { 753 this.javaEncoding = javaEncoding; 754 } 755 756 String compilerClassName = config.getInitParameter("compilerClassName"); 757 if(compilerClassName != null) 758 { 759 this.compilerClassName = compilerClassName; 760 } 761 762 String fork = config.getInitParameter("fork"); 763 if (fork != null) 764 { 765 if (fork.equalsIgnoreCase("true")) 766 { 767 this.fork = true; 768 } 769 else if (fork.equalsIgnoreCase("false")) 770 { 771 this.fork = false; 772 } 773 else 774 { 775 log.warn(Localizer.getMessage("jsp.warning.fork")); 776 } 777 } 778 779 String xpoweredBy = config.getInitParameter("xpoweredBy"); 780 if (xpoweredBy != null) 781 { 782 if (xpoweredBy.equalsIgnoreCase("true")) 783 { 784 this.xpoweredBy = true; 785 } 786 else if (xpoweredBy.equalsIgnoreCase("false")) 787 { 788 this.xpoweredBy = false; 789 } 790 else 791 { 792 log.warn(Localizer.getMessage("jsp.warning.xpoweredBy")); 793 } 794 } 795 796 799 String base = "tagLibJar"; 800 ArrayList tldJars = new ArrayList (); 801 int count = 0; 802 String jarPath = null; 803 do 804 { 805 String name = base + count; 806 jarPath = config.getInitParameter(name); 807 if( jarPath != null ) 808 tldJars.add(jarPath); 809 count ++; 810 } while( jarPath != null ); 811 812 tldLocationsCache = new TagLibCache(context, tldJars); 813 814 jspConfig = new JspConfig(context); 816 817 tagPluginManager = new TagPluginManager(context); 819 } 820 821 } 822 | Popular Tags |