abstractrenderer.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 663 行 · 第 1/2 页

JAVA
663
字号
  /**   * Return an OutputStream that wraps the passed OutputStream, or null   * if there is no specialized writer for this request.   */  public OutputStream getOutputStream( OutputStream out,                                        RenderRequest request,                                        String namespace )    throws IOException  {    boolean doPage = (request.getAttribute(PAGE_HEADER_RENDERED) == null);    boolean doWindow = _isDecorateWindow == null                         ? !doPage                        : _isDecorateWindow.booleanValue();    if (doPage) {      beginPage(out, request, namespace);      request.setAttribute(PAGE_HEADER_RENDERED, this);    }    if (doWindow)      beginWindow(out, request, namespace);    return out;  }    /**   * Derived classes override to insert header content for a page,   * called only when beginPage() has not been called on some instance of   * AbstractRenderer for this request.   *   * <code>request.getResponseContentType()</code> can be used   * to determine the content type.   *   * request.getAttribute("javax.portlet.title") may contain a title   * for the Window, if the portlet has set one.    */  protected void beginPage( OutputStream out,                             RenderRequest request,                             String namespace )    throws IOException  {  }  /**   * Derived classes override to insert header content before a portlet   * has been rendered.   *   * <code>request.getResponseContentType()</code> is used   * to determine the content type.   *   * request.getAttribute("javax.portlet.title") may contain a title   * for the Window, if the portlet has set one.    */  protected void beginWindow( OutputStream out,                               RenderRequest request,                               String namespace )    throws IOException  {  }  /**   * Derived classes override to append footer content after a portlet   * has been rendered.   *   * <code>request.getResponseContentType()</code> can be used   * to determine the content type.   *   */  protected void endWindow( OutputStream out,                             RenderRequest request,                             String namespace )    throws IOException  {  }  /**   * Derived classes override to insert footer content for a page,   * called from  only when beginPage() has been called for the Window.   *   * <code>request.getResponseContentType()</code> can be used   * to determine the content type.   */  protected void endPage( OutputStream out,                           RenderRequest request,                           String namespace )    throws IOException  {  }  /**   * Finish with an OutputStream produced by this factory.   * This may be called even if the outputStream threw an Exception.   *   * This implementation calls endWindow() and endPage() if needed.   */  public void finish( OutputStream out,                      RenderRequest request,                      String namespace,                      boolean isDiscarded )    throws IOException  {    boolean doPage = (this == request.getAttribute(PAGE_HEADER_RENDERED));    boolean doWindow = _isDecorateWindow == null                         ? !doPage                        : _isDecorateWindow.booleanValue();    if (!isDiscarded) {      if (doWindow)        endWindow(out, request, namespace);      if (doPage)        endPage(out, request, namespace);    }    else {      if (this == request.getAttribute(PAGE_HEADER_RENDERED))        request.removeAttribute(PAGE_HEADER_RENDERED);    }  }  /**   * Return the content type to use for the response.   */  protected String getContentType(RenderRequest request)  {    return request.getResponseContentType();  }  /**   * Return the locale to use for the response.   */  protected Locale getLocale(RenderRequest request)  {    return request.getLocale();  }  /**   * Return the title for the window, or null if it has not been set.   * The title is the first of:   * <ul>   * <li>A title set by the portlet using response.setTitle()   *     or request.setAttribute("javax.portlet.title");   * <li>The value of a lookup in the windows resource bundle for   *     "javax.portlet.title" using the locale dertmined by   *     {@link #getLocale(javax.portlet.RenderRequest) getLocale(request)}.   * </ul>   */  protected String getTitle(RenderRequest request)  {   String title = (String) request.getAttribute("javax.portlet.title");   if (title == null) {     PortletConfig portletConfig       = (PortletConfig) request.getAttribute("javax.portlet.portletConfig");     Locale locale = getLocale(request);     ResourceBundle bundle = portletConfig.getResourceBundle(locale);     if (bundle != null)       title = bundle.getString("javax.portlet.title");   }   return title;  }  /**   * Return the short title for the window, or null if a title is not   * available.   *   * <ul>   * <li>A title set by the portlet using    *     request.setAttribute("javax.portlet.short-title");   * <li>A title set by the portlet using response.setTitle()   *     or request.setAttribute("javax.portlet.title");   * <li>The value of a lookup in the windows resource bundle for   *     "javax.portlet.short-title" using the locale determined by   *     {@link #getLocale(javax.portlet.RenderRequest) getLocale(request)}.   * <li>The value of a lookup in the windows resource bundle for   *     "javax.portlet.title" using the locale determined by   *     {@link #getLocale(javax.portlet.RenderRequest) getLocale(request)}.   * </ul>   */  protected String getShortTitle( RenderRequest request )  {    String title = (String) request.getAttribute("javax.portlet.short-title");    if (title == null)      title = (String) request.getAttribute("javax.portlet.title");    if (title == null) {      PortletConfig portletConfig        = (PortletConfig) request.getAttribute("javax.portlet.portletConfig");      Locale locale = getLocale(request);      ResourceBundle bundle = portletConfig.getResourceBundle(locale);      title = bundle.getString("javax.portlet.short-title");      if (title == null)        title = bundle.getString("javax.portlet.title");    }    return title;  }  /**   * Create a PortletURL for a control, such as a link to change the window   * state or portlet mode.  Control URLs are render urls that maintain   * existing render parameters.   */  protected PortletURL createControlURL(RenderRequest request)  {    RenderResponse response       = (RenderResponse) request.getAttribute("javax.portlet.renderResponse");    Map<String, String[]> renderParamMap = request.getParameterMap();    PortletURL url = response.createRenderURL();    url.setParameters(renderParamMap);    return url;  }  /**   * Return an Set of the possible portlet modes that the window can   * have.  The list of all possibilities is first obtained from    * {@link javax.portlet.PortalContext#getSupportedPortletModesa() PortalContext.getSupportedPortletModes()}.    * Each one is checked with    * {@link javax.portlet.PortletRequest#isPortletModeAllowed(javax.portlet.PortletMode) request.isPortletModeAllowed()},   * if it is allowed then it is included in the returned Set.   */  protected Set<PortletMode> getPortletModes( RenderRequest request )  {    Set<PortletMode> portletModes = new LinkedHashSet<PortletMode>();    Enumeration<PortletMode> e = (Enumeration<PortletMode>)       request.getPortalContext().getSupportedPortletModes();    while (e.hasMoreElements())  {      PortletMode portletMode = e.nextElement();      if (request.isPortletModeAllowed(portletMode))        portletModes.add(portletMode);    }    return portletModes;  }  /**   * Return an Set of the possible window states that the window can   * have.  The list of all possibilities is first obtained from    * {@link javax.portlet.PortalContext#getSupportedWindowStates() PortalContext.getSupportedWindowStates()}.    * Each one is checked with    * {@link javax.portlet.PortletRequest#isWindowStateAllowed(javax.portlet.WindowState) request.isWindowStateAllowed()},   * if it is allowed then it is included in the returned Set.   */  protected Set<WindowState> getWindowStates( RenderRequest request )  {    Set<WindowState> windowStates = new LinkedHashSet<WindowState>();    Enumeration<WindowState> e = (Enumeration<WindowState>)       request.getPortalContext().getSupportedWindowStates();    while (e.hasMoreElements())  {      WindowState windowState = e.nextElement();      if (request.isWindowStateAllowed(windowState))        windowStates.add(windowState);    }    return windowStates;  }  /**   * Get a resource bundle for the portlet being rendered.   */  protected ResourceBundle getResourceBundle( RenderRequest request )  {    Locale locale = getLocale( request );    PortletConfig portletConfig = getPortletConfig( request );    return portletConfig.getResourceBundle( locale );  } /**   * Get the PortletConfig for the portlet being rendered.   */  protected PortletConfig getPortletConfig(RenderRequest request)  {    return (PortletConfig) request.getAttribute("javax.portlet.portletConfig");  }  /**   * Get the RenderResponse for the portlet being rendered.   */  protected RenderResponse getRenderResponse(RenderRequest request)  {    return (RenderResponse) request.getAttribute("javax.portlet.renderResponse");  }  /**   * Print a string with appropriate escaping for XML, for example '&lt;'   * becomes '&amp;lt;'.   */  protected PrintWriter printEscaped( PrintWriter out, CharSequence string )  {    if ( string == null ) {      out.print( (String) null );      return out;    }    for ( int i = 0; i < string.length(); i++  ) {      char ch = string.charAt( i );      switch ( ch ) {        case '<': out.print( "&lt;" ); break;        case '>': out.print( "&gt;" ); break;        case '&': out.print( "&amp;" ); break;        case '\"': out.print( "&quot;" ); break;        case '\'': out.print( "&rsquo;" ); break;        default: out.print( ch );      }    }    return out;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?