posts - 12, comments - 19, trackbacks - 0, articles - 23
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Portlet應用開發 (JSR168)(二)

          Posted on 2006-08-10 20:22 毛里求斯的化石 閱讀(478) 評論(0)  編輯  收藏 所屬分類: portal相關

          By Terry.lee

          SpiritSeekerS@sqatester.com

          ?

          ?

          本部分使用本系列中 Part1 搭建的開發環境 , 如果還沒有搭建好開發環境 , 請參考 Portlet 應用開發 (JSR168),Part1 進行開發環境的搭建 .

          ?

          Part1 , 我們開發了一個簡單的 portlet 程序 , 但是 幾乎 所有的 代碼和文件 都是由 Eclipse pluto plugin 替我們完成的 , 如何配置用來在 Pluto 中的 Portal 中添加新的 Portal Page 并且將新的 Portlet 添加到新的 Page 中去呢 ? Part2 將一步一步教你如何創建一個新 Portal Page.

          ?

          ?

          · ???????? Portal 的設定
          Tomcat Webapps 目錄 : 其中 pluto portal 所在目錄 , 用以配置 Portal Page 的兩個文件分別是 pageregistry.xml portletentityregistry.xml ( 如圖 Figure1_1)

          Figure1_1

          ?

          ?

          其中 pageregistry.xml 用來在 Portal 中配置 Portal Page, portletentityregistry.xml 用來在 Page 中配置 Portlet.

          ?

          · ???????? portletentityregistry.xml
          打開 pageregistry.xml, 內容如下
          :

          <?xml version="1.0" encoding="UTF-8"?>

          <portlet-entity-registry>

          ??? <application id="1">

          ??????? <definition-id>portlets</definition-id>

          ??????? <portlet id="1">

          ??????????? <definition-id>portlets.SimplePortlet</definition-id>

          ??????? </portlet>

          ??? </application>

          </portlet-entity-registry>

          其中 application 標簽表明了目前的 application ID, portlet 標簽定義了一個 Portlet , 如果你新開發了一個 Portlet , 可以加入以下內容
          :

          <?xml version="1.0" encoding="UTF-8"?>

          <portlet-entity-registry>

          ??? <application id="1">

          ??????? <definition-id>portlets</definition-id>

          ??????? <portlet id="1">

          ??????????? <definition-id>portlets.SimplePortlet</definition-id>

          ??????? </portlet>

          ??????? <portlet id="2">

          ??????????? <definition-id>portlets.IntroPortlet</definition-id>

          ??????? </portlet>

          ??? </application>

          </portlet-entity-registry>

          ?

          這樣一來你又在 portal 中注冊了一個新的 Portlet, 接下來是將新注冊的 Portlet 加入 Page .

          ?

          · ???????? pageregistry.xml
          打開 pageregistry.xml, 內容如下
          :

          <?xml version="1.0"?>

          <portal>

          ?

          ??? <fragment name="navigation" class="org.apache.pluto.portalImpl.aggregation.navigation.TabNavigation">

          ??? </fragment>

          ???

          ??? <fragment name="sample" type="page">

          ??????? <navigation>

          ??????????? <title>Sample Portlet</title>

          ??????????? <description>Basic page to show the simple portlet</description>

          ??????? </navigation>

          ?

          ??????? <fragment name="row" type="row">

          ?

          ??????????? <fragment name="col1" type="column">

          ?

          ???????? ???????<fragment name="p1" type="portlet">

          ??????????????????? <property name="portlet" value="1.1"/>

          ??????????????? </fragment>

          ?

          ??????????? </fragment>

          ?

          ??????? </fragment>

          ?

          ??? </fragment>

          </portal>

          ?

          以上是 sample portlet 的配置 .

          ?

          Fragment 標簽用來配置 navigation ( 導航欄 ), Page, 以及 Page 中的 Column Row.

          分別用 fragment 標簽的 type 屬性來標識 . Pluto 自帶的 Portal 使用 fragment 標簽來配置及處理簡單的 Portlet Layout.

          ?

          <property name="portlet" value="1.1"/> 中的 value 值是在 portletentityregistry.xml 中定義的 . 分別對應 application id portlet id , 將其值用 ”.” 連接起來使用用以定義一個 Portlet . 同樣 , 如果使用 <property name="portlet" value="1.2"/> , 則將使用 portlets.IntroPortlet.

          ????????

          ?

          ?

          1)???? 配置同一行中的兩個 Portlet, 如下 :

          <?xml version="1.0"?>

          <portal>

          ?

          ??? <fragment name="navigation" class="org.apache.pluto.portalImpl.aggregation.navigation.TabNavigation">

          ??? </fragment>

          ???

          ??? <fragment name="sample" type="page">

          ??????? <navigation>

          ??????????? <title>Sample Portlet</title>

          ??????????? <description>Basic page to show the simple portlet</description>

          ??????? </navigation>

          ?

          ??????? <fragment name="row" type="row">

          ?

          ??????????? <fragment name="col1" type="column">

          ?

          ??????????????? <fragment name="p1" type="portlet">

          ??????????????????? <property name="portlet" value="1.1"/>

          ??????????????? </fragment>

          ?

          ??????????????? <fragment name="p2" type="portlet">

          ??????????????????? <property name="portlet" value="1.1"/>

          ??????????????? </fragment>

          ?

          ??????????? </fragment>

          ?

          ??????? </fragment>

          ?

          ??? </fragment>

          ?

          </portal>

          ?

          2) ???? 配置同一列中的 兩個 Portlet, 如下 :

          <?xml version="1.0"?>

          <portal>

          ?

          ??? <fragment name="navigation" class="org.apache.pluto.portalImpl.aggregation.navigation.TabNavigation">

          ??? </fragment>

          ???

          ??? <fragment name="sample" type="page">

          ??????? <navigation>

          ??????????? <title>Sample Portlet</title>

          ??????????? <description>Basic page to show the simple portlet</description>

          ??????? </navigation>

          ?

          ??????? <fragment name="row1" type="row">

          ?

          ??????????? <fragment name="col1" type="column">

          ?

          ??????????????? <fragment name="p1" type="portlet">

          ??????????????????? <property name="portlet" value="1.1"/>

          ??????????????? </fragment>

          ?

          ??????????? </fragment>

          ?

          ??????? </fragment>

          ?

          ??????? <fragment name="row2" type="row">

          ?

          ??????????? <fragment name="col1" type="column">

          ?

          ??????????????? <fragment name="p1" type="portlet">

          ??????????????????? <property name="portlet" value="1.1"/>

          ??????????????? </fragment>

          ?

          ??????????? </fragment>

          ?

          ??????? </fragment>

          ?

          ??? </fragment>

          ?

          </portal>

          ?

          ?

          ?

          ?

          · ???????? Portlet Modes Portlet window state s
          Portlet
          模式 (Portlet Mode) Portlet 提供的用以區分 Portlet 所執行功能的一個概念 . 通常情況下其擁有以下幾種模式
          :
          1. VIEW

          2. EDIT

          3. HELP

          以上各模式分別對應 GenericPortlet 中的 doView(…) , doEdit(…) , doHelp(…) 方法 , 分別調用以上方法來產生各個模式中的 Fragment 內容 . 非常類似 Servlet 中的 doGet(…) , doPost(…) 方法 , 都是 Helper 方法 , 但是概念不同 .

          ?

          Portlet 狀態 (Portlet window states) 提供了對于 Portlet 窗口的控制功能 , 其中有如下三種最基本的狀態 :

          1. ???? Normal

          2. ???? Maximized

          3. ???? Minimized

          ?

          Portlet 開發人員可以在處理 ActionRequest ( 以后的章節將講述其概念 ) 時使用代碼實現 Portlet 模式 , 及其 Portlet 狀態的轉變 .

          ?

          : 只能在處理 ActionRequest 時改變 Portlet Modes Portlet Window states.

          ?????

          以上 Portlet Modes Portlet window states 都可以配置成 custom Portlet mode custom portlet window state. 不同的地方在于對于 Mode 來說 , 定制化的 Mode 需要對 GenericPortlet doDispatch 方法進行重寫 (Overriding), 因為 GenericPortlet 類通過 render 方法按照不同的 Portlet Mode request 分別分發給 doView,doEdit,doHelp 等輔助方法 . 如果需要定制的 Mode , 必須重寫 doDispatch 方法 . 同時如果使用 Portal 提供商的 Portlet Modes 或者 Portlet window States, 都必須在部署描述中添加相關的設定 .

          ?

          A. ???? 添加 Custom Portlet Modes

          以下使用代碼實現了一個新的 Portlet Mode: CONFIG , 當然也可以使用 Portal 提供商支持的 Portlet Mode. 但是需要 Mapping Portal 提供商所支持的 Portlet Mode. 使用如下描述 :

          ?

          ??? <custom-portlet-mode>

          ???????? <description>Provides administration functions</description>

          ???????? <portlet-mode>CONFIG</portlet-mode>

          ??? </custom-portlet-mode>

          ?

          1. Portlet 代碼 ( CustomPortletModeExample .java)

          ?

          package portlets.portletmode;

          ?

          /**

          ? * @author terry

          ? *

          ? * To change the template for this generated type comment go to

          ? * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments

          ? */

          import javax.portlet.*;

          import java.io.IOException;

          ?

          public class CustomPortletModeExample extends GenericPortlet{

          ?

          ? public void doView(RenderRequest request, RenderResponse response)

          ? throws PortletException, IOException

          ? {

          ? response.setContentType( "text/html" );

          ?

          ? String jspName = getPortletConfig().getInitParameter( "all" );

          ?

          ? PortletRequestDispatcher rd =

          ? ? getPortletContext().getRequestDispatcher(jspName);

          ?

          ? rd.include(request, response);

          ? }

          ?

          ? public void doEdit(RenderRequest request, RenderResponse response)

          ? throws PortletException, IOException

          ? {

          ? response.setContentType( "text/html" );

          ?

          ? String jspName = getPortletConfig().getInitParameter( "all" );

          ?

          ? PortletRequestDispatcher rd =

          ? ? getPortletContext().getRequestDispatcher(jspName);

          ?

          ? rd.include(request, response);

          ? }

          ? ?

          ? public void render(RenderRequest request, RenderResponse response)

          ? throws PortletException, IOException{

          ???????? doDispatcher(request,response);

          ? }

          ? ?

          ? public void doDispatcher(RenderRequest request, RenderResponse response)

          ???????? throws PortletException, IOException{

          ???????? if(!request.getWindowState().equals(WindowState.MINIMIZED)){

          ???????? if (request.getPortletMode().equals(PortletMode.VIEW)){

          ??????????????? doView(request,response);

          ???????? } else if (request.getPortletMode().equals(PortletMode.EDIT)){

          ??????????????? doEdit(request,response);

          ???????? } else if (request.getPortletMode().equals( new PortletMode( "CONFIG" ))){

          ??????????????? doConfig(request,response);

          ???????? }

          }

          ? }

          ?

          ? public void doConfig(RenderRequest request, RenderResponse response)

          ? ? throws PortletException, IOException

          ? {

          ? ? response.setContentType( "text/html" );

          ?

          ? ? String jspName = getPortletConfig().getInitParameter( "all" );

          ?

          ? ? PortletRequestDispatcher rd =

          ???????? getPortletContext().getRequestDispatcher(jspName);

          ?

          ? ? rd.include(request, response);

          ? }

          ?

          ? public void processAction(ActionRequest request, ActionResponse response)

          ???????? throws PortletException, IOException

          ? {

          ???????? String action=request.getParameter( "ACTION" );

          ???????? System.out.println( "ACTION" + action);

          ???????? if (action== null ){

          ??????????????? action= "" ;

          ???????? }

          ???????? response.setRenderParameter( "ACTION" ,action);

          ? }

          }

          ?

          2. JSP(all_mode.jsp)

          <%@ page session="false" %>

          <%@ page import="javax.portlet.*"%>

          <%@ page import="java.util.*"%>

          <%@ taglib uri='/WEB-INF/tld/portlet.tld' prefix='portlet'%>

          <portlet:defineObjects/>

          <br>

          <h3>Custom Portlet Mode Example</h3>

          Current Portlet Mode: <b><%=renderRequest.getPortletMode()%></b><br>

          Current Window State : <b><%=renderRequest.getWindowState()%></b><br>

          <br>

          ?

          ?


          5. Portlet.xml


          <?xml version="1.0" encoding="UTF-8"?>

          <portlet-app xmlns="/org/apache/pluto/portalImpl/xml/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="/org/apache/pluto/portalImpl/xml/portlet-app_1_0.xsd /org/apache/pluto/portalImpl/xml/portlet-app_1_0.xsd">

          ?

          ? <!-- Custom PortletMode Example -->

          ? <portlet>

          ???????? <description>CustomPortletModeExample Example</description>

          ???????? <portlet-name>CustomPortletModeExample</portlet-name>

          ???????? <display-name>CustomPortletModeExample</display-name>

          ???????? <portlet-class>portlets.portletmode.CustomPortletModeExample</portlet-class>

          ???????? <init-param>

          ??????????????? <name>all</name>

          ??????????????? <value>/fragments/portletmode/all_mode.jsp</value>

          ???????? </init-param>

          ???????? <expiration-cache>-1</expiration-cache>

          ???????? <supports>

          ??????????????? <mime-type>text/html</mime-type>

          ??????????????? <portlet-mode>VIEW</portlet-mode>

          ??????????????? <portlet-mode>EDIT</portlet-mode>

          ??????????????? <portlet-mode>CONFIG</portlet-mode>

          ???????? </supports>

          ???????? <supported-locale>en</supported-locale>

          ???????? <portlet-info>

          ? ????????????? <title>Custom PortletMode Example</title>

          ??????????????? <short-title>PortletMode</short-title>

          ??????????????? <keywords>PortletMode</keywords>

          ???????? </portlet-info>

          ??? </portlet>

          ?

          </portlet-app>


          6. portletregistry.xml.

          ?

          <?xml version="1.0" encoding="UTF-8"?>

          <portlet-entity-registry>

          ??? <application id="10">

          ??????? <definition-id>portlets</definition-id>

          ??????? <portlet id="10">

          ??????????? <definition-id> portlets.CustomPortletModeExample </definition-id>

          ??????? </portlet>

          ??? </application>

          </portlet-entity-registry>

          ?

          7. pageregistry.xml


          <?xml version="1.0"?>

          <portal>

          ?

          ??? <fragment name="navigation" class="org.apache.pluto.portalImpl.aggregation.navigation.TabNavigation">

          ??? </fragment>

          ???

          ?????? ? <!-- Custom PortletMode Example Page -->

          ??? ??<fragment name="customportletmodepage" type="page">

          ??????? <navigation>

          ??????????? <title>Custom PortletMode Example Page</title>

          ??????????? <description>Custom PortletMode Example Page</description>

          ??????? </navigation>

          ??????? <fragment name="row1" type="row">

          ??????????? <fragment name="col1" type="column">

          ??????????????? <fragment name="p1" type="portlet">

          ??????????????????? <property name="portlet" value="10.10"/>

          ??????????????? </fragment>

          ??????????? </fragment>

          ??????? </fragment>

          ? </fragment>

          ?

          </portal>

          ?

          ?

          將以上源代碼編譯后 , 再通過 Eclipse 生成 / 更新 Portlet web.xml ,? 將所有配置及相關文件部署后 , 啟動 Tomcat.

          ?

          ?

          ?

          Browser 中加載如下頁面 : Http://localhost:8080/pluto/portal , 可以看到如下的頁面 ( :2_1)

          ?

          ????? ???????????????????????? 2-1

          ?

          ?

          單擊 Custom PortletMode Example Page 后可以看到如下 Portlet 頁面 :

          ?

          2-2

          ?

          單擊右上角的 config , 可以看到如下頁面片段 :

          ?

          2-3

          ?

          以上可以看到新添加的 Portlet Mode: config.

          ?

          ?

          B. ???? 添加 Custom Window States

          ?

          ? 添加新的 window states 同樣需要在配置文件中加入相應的描述 , 如下 :
          <custom-window-state>

          <description>Occupies 50% of the portal page</description>

          <name>half_page</name>

          </custom-window-state>

          ?

          但是同樣需要 Mapping Portal 提供商所支持的 Window state.

          ?

          總結 :

          因為 Eclipse Pluto plugin 使用的是 version1.0 , 所以可能有許多 Bugs 或者沒有實現的功能 , 所以如果需要最新版本的 Pluto , 可以在 Apache CVS 上下載 , 下載的代碼中有現成的 Build scripts 以及相關的 deploy script. 請參考相關文檔資料 .

          ?

          資源 :

          ·???????? Pluto
          http://jakarta.apache.org/pluto

          ·???????? Pluto Mail List
          http://news.gmane.org/gmane.comp.jakarta.pluto.user

          ·???????? WSRP Spec1.0
          http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wsrp

          ·???????? Apache WSRP 實現
          http://ws.apache.org/wsrp4j/

          ·???????? Apache’s Portal, JetSpeed:
          http://jakarta.apache.org/jetspeed/site/index.html

          ·???????? JSR 168:
          http://www.jcp.org/en/jsr/detail?id=168

          · "Portlet 規范介紹 " By Stefan Hepper Stephan Hesmer

          Part 1: Get your feet wet with the specification's underlying terms and concepts (August 2003)

          Part 2: The Portlet API's reference implementation reveals its secrets (September 2003)

          主站蜘蛛池模板: 云霄县| 师宗县| 高雄市| 万山特区| 宿松县| 金坛市| 临夏县| 马龙县| 灌南县| 枣阳市| 桐城市| 彭州市| 嵩明县| 鸡泽县| 新余市| 万源市| 德江县| 江油市| 略阳县| 宾川县| 延川县| 松桃| 昌平区| 西藏| 龙州县| 福州市| 清水县| 韶关市| 香港 | 马龙县| 敦化市| 醴陵市| 蚌埠市| 柳河县| 湄潭县| 永济市| 分宜县| 偃师市| 平利县| 博客| 陈巴尔虎旗|