portletservlet.java

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

JAVA
788
字号
      setPortalClass( p );    p = super.getInitParameter("portal-ref");    if (p != null)      setPortalRef(p);    if (_portal == null)      _portal = new GenericPortal();    p = super.getInitParameter("portlet-class");    if (p != null)      setPortletClass( p );    if (_portlet == null)      throw new ServletException("`portlet' is required");    p = super.getInitParameter("portlet-name");    if (p != null)      setPortletName(p);    if (_portletName == null)      _portletName = servletConfig.getServletName();    p = super.getInitParameter("expiration-cache");    if (p != null)      setExpirationCache(Integer.parseInt(p));    p = super.getInitParameter("private");    if (p != null)      setPrivate(Boolean.valueOf(p).booleanValue());    p = super.getInitParameter("buffer-size");    if (p != null)      setBufferSize(Integer.parseInt(p));    p = super.getInitParameter("supported-locales");    if (p != null)      addSupportedLocales( p );    p = super.getInitParameter("resource-bundle");    if (p != null)      setResourceBundle( p );    p = super.getInitParameter("renderer-class");    if (p != null)      setRendererClass( p );    _portletContext = new HttpPortletContext(getServletContext());    try {      _portlet.init(this);    }    catch (PortletException ex) {      throw new ServletException(ex);    }  }  protected Object newInstance(Class targetClass, String className)    throws IllegalArgumentException  {    Class cl = null;    ClassLoader loader = Thread.currentThread().getContextClassLoader();    try {      cl = Class.forName(className, false, loader);    } catch (ClassNotFoundException e) {    }    if (cl == null)      throw new IllegalArgumentException(          "`" + className + "' is not a known class");    if (!targetClass.isAssignableFrom(cl))      throw new IllegalArgumentException(          "'" + className + "' must implement " + targetClass.getName());    if (Modifier.isAbstract(cl.getModifiers()))      throw new IllegalArgumentException(          "'" + className + "' must not be abstract.");    if (!Modifier.isPublic(cl.getModifiers()))      throw new IllegalArgumentException(          "'" + className + "' must be public.");    Constructor []constructors = cl.getDeclaredConstructors();    Constructor zeroArg = null;    for (int i = 0; i < constructors.length; i++) {      if (constructors[i].getParameterTypes().length == 0) {        zeroArg = constructors[i];        break;      }    }    if (zeroArg == null || !Modifier.isPublic(zeroArg.getModifiers()))      throw new IllegalArgumentException(          "'" + className + "' must have a public zero arg constructor");    Object obj = null;    try {      obj =  cl.newInstance();    }    catch (Exception ex) {      throw new IllegalArgumentException(          "error instantiating `" + className + "': " + ex.toString(), ex);    }    return obj;  }  public PortletConfig getPortletConfig()  {    return this;  }  public String getInitParameter(String name)  {    if (_initParamMap == null)      return super.getInitParameter(name);    else      return _initParamMap.get(name);  }  public Enumeration getInitParameterNames()  {    if (_initParamMap == null)      return super.getInitParameterNames();    else      return Collections.enumeration(_initParamMap.keySet());  }  /**   * {@inheritDoc}   */   public int getExpirationCache()  {    return _expirationCache;  }  /**   * {@inheritDoc}   */   public boolean isPrivate()  {    return _isPrivate;  }  /**   * {@inheritDoc}   *   * This implementation returns true.   */   public boolean isWindowStateAllowed(PortletRequest request,                                      WindowState windowState)  {    // XXX: todo: support a window-states init-param like    // normal, minimized    return true;  }  /**   * {@inheritDoc}   *   * This implementation returns true.   */   public boolean isPortletModeAllowed(PortletRequest request,                                      PortletMode portletMode)  {    // todo: see getSupportedContentTypes()    return true;  }  /**   * {@inheritDoc}   *   * This implementation returns null, which means that all content   * types are supported.   */   public Set<String> getSupportedContentTypes(PortletMode portletMode)  {    // XXX: todo: support a content-type init-param like    // edit(text/html), view(text/html, application/pdf)    return null;  }  /**   * {@inheritDoc}   *   * This implementation returns null, which means that all locales are   * supported.   */   public Set<Locale> getSupportedLocales()  {    return _supportedLocales;  }  /**   * {@inheritDoc}   *   * This implementation returns null.   */   public PortletPreferences getDefaultPreferences()  {    return _defaultPreferences;  }  /**   * {@inheritDoc}   */   public ArrayList<PreferencesValidator> getPreferencesValidators()  {    if (_defaultPreferences != null)      return _defaultPreferences.getPreferencesValidators();    else      return null;  }  /**   * {@inheritDoc}   *   * This implementation returns null.   */   public Map<String, String> getRoleRefMap()  {    return null;    // todo  }  /**   * {@inheritDoc}   *   * This implementation returns null.   */   public ArrayList<Constraint> getConstraints()  {    return null;    // todo  }  /**   * {@inheritDoc}   */  public Renderer getRenderer()  {    return _renderer;  }  /**   * {@inheritDoc}   *   * This implementation returns PortletMode.VIEW.    */  public PortletMode handlePortletModeFailure( PortletRequest request,                                                PortletMode notAllowed )  {    return PortletMode.VIEW;  }  /**   * {@inheritDoc}   *   * This implementation returns WindowState.NORMAL.    */  public WindowState handleWindowStateFailure( PortletRequest request,                                                WindowState notAllowed )  {    return WindowState.NORMAL;  }  /**   * {@inheritDoc}   *   * This implementation does nothing.   */   public void handleConstraintFailure(RenderRequest request,                                       RenderResponse response,                                       ConstraintFailureEvent event)  {  }  /**   * {@inheritDoc}   *   * This implementation does nothing.    */   public void handleException(RenderRequest request,                               RenderResponse response,                               ExceptionEvent event)  {    // XXX: todo: support error-page  }  /**   * {@inheritDoc}   */  public String getPortletName()  {    return _portletName;  }  /**   * {@inheritDoc}   */  public PortletContext getPortletContext()  {    return _portletContext;  }  /**   * {@inheritDoc}   */  public ResourceBundle getResourceBundle(Locale locale)  {    if (_resourceBundleFactory == null)      _resourceBundleFactory = new ResourceBundleFactory();    return _resourceBundleFactory.getResourceBundle(locale);  }  /**   * {@inheritDoc}   */  public int getBufferSize()  {    return _bufferSize;  }  protected void doGet(HttpServletRequest req, HttpServletResponse res)    throws ServletException, IOException  {    doRequest(req, res);  }  protected void doPost(HttpServletRequest req, HttpServletResponse res)    throws ServletException, IOException  {    doRequest(req, res);  }  protected void doRequest(HttpServletRequest httpRequest,                            HttpServletResponse httpResponse)    throws ServletException, IOException  {         HttpPortletConnection connection = new HttpPortletConnection();    connection.start(_portal, _portletContext, httpRequest, httpResponse, true);    try {      Action action = connection.getAction(this, _namespace);      if (action != null) {        try {          if (action.isTarget())  {            action.processAction(_portlet);          }        }         finally {           action.finish();         }       }      Render render = connection.getRender(this, _namespace);      if (render != null) {        try {          render.render(_portlet);        }         finally {           render.finish();         }       }      connection.checkForFailure();    }    catch (PortletException ex) {      throw new ServletException(ex);    }    finally {      connection.finish();    }  }  public void destroy()  {    if (_portlet != null)      _portlet.destroy();  }}

⌨️ 快捷键说明

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