1 17 18 package org.apache.jasper; 19 20 import java.io.File ; 21 import java.util.*; 22 23 import javax.servlet.ServletConfig ; 24 import javax.servlet.ServletContext ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.jasper.compiler.TldLocationsCache; 29 import org.apache.jasper.compiler.JspConfig; 30 import org.apache.jasper.compiler.TagPluginManager; 31 import org.apache.jasper.compiler.Localizer; 32 import org.apache.jasper.xmlparser.ParserUtils; 33 34 41 public final class EmbeddedServletOptions implements Options { 42 43 private Log log = LogFactory.getLog(EmbeddedServletOptions.class); 45 46 private Properties settings = new Properties(); 47 48 51 private boolean development = true; 52 53 56 public boolean fork = true; 57 58 61 private boolean keepGenerated = true; 62 63 66 private boolean trimSpaces = false; 67 68 71 private boolean isPoolingEnabled = true; 72 73 78 private boolean mappedFile = true; 79 80 85 private boolean sendErrorToClient = false; 86 87 90 private boolean classDebugInfo = true; 91 92 95 private int checkInterval = 0; 96 97 100 private boolean isSmapSuppressed = false; 101 102 105 private boolean isSmapDumped = false; 106 107 110 private boolean genStringAsCharArray = false; 111 112 private boolean errorOnUseBeanInvalidClassAttribute = true; 113 114 118 private File scratchDir; 119 120 125 private String ieClassId = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"; 126 127 130 private String classpath = null; 131 132 135 private String compiler = null; 136 137 140 private String compilerTargetVM = "1.5"; 141 142 145 private String compilerSourceVM = "1.5"; 146 147 150 private String compilerClassName = null; 151 152 155 private TldLocationsCache tldLocationsCache = null; 156 157 160 private JspConfig jspConfig = null; 161 162 165 private TagPluginManager tagPluginManager = null; 166 167 171 private String javaEncoding = "UTF8"; 172 173 176 private int modificationTestInterval = 4; 177 178 181 private boolean xpoweredBy; 182 183 187 private boolean displaySourceFragment = true; 188 189 190 public String getProperty(String name ) { 191 return settings.getProperty( name ); 192 } 193 194 public void setProperty(String name, String value ) { 195 if (name != null && value != null){ 196 settings.setProperty( name, value ); 197 } 198 } 199 200 203 public boolean getKeepGenerated() { 204 return keepGenerated; 205 } 206 207 210 public boolean getTrimSpaces() { 211 return trimSpaces; 212 } 213 214 public boolean isPoolingEnabled() { 215 return isPoolingEnabled; 216 } 217 218 221 public boolean getMappedFile() { 222 return mappedFile; 223 } 224 225 228 public boolean getSendErrorToClient() { 229 return sendErrorToClient; 230 } 231 232 235 public boolean getClassDebugInfo() { 236 return classDebugInfo; 237 } 238 239 242 public int getCheckInterval() { 243 return checkInterval; 244 } 245 246 249 public int getModificationTestInterval() { 250 return modificationTestInterval; 251 } 252 253 256 public boolean getDevelopment() { 257 return development; 258 } 259 260 263 public boolean isSmapSuppressed() { 264 return isSmapSuppressed; 265 } 266 267 270 public boolean isSmapDumped() { 271 return isSmapDumped; 272 } 273 274 277 public boolean genStringAsCharArray() { 278 return this.genStringAsCharArray; 279 } 280 281 284 public String getIeClassId() { 285 return ieClassId; 286 } 287 288 291 public File getScratchDir() { 292 return scratchDir; 293 } 294 295 299 public String getClassPath() { 300 return classpath; 301 } 302 303 306 public boolean isXpoweredBy() { 307 return xpoweredBy; 308 } 309 310 313 public String getCompiler() { 314 return compiler; 315 } 316 317 320 public String getCompilerTargetVM() { 321 return compilerTargetVM; 322 } 323 324 327 public String getCompilerSourceVM() { 328 return compilerSourceVM; 329 } 330 331 334 public String getCompilerClassName() { 335 return compilerClassName; 336 } 337 338 public boolean getErrorOnUseBeanInvalidClassAttribute() { 339 return errorOnUseBeanInvalidClassAttribute; 340 } 341 342 public void setErrorOnUseBeanInvalidClassAttribute(boolean b) { 343 errorOnUseBeanInvalidClassAttribute = b; 344 } 345 346 public TldLocationsCache getTldLocationsCache() { 347 return tldLocationsCache; 348 } 349 350 public void setTldLocationsCache( TldLocationsCache tldC ) { 351 tldLocationsCache = tldC; 352 } 353 354 public String getJavaEncoding() { 355 return javaEncoding; 356 } 357 358 public boolean getFork() { 359 return fork; 360 } 361 362 public JspConfig getJspConfig() { 363 return jspConfig; 364 } 365 366 public TagPluginManager getTagPluginManager() { 367 return tagPluginManager; 368 } 369 370 public boolean isCaching() { 371 return false; 372 } 373 374 public Map getCache() { 375 return null; 376 } 377 378 382 public boolean getDisplaySourceFragment() { 383 return displaySourceFragment; 384 } 385 386 390 public EmbeddedServletOptions(ServletConfig config, 391 ServletContext context) { 392 393 try { 395 if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) { 396 compilerSourceVM = compilerTargetVM = "1.5"; 397 } else { 398 compilerSourceVM = compilerTargetVM = "1.4"; 399 } 400 } catch (NumberFormatException e) { 401 } 403 404 Enumeration enumeration=config.getInitParameterNames(); 405 while( enumeration.hasMoreElements() ) { 406 String k=(String )enumeration.nextElement(); 407 String v=config.getInitParameter( k ); 408 setProperty( k, v); 409 } 410 411 String validating=config.getInitParameter( "validating"); 413 if( "false".equals( validating )) ParserUtils.validating=false; 414 415 String keepgen = config.getInitParameter("keepgenerated"); 416 if (keepgen != null) { 417 if (keepgen.equalsIgnoreCase("true")) { 418 this.keepGenerated = true; 419 } else if (keepgen.equalsIgnoreCase("false")) { 420 this.keepGenerated = false; 421 } else { 422 if (log.isWarnEnabled()) { 423 log.warn(Localizer.getMessage("jsp.warning.keepgen")); 424 } 425 } 426 } 427 428 429 String trimsp = config.getInitParameter("trimSpaces"); 430 if (trimsp != null) { 431 if (trimsp.equalsIgnoreCase("true")) { 432 trimSpaces = true; 433 } else if (trimsp.equalsIgnoreCase("false")) { 434 trimSpaces = false; 435 } else { 436 if (log.isWarnEnabled()) { 437 log.warn(Localizer.getMessage("jsp.warning.trimspaces")); 438 } 439 } 440 } 441 442 this.isPoolingEnabled = true; 443 String poolingEnabledParam 444 = config.getInitParameter("enablePooling"); 445 if (poolingEnabledParam != null 446 && !poolingEnabledParam.equalsIgnoreCase("true")) { 447 if (poolingEnabledParam.equalsIgnoreCase("false")) { 448 this.isPoolingEnabled = false; 449 } else { 450 if (log.isWarnEnabled()) { 451 log.warn(Localizer.getMessage("jsp.warning.enablePooling")); 452 } 453 } 454 } 455 456 String mapFile = config.getInitParameter("mappedfile"); 457 if (mapFile != null) { 458 if (mapFile.equalsIgnoreCase("true")) { 459 this.mappedFile = true; 460 } else if (mapFile.equalsIgnoreCase("false")) { 461 this.mappedFile = false; 462 } else { 463 if (log.isWarnEnabled()) { 464 log.warn(Localizer.getMessage("jsp.warning.mappedFile")); 465 } 466 } 467 } 468 469 String senderr = config.getInitParameter("sendErrToClient"); 470 if (senderr != null) { 471 if (senderr.equalsIgnoreCase("true")) { 472 this.sendErrorToClient = true; 473 } else if (senderr.equalsIgnoreCase("false")) { 474 this.sendErrorToClient = false; 475 } else { 476 if (log.isWarnEnabled()) { 477 log.warn(Localizer.getMessage("jsp.warning.sendErrToClient")); 478 } 479 } 480 } 481 482 String debugInfo = config.getInitParameter("classdebuginfo"); 483 if (debugInfo != null) { 484 if (debugInfo.equalsIgnoreCase("true")) { 485 this.classDebugInfo = true; 486 } else if (debugInfo.equalsIgnoreCase("false")) { 487 this.classDebugInfo = false; 488 } else { 489 if (log.isWarnEnabled()) { 490 log.warn(Localizer.getMessage("jsp.warning.classDebugInfo")); 491 } 492 } 493 } 494 495 String checkInterval = config.getInitParameter("checkInterval"); 496 if (checkInterval != null) { 497 try { 498 this.checkInterval = Integer.parseInt(checkInterval); 499 if (this.checkInterval == 0) { 500 this.checkInterval = 300; 501 if (log.isWarnEnabled()) { 502 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 503 } 504 } 505 } catch(NumberFormatException ex) { 506 if (log.isWarnEnabled()) { 507 log.warn(Localizer.getMessage("jsp.warning.checkInterval")); 508 } 509 } 510 } 511 512 String modificationTestInterval = config.getInitParameter("modificationTestInterval"); 513 if (modificationTestInterval != null) { 514 try { 515 this.modificationTestInterval = Integer.parseInt(modificationTestInterval); 516 } catch(NumberFormatException ex) { 517 if (log.isWarnEnabled()) { 518 log.warn(Localizer.getMessage("jsp.warning.modificationTestInterval")); 519 } 520 } 521 } 522 523 String development = config.getInitParameter("development"); 524 if (development != null) { 525 if (development.equalsIgnoreCase("true")) { 526 this.development = true; 527 } else if (development.equalsIgnoreCase("false")) { 528 this.development = false; 529 } else { 530 if (log.isWarnEnabled()) { 531 log.warn(Localizer.getMessage("jsp.warning.development")); 532 } 533 } 534 } 535 536 String suppressSmap = config.getInitParameter("suppressSmap"); 537 if (suppressSmap != null) { 538 if (suppressSmap.equalsIgnoreCase("true")) { 539 isSmapSuppressed = true; 540 } else if (suppressSmap.equalsIgnoreCase("false")) { 541 isSmapSuppressed = false; 542 } else { 543 if (log.isWarnEnabled()) { 544 log.warn(Localizer.getMessage("jsp.warning.suppressSmap")); 545 } 546 } 547 } 548 549 String dumpSmap = config.getInitParameter("dumpSmap"); 550 if (dumpSmap != null) { 551 if (dumpSmap.equalsIgnoreCase("true")) { 552 isSmapDumped = true; 553 } else if (dumpSmap.equalsIgnoreCase("false")) { 554 isSmapDumped = false; 555 } else { 556 if (log.isWarnEnabled()) { 557 log.warn(Localizer.getMessage("jsp.warning.dumpSmap")); 558 } 559 } 560 } 561 562 String genCharArray = config.getInitParameter("genStrAsCharArray"); 563 if (genCharArray != null) { 564 if (genCharArray.equalsIgnoreCase("true")) { 565 genStringAsCharArray = true; 566 } else if (genCharArray.equalsIgnoreCase("false")) { 567 genStringAsCharArray = false; 568 } else { 569 if (log.isWarnEnabled()) { 570 log.warn(Localizer.getMessage("jsp.warning.genchararray")); 571 } 572 } 573 } 574 575 String errBeanClass = 576 config.getInitParameter("errorOnUseBeanInvalidClassAttribute"); 577 if (errBeanClass != null) { 578 if (errBeanClass.equalsIgnoreCase("true")) { 579 errorOnUseBeanInvalidClassAttribute = true; 580 } else if (errBeanClass.equalsIgnoreCase("false")) { 581 errorOnUseBeanInvalidClassAttribute = false; 582 } else { 583 if (log.isWarnEnabled()) { 584 log.warn(Localizer.getMessage("jsp.warning.errBean")); 585 } 586 } 587 } 588 589 String ieClassId = config.getInitParameter("ieClassId"); 590 if (ieClassId != null) 591 this.ieClassId = ieClassId; 592 593 String classpath = config.getInitParameter("classpath"); 594 if (classpath != null) 595 this.classpath = classpath; 596 597 600 String dir = config.getInitParameter("scratchdir"); 601 if (dir != null) { 602 scratchDir = new File (dir); 603 } else { 604 scratchDir = (File ) context.getAttribute(Constants.TMP_DIR); 606 if (scratchDir == null) { 607 dir = System.getProperty("java.io.tmpdir"); 610 if (dir != null) 611 scratchDir = new File (dir); 612 } 613 } 614 if (this.scratchDir == null) { 615 log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir")); 616 return; 617 } 618 619 if (!(scratchDir.exists() && scratchDir.canRead() && 620 scratchDir.canWrite() && scratchDir.isDirectory())) 621 log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", 622 scratchDir.getAbsolutePath())); 623 624 this.compiler = config.getInitParameter("compiler"); 625 626 String compilerTargetVM = config.getInitParameter("compilerTargetVM"); 627 if(compilerTargetVM != null) { 628 this.compilerTargetVM = compilerTargetVM; 629 } 630 631 String compilerSourceVM = config.getInitParameter("compilerSourceVM"); 632 if(compilerSourceVM != null) { 633 this.compilerSourceVM = compilerSourceVM; 634 } 635 636 String javaEncoding = config.getInitParameter("javaEncoding"); 637 if (javaEncoding != null) { 638 this.javaEncoding = javaEncoding; 639 } 640 641 String compilerClassName = config.getInitParameter("compilerClassName"); 642 if (compilerClassName != null) { 643 this.compilerClassName = compilerClassName; 644 } 645 646 String fork = config.getInitParameter("fork"); 647 if (fork != null) { 648 if (fork.equalsIgnoreCase("true")) { 649 this.fork = true; 650 } else if (fork.equalsIgnoreCase("false")) { 651 this.fork = false; 652 } else { 653 if (log.isWarnEnabled()) { 654 log.warn(Localizer.getMessage("jsp.warning.fork")); 655 } 656 } 657 } 658 659 String xpoweredBy = config.getInitParameter("xpoweredBy"); 660 if (xpoweredBy != null) { 661 if (xpoweredBy.equalsIgnoreCase("true")) { 662 this.xpoweredBy = true; 663 } else if (xpoweredBy.equalsIgnoreCase("false")) { 664 this.xpoweredBy = false; 665 } else { 666 if (log.isWarnEnabled()) { 667 log.warn(Localizer.getMessage("jsp.warning.xpoweredBy")); 668 } 669 } 670 } 671 672 String displaySourceFragment = config.getInitParameter("displaySourceFragment"); 673 if (displaySourceFragment != null) { 674 if (displaySourceFragment.equalsIgnoreCase("true")) { 675 this.displaySourceFragment = true; 676 } else if (displaySourceFragment.equalsIgnoreCase("false")) { 677 this.displaySourceFragment = false; 678 } else { 679 if (log.isWarnEnabled()) { 680 log.warn(Localizer.getMessage("jsp.warning.displaySourceFragment")); 681 } 682 } 683 } 684 685 tldLocationsCache = new TldLocationsCache(context); 688 689 jspConfig = new JspConfig(context); 691 692 tagPluginManager = new TagPluginManager(context); 694 } 695 696 } 697 698 | Popular Tags |