simple.template
Class View

java.lang.Object
  extended by simple.http.serve.Component
      extended by simple.http.load.Service
          extended by simple.template.Controller
              extended by simple.template.View
All Implemented Interfaces:
Resource

public abstract class View
extends Controller

The View object provides a service controller implementation for providing a document view. It is used to implement controllers that ultimately render a view for a template. Typically the execute methods are implemented to populate a template document with the objects that are used by the template to render the dynamic content.

The lookup and resolve methods are used to acquire the desired template document. This must then be returned for the view to be rendered. If at any stage during processing and error occurs then an exception may be thrown to the calling method to indicate the problem.

Author:
Niall Gallagher

Field Summary
 
Fields inherited from class simple.template.Controller
data, system
 
Fields inherited from class simple.http.load.Service
engine
 
Fields inherited from class simple.http.serve.Component
context
 
Constructor Summary
View(Context context)
          Constructor for the View object.
 
Method Summary
 Document execute(Request req, Response resp)
          The execute method is used to perform various operations before a template is rendered.
 Document execute(Request req, Response resp, Document doc)
          The execute method is used to perform various operations before a template is rendered.
 Document lookup(java.lang.String target)
          This method is used to retrieve templates using the name or path for that template.
protected  void process(Request req, Response resp)
          This process method is used to drive the execute methods.
 Document resolve(java.lang.String target)
          This method is used to retrieve templates using a specific URI.
 
Methods inherited from class simple.template.Controller
prepare, prepare
 
Methods inherited from class simple.http.load.Service
prepare
 
Methods inherited from class simple.http.serve.Component
handle, handle, handle, process, process
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

View

public View(Context context)
Constructor for the View object. This is used to create an View implementation that can be used as a controller service. Any subclass of this can initialize itself using the prepare method.

Parameters:
context - the context this controller is rooted at
Method Detail

process

protected void process(Request req,
                       Response resp)
                throws java.lang.Exception
This process method is used to drive the execute methods. This will simply invoke the method and write the resulting Document to the responses output. This also sets the HTTP "Content-Type" header using the name of the target. This will is only set is it has not already been done so. However, this should not be relied upon and each implementation should set its own MIME type in order for the charset to be correct.

Specified by:
process in class Component
Parameters:
req - the HTTP request object representing the client
resp - the HTTP response object to send a reply with
Throws:
java.lang.Exception - thrown if there is a problem processing

execute

public Document execute(Request req,
                        Response resp)
                 throws java.lang.Exception
The execute method is used to perform various operations before a template is rendered. This typically collects data that is used to render the template with the information. This encourages the Model View Controller (MVC) architecture to be used, and avoids dealing with the view.

Parameters:
req - the HTTP request object representing the client
resp - the HTTP response object to send a reply with
Returns:
this returns the document that is to be rendered
Throws:
java.lang.Exception - thrown if there is a problem processing

execute

public Document execute(Request req,
                        Response resp,
                        Document doc)
                 throws java.lang.Exception
The execute method is used to perform various operations before a template is rendered. This typically collects data that is used to render the template with the information. This encourages the Model View Controller (MVC) architecture to be used, and avoids dealing with the view.

This method is useful when a layout or other such embedding is required. This also avoids having to deal directly with the resolve and lookup methods.

Parameters:
req - the HTTP request object representing the client
resp - the HTTP response object to send a reply with
doc - the document object suggested for processing
Returns:
this returns the document that is to be rendered
Throws:
java.lang.Exception - thrown if there is a problem processing

lookup

public Document lookup(java.lang.String target)
                throws java.lang.Exception
This method is used to retrieve templates using the name or path for that template. This will typically map directly to the Environment object's lookup. However, if desired, extra functionality can be introduced to provide more useful names for templates, like "failure".

Parameters:
target - the name or path referencing the template
Returns:
the Document for the template
Throws:
java.lang.Exception

resolve

public Document resolve(java.lang.String target)
                 throws java.lang.Exception
This method is used to retrieve templates using a specific URI. The URI format is not important, this method should be able to handle absolute and realitive URI formats. The following list of URI strings should be acceptable forms:
 
 http://www.domain.com/path?query
 /path;param=value?query
 /path/file

 
Like the lookup method this will typically map directly to its counterpart Environment method. However, extra functionality can be introduced to map URI strings to the desired template documents.

Parameters:
target - the URI string referencing the template
Returns:
the Document for the template
Throws:
java.lang.Exception