1 14 15 package com.sun.facelets; 16 17 import java.io.FileNotFoundException ; 18 import java.io.IOException ; 19 import java.io.Writer ; 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Locale ; 27 import java.util.Map ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 import javax.el.ELException; 32 import javax.faces.FacesException; 33 import javax.faces.application.StateManager; 34 import javax.faces.application.ViewHandler; 35 import javax.faces.component.UIComponent; 36 import javax.faces.component.UIViewRoot; 37 import javax.faces.context.ExternalContext; 38 import javax.faces.context.FacesContext; 39 import javax.faces.context.ResponseWriter; 40 import javax.faces.render.RenderKit; 41 import javax.portlet.PortletResponse; 42 import javax.servlet.ServletRequest ; 43 import javax.servlet.ServletResponse ; 44 import javax.servlet.http.HttpServletRequest ; 45 import javax.servlet.http.HttpServletResponse ; 46 47 import com.sun.facelets.compiler.Compiler; 48 import com.sun.facelets.compiler.SAXCompiler; 49 import com.sun.facelets.compiler.TagLibraryConfig; 50 import com.sun.facelets.impl.DefaultFaceletFactory; 51 import com.sun.facelets.impl.DefaultResourceResolver; 52 import com.sun.facelets.impl.ResourceResolver; 53 import com.sun.facelets.tag.TagDecorator; 54 import com.sun.facelets.tag.TagLibrary; 55 import com.sun.facelets.tag.jsf.ComponentSupport; 56 import com.sun.facelets.tag.ui.UIDebug; 57 import com.sun.facelets.util.DevTools; 58 import com.sun.facelets.util.FacesAPI; 59 import com.sun.facelets.util.FastWriter; 60 import com.sun.facelets.util.Resource; 61 62 69 public class FaceletViewHandler extends ViewHandler { 70 71 protected final static Logger log = Logger 72 .getLogger("facelets.viewhandler"); 73 74 public final static long DEFAULT_REFRESH_PERIOD = 2; 75 76 public final static String PARAM_REFRESH_PERIO = "facelets.REFRESH_PERIOD"; 77 78 public final static String PARAM_SKIP_COMMENTS = "facelets.SKIP_COMMENTS"; 79 80 108 public final static String PARAM_VIEW_MAPPINGS = "facelets.VIEW_MAPPINGS"; 109 110 public final static String PARAM_LIBRARIES = "facelets.LIBRARIES"; 111 112 public final static String PARAM_DECORATORS = "facelets.DECORATORS"; 113 114 public final static String PARAM_DEVELOPMENT = "facelets.DEVELOPMENT"; 115 116 public final static String PARAM_RESOURCE_RESOLVER = "facelets.RESOURCE_RESOLVER"; 117 118 public final static String PARAM_BUILD_BEFORE_RESTORE = "facelets.BUILD_BEFORE_RESTORE"; 119 120 public final static String PARAM_BUFFER_SIZE = "facelets.BUFFER_SIZE"; 121 122 private final static String STATE_KEY = "~facelets.VIEW_STATE~"; 123 124 private final static int STATE_KEY_LEN = STATE_KEY.length(); 125 126 private final static Object STATE_NULL = new Object (); 127 128 private final ViewHandler parent; 129 130 private boolean developmentMode = false; 131 132 private boolean buildBeforeRestore = false; 133 134 private int bufferSize; 135 136 private String defaultSuffix; 137 138 private FaceletFactory faceletFactory; 139 140 private String [] extensionsArray; 142 143 private String [] prefixesArray; 145 146 149 public FaceletViewHandler(ViewHandler parent) { 150 this.parent = parent; 151 } 152 153 156 protected void initialize(FacesContext context) { 157 synchronized (this) { 158 if (this.faceletFactory == null) { 159 log.fine("Initializing"); 160 Compiler c = this.createCompiler(); 161 this.initializeCompiler(c); 162 this.faceletFactory = this.createFaceletFactory(c); 163 164 this.initializeMappings(context); 165 this.initializeMode(context); 166 this.initializeBuffer(context); 167 168 log.fine("Initialization Successful"); 169 } 170 } 171 } 172 173 private void initializeMode(FacesContext context) { 174 ExternalContext external = context.getExternalContext(); 175 String param = external.getInitParameter(PARAM_DEVELOPMENT); 176 this.developmentMode = "true".equals(param); 177 178 String restoreMode = external 179 .getInitParameter(PARAM_BUILD_BEFORE_RESTORE); 180 this.buildBeforeRestore = "true".equals(restoreMode); 181 } 182 183 private void initializeBuffer(FacesContext context) { 184 ExternalContext external = context.getExternalContext(); 185 String param = external.getInitParameter(PARAM_BUFFER_SIZE); 186 this.bufferSize = (param != null && !"".equals(param)) ? Integer 187 .parseInt(param) : -1; 188 } 189 190 193 private void initializeMappings(FacesContext context) { 194 ExternalContext external = context.getExternalContext(); 195 String viewMappings = external.getInitParameter(PARAM_VIEW_MAPPINGS); 196 if ((viewMappings != null) && (viewMappings.length() > 0)) { 197 String [] mappingsArray = viewMappings.split(";"); 198 199 List extensionsList = new ArrayList (mappingsArray.length); 200 List prefixesList = new ArrayList (mappingsArray.length); 201 202 for (int i = 0; i < mappingsArray.length; i++) { 203 String mapping = mappingsArray[i].trim(); 204 int mappingLength = mapping.length(); 205 if (mappingLength <= 1) { 206 continue; 207 } 208 209 if (mapping.charAt(0) == '*') { 210 extensionsList.add(mapping.substring(1)); 211 } else if (mapping.charAt(mappingLength - 1) == '*') { 212 prefixesList.add(mapping.substring(0, mappingLength - 1)); 213 } 214 } 215 216 extensionsArray = new String [extensionsList.size()]; 217 extensionsList.toArray(extensionsArray); 218 219 prefixesArray = new String [prefixesList.size()]; 220 prefixesList.toArray(prefixesArray); 221 } 222 } 223 224 protected FaceletFactory createFaceletFactory(Compiler c) { 225 226 long refreshPeriod = DEFAULT_REFRESH_PERIOD; 228 FacesContext ctx = FacesContext.getCurrentInstance(); 229 String userPeriod = ctx.getExternalContext().getInitParameter( 230 PARAM_REFRESH_PERIO); 231 if (userPeriod != null && userPeriod.length() > 0) { 232 refreshPeriod = Long.parseLong(userPeriod); 233 } 234 235 ResourceResolver resolver = new DefaultResourceResolver(); 237 String resolverName = ctx.getExternalContext().getInitParameter( 238 PARAM_RESOURCE_RESOLVER); 239 if (resolverName != null && resolverName.length() > 0) { 240 try { 241 resolver = (ResourceResolver) Class.forName(resolverName, true, 242 Thread.currentThread().getContextClassLoader()) 243 .newInstance(); 244 } catch (Exception e) { 245 throw new FacesException("Error Initializing ResourceResolver[" 246 + resolverName + "]", e); 247 } 248 } 249 250 return new DefaultFaceletFactory(c, resolver, refreshPeriod); 252 } 253 254 protected Compiler createCompiler() { 255 return new SAXCompiler(); 256 } 257 258 protected void initializeCompiler(Compiler c) { 259 FacesContext ctx = FacesContext.getCurrentInstance(); 260 ExternalContext ext = ctx.getExternalContext(); 261 262 String libParam = ext.getInitParameter(PARAM_LIBRARIES); 264 if (libParam != null) { 265 libParam = libParam.trim(); 266 String [] libs = libParam.split(";"); 267 URL src; 268 TagLibrary libObj; 269 for (int i = 0; i < libs.length; i++) { 270 try { 271 src = ext.getResource(libs[i].trim()); 272 if (src == null) { 273 throw new FileNotFoundException (libs[i]); 274 } 275 libObj = TagLibraryConfig.create(src); 276 c.addTagLibrary(libObj); 277 log.fine("Successfully Loaded Library: " + libs[i]); 278 } catch (IOException e) { 279 log.log(Level.SEVERE, "Error Loading Library: " + libs[i], 280 e); 281 } 282 } 283 } 284 285 String decParam = ext.getInitParameter(PARAM_DECORATORS); 287 if (decParam != null) { 288 decParam = decParam.trim(); 289 String [] decs = decParam.split(";"); 290 TagDecorator decObj; 291 for (int i = 0; i < decs.length; i++) { 292 try { 293 decObj = (TagDecorator) Class.forName(decs[i]) 294 .newInstance(); 295 c.addTagDecorator(decObj); 296 log.fine("Successfully Loaded Decorator: " + decs[i]); 297 } catch (Exception e) { 298 log.log(Level.SEVERE, 299 "Error Loading Decorator: " + decs[i], e); 300 } 301 } 302 } 303 304 String skipParam = ext.getInitParameter(PARAM_SKIP_COMMENTS); 306 if (skipParam != null && "true".equals(skipParam)) { 307 c.setTrimmingComments(true); 308 } 309 } 310 311 public UIViewRoot restoreView(FacesContext context, String viewId) { 312 System.out.println("FaceletViewHandler.restoreView() viewId: " + viewId); 313 if (UIDebug.debugRequest(context)) { 314 return new UIViewRoot(); 315 } 316 317 if (!this.buildBeforeRestore || !handledByFacelets(viewId)) { 318 UIViewRoot root = this.parent.restoreView(context, viewId); 319 System.out.println("FaceletViewHandler.restoreView() !this.buildBeforeRestore || !handledByFacelets(viewId) -> parent.restoreView: " + (root == null ? "null" : Integer.toString(root.getChildCount()))); 320 return root; 321 } 322 323 if (this.faceletFactory == null) { 324 this.initialize(context); 325 } 326 327 System.out.println("FaceletViewHandler.restoreView() FacesAPI.version: " + FacesAPI.getVersion() + " isPostback11: " + isPostback11(context)); 332 if (FacesAPI.getVersion() < 12) { 333 if (!isPostback11(context)) { 334 System.out.println("FaceletViewHandler.restoreView() FacesAPI.version < 12 && !isPostback11 -> return null"); 335 return null; 336 } 337 } 338 339 ViewHandler outerViewHandler = context.getApplication() 340 .getViewHandler(); 341 String renderKitId = outerViewHandler.calculateRenderKitId(context); 342 343 System.out.println("FaceletViewHandler.restoreView() Before createView"); 344 UIViewRoot viewRoot = createView(context, viewId); 345 System.out.println("FaceletViewHandler.restoreView() After createView viewRoot: " + (viewRoot == null ? "null" : Integer.toString(viewRoot.getChildCount()))); 346 context.setViewRoot(viewRoot); 347 try { 348 System.out.println("FaceletViewHandler.restoreView() Before buildView"); 349 this.buildView(context, viewRoot); 350 System.out.println("FaceletViewHandler.restoreView() After buildView viewRoot: " + (viewRoot == null ? "null" : Integer.toString(viewRoot.getChildCount()))); 351 } catch (IOException ioe) { 352 log.log(Level.SEVERE, "Error Building View", ioe); 353 } 354 context.getApplication().getStateManager().restoreView(context, viewId, 355 renderKitId); 356 System.out.println("FaceletViewHandler.restoreView() return viewRoot: " + (viewRoot == null ? "null" : Integer.toString(viewRoot.getChildCount()))); 357 return viewRoot; 358 } 359 360 365 protected ViewHandler getWrapped() { 366 return this.parent; 367 } 368 369 protected ResponseWriter createResponseWriter(FacesContext context) 370 throws IOException , FacesException { 371 ExternalContext extContext = context.getExternalContext(); 372 RenderKit renderKit = context.getRenderKit(); 373 if (renderKit == null) { 376 String id = context.getViewRoot().getRenderKitId(); 377 throw new IllegalStateException ( 378 "No render kit was available for id \"" + id + "\""); 379 } 380 381 ServletResponse response = (ServletResponse ) extContext.getResponse(); 382 383 if (this.bufferSize != -1) { 385 response.setBufferSize(this.bufferSize); 386 } 387 388 String contentType = null; 390 391 String encoding = null; 393 394 ResponseWriter writer = renderKit.createResponseWriter( 398 NullWriter.Instance, contentType, encoding); 399 400 contentType = getResponseContentType(context, writer.getContentType()); 401 encoding = getResponseEncoding(context, writer.getCharacterEncoding()); 402 403 response.setContentType(contentType + "; charset=" + encoding); 405 406 409 writer = writer.cloneWithWriter(response.getWriter()); 411 412 return writer; 413 } 414 415 422 protected String getResponseEncoding(FacesContext context, String orig) { 423 String encoding = orig; 424 425 Map m = context.getExternalContext().getRequestMap(); 427 Map sm = context.getExternalContext().getSessionMap(); 428 429 if (m.containsKey("facelets.Encoding")) { 431 encoding = (String ) m.get("facelets.Encoding"); 432 if (log.isLoggable(Level.FINEST)) { 433 log.finest("Facelet specified alternate encoding '" + encoding 434 + "'"); 435 } 436 sm.put(CHARACTER_ENCODING_KEY, encoding); 437 } 438 439 Object request = context.getExternalContext().getRequest(); 441 if (encoding == null && request instanceof ServletRequest ) { 442 encoding = ((ServletRequest ) request).getCharacterEncoding(); 443 } 444 445 if (encoding == null) { 447 encoding = (String ) sm.get(CHARACTER_ENCODING_KEY); 448 if (log.isLoggable(Level.FINEST)) { 449 log.finest("Session specified alternate encoding '" + encoding 450 + "'"); 451 } 452 } 453 454 if (encoding == null) { 456 encoding = "UTF-8"; 457 if (log.isLoggable(Level.FINEST)) { 458 log 459 .finest("ResponseWriter created had a null CharacterEncoding, defaulting to UTF-8"); 460 } 461 } 462 463 return encoding; 464 } 465 466 473 protected String getResponseContentType(FacesContext context, String orig) { 474 String contentType = orig; 475 476 Map m = context.getExternalContext().getRequestMap(); 478 if (m.containsKey("facelets.ContentType")) { 479 contentType = (String ) m.get("facelets.ContentType"); 480 if (log.isLoggable(Level.FINEST)) { 481 log.finest("Facelet specified alternate contentType '" 482 + contentType + "'"); 483 } 484 } 485 486 if (contentType == null) { 488 contentType = "text/html"; 489 if (log.isLoggable(Level.FINEST)) { 490 log 491 .finest("ResponseWriter created had a null ContentType, defaulting to text/html"); 492 } 493 } 494 495 return contentType; 496 } 497 498 protected void buildView(FacesContext context, UIViewRoot viewToRender) 499 throws IOException , FacesException { 500 String renderedViewId = this.getRenderedViewId(context, viewToRender 502 .getViewId()); 503 viewToRender.setViewId(renderedViewId); 504 System.out.println("FaceletViewHandler.buildView() renderedViewId: " + renderedViewId); 505 506 if (log.isLoggable(Level.FINE)) { 507 log.fine("Building View: " + renderedViewId); 508 } 509 510 Facelet f = null; 512 FaceletFactory.setInstance(this.faceletFactory); 513 try { 514 f = this.faceletFactory.getFacelet(viewToRender.getViewId()); 515 } finally { 516 FaceletFactory.setInstance(null); 517 } 518 519 long time = System.currentTimeMillis(); 521 System.out.println("FaceletViewHandler.buildView() Before apply viewToRender: " + (viewToRender == null ? "null" : Integer.toString(viewToRender.getChildCount()))); 522 f.apply(context, viewToRender); 523 System.out.println("FaceletViewHandler.buildView() After apply viewToRender: " + (viewToRender == null ? "null" : Integer.toString(viewToRender.getChildCount()))); 524 time = System.currentTimeMillis() - time; 525 if (log.isLoggable(Level.FINE)) { 526 log.fine("Took " + time + "ms to build view: " 527 + viewToRender.getViewId()); 528 } 529 } 530 531 public void renderView(FacesContext context, UIViewRoot viewToRender) 532 throws IOException , FacesException { 533 534 System.out.println("FaceletViewHandler.renderView() viewToRender: " + (viewToRender == null ? "null" : Integer.toString(viewToRender.getChildCount()))); 535 if (this.faceletFactory == null) { 537 this.initialize(context); 538 } 539 540 if (!viewToRender.isRendered()) { 542 return; 543 } 544 545 if (!handledByFacelets(viewToRender.getViewId())) { 547 System.out.println("FaceletViewHandler.renderView() !handledByFacelets: " + viewToRender.getViewId() + " -> parent.renderView"); 548 this.parent.renderView(context, viewToRender); 549 return; 550 } 551 552 if (log.isLoggable(Level.FINE)) { 554 log.fine("Rendering View: " + viewToRender.getViewId()); 555 } 556 557 StateWriter stateWriter = null; 558 try { 559 if (!this.buildBeforeRestore 567 || viewToRender.getChildren().isEmpty()) { 568 System.out.println("FaceletViewHandler.renderView() Before buildView viewToRender: " + (viewToRender == null ? "null" : Integer.toString(viewToRender.getChildCount()))); 569 this.buildView(context, viewToRender); 570 System.out.println("FaceletViewHandler.renderView() After buildView viewToRender: " + (viewToRender == null ? "null" : Integer.toString(viewToRender.getChildCount()))); 571 } 572 573 ResponseWriter origWriter = this.createResponseWriter(context); 575 stateWriter = new StateWriter(origWriter, 579 this.bufferSize != -1 ? this.bufferSize : 1024); 580 581 ResponseWriter writer = origWriter.cloneWithWriter(stateWriter); 582 context.setResponseWriter(writer); 583 584 StateManager stateMgr = context.getApplication().getStateManager(); 586 if (!stateMgr.isSavingStateInClient(context)) { 587 context.getExternalContext().getSession(true); 588 } 589 590 long time = System.currentTimeMillis(); 591 592 writer.startDocument(); 594 if (FacesAPI.getVersion() >= 12) { 595 viewToRender.encodeAll(context); 596 } else { 597 ComponentSupport.encodeRecursive(context, viewToRender); 598 } 599 writer.endDocument(); 600 601 writer.close(); 603 604 if (FacesAPI.getVersion() < 12) { 606 ComponentSupport.removeTransient(viewToRender); 607 } 608 609 boolean writtenState = stateWriter.isStateWritten(); 610 if (writtenState) { 612 String content = stateWriter.getAndResetBuffer(); 613 int end = content.indexOf(STATE_KEY); 614 if (end >= 0) { 617 Object stateObj = stateMgr.saveSerializedView(context); 619 String stateStr; 620 if (stateObj == null) { 621 stateStr = null; 622 } else { 623 stateMgr.writeState(context, 624 (StateManager.SerializedView) stateObj); 625 stateStr = stateWriter.getAndResetBuffer(); 626 } 627 628 int start = 0; 629 630 while (end != -1) { 631 origWriter.write(content, start, end - start); 632 if (stateStr != null) { 633 origWriter.write(stateStr); 634 } 635 start = end + STATE_KEY_LEN; 636 end = content.indexOf(STATE_KEY, start); 637 } 638 origWriter.write(content, start, content.length() - start); 639 } else { 642 origWriter.write(content); 643 if ((FacesAPI.getVersion() < 12) 648 && !stateMgr.isSavingStateInClient(context)) { 649 stateMgr.saveSerializedView(context); 650 } 651 } 652 } 653 654 time = System.currentTimeMillis() - time; 655 if (log.isLoggable(Level.FINE)) { 656 log.fine("Took " + time + "ms to render view: " 657 + viewToRender.getViewId()); 658 } 659 660 } catch (FileNotFoundException fnfe) { 661 this.handleFaceletNotFound(context, viewToRender.getViewId()); 662 } catch (Exception e) { 663 this.handleRenderException(context, e); 664 } finally { 665 if (stateWriter != null) 666 stateWriter.release(); 667 } 668 } 669 670 protected void handleRenderException(FacesContext context, Exception e) 671 throws IOException , ELException, FacesException { 672 Object resp = context.getExternalContext().getResponse(); 673 674 if (log.isLoggable(Level.SEVERE)) { 676 UIViewRoot root = context.getViewRoot(); 677 StringBuffer sb = new StringBuffer (64); 678 sb.append("Error Rendering View"); 679 if (root != null) { 680 sb.append('['); 681 sb.append(root.getViewId()); 682 sb.append(']'); 683 } 684 log.log(Level.SEVERE, sb.toString(), e); 685 } 686 687 if (this.developmentMode && !context.getResponseComplete() 689 && resp instanceof HttpServletResponse ) { 690 HttpServletResponse httpResp = (HttpServletResponse ) resp; 691 httpResp.reset(); 692 httpResp.setContentType("text/html; charset=UTF-8"); 693 Writer w = httpResp.getWriter(); 694 DevTools.debugHtml(w, context, e); 695 w.flush(); 696 context.responseComplete(); 697 } else if (e instanceof RuntimeException ) { 698 throw (RuntimeException ) e; 699 } else if (e instanceof IOException ) { 700 throw (IOException ) e; 701 } else { 702 throw new FacesException(e.getMessage(), e); 703 } 704 } 705 706 protected void handleFaceletNotFound(FacesContext context, String viewId) 707 throws FacesException, IOException { 708 String actualId = this.getActionURL(context, viewId); 709 Object respObj = context.getExternalContext().getResponse(); 710 if (respObj instanceof HttpServletResponse ) { 711 HttpServletResponse respHttp = (HttpServletResponse ) respObj; 712 respHttp.sendError(HttpServletResponse.SC_NOT_FOUND, actualId); 713 context.responseComplete(); 714 } 715 } 716 717 720 private boolean handledByFacelets(String viewId) { 721 if ((extensionsArray == null) && (prefixesArray == null)) { 724 return true; 725 } 726 727 if (extensionsArray != null) { 728 for (int i = 0; i < extensionsArray.length; i++) { 729 String extension = extensionsArray[i]; 730 if (viewId.endsWith(extension)) { 731 return true; 732 } 733 } 734 } 735 736 if (prefixesArray != null) { 737 for (int i = 0; i < prefixesArray.length; i++) { 738 String prefix = prefixesArray[i]; 739 if (viewId.startsWith(prefix)) { 740 return true; 741 } 742 } 743 } 744 745 return false; 746 } 747 748 public String getDefaultSuffix(FacesContext context) throws FacesException { 749 if (this.defaultSuffix == null) { 750 ExternalContext extCtx = context.getExternalContext(); 751 String viewSuffix = extCtx 752 .getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME); 753 this.defaultSuffix = (viewSuffix != null) ? viewSuffix 754 : ViewHandler.DEFAULT_SUFFIX; 755 } 756 return this.defaultSuffix; 757 } 758 759 protected String getRenderedViewId(FacesContext context, String actionId) { 760 ExternalContext extCtx = context.getExternalContext(); 761 String viewId = actionId; 762 if (extCtx.getRequestPathInfo() == null) { 763 String facesSuffix = actionId.substring(actionId.lastIndexOf('.')); 764 String viewSuffix = this.getDefaultSuffix(context); 765 viewId = actionId.replaceFirst(facesSuffix, viewSuffix); 766 } 767 if (log.isLoggable(Level.FINE)) { 768 log.fine("ActionId -> ViewId: " + actionId + " -> " + viewId); 769 } 770 return viewId; 771 } 772 773 public void writeState(FacesContext context) throws IOException { 774 if (handledByFacelets(context.getViewRoot().getViewId())) { 775 StateWriter.getCurrentInstance().writingState(); 777 context.getResponseWriter().write(STATE_KEY); 782 } else { 783 this.parent.writeState(context); 784 } 785 } 786 787 public Locale calculateLocale(FacesContext context) { 788 return this.parent.calculateLocale(context); 789 } 790 791 public String calculateRenderKitId(FacesContext context) { 792 return this.parent.calculateRenderKitId(context); 793 } 794 795 public UIViewRoot createView(FacesContext context, String viewId) { 796 if (UIDebug.debugRequest(context)) { 797 return new UIViewRoot(); 798 } 799 UIViewRoot root = this.parent.createView(context, viewId); 800 System.out.println("FaceletViewHandler.createView() root: " + (root == null ? "null" : Integer.toString(root.getChildCount()))); 801 return root; 802 } 803 804 public String getActionURL(FacesContext context, String viewId) { 805 return this.parent.getActionURL(context, viewId); 806 } 807 808 public String getResourceURL(FacesContext context, String path) { 809 return this.parent.getResourceURL(context, path); 810 } 811 812 819 static private boolean isPostback11(FacesContext context) { 820 Object reqObject = context.getExternalContext().getRequest(); 821 if (reqObject instanceof HttpServletRequest ) { 822 HttpServletRequest request = (HttpServletRequest ) reqObject; 823 824 String method = request.getMethod(); 825 826 if ("POST".equals(method) || "PUT".equals(method)) { 828 return true; 829 } 830 831 return false; 832 } else { 833 Map paramMap = context.getExternalContext() 834 .getRequestParameterMap(); 835 return !paramMap.isEmpty(); 836 } 837 } 838 839 protected static class NullWriter extends Writer { 840 841 static final NullWriter Instance = new NullWriter(); 842 843 public void write(char[] buffer) { 844 } 845 846 public void write(char[] buffer, int off, int len) { 847 } 848 849 public void write(String str) { 850 } 851 852 public void write(int c) { 853 } 854 855 public void write(String str, int off, int len) { 856 } 857 858 public void close() { 859 } 860 861 public void flush() { 862 } 863 } 864 } 865 | Popular Tags |