HttpPageletAdaptor¶
-
public abstract class
HttpPageletAdaptor
extends HttpRequestAdaptor¶ HttpPageletAdaptor is an HTTP request adaptor which generates a page from a template pagelet. A template pagelet may contain the content, or part of the content, of the page to be generated. It also describes the layout of other pagelets in the page.
The tag in the template which declares a pagelet should follow the convention stated below:
<!-- template-[pagelet-id] -->
By default, there are two generation modes of the page.
- full - Generate the page according to the template pre-defined by this adaptor. This is the default generation mode.
- raw - Generate the page according to the dynamically specified pagelet.
Note: All the pagelets, including the template, must be saved in UTF-8 encoding.
Author: Hugo Y. K. Lam See also:
Pagelet
,PageletStore
,Template
Methods¶
getErrorPagelet¶
-
protected Pagelet
getErrorPagelet
(HttpServletRequest request)¶ Gets the error pagelet. This method invokes getPagelet() with a parameter “&pagelet-error”.
Parameters: - request – the servlet request.
Returns: the template pagelet.
getPagelet¶
-
protected Pagelet
getPagelet
(String id)¶ Gets the pagelet from the underlying pagelet store. If the specified ID is preceded by an ampersand, it indicates the pagelet id should be firstly treated as a listener parameter name which has a value of the target pagelet ID. In this case, if there is a corresponding listener parameter, its value will be used as the target pagelet ID. Otherwise, the specified id will be matched against the underlying pagelet store as if there is no ampersand indicator.
Parameters: - id – the pagelet ID.
Returns: the corresponding pagelet or null if not found.
getPageletStore¶
-
protected abstract PageletStore
getPageletStore
()¶ Gets the pagelet store which holds all the registered pagelets of this adaptor.
Returns: a pagelet store.
getTemplate¶
-
protected Pagelet
getTemplate
(HttpServletRequest request)¶ Gets the template pagelet. This method invokes getPagelet() with a parameter “&pagelet-template”.
Parameters: - request – the servlet request.
Returns: the template pagelet.
processError¶
-
protected void
processError
(TemplateElement element, Throwable error, HttpServletRequest request, HttpServletResponse response)¶ Processes the error generated when processing a pagelet.
Parameters: - element – the template element which represents the pagelet.
- error – the error generated by the pagelet process.
- request – the servlet request.
- response – the servlet response.
Throws: - RequestListenerException – if unable to process the pagelet error.
See also:
.processTemplate(HttpServletRequest,HttpServletResponse)
processPagelet¶
-
protected void
processPagelet
(TemplateElement element, Pagelet pagelet, HttpServletRequest request, HttpServletResponse response)¶ Processes the pagelet of the generating page by reading the content from the pagelet and generates it to the output.
Parameters: - element – the template element which represents the pagelet.
- pagelet – the pagelet to be processed.
- request – the servlet request.
- response – the servlet response.
Throws: - RequestListenerException – if unable to process the pagelet.
See also:
.processTemplate(HttpServletRequest,HttpServletResponse)
processRequest¶
-
public String
processRequest
(HttpServletRequest request, HttpServletResponse response)¶ Processes the page request. This method determines if the generation mode is “raw”. If not, it invokes processTemplate() to complete the rest of the generation.
See also:
.processTemplate(HttpServletRequest,HttpServletResponse)
,hk.hku.cecid.piazza.commons.servlet.http.HttpRequestListener.processRequest(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
processTemplate¶
-
protected void
processTemplate
(HttpServletRequest request, HttpServletResponse response)¶ Processes the template of the generating page. This method invokes getTemplate() to retrieve the template pagelet. It then generates the page according to the pagelet. The content of the template pagelet will be parsed according to the following alogirthm:
- When it encounters any text other than a template tag, it invokes processText() to generate the content.
- When it encounters a template tag in the template, it invokes processPagelet() to generate the content.
- When it encounters any errors while invoking processPagelet(), it will invokes processError() to generate the content.
Parameters: - request – the servlet request.
- response – the servlet response.
Throws: - RequestListenerException – if unable to process the template.
See also:
.getTemplate(HttpServletRequest)
,.processText(TemplateElement,String,HttpServletRequest,HttpServletResponse)
,.processPagelet(TemplateElement,Pagelet,HttpServletRequest,HttpServletResponse)
,.processError(TemplateElement,Throwable,HttpServletRequest,HttpServletResponse)
processText¶
-
protected void
processText
(TemplateElement element, String text, HttpServletRequest request, HttpServletResponse response)¶ Processes the text part of the generating page by simply generating the text to the output.
Parameters: - element – the template element which represents the text.
- text – the text to be processed.
- request – the servlet request.
- response – the servlet response.
Throws: - RequestListenerException – if unable to process the text.
See also:
.processTemplate(HttpServletRequest,HttpServletResponse)