1 7 22 23 package org.jboss.web.tomcat.tc5.jasper; 24 25 import java.util.Properties ; 26 import java.util.Enumeration ; 27 import java.util.ArrayList ; 28 import java.io.File ; 29 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletContext ; 32 33 import org.apache.jasper.Options; 34 import org.apache.jasper.Constants; 35 import org.apache.jasper.xmlparser.ParserUtils; 36 import org.apache.jasper.compiler.TldLocationsCache; 37 import org.apache.jasper.compiler.JspConfig; 38 import org.apache.jasper.compiler.TagPluginManager; 39 import org.apache.jasper.compiler.Localizer; 40 import org.jboss.logging.Logger; 41 42 49 public class JspServletOptions 50 implements Options 51 { 52 static Logger log = Logger.getLogger(JspServletOptions.class); 53 54 private Properties settings = new Properties (); 55 56 59 private boolean development = 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 compilerTargetVM = "1.4"; 148 149 152 private String compilerSourceVM = "1.4"; 153 154 157 private TldLocationsCache tldLocationsCache = null; 158 159 162 private JspConfig jspConfig = null; 163 164 167 private TagPluginManager tagPluginManager = null; 168 169 172 private String javaEncoding = "UTF8"; 173 174 177 private int modificationTestInterval = 4; 178 179 182 private boolean xpoweredBy; 183 184 public String getProperty(String name) 185 { 186 return settings.getProperty(name); 187 } 188 189 public void setProperty(String name, String value) 190 { 191 if (name != null && value != null) 192 { 193 settings.setProperty(name, value); 194 } 195 } 196 197 200 public boolean getKeepGenerated() 201 { 202 return keepGenerated; 203 } 204 205 208 public boolean getTrimSpaces() 209 { 210 return trimSpaces; 211 } 212 213 public boolean isPoolingEnabled() 214 { 215 return isPoolingEnabled; 216 } 217 218 221 public boolean getMappedFile() 222 { 223 return mappedFile; 224 } 225 226 229 public boolean getSendErrorToClient() 230 { 231 return sendErrorToClient; 232 } 233 234 237 public boolean getClassDebugInfo() 238 { 239 return classDebugInfo; 240 } 241 242 245 public int getCheckInterval() 246 { 247 return checkInterval; 248 } 249 250 253 public int getModificationTestInterval() 254 { 255 return modificationTestInterval; 256 } 257 258 261 public boolean getDevelopment() 262 { 263 return development; 264 } 265 266 269 public boolean isSmapSuppressed() 270 { 271 return isSmapSuppressed; 272 } 273 274 277 public boolean isSmapDumped() 278 { 279 return isSmapDumped; 280 } 281 282 285 public boolean genStringAsCharArray() 286 { 287 return this.genStringAsCharArray; 288 } 289 290 293 public String getIeClassId() 294 { 295 return ieClassId; 296 } 297 298 301 public File getScratchDir() 302 { 303 return scratchDir; 304 } 305 306 310 public String getClassPath() 311 { 312 return classpath; 313 } 314 315 318 public boolean isXpoweredBy() 319 { 320 return xpoweredBy; 321 } 322 323 326 public String getCompiler() 327 { 328 return compiler; 329 } 330 331 334 public String getCompilerTargetVM() 335 { 336 return compilerTargetVM; 337 } 338 339 342 public String getCompilerSourceVM() 343 { 344 return compilerSourceVM; 345 } 346 347 public boolean getErrorOnUseBeanInvalidClassAttribute() 348 { 349 return errorOnUseBeanInvalidClassAttribute; 350 } 351 352 public void setErrorOnUseBeanInvalidClassAttribute(boolean b) 353 { 354 errorOnUseBeanInvalidClassAttribute = b; 355 } 356 357 public TldLocationsCache getTldLocationsCache() 358 { 359 return tldLocationsCache; 360 } 361 362 public void setTldLocationsCache(TldLocationsCache tldC) 363 { 364 tldLocationsCache = tldC; 365 } 366 367 public String getJavaEncoding() 368 { 369 return javaEncoding; 370 } 371 372 public boolean getFork() 373 { 374 return fork; 375 } 376 377 public JspConfig getJspConfig() 378 { 379 return jspConfig; 380 } 381 382 public TagPluginManager getTagPluginManager() 383 { 384 return tagPluginManager; 385 } 386 387 391 public JspServletOptions(ServletConfig config, ServletContext context) 392 { 393 394 Enumeration enumeration = config.getInitParameterNames(); 395 while (enumeration.hasMoreElements()) 396 { 397 String k = (String ) enumeration.nextElement(); 398 String v = config.getInitParameter(k); 399 setProperty(k, v); 400 } 401 402 String validating = config.getInitParameter("validating"); 404 if ("false".equals(validating)) ParserUtils.validating = false; 405 406 String keepgen = config.getInitParameter("keepgenerated"); 407 if (keepgen != null) 408 { 409 if (keepgen.equalsIgnoreCase("true")) 410 { 411 this.keepGenerated = true; 412 } 413 else if (keepgen.equalsIgnoreCase("false")) 414 { 415 this.keepGenerated = false; 416 } 417 else 418 { 419 log.warn(Localizer.getMessage("jsp.warning.keepgen")); 420 } 421 } 422 423 424 String trimsp = config.getInitParameter("trimSpaces"); 425 if (trimsp != null) 426 { 427 if (trimsp.equalsIgnoreCase("true")) 428 { 429 trimSpaces = true; 430 } 431 else if (trimsp.equalsIgnoreCase("false")) 432 { 433 trimSpaces = false; 434 } 435 else 436 { 437 log.warn(Localizer.getMessage("jsp.warning.trimspaces")); 438 } 439 } 440 441 this.isPoolingEnabled = true; 442 String poolingEnabledParam 443 = config.getInitParameter("enablePooling"); 444 if (poolingEnabledParam != null 445 && !poolingEnabledParam.equalsIgnoreCase("true")) 446 { 447 if (poolingEnabledParam.equalsIgnoreCase("false")) 448 { 449 this.isPoolingEnabled = false; 450 } 451 else 452 { 453 log.warn(Localizer.getMessage("jsp.warning.enablePooling")); 454 } 455 } 456 457 String mapFile = config.getInitParameter("mappedfile"); 458 if (mapFile != null) 459 { 460 if (mapFile.equalsIgnoreCase("true")) 461 { 462 this.mappedFile = true; 463 } 464 else if (mapFile.equalsIgnoreCase("false")) 465 { 466 this.mappedFile = false; 467 } 468 else 469 { 470 log.warn(Localizer.getMessage("jsp.warning.mappedFile")); 471 } 472 } 473 474 String senderr = config.getInitParameter("sendErrToClient"); 475 if (senderr != null) 476 { 477 if (senderr.equalsIgnoreCase("true")) 478 { 479 this.sendErrorToClient = true; 480 } 481 else if (senderr.equalsIgnoreCase("false")) 482 { 483 this.sendErrorToClient = false; 484 } 485 else 486 { 487 log.warn(Localizer.getMessage("jsp.warning.sendErrToClient")); 488 } 489 } 490 491 String debugInfo = config.getInitParameter("classdebuginfo"); 492 if (debugInfo != null) 493 { 494 if (debugInfo.equalsIgnoreCase("true")) 495 { 496 this.classDebugInfo = true; 497 } 498 else if (debugInfo.equalsIgnoreCase("false")) 499 { 500 this.classDebugInfo = false; 501 } 502 else 503 { 504 log.warn(Localizer.getMessage("jsp.warning.classDebugInfo")); 505 } 506 } 507 508 String checkInterval = config.getInitParameter("checkInterval"); 509 if (checkInterval != null) 510 { 511 try 512 { 513 this.checkInterval = Integer.parseInt(checkInterval); 514 if (this.checkInterval == 0) 515 { 516 this.checkInterval = 300; 517 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 518 } 519 } 520 catch (NumberFormatException ex) 521 { 522 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 523 } 524 } 525 526 String modificationTestInterval = config.getInitParameter("modificationTestInterval"); 527 if (modificationTestInterval != null) 528 { 529 try 530 { 531 this.modificationTestInterval = Integer.parseInt(modificationTestInterval); 532 } 533 catch (NumberFormatException ex) 534 { 535 log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval")); 536 } 537 } 538 539 String development = config.getInitParameter("development"); 540 if (development != null) 541 { 542 if (development.equalsIgnoreCase("true")) 543 { 544 this.development = true; 545 } 546 else if (development.equalsIgnoreCase("false")) 547 { 548 this.development = false; 549 } 550 else 551 { 552 log.warn(Localizer.getMessage("jsp.warning.development")); 553 } 554 } 555 556 String suppressSmap = config.getInitParameter("suppressSmap"); 557 if (suppressSmap != null) 558 { 559 if (suppressSmap.equalsIgnoreCase("true")) 560 { 561 isSmapSuppressed = true; 562 } 563 else if (suppressSmap.equalsIgnoreCase("false")) 564 { 565 isSmapSuppressed = false; 566 } 567 else 568 { 569 log.warn(Localizer.getMessage("jsp.warning.suppressSmap")); 570 } 571 } 572 573 String dumpSmap = config.getInitParameter("dumpSmap"); 574 if (dumpSmap != null) 575 { 576 if (dumpSmap.equalsIgnoreCase("true")) 577 { 578 isSmapDumped = true; 579 } 580 else if (dumpSmap.equalsIgnoreCase("false")) 581 { 582 isSmapDumped = false; 583 } 584 else 585 { 586 log.warn(Localizer.getMessage("jsp.warning.dumpSmap")); 587 } 588 } 589 590 String genCharArray = config.getInitParameter("genStrAsCharArray"); 591 if (genCharArray != null) 592 { 593 if (genCharArray.equalsIgnoreCase("true")) 594 { 595 genStringAsCharArray = true; 596 } 597 else if (genCharArray.equalsIgnoreCase("false")) 598 { 599 genStringAsCharArray = false; 600 } 601 else 602 { 603 log.warn(Localizer.getMessage("jsp.warning.genchararray")); 604 } 605 } 606 607 String errBeanClass = 608 config.getInitParameter("errorOnUseBeanInvalidClassAttribute"); 609 if (errBeanClass != null) 610 { 611 if (errBeanClass.equalsIgnoreCase("true")) 612 { 613 errorOnUseBeanInvalidClassAttribute = true; 614 } 615 else if (errBeanClass.equalsIgnoreCase("false")) 616 { 617 errorOnUseBeanInvalidClassAttribute = false; 618 } 619 else 620 { 621 log.warn(Localizer.getMessage("jsp.warning.errBean")); 622 } 623 } 624 625 String ieClassId = config.getInitParameter("ieClassId"); 626 if (ieClassId != null) 627 this.ieClassId = ieClassId; 628 629 String classpath = config.getInitParameter("classpath"); 630 if (classpath != null) 631 this.classpath = classpath; 632 633 636 String dir = config.getInitParameter("scratchdir"); 637 if (dir != null) 638 { 639 scratchDir = new File (dir); 640 } 641 else 642 { 643 scratchDir = (File ) context.getAttribute(Constants.TMP_DIR); 645 if (scratchDir == null) 646 { 647 dir = System.getProperty("java.io.tmpdir"); 650 if (dir != null) 651 scratchDir = new File (dir); 652 } 653 } 654 if (this.scratchDir == null) 655 { 656 log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir")); 657 return; 658 } 659 660 if (!(scratchDir.exists() && scratchDir.canRead() && 661 scratchDir.canWrite() && scratchDir.isDirectory())) 662 log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", 663 scratchDir.getAbsolutePath())); 664 665 this.compiler = config.getInitParameter("compiler"); 666 667 String compilerTargetVM = config.getInitParameter("compilerTargetVM"); 668 if (compilerTargetVM != null) 669 { 670 this.compilerTargetVM = compilerTargetVM; 671 } 672 673 String compilerSourceVM = config.getInitParameter("compilerSourceVM"); 674 if (compilerSourceVM != null) 675 { 676 this.compilerSourceVM = compilerSourceVM; 677 } 678 679 String javaEncoding = config.getInitParameter("javaEncoding"); 680 if (javaEncoding != null) 681 { 682 this.javaEncoding = javaEncoding; 683 } 684 685 String fork = config.getInitParameter("fork"); 686 if (fork != null) 687 { 688 if (fork.equalsIgnoreCase("true")) 689 { 690 this.fork = true; 691 } 692 else if (fork.equalsIgnoreCase("false")) 693 { 694 this.fork = false; 695 } 696 else 697 { 698 log.warn(Localizer.getMessage("jsp.warning.fork")); 699 } 700 } 701 702 String xpoweredBy = config.getInitParameter("xpoweredBy"); 703 if (xpoweredBy != null) 704 { 705 if (xpoweredBy.equalsIgnoreCase("true")) 706 { 707 this.xpoweredBy = true; 708 } 709 else if (xpoweredBy.equalsIgnoreCase("false")) 710 { 711 this.xpoweredBy = false; 712 } 713 else 714 { 715 log.warn(Localizer.getMessage("jsp.warning.xpoweredBy")); 716 } 717 } 718 719 722 String base = "tagLibJar"; 723 ArrayList tldJars = new ArrayList (); 724 int count = 0; 725 String jarPath = null; 726 do 727 { 728 String name = base + count; 729 jarPath = config.getInitParameter(name); 730 if( jarPath != null ) 731 tldJars.add(jarPath); 732 count ++; 733 } while( jarPath != null ); 734 735 tldLocationsCache = new TagLibCache(context, tldJars); 736 737 jspConfig = new JspConfig(context); 739 740 tagPluginManager = new TagPluginManager(context); 742 } 743 744 } 745 | Popular Tags |