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

          By Terry. Lee

          SpiritSeekerS@sqatester.com

          ?

          本系列將介紹如何開發(fā)基于 Portlet Specification v1.0 (JSR168) Portlet 應(yīng)用程序以及相關(guān)的概念. 這里使用 Pluto v1.0 作為 Portal/Portlet Container . 并且可以將開發(fā)完成的 Portlet 應(yīng)用程序發(fā)布到任何遵循 JSR168 規(guī)范的其他 Portlet Container Portal Server .

          ?

          ·?? 為什么要發(fā)布 Portlet Specification ? 什么是 JSR168 ?

          越來越多的公司開發(fā)了各自的 Portal 組件和基于其的 Portal 產(chǎn)品( Bea, IBM, Oracle, Sun, Sybase, Vignette, Novell, SAP, Plumtree , Apache . 這種互不兼容的接口實現(xiàn)帶給軟件開發(fā)商以及Web開發(fā)人員各種問題, 為了解決這些問題, JCP 發(fā)布了 JSP168 (Java Specification Request), Portlet Specification v1.0, 用以提供不同 Portal Portlets 的實現(xiàn) 之間的互通性.可能許多軟件開發(fā)商 (如上所列) 提供更為強(qiáng)大的 Portlet 實現(xiàn), 但是如果希望開發(fā)人員希望所開發(fā)的 Portlet 程序 能夠不依賴于某一種或者幾種平臺, 那么使用 JSR168 Portlet 毫無疑問是你的首選.

          ?

          ·???????? 什么是 Portal?

          Portal 是基于 WEB 的應(yīng)用程序, 一個信息平臺, 它將不同來源的各種資源進(jìn)行整合并集中展現(xiàn)給客戶.

          ?

          通常其有如下三個特點:

          ?

          a.???????????????? P ersonalization ( 個性化 )

          b.???????????????? Single sign on ( 單點登陸 )

          c.????????????????? Content aggregation ( 內(nèi)容聚合 )

          ?

          Personalization Portal 提供的特性之一 , 用來提供用戶的個性化設(shè)置 .

          Single sign on J2EE 的一個特性 . 其中 Content aggregation Portal 比較有特色的特性 , 它將不同來源的信息整合到一個同一個頁面中 , 使得用戶可以更便捷 , 更快速的進(jìn)行某些商業(yè)應(yīng)用 .

          ?

          這里舉一個簡單的商業(yè)應(yīng)用的例子 , 如果某一客戶需要進(jìn)行一次商業(yè)采購行為 , 以往需要訪問不同的產(chǎn)品供應(yīng)商的主頁得到相關(guān)信息 , 這往往是一個耗時耗力的過程 , 但如果使用 Portal 將所有經(jīng)常使用的相關(guān)商品供應(yīng)商的商品 頁面都整合到一個 Portal 頁面中 , 那么所有的供應(yīng)商的商品都可以更快的被瀏覽 , 篩選 , 加快了客戶的商業(yè)運作效率 .

          ?

          ·???????? 什么是 Portlet?
          Portlet 是一種基于 WEB 組件的 JAVA 技術(shù), Portlet Container 進(jìn)行管理. 處理請求并動態(tài)返回頁面, 可以作為 Portal 的可 即插即用 的界面組件.

          ?

          ·???????? 什么是 Portlet Container? Portlet Container 用來管理 Portlet 的生命周期并且提供其運行所需要的必要環(huán)境. 并且給 Portlet Preferences 提供持久性( Persistent ) 存取服務(wù).但是其不支持 Portlet aggregation( 內(nèi)容聚合 ). 內(nèi)容聚合 Portal 組件提供.這個概念需要弄清楚.

          ?

          : Portlet Preferences Portlet 的一個新特性,提供類似數(shù)據(jù)庫的功能.但是不是用來取代數(shù)據(jù)庫. 只能用來存取簡單的 Portlet 配置參數(shù).

          ???????

          ·???????? 什么是 WSRP?
          WSRP
          OASIS Web Service for Remote Portlets 的縮寫 . WSRP Web service 的一種新的商業(yè)應(yīng)用 , 一種新的標(biāo)準(zhǔn) , 主要用來簡化 Portal 對于各種資源或者程序整合的復(fù)雜性 , 可以避免編程帶來的整合麻煩和問題 . 而且 Portal 的管理員可以從海量的 WSRP 服務(wù)中選擇需要的功能用以整和到目前使用的 Portal . 它有三種 Roles:

          1) Producer -> 提供 Portlet
          2) Consumer ->
          使用 Portlet
          3) End User ->
          最終用戶

          它的特點在于 Producer Consumer 所需要的信息通過 WSRP 返回給 Consumer, 這些信息是相對的標(biāo)記 Fragment( 片段 ), 例如 HTML,XHTML , 直接可以鑲?cè)胗脩舻?/span> Page , 而不用象 Web service 一樣需要單獨開發(fā)用戶端接口 .

          再舉個 WSRP 的商業(yè)應(yīng)用的例子:

          如果一個
          客戶需要采購一些 PC 軟件 , 那么這個客戶通過互聯(lián)網(wǎng)登陸某家 PC 軟件 代理供應(yīng)商的網(wǎng)頁 , 查詢相關(guān)信息 , 但是做為 軟件 代理公司 ,PC 軟件的高級使用指南及配置工具是非常缺乏或者是無法及時更新的 , 這樣一來使得用戶需要登陸軟件開發(fā)商的站點上才能得到相關(guān)信息 . 然后再回到代理商主頁進(jìn)行訂購 .

          而比較理想的商業(yè)應(yīng)用應(yīng)該是代理公司可以整合軟件開發(fā)商提供的使用指南或者配置工具 ( 可以由開發(fā)商及時更新 ). 但是如果使用 XML API, 那么需要針對不同軟件提供商開發(fā)不同的接口實現(xiàn) . 而使用 WSRP 可以將相關(guān)的信息及工具直接鑲?cè)氲酱砩痰捻撁嬗靡詣討B(tài) , 及時提供給客戶 .

          WSRP4J
          Apache WSRP 標(biāo)準(zhǔn)實現(xiàn) , 請參考文章末尾的資源部分.

          ·?? Portlet and Servlet 比較

          ?

          摘自 (Portlet Specs v1.0)

          ?

          相同點:

          ? Portlets are Java technology based web components

          ? Portlets are managed by a specialized container

          ? Portlets generate dynamic content

          ? Portlets lifecycle is managed by a container

          ? Portlets interact with web client via a request/response paradigm

          ?

          不同點 :

          ? Portlets only generate markup fragments, not complete documents. The Portal aggregates portlet markup fragments into a complete portal page

          ? Portlets are not directly bound to a URL

          ? Web clients interact with portlets through a portal system

          ? Portlets have a more refined request handling, action requests and render requests

          ? Portlets have predefined portlet modes and window states that indicate the function the portlet is performing and the amount of real state in the portal page

          ? Portlets can exist many times in a portal page

          ?

          Portlet 特有 :

          ? Portlets have means for accessing and storing persistent configuration and customization data

          ? Portlets have access to user profile information

          ? Portlets have URL rewriting functions for creating hyperlinks within their content, which allow portal server agnostic creation of links and actions in page fragments

          ? Portlets can store transient data in the portlet session in two different scopes: the application-wide scope and the portlet private scope

          ?

          ? Servlet 特有 :

          ? Setting the character set encoding of the response

          ? Setting HTTP headers on the response

          ? The URL of the client request to the portal

          ? ?

          ·?? 什么是 Pluto ?
          ???????
          Pluto Apache 的一個 Open Source 項目 , 是基于 Portlet Spec (v1.0) (JSR168) 的一個 Portlet Container 的實現(xiàn) . 它也提供了 一個演示版的 Sample Portal 實現(xiàn) , 用以進(jìn)行 Portlet Container 測試 . 但是功能相對簡單 :

          ?? ?
          例如 ,
          ?? ?1)
          沒有復(fù)雜的 Layout 實現(xiàn) .
          ?? ?2)
          不是 multi -user enabled , 比如 , 不同 User 之間的 Portlet Preferences 互相是 ? 可以 share .??

          ??
          請記住 Pluto 只是一個 Portlet Container 的實現(xiàn) , 不是一個 Portal 的實現(xiàn) . 如果你需要功能更為強(qiáng)大的 Portal , 可以使用 JetSpeed 或者其他功能更強(qiáng)大的 Portal , 它同樣也是 Apache 的一個 Open Source Project . 請參考文章末尾的資源部分 .

          ?

          ·?? 概念
          ?????
          如圖 : Figure 1.1

          a.???? Decorations and controls ( 部分 及 控制 部分 )

          b.???? Portlet fragment (Portlet 片段 )

          c.????? Portlet window (Portlet 窗口 )

          d.?????? Portlet page (Portlet 頁面 )

          ?

          ?

          Figure 1.1

          ?

          ·???????? 開發(fā)工具 ( Eclipse2.1, Pluto-plugin, Jakarta-tomcat-4.1.29)

          下載地址 :

          Eclipse

          http://www.eclipse.org/downloads/index.php

          ?

          Pluto-plugin

          http://prdownloads.sourceforge.net/plutoeclipse/org.eclipsefan.pluto.ui_1.0.0.zip?download

          ?

          Tomcat4.1

          http://mirrors.midco.net/pub/apache.org/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.zip

          ?

          JDK1.4

          http://Java.sun.com

          ?

          ·?? 配置開發(fā)環(huán)境
          ?? ??? Step1 :? 解壓 eclipse-SDK-2.1.1-win32.zip
          ?Step2 :?
          解壓 org.eclipsefan.pluto.ui_1.0.0.zip , 并將其拷入 eclipse\plugins 目錄

          , 如下 : eclipse\plugins\org.eclipsefan.pluto.ui_1.0.0\

          \Icon

          \Lib

          \Source

          \Webapp

          ?????????? Step3 :? 解壓 tomat4.1 到一目錄 . 并且配置好 Tomcat 服務(wù)器 .

          ?????

          ????????????? 配置完成 .


          a. 使用 Portlet Wizard 來創(chuàng)建 Portal
          1)
          選擇 File > New > Project… > Portal > Pluto Portal application, ? ????? Next , 如圖 :

          Figure 1.2

          ?

          2) 指定 Project 名稱 ( 如圖 1.3), 這里使用 pluto , 然后單擊 Next .

          Figure 1.3

          ?

          ?

          ?

          3) 指定 Tomcat 路徑 , 單擊 Finish .? eclipse 會將 Pluto 安裝到 tomcat , 并且自動配置好環(huán)境 .

          Figure 1.4

          ?

          ?

          ?

          ?

          b. 創(chuàng)建 Portlets Application

          ?

          ?

          1) 創(chuàng)建 Pluto portlet application ( 如圖 Figure 1.5 )

          ????????????????????????????????????????? Figure 1.5

          ?

          ????????????? 2) 輸入 project 名稱 ( 如圖 Figure 1.6 ), 這里用 portlets

          ?????????????

          ??????????????????????????????????????????????????? Figure 1.6

          ?

          ?

          ?


          ? ??????
          c. 最后生成的工程如圖 ( Figure 1.7 ):

          ?? .

          Figure 1.7 ???????????????????

          d. 通過 portlet.xml 生成 / 更新 web.xml ( 如圖 Figure 1.8)

          ?????
          : 如果每次對 Portlet.xml 文件進(jìn)行修改后 , 比如添加新的 Portlet , 必須更新 ?

          web.xml , 生成對應(yīng)的 Wrap Servlet , 否則 Portlet 無法在 Portal 中加載 .

          ??????

          Figure 1.8

          ?

          e. 部署 Portlets


          1)
          編譯 portlets 工程 .
          2)
          [your tomcat installation directory]/webapps , 新建目錄 portlets

          3) portlets 工程下的 web-root 目錄下所有文件 , 拷入以上新建的 portlets 目錄中 .

          Tip: 如果在每次修改后你厭倦了 Ctrl+C Ctrl+V, 你可以在 Portlets 工程目錄下自己編一個 Bat 文件 , 然后你可以在 eclipse 里的 Package Explorer 中看到它 , 雙擊就可以了 . 如上圖 ( Figure 1.8 ): 其中 deploy.bat 文件就是實現(xiàn) Deploy .


          4)
          Start tomcat.
          5)
          IE 中輸入 : http://localhost: 8080/pluto/portal , 你應(yīng)該能看到 portal 頁面.

          ?

          ?

          ·?? Sample Portlet
          Portlets 工程文件創(chuàng)建過程中 , 自動生成許多文件 , 包括一個簡單的 Portlet 小程序 , 現(xiàn)在我們來簡單觀察一下生成的 sample portlet.

          ?

          ?

          1) Servlet 非常類似 , Portlet 擴(kuò)展自 GenericPortlet

          import javax.portlet.*;

          ?

          public class SimplePortlet extends GenericPortlet

          ?

          2) 其三個方法對應(yīng)了 Portlet 標(biāo)題欄中的三個 (View, Edit, Help) 所執(zhí)行的功能 .


          public void doView( …)

          ?

          public void doEdit( …)

          ?

          public void doHelp( …)

          3) 三個方法分別調(diào)用了三個 JSP 文件 , 用以生成 Portlet fragment , 同樣也可以調(diào)用 Servlet 產(chǎn)生 Portlet fragment , 或者不調(diào)用 JSP 或者 Servlet, 直接在方法中得到 PrintWriter, 用最簡單的 pw.println(…) 打印出內(nèi)容 , 類似 Servlet, 如下 :

          ?

          ?

          PrintWriter pw=renderResponse.getWriter();

          pw.println( " Hello, Portlet! " );

          ?

          ?

          Servlet 應(yīng)用類似 , 也可以使用

          getInitParameter (String s) 方法 , 得到配置文件中 Portlet 的初始值 . 只不過 Servlet 使用 web.xml , Portlet 使用 portlet.xml 文件 .

          ?

          ?

          portlet.xml

          ?

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

          ??????????? <name>jspView</name>

          ??????????? <value>/jsp/view.jsp</value>

          </init-param>

          ?

          ?

          SimplePortlet.java

          ?

          String jspName =

          getPortletConfig().getInitParameter( "jspView" );

          ?

          ?

          ·?? Portlet Tag library

          ?

          1) defineObjects Tag

          ?

          如果打開其中的一個JSP文件,你會發(fā)現(xiàn),Servlet一樣,JSP中可以使用Portlet的一些 variables . 例如:

          ?

          renderResponse

          renderRequest

          portletConfig

          ?

          但是必須聲名 :

          <portlet:defineObjects/>

          其中不可以定義任何屬性或者包含任何內(nèi)容 .

          ?

          2) actionURL Tag

          屬性

          值類型

          對應(yīng)值

          windowState

          String

          minimized

          normal

          maximized .

          ?

          portletMode

          String

          view, edit , help

          var

          String

          ?

          secure

          ?

          String

          true

          false

          ?

          <portlet:actionURL windowState=”normal” portletMode=”edit”>

          <portlet:param name=”action” value=”login”/>

          </portlet:actionURL>

          ?

          創(chuàng)建一個 action URL , 當(dāng)訪問它時將使 portlet window 變?yōu)?/font> normal 裝態(tài) , 模式變?yōu)?/font> edit.

          ?

          3) renderURL Tag

          屬性

          值類型

          對應(yīng)值

          windowState

          String

          minimized

          normal

          maximized .

          ?

          portletMode

          String

          view, edit , help

          var

          String

          ?

          secure

          ?

          String

          true

          false

          ?

          <portlet:renderURL portletMode=”view” windowState=”maximized”>

          <portlet:param name=”number” value=”1”/>

          <portlet:param name=”page” value=”2”/>

          </portlet:renderURL>

          ?

          創(chuàng)建一個 render URL , 當(dāng)訪問它時將使 portlet window 變?yōu)?/font> maximized 裝態(tài) , 模式變?yōu)?/font> view.

          ?

          4) namespace Tag

          為目前的 Portlet 產(chǎn)生一個唯一的 Value. 防止和其他的 Portlet 或者 Portal 頁面上的 value 產(chǎn)生沖突 .

          <A HREF=”javascript: <portlet:namespace/>doFoo()”>Foo</A>

          ?

          5) param Tag

          屬性

          值類型

          name

          String

          <portlet:param name=”myParam” value=”someValue”/>

          : param Tag 不可以有 body content.

          ?

          ?

          總結(jié)

          Pluto 目前是 v1.0 , 有部分 Portlet 規(guī)范 沒有完全實現(xiàn) , 例如 , renderResponse.setTitle (), 同時 你可以從 Apache CVS 下載最新的 Pluto 代碼 , 希望這編文章可以幫大家搭建一個簡單的 Portlet 開發(fā)環(huán)境 , 熟悉 Portlet 相關(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 實現(xiàn) (WSRP4J)
          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

          ?

          主站蜘蛛池模板: 永康市| 晋州市| 密云县| 海口市| 阿勒泰市| 九龙县| 东源县| 外汇| 芦溪县| 上思县| 仁怀市| 闵行区| 栖霞市| 封丘县| 长宁县| 马山县| 泸定县| 罗山县| 临泉县| 安国市| 高雄市| 开鲁县| 格尔木市| 彭州市| 海阳市| 五寨县| 西充县| 卓资县| 兴业县| 公主岭市| 嘉义市| 铜鼓县| 昌宁县| 乡宁县| 邵阳县| 泸定县| 德令哈市| 潞西市| 南木林县| 库伦旗| 梨树县|