Portal implementation principle

Source: Internet
Author: User
Portal implementation principle

1. Portal Use Cases

Readers can register their own users on the following three websites to understand the portal functions.
Http://my.msn.com
Http://my.yahoo.com
Http://my.liferay.com

My msn has the most flexible and powerful functions. You can drag and drop the column and content column positions and numbers.
My liferay can only select a fixed column layout, but you can move the content section in this column.
My Yahoo can only select a fixed column layout, and cannot move the content location.

The portal structure is divided into three layers.
(1) Page
(2) column, or pane
(3) content, or Portlet

Let's take a look at the entire portal operation process.
(1) There is a [add content] button at the bottom of each column, allowing users to choose to add their favorite content.
From here, we know that there is a common Portlet repository in the portal system for users to choose from.

The jsr168 Portlet Specification defines the Portlet deployment discriptor. The common Portlet repository is stored in the deployment discriptor format of this Portlet.

The xreg file of the open-source jetspeed project is used to store the definition of the common Portlet repository.

(2) After adding content, the content is added to the user's page and column. Next time you log on, you will see the custom portal layout.
From this, we can see that the portal system records the user's personal portal configuration information-user portal config.

The open-source jetspeed psml file is used to store the user portal config definition.

------- In summary.
The entire process of add content is:
Common Portlet repository --> add content --> personal portal config

The entire display portal process is as follows:
Read the user-configured Portlet ID from the personal portal config --> Find the detailed Portlet definition from the common Portlet repository according to the Portlet id --> display the Portlet according to the detailed Portlet definition.

2. portal implementation
 
We will consider how to use Java to implement the portal.

2.1 dynamic include

First, we adopt the simplest idea. We use 100 JSP files (1.jsp, 2.jsp, 3.jsp ,... 100. jsp, etc.), representing 100 Portlet.
The user page mypage. jsp contains multiple selected Portlet.
Now, if the selected Portlet is 1.jsp, 3.jsp, and 7. jsp, how can we display these Portlet in mypage. jsp? The most intuitive way is to use JSP: include. For example:
<Table>
<Tr> <TD>
<JSP: Include page = "1. jsp"/>
</TD> </tr>
<Tr> <TD>
<JSP: Include page = "3. jsp"/>
</TD> </tr>
<Tr> <TD>
<JSP: Include page = "7. jsp"/>
</TD> </tr>
</Table>
Since <JSP: Include> only fixed JSP file names can be specified, JSP file names cannot be dynamically specified. We need to translate <JSP: Include> into Java code-requestdispatcher. Include ();
Next we will replace it with this method.

Java code
<Table>
<Tr> <TD>
<% Request. getrequestdispatcher ("1. jsp"). Include (request, response);/>
</TD> </tr>
<Tr> <TD>
<% Request. getrequestdispatcher ("3. jsp"). Include (request, response);/>
</TD> </tr>
<Tr> <TD>
<% Request. getrequestdispatcher ("7. jsp"). Include (request, response);/>
</TD> </tr>
</Table>

Further improve mypage. jsp.
<% String [] filenames = {"1. jsp", "3. jsp", "7. jsp"}; %>
<Table>
<% For (INT I = 0; I <filenames. length; I ++ ){
String filename = filename s [I]; %>
<Tr> <TD>
<% Request. getrequestdispatcher (filename). Include (request, response);/>
</TD> </tr>
<%} // End for %>
</Table>

The content of filenames can be varied as long as requestdispatcher can process it.
For example, velocity, filenames = {"1. VM", "3. VM", "7. VM "};
For example, URL, filenames = {"/portlet1.do", "/portlet3.do", "/portlet4.do "};
We can see that if we read the content of filenames from the user configuration, this is a simple portal implementation.

Java code
<% String [] filenames = (string []) Session. getattribute ("portlets. config"); %>
<Table>
<% For (INT I = 0; I <filenames. length; I ++ ){
String filename = filenames [I]; %>
<Tr> <TD>
<% Request. getrequestdispatcher (filename). Include (request, response);/>
</TD> </tr>
<%} // End for %>
</Table>

2.2 Portlet Interface

Next we will extend this example.
Assume that each Portlet requires a Portlet interface.
 
Interface Portlet {
Void render (request, response );
};

Mypage. jsp is as follows:

<% String [] portletclassnames = (string []) Session. getattribute ("portlets. config"); %>
<Table>
<% For (INT I = 0; I <portletclassnames. length; I ++ ){
String classname = portletclassnames [I];
Portlet = (Portlet) class. forname (classname). newinstance (); %>
<Tr> <TD>
<% Portlet. Render (request, response);/>
</TD> </tr>
<%} // End for %>
</Table>

The sample code of the Portlet class is as follows:

Public class portlet7 {
Public void render (request, response ){
Request. getrequestdispatcher ("7. jsp"). Include (request, response );
}
};

The above code is a simplified version of the portal's core process of displaying the Portlet.
The jsr168 Portlet Specification defines the real Portlet interface definition.

2.3 Portlet action

Portlet operations include maximizing, minimizing, recovering, closing, editing, help, and moving up and down.
These operations have corresponding action classes.
The module/actions/controls directory of the open-source jetspeed project contains the maximize, minimize, close and other action classes.
The portal/Action directory of the liferay open-source project contains maximize, minimize, close, and other action classes.

Portal operations include not only the preceding Portlet operations, but also other advanced operations.
For example, add/move page, add/move column, layout, skin, and so on.

2.4 Portlet Cache

When operating A Portlet, we usually only operate on a specific Portlet, or just change the position of the Portlet. At this time, the content of most porlets on the page remains unchanged, with only one small Portlet changed.
We need to cache the content of the Portlet. The Portlet interface has a render (request, response) method. We can customize the response class, intercept the output of the Portlet, and save it to the content cache of the portal system.
For example, the stringservletresponse class of the liferay open-source project saves the output of the Portlet to a string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.