1 29 30 package com.caucho.jsp; 31 32 import com.caucho.java.LineMap; 33 import com.caucho.jsp.cfg.JspPropertyGroup; 34 import com.caucho.log.Log; 35 import com.caucho.server.webapp.Application; 36 import com.caucho.util.CharBuffer; 37 import com.caucho.util.CharScanner; 38 import com.caucho.util.L10N; 39 import com.caucho.util.StringCharCursor; 40 import com.caucho.vfs.Depend; 41 import com.caucho.vfs.Path; 42 import com.caucho.xml.QName; 43 44 import java.util.ArrayList ; 45 import java.util.logging.Logger ; 46 47 50 public class ParseState { 51 private static final L10N L = new L10N(ParseState.class); 52 static final Logger log = Log.open(ParseState.class); 53 54 private Application _application; 55 56 private JspPropertyGroup _jspPropertyGroup = new JspPropertyGroup(); 57 58 private boolean _isELIgnored = false; 59 private boolean _isELIgnoredSet = false; 60 private boolean _isELIgnoredDefault = true; 61 62 private boolean _isScriptingInvalid = false; 63 64 private boolean _isVelocityEnabled; 65 66 private boolean _isSession = true; 67 private boolean _isOptionalSession = false; 68 private boolean _isSessionSet = false; 69 70 private boolean _isErrorPage = false; 71 private boolean _isErrorPageSet = false; 72 73 private boolean _isAutoFlush = true; 74 private boolean _isAutoFlushSet = false; 75 76 private boolean _isThreadSafe = true; 77 private boolean _isThreadSafeSet = false; 78 79 private boolean _isTag = false; 80 private boolean _isXml = false; 81 private boolean _isForbidXml = false; 82 83 private int _buffer = 8192; 84 private boolean _isBufferSet = false; 85 86 private String _info; 87 private String _errorPage; 88 private String _contentType; 89 private String _charEncoding; 90 private String _pageEncoding; 91 private Class _extends; 92 93 private boolean _recycleTags = true; 94 private boolean _isTrimWhitespace; 95 private boolean _isDeferredSyntaxAllowedAsLiteral; 96 97 private JspResourceManager _resourceManager; 98 99 private JspBuilder _jspBuilder; 100 101 private ArrayList <String > _importList = new ArrayList <String >(); 102 103 private String _uriPwd; 104 105 private ArrayList <Depend> _depends = new ArrayList <Depend>(); 106 private LineMap _lineMap; 107 108 private Namespace _namespaces; 109 110 113 public ParseState() 114 { 115 } 116 117 120 public void setJspPropertyGroup(JspPropertyGroup group) 121 { 122 _jspPropertyGroup = group; 123 } 124 125 128 public JspPropertyGroup getJspPropertyGroup() 129 { 130 return _jspPropertyGroup; 131 } 132 133 136 public boolean isELIgnored() 137 { 138 return _isELIgnored; 139 } 140 141 144 public boolean setELIgnored(boolean isELIgnored) 145 { 146 boolean oldELIgnored = _isELIgnored; 147 148 _isELIgnored = isELIgnored; 149 _isELIgnoredDefault = false; 150 151 return (oldELIgnored == isELIgnored || ! _isELIgnoredSet); 152 } 153 154 157 public void markELIgnoredSet() 158 { 159 _isELIgnoredSet = true; 160 } 161 162 165 public void setELIgnoredDefault(boolean isELIgnored) 166 { 167 if (_isELIgnoredDefault) 168 _isELIgnored = isELIgnored; 169 } 170 171 174 public boolean isScriptingInvalid() 175 { 176 return _isScriptingInvalid; 177 } 178 179 182 public void setScriptingInvalid(boolean isScriptingInvalid) 183 { 184 _isScriptingInvalid = isScriptingInvalid; 185 } 186 187 190 public void setVelocityEnabled(boolean isVelocity) 191 { 192 _isVelocityEnabled = isVelocity; 193 } 194 195 198 public boolean isVelocityEnabled() 199 { 200 return _isVelocityEnabled; 201 } 202 203 206 public boolean isSession() 207 { 208 return _isSession; 209 } 210 211 214 public boolean isOptionalSession() 215 { 216 return _isOptionalSession; 217 } 218 219 222 public boolean setSession(boolean session) 223 { 224 boolean isSession = _isSession; 225 226 _isSession = session; 227 _isOptionalSession = session; 228 229 return (session == isSession || ! _isSessionSet); 230 } 231 232 235 public void markSessionSet() 236 { 237 _isSessionSet = true; 238 } 239 240 243 public boolean isAutoFlush() 244 { 245 return _isAutoFlush; 246 } 247 248 251 public boolean setAutoFlush(boolean autoFlush) 252 { 253 boolean isAutoFlush = _isAutoFlush; 254 255 _isAutoFlush = autoFlush; 256 257 return (autoFlush == isAutoFlush || ! _isAutoFlushSet); 258 } 259 260 263 public void markAutoFlushSet() 264 { 265 _isAutoFlushSet = true; 266 } 267 268 271 public boolean isThreadSafe() 272 { 273 return _isThreadSafe; 274 } 275 276 279 public boolean setThreadSafe(boolean threadSafe) 280 { 281 boolean isThreadSafe = _isThreadSafe; 282 283 _isThreadSafe = threadSafe; 284 285 return (threadSafe == isThreadSafe || ! _isThreadSafeSet); 286 } 287 288 291 public void markThreadSafeSet() 292 { 293 _isThreadSafeSet = true; 294 } 295 296 299 public boolean setErrorPage(boolean errorPage) 300 { 301 boolean isErrorPage = _isErrorPage; 302 303 _isErrorPage = errorPage; 304 305 return (errorPage == isErrorPage || ! _isErrorPageSet); 306 } 307 308 311 public boolean isErrorPage() 312 { 313 return _isErrorPage; 314 } 315 316 319 public void markErrorPage() 320 { 321 _isErrorPageSet = true; 322 } 323 324 327 public int getBuffer() 328 { 329 return _buffer; 330 } 331 332 335 public boolean setBuffer(int buffer) 336 { 337 int oldBuffer = _buffer; 338 339 _buffer = buffer; 340 341 return (buffer == oldBuffer || ! _isBufferSet); 342 } 343 344 347 public void markBufferSet() 348 { 349 _isBufferSet = true; 350 } 351 352 355 public void setErrorPage(String errorPage) 356 { 357 _errorPage = errorPage; 358 } 359 360 363 public String getErrorPage() 364 { 365 return _errorPage; 366 } 367 368 371 public void setContentType(String contentType) 372 { 373 _contentType = contentType; 374 } 375 376 379 public String getContentType() 380 { 381 return _contentType; 382 } 383 384 387 public void setCharEncoding(String charEncoding) 388 throws JspParseException 389 { 390 396 397 _charEncoding = charEncoding; 398 } 399 400 403 public String getCharEncoding() 404 { 405 return _charEncoding; 406 } 407 408 411 public void setPageEncoding(String pageEncoding) 412 throws JspParseException 413 { 414 if (pageEncoding == null) 415 return; 416 417 if (_pageEncoding == null 418 || _pageEncoding.equalsIgnoreCase(pageEncoding)) { 419 _pageEncoding = pageEncoding; 420 } 421 else if ("UTF-16".equalsIgnoreCase(_pageEncoding) 422 && ("UTF-16LE".equalsIgnoreCase(pageEncoding) 423 || "UTF-16BE".equalsIgnoreCase(pageEncoding))) { 424 _pageEncoding = pageEncoding; 425 } 426 else if ("UTF-16".equalsIgnoreCase(pageEncoding) 427 && ("UTF-16LE".equalsIgnoreCase(_pageEncoding) 428 || "UTF-16BE".equalsIgnoreCase(_pageEncoding))) { 429 } 430 else { 431 String oldPageEncoding = _pageEncoding; 432 433 _pageEncoding = pageEncoding; 434 435 throw new JspParseException(L.l("Cannot change page encoding to '{0}' (old value '{1}'). The page encoding may only be set once.", 436 pageEncoding, oldPageEncoding)); 437 } 438 439 } 440 441 444 public String getPageEncoding() 445 { 446 return _pageEncoding; 447 } 448 449 452 public String getInfo() 453 { 454 return _info; 455 } 456 457 460 public void setInfo(String info) 461 { 462 _info = info; 463 } 464 465 468 public Class getExtends() 469 { 470 return _extends; 471 } 472 473 476 public void setExtends(Class extendsValue) 477 { 478 _extends = extendsValue; 479 } 480 481 484 public boolean isTag() 485 { 486 return _isTag; 487 } 488 489 492 public void setTag(boolean isTag) 493 { 494 _isTag = isTag; 495 } 496 497 500 public boolean isXml() 501 { 502 return _isXml; 503 } 504 505 508 public void setXml(boolean isXml) 509 { 510 _isXml = isXml; 511 } 512 513 516 public boolean isForbidXml() 517 { 518 return _isForbidXml; 519 } 520 521 524 public void setForbidXml(boolean isForbidXml) 525 { 526 _isForbidXml = isForbidXml; 527 } 528 529 532 public boolean isPrintNullAsBlank() 533 { 534 return _jspPropertyGroup.isPrintNullAsBlank(); 535 } 536 537 540 public boolean isTrimWhitespace() 541 { 542 return _isTrimWhitespace; 543 } 544 545 548 public void setTrimWhitespace(boolean trim) 549 { 550 _isTrimWhitespace = trim; 551 } 552 553 556 public boolean isDeferredSyntaxAllowedAsLiteral() 557 { 558 return _isDeferredSyntaxAllowedAsLiteral; 559 } 560 561 564 public void setDeferredSyntaxAllowedAsLiteral(boolean trim) 565 { 566 _isDeferredSyntaxAllowedAsLiteral = trim; 567 } 568 569 572 public JspResourceManager getResourceManager() 573 { 574 return _resourceManager; 575 } 576 577 580 public void setResourceManager(JspResourceManager resourceManager) 581 { 582 _resourceManager = resourceManager; 583 } 584 585 588 public JspBuilder getBuilder() 589 { 590 return _jspBuilder; 591 } 592 593 596 public void setBuilder(JspBuilder jspBuilder) 597 { 598 _jspBuilder = jspBuilder; 599 } 600 601 private static CharScanner COMMA_DELIM_SCANNER = new CharScanner(" \t\n\r,"); 602 603 606 public void addImport(String importString) 607 throws JspParseException 608 { 609 StringCharCursor cursor = new StringCharCursor(importString); 610 CharBuffer cb = new CharBuffer(); 611 while (cursor.current() != cursor.DONE) { 612 char ch; 613 COMMA_DELIM_SCANNER.skip(cursor); 614 615 cb.clear(); 616 ch = COMMA_DELIM_SCANNER.scan(cursor, cb); 617 618 if (cb.length() != 0) { 619 String value = cb.toString(); 620 621 if (! _importList.contains(value)) 622 _importList.add(value); 623 } 624 else if (ch != cursor.DONE) 625 throw new JspParseException(L.l("`{0}' is an illegal page import directive.", 626 importString)); 627 } 628 } 629 630 633 public ArrayList <String > getImportList() 634 { 635 return _importList; 636 } 637 638 641 public void setUriPwd(String uriPwd) 642 { 643 _uriPwd = uriPwd; 644 } 645 646 649 public String getUriPwd() 650 { 651 return _uriPwd; 652 } 653 654 657 public LineMap getLineMap() 658 { 659 return _lineMap; 660 } 661 662 665 public void addDepend(Path path) 666 { 667 Depend depend = new Depend(path); 668 if (! _depends.contains(depend)) 669 _depends.add(depend); 670 } 671 672 675 public ArrayList <Depend> getDependList() 676 { 677 return _depends; 678 } 679 680 687 public Path resolvePath(String uri) 688 { 689 return getResourceManager().resolvePath(uri); 690 } 691 692 695 public void setRecycleTags(boolean recycleTags) 696 { 697 _recycleTags = recycleTags; 698 } 699 700 703 public boolean isRecycleTags() 704 { 705 return _recycleTags; 706 } 707 708 711 public QName getQName(String name) 712 { 713 int p = name.indexOf(':'); 714 715 if (p < 0) 716 return new QName(name); 717 else { 718 String prefix = name.substring(0, p); 719 String uri = Namespace.find(_namespaces, prefix); 720 721 if (uri != null) 722 return new QName(name, uri); 723 else 724 return new QName(name); 725 } 726 } 727 728 public Namespace getNamespaces() 729 { 730 return _namespaces; 731 } 732 733 736 public void pushNamespace(String prefix, String uri) 737 { 738 _namespaces = new Namespace(_namespaces, prefix, uri); 739 } 740 741 744 public void popNamespace(String prefix) 745 { 746 if (_namespaces._prefix.equals(prefix)) 747 _namespaces = _namespaces.getNext(); 748 else 749 throw new IllegalStateException (); 750 } 751 } 752 753 | Popular Tags |