1 29 30 package com.caucho.jsp.cfg; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.types.FileSetType; 34 import com.caucho.config.types.Period; 35 import com.caucho.jsp.JspServlet; 36 import com.caucho.jsp.JspXmlServlet; 37 import com.caucho.server.dispatch.ServletMapping; 38 import com.caucho.server.dispatch.UrlMap; 39 import com.caucho.server.webapp.WebApp; 40 import com.caucho.util.L10N; 41 import com.caucho.vfs.Path; 42 43 import javax.annotation.PostConstruct; 44 import javax.servlet.ServletException ; 45 import java.util.ArrayList ; 46 import java.util.regex.Pattern ; 47 48 51 public class JspPropertyGroup { 52 private static final L10N L = new L10N(JspPropertyGroup.class); 53 54 private static int _gId; 55 56 private WebApp _webApp; 57 58 private String _id; 59 private ArrayList <String > _urlPatterns = new ArrayList <String >(); 60 private String _pageEncoding; 61 private Boolean _isELIgnored; 62 private boolean _isScriptingInvalid = false; 63 private Boolean _isXml = null; 64 private ArrayList <String > _includePrelude = new ArrayList <String >(); 65 private ArrayList <String > _includeCoda = new ArrayList <String >(); 66 67 private boolean _precompile = true; 69 private boolean _fastJstl = true; 70 private boolean _ideHack = false; 71 private boolean _velocity = false; 72 private boolean _session = true; 73 private boolean _staticEncoding = true; 74 private boolean _recycleTags = true; 75 private boolean _autoCompile = true; 76 private boolean _requireSource = false; 77 private boolean _ignoreELException = true; 78 private boolean _isValidateTaglibSchema = true; 79 private boolean _isPrintNullAsBlank = false; 80 81 private int _jspMax = 0; 82 private boolean _disableLog = true; 83 private long _dependencyCheckInterval = Long.MIN_VALUE; 84 private boolean _staticPageGeneratesClass = true; 85 86 private boolean _recompileOnError = false; 87 private FileSetType _tldFileSet; 88 89 private boolean _isTrimWhitespace = false; 90 private boolean _isDeferredSyntaxAllowedAsLiteral = false; 91 92 public JspPropertyGroup() 93 { 94 } 95 96 public JspPropertyGroup(WebApp webApp) 97 { 98 _webApp = webApp; 99 } 100 101 104 public String getId() 105 { 106 return _id; 107 } 108 109 112 public void setId(String id) 113 { 114 _id = id; 115 } 116 117 120 public void setDescription(String description) 121 { 122 } 123 124 127 public void setDisplayName(String displayName) 128 { 129 } 130 131 134 public void addURLPattern(String urlPattern) 135 { 136 _urlPatterns.add(urlPattern); 137 } 138 139 142 public void setPageEncoding(String pageEncoding) 143 { 144 _pageEncoding = pageEncoding; 145 } 146 147 150 public String getPageEncoding() 151 { 152 return _pageEncoding; 153 } 154 155 158 public void setELIgnored(boolean isELIgnored) 159 { 160 _isELIgnored = isELIgnored ? Boolean.TRUE : Boolean.FALSE;; 161 } 162 163 166 public Boolean isELIgnored() 167 { 168 return _isELIgnored; 169 } 170 171 174 public void setDependencyCheckInterval(Period period) 175 { 176 _dependencyCheckInterval = period.getPeriod(); 177 } 178 179 182 public long getDependencyCheckInterval() 183 { 184 return _dependencyCheckInterval; 185 } 186 187 190 public void setScriptingInvalid(boolean isScriptingInvalid) 191 { 192 _isScriptingInvalid = isScriptingInvalid; 193 } 194 195 198 public boolean isScriptingInvalid() 199 { 200 return _isScriptingInvalid; 201 } 202 203 206 public void setIsXml(boolean isXml) 207 { 208 _isXml = isXml ? Boolean.TRUE : Boolean.FALSE; 209 } 210 211 214 public Boolean isXml() 215 { 216 return _isXml; 217 } 218 219 222 public void addIncludePrelude(String url) 223 { 224 _includePrelude.add(url); 225 } 226 227 230 public ArrayList <String > getIncludePreludeList() 231 { 232 return _includePrelude; 233 } 234 235 238 public void addIncludeCoda(String url) 239 { 240 _includeCoda.add(url); 241 } 242 243 246 public ArrayList <String > getIncludeCodaList() 247 { 248 return _includeCoda; 249 } 250 251 253 256 public void setPrecompile(boolean precompile) 257 { 258 _precompile = precompile; 259 } 260 261 264 public boolean getPrecompile() 265 { 266 return _precompile; 267 } 268 269 272 public boolean isAutoCompile() 273 { 274 return _autoCompile; 275 } 276 277 280 public void setAutoCompile(boolean compile) 281 { 282 _autoCompile = compile; 283 } 284 285 288 public void setRequireSource(boolean requireSource) 289 { 290 _requireSource = requireSource; 291 } 292 293 296 public boolean getRequireSource() 297 { 298 return _requireSource; 299 } 300 301 304 public void setPrintNullAsBlank(boolean enable) 305 { 306 _isPrintNullAsBlank = enable; 307 } 308 309 312 public boolean isPrintNullAsBlank() 313 { 314 return _isPrintNullAsBlank; 315 } 316 317 320 public boolean isIgnoreELException() 321 { 322 return _ignoreELException; 323 } 324 325 328 public void setIgnoreELException(boolean ignore) 329 { 330 _ignoreELException = ignore; 331 } 332 333 336 public void setFastJstl(boolean fastJstl) 337 { 338 _fastJstl = fastJstl; 339 } 340 341 344 public boolean isFastJstl() 345 { 346 return _fastJstl; 347 } 348 349 352 public void setVelocityEnabled(boolean velocity) 353 { 354 _velocity = velocity; 355 } 356 357 360 public boolean isVelocityEnabled() 361 { 362 return _velocity; 363 } 364 365 368 public void setSession(boolean session) 369 { 370 _session = session; 371 } 372 373 376 public boolean isSession() 377 { 378 return _session; 379 } 380 381 384 public void setStaticEncoding(boolean staticEncoding) 385 { 386 _staticEncoding = staticEncoding; 387 } 388 389 392 public boolean isStaticEncoding() 393 { 394 return _staticEncoding; 395 } 396 397 400 public void setRecycleTags(boolean recycleTags) 401 { 402 _recycleTags = recycleTags; 403 } 404 405 408 public boolean isRecycleTags() 409 { 410 return _recycleTags; 411 } 412 413 416 public void setIdeHack(boolean ideHack) 417 { 418 _ideHack = ideHack; 419 } 420 421 424 public boolean getIdeHack() 425 { 426 return _ideHack; 427 } 428 429 432 public void setJspMax(int max) 433 throws ConfigException 434 { 435 if (max <= 0) 436 throw new ConfigException(L.l("`{0}' is too small a value for jsp-max", 437 max)); 438 439 _jspMax = max; 440 } 441 442 445 public int getJspMax() 446 { 447 return _jspMax; 448 } 449 450 453 public boolean isDisableLog() 454 { 455 return _disableLog; 456 } 457 458 461 public void setDeferredSyntaxAllowedAsLiteral(boolean isAllowed) 462 { 463 _isDeferredSyntaxAllowedAsLiteral = isAllowed; 464 } 465 466 469 public boolean isDeferredSyntaxAllowedAsLiteral() 470 { 471 return _isDeferredSyntaxAllowedAsLiteral; 472 } 473 474 477 public void setRecompileOnError(boolean recompile) 478 { 479 _recompileOnError = recompile; 480 } 481 482 485 public boolean isRecompileOnError() 486 { 487 return _recompileOnError; 488 } 489 490 493 public void setValidateTaglibSchema(boolean isValidate) 494 { 495 _isValidateTaglibSchema = isValidate; 496 } 497 498 501 public boolean isValidateTaglibSchema() 502 { 503 return _isValidateTaglibSchema; 504 } 505 506 509 public void setTldFileSet(FileSetType fileSet) 510 { 511 _tldFileSet = fileSet; 512 } 513 514 517 public FileSetType getTldFileSet() 518 { 519 return _tldFileSet; 520 } 521 522 525 public void setTldDir(Path tldDir) 526 { 527 _tldFileSet = new FileSetType(); 528 _tldFileSet.setDir(tldDir); 529 } 530 531 534 public void setStaticPageGeneratesClass(boolean generate) 535 { 536 _staticPageGeneratesClass = generate; 537 } 538 539 542 public boolean getStaticPageGeneratesClass() 543 { 544 return _staticPageGeneratesClass; 545 } 546 547 550 public boolean isTrimDirectiveWhitespaces() 551 { 552 return _isTrimWhitespace; 553 } 554 555 558 public void setTrimDirectiveWhitespaces(boolean isTrim) 559 { 560 _isTrimWhitespace = isTrim; 561 } 562 563 @PostConstruct 564 public void init() 565 throws ServletException 566 { 567 if (_webApp != null) { 568 ServletMapping mapping = new ServletMapping(); 569 mapping.setServletName("jsp-property-group-" + _gId++); 570 571 if (Boolean.TRUE.equals(_isXml)) 572 mapping.setServletClass(JspXmlServlet.class.getName()); 573 else 574 mapping.setServletClass(JspServlet.class.getName()); 575 576 for (int i = 0; i < _urlPatterns.size(); i++) { 577 mapping.addURLPattern(_urlPatterns.get(i)); 578 } 579 580 _webApp.addServletMapping(mapping); 581 } 582 } 583 584 587 public boolean match(String url) 588 { 589 if (_urlPatterns.size() == 0) 590 return true; 591 592 for (int i = 0; i < _urlPatterns.size(); i++) { 593 String urlPattern = _urlPatterns.get(i); 594 String regexpPattern = UrlMap.urlPatternToRegexpPattern(urlPattern); 595 596 if (Pattern.compile(regexpPattern).matcher(url).find()) { 597 return true; 598 } 599 } 600 601 return false; 602 } 603 } 604 | Popular Tags |