posts - 12, comments - 19, trackbacks - 0, articles - 23
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          By Terry.lee

          SpiritSeekerS@sqatester.com

          ?

          ?

          本部分使用本系列中 Part1 搭建的開發(fā)環(huán)境 , 如果還沒有搭建好開發(fā)環(huán)境 , 請(qǐng)參考 Portlet 應(yīng)用開發(fā) (JSR168),Part1 進(jìn)行開發(fā)環(huán)境的搭建 .

          ?

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

          ?

          ?

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

          Figure1_1

          ?

          ?

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

          ?

          · ???????? portletentityregistry.xml
          打開 pageregistry.xml, 內(nèi)容如下
          :

          <?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 標(biāo)簽表明了目前的 application ID, portlet 標(biāo)簽定義了一個(gè) Portlet , 如果你新開發(fā)了一個(gè) Portlet , 可以加入以下內(nèi)容
          :

          <?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 中注冊(cè)了一個(gè)新的 Portlet, 接下來是將新注冊(cè)的 Portlet 加入 Page .

          ?

          · ???????? pageregistry.xml
          打開 pageregistry.xml, 內(nèi)容如下
          :

          <?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 標(biāo)簽用來配置 navigation ( 導(dǎo)航欄 ), Page, 以及 Page 中的 Column Row.

          分別用 fragment 標(biāo)簽的 type 屬性來標(biāo)識(shí) . Pluto 自帶的 Portal 使用 fragment 標(biāo)簽來配置及處理簡(jiǎn)單的 Portlet Layout.

          ?

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

          ????????

          ?

          ?

          1)???? 配置同一行中的兩個(gè) 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) ???? 配置同一列中的 兩個(gè) 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 提供的用以區(qū)分 Portlet 所執(zhí)行功能的一個(gè)概念 . 通常情況下其擁有以下幾種模式
          :
          1. VIEW

          2. EDIT

          3. HELP

          以上各模式分別對(duì)應(yīng) GenericPortlet 中的 doView(…) , doEdit(…) , doHelp(…) 方法 , 分別調(diào)用以上方法來產(chǎn)生各個(gè)模式中的 Fragment 內(nèi)容 . 非常類似 Servlet 中的 doGet(…) , doPost(…) 方法 , 都是 Helper 方法 , 但是概念不同 .

          ?

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

          1. ???? Normal

          2. ???? Maximized

          3. ???? Minimized

          ?

          Portlet 開發(fā)人員可以在處理 ActionRequest ( 以后的章節(jié)將講述其概念 ) 時(shí)使用代碼實(shí)現(xiàn) Portlet 模式 , 及其 Portlet 狀態(tài)的轉(zhuǎn)變 .

          ?

          : 只能在處理 ActionRequest 時(shí)改變 Portlet Modes Portlet Window states.

          ?????

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

          ?

          A. ???? 添加 Custom Portlet Modes

          以下使用代碼實(shí)現(xiàn)了一個(gè)新的 Portlet Mode: CONFIG , 當(dāng)然也可以使用 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 ,? 將所有配置及相關(guān)文件部署后 , 啟動(dòng) Tomcat.

          ?

          ?

          ?

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

          ?

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

          ?

          ?

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

          ?

          2-2

          ?

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

          ?

          2-3

          ?

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

          ?

          ?

          B. ???? 添加 Custom Window States

          ?

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

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

          <name>half_page</name>

          </custom-window-state>

          ?

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

          ?

          總結(jié) :

          因?yàn)?/span> Eclipse Pluto plugin 使用的是 version1.0 , 所以可能有許多 Bugs 或者沒有實(shí)現(xiàn)的功能 , 所以如果需要最新版本的 Pluto , 可以在 Apache CVS 上下載 , 下載的代碼中有現(xiàn)成的 Build scripts 以及相關(guān)的 deploy script. 請(qǐng)參考相關(guān)文檔資料 .

          ?

          資源 :

          ·???????? 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 實(shí)現(xiàn)
          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 規(guī)范介紹 " 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)

          主站蜘蛛池模板: 安康市| 巴南区| 敖汉旗| 蒙山县| 关岭| 湖南省| 上虞市| 精河县| 万年县| 遵义市| 苗栗市| 兰西县| 天台县| 讷河市| 天长市| 文水县| 宝鸡市| 赞皇县| 涿州市| 浪卡子县| 桐城市| 泽州县| 云安县| 西和县| 青川县| 漳州市| 兴隆县| 阜平县| 青铜峡市| 淮滨县| 泰兴市| 重庆市| 满洲里市| 巩留县| 潞城市| 虹口区| 江永县| 广元市| 蓬安县| 陕西省| 南岸区|