⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portlet-generic.xtp

📁 RESIN 3.2 最新源码
💻 XTP
字号:
<document><header><product>resin</product><title>Generic Portal</title><description><p>The Generic Portal is an implementation of the basic functionality of a portal,released with an Apache open source license.  It provides the basicbuilding blocks for a portal that runs within a servlet container.</p><p>The portlet specification has a well defined interface for Portlets.  However,portlets are not usable on their own, and need a supporting environment (aPortal). Since the functionality provided by a Portal is largely unspecified,developers that wish to leverage the advantages of Portlets may need to make asignificant commitment to a particular, proprietary, Portal implementation.</p><p>The Generic Portal package addresses these problems in the following way:</p><ul><li>it has an Apache open source license</li><li>it provides the classes necessary to use portlets in any servlet container</li><li>configuration information is represented by a small number of classes withsimple implementations.  They can be used on their own, or easily specializedto provide an interface to particular portal implementations.</li></ul></description></header><body><summary/><s1 title="Portlets as Servlets"><p>The generic portal classes, at their simplest, can be used to deploy portletslike servlets.  Functionality for pages is programmed in a Portlet, whichprovides a flexible and general programming pattern.  Using components of thegeneric portal, a servlet does a simple dispatch to the portlet class.  </p><p>This approach is valuable for developers that wish to take advantage ofthe well defined pattern that portlets provide without  a full commitment to acomprehensive portal implementation .</p><p>The generic portal includes <a href="javadoc|com.caucho.portal.generic.PortaletServlet|"/>.  A number of <a href="doc|portlet|tutorial/basic.xtp">tutorials</a> demonstrate the use ofPortalServlet.  </p></s1><s1 title="Configuration and portlets.xml"><p>The portlet specification indicates the portlets.xml file as the source ofconfiguration information.  The generic portal implementation does not readthe XML files, but does provide two classes that are used to completely represent the configuration.</p><p>Users that wish to use the generic portal package in application serversother than Resin will be most interested in this section.</p><s2 title="GenericPortletContext"><p>The <a href="javadoc|javax.portlet.PortletContext|"/> interface is theinterface between the portal and the servlet container or application server(Resin, for example).  It's API is similar to the familiar <a href="javadoc|javax.servlet.ServletContext|"/>, and it is roughly analgousto a web application.  </p><p></p><p><a href="javadoc|com.caucho.portal.GenericPortletContext|"/> is anabstract implementation of PortletContext.  It provides an implementationof methods for storing and retrieving GenericPortletConfig objects. It corresponds to the &lt;portlet&gt; elements within portlets.xml.</p><s3 title="HttpPortletContext"><p>HttpPortletContext extends GenericPortletContext and completes the PortletContext interface requirements by providing a wrapper around a ServletContext.</p></s3></s2><s2 title="GenericPortletConfig"><p>The <a href="javadoc|javax.portlet.PortletConfig|"/> interface is theconfiguration of a portlet.  It is roughly analgous to ServletConfig.The GenericPortletConfig class implements the functionality of PortletConfigand adds methods to handle the full range of configuration that is possible ina &lt;portlet&gt; configuration in portlets.xml.</p></s2><s2 name="jndi" title="JNDI"><p>The Generic Portal implementation uses JNDI to store and retrieve theGenericPortletContext.  Resin is easily configured to read the portlets.xmland store the results in JNDI.  For other application servers, or for greaterportability, the GenericPortletContext class can be configured directly andthen stored in JNDI.  </p><p>This configuration could take place in the init() of a load-on-startup servlet.It might provide the ability to read the portlets.xml file, or it can beconfigured programmatically without the use of the xml file.  </p><p>The default JNDI name is "java:comp/env/PortletContext".</p></s2><s2 title="Example - using the API to configure"><p>The following example shows how the generic portal API is used tocreate a configuration for a portal.  If this code were placed inthe init() of a load-on-startup servlet then it would provide configurationwithin being dependent on any particular application server.</p><example title="Using the API to configure a portal">  import javax.naming.InitialContext;  import javax.naming.NamingException;  ...  private  servletContext  ...  public void init(ServletConfig config)    throws ServletException  {    super.init(config);    HttpPortletContext portletContext = new HttpPortletContext();    portletContext.setServletContext(config.getServletContext());    portletContext.addCustomMode(new PortletMode("goodbye"));    GenericPortletConfig helloConfig = new GenericPortletConfig(portletContext);    helloConfig.setPortletName("HelloWorldPortlet");    helloConfig.setPortletClass("com.caucho.portal.generic.example.HelloWorldPortlet");    helloConfig.addSupports("text/html",PortletMode.VIEW);    helloConfig.addSupports("text/html",PortletMode.EDIT);    helloConfig.setResourceBundle("com.caucho.portal.generic.example.HelloWorldPortlet");    portletContext.addPortletConfig(_helloConfig);    // bind in jndi    String jndiName = "java:comp/env/PortletContext";    if (log.isLoggable(Level.FINE))      log.fine("binding with jndi name `" + jndiName + "'");    try {      InitialContext ic = new InitialContext();      ic.bind(jndiName,this);    }    catch (NamingException ex) {      throw new ServletException(ex);    }  }  ...</example><p>The API of GenericPortletContext closely matches the format of a portlets.xmlfile.  "portlet-name" in the xml file is "setPortletName" in the api;"supports" in the xml file is "addSupports" in the api.  The following is anexample of a portlets.xml file that corresponds to the configuration above:</p><example>&lt;portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"              version="1.0"&gt;  &lt;portlet&gt;    &lt;portlet-name&gt;HelloWorldPortlet&lt;/portlet-name&gt;    &lt;portlet-class&gt;com.caucho.portal.generic.example.HelloWorldPortlet&lt;/portlet-class&gt;    &lt;supports&gt;      &lt;mime-type&gt;text/html&lt;/mime-type&gt;      &lt;portlet-mode&gt;view&lt;/portlet-mode&gt;      &lt;portlet-mode&gt;edit&lt;/portlet-mode&gt;    &lt;/supports&gt;  &lt;/portlet&gt;  &lt;custom-portlet-mode&gt;    &lt;portlet-mode&gt;goodbye&lt;/portlet-mode&gt;  &lt;/custom-portlet-mode&gt;&lt;/portlet-app&gt;</example></s2></s1> <!-- configuration --><s1 name="customization" title="Customizing Portal behaviour"><s2 title="GenericPortalContext"><p>The <a href="javadoc|javax.portlet.PortalContext|"/> interface is a means forthe Portal to provide information about it's capabilities.  When using thegeneric portal implementation, you are creating a portal.  You can use thePortalContext to publish the capabilities of your portal.</p><p><a href="javadoc|com.caucho.portal.GenericPortalContext|"/> is anabstract implementation of PortalContext.  It provides setters to match thegetters defined by PortalContext.  Many portal's can simply instantiate aGenericPortalContext.  </p></s2><!--<section title="Request and Response"><p>To use a portal, it must be provided a request and a response.  The<a href="javadoc|com.caucho.portal.generic.GenericPortletRequest|"/> and <a href="javadoc|com.caucho.portal.generic.GenericPortletResponse|"/> are wrappers around the HttpServletRequest and HttpServletResponse that areavailable within the servlet.</p><p>The GenericPortletRequest and GenericPortletResponse provide much of theirfunctionality by falling through to the underlying HTTP request and response.</p><p>The portlet specification has separate interfaces for the "action" phase andthe "render" phase of a portlet.  The generic implementations implement bothinterfaces.  </p></section>--></s1> <!-- customization --></body></document>

⌨️ 快捷键说明

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