org.locomotive.module.discuss
Class DiscussionHandler

java.lang.Object
  |
  +--org.locomotive.loco.handler.GenericHandler
        |
        +--org.locomotive.module.discuss.DiscussionHandler

public class DiscussionHandler
extends GenericHandler

This class is the main handler class for The Locomotive Discussion system. The Locomotive Discussion system is a simple three-level web-based conferencing system for hosting non-threaded discussions. This particular class directs the appropriate requests to the appropriate Handlers and provides a number of utility methods for use by those handlers. The templates used for the various URL's handled by this class are listed under the handleRequest method.

See Also:
handleRequest

Field Summary
protected static DiscussionLib lib
           
static int numPostsToDisplay
          SET THIS TO DETERMINE THE NUMBER OF POSTS TO DISPLAY ON THE PAGE
 
Fields inherited from class org.locomotive.loco.handler.GenericHandler
already_displayed_page, conn, DEBUG, ERROR, form_data, handler_uri, hd, NORMAL, session, steam_vars, url_tokens, user, WARNING
 
Constructor Summary
DiscussionHandler()
           
 
Method Summary
protected  void addPost()
          This method handles adding a post to a topic.
protected  void addTopic()
          This method handles adding a topic to a category.
 void handleRequest(HandlerData hd_in)
          The main method to call for this Handler.
 boolean init(Log log)
          The required init method, as defined in org.locomotive.loco.Handler.
protected static void insertTemplate(HandlerData hd, java.lang.String key)
          evaluate a template using the template path from the template hash and flush the template through hd.resp.
protected  SortableTable permPruneCategoriesTable(SortableTable categoriesTable)
          Permission prune the categories table, removing the categories for which this user does not have read permission.
protected  SortableTable permPruneTopicsTable(SortableTable topicsTable)
           
protected  void showCategory()
          This method displays the Discussion cateogory page, which shows a list of the topics in that category.
protected  void showDefault()
          This method displays the default Discussion Page, which contains a list of categories to choose from along with choices on where to go.
protected  void showSummary()
          This method shows a summary of posts for a given topic.
protected  void showTopic()
          This method displays the topic page, which contains a set of the posts for that topic.
 boolean shutdown(Log log)
          The required shutdown method, as defined in org.locomotive.loco.Handler.
 
Methods inherited from class org.locomotive.loco.handler.GenericHandler
displayPage, displayString, handleException, log, logEvent, sayBadURL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lib

protected static DiscussionLib lib

numPostsToDisplay

public static final int numPostsToDisplay
SET THIS TO DETERMINE THE NUMBER OF POSTS TO DISPLAY ON THE PAGE
Constructor Detail

DiscussionHandler

public DiscussionHandler()
Method Detail

handleRequest

public void handleRequest(HandlerData hd_in)
The main method to call for this Handler. Directs the handling of the request to the appropriate places depending on the url tokens found. Presently handles five different URL Tokens. To do any custom handling for these tokens, override the methods which handle the actions involved with each token. The tokens and their corresponding methods are:
  Token      Method            Template
  CMCAT      showCategory()    discuss/community/comm_disc.tmpl
  CMTOP      showTopic()       discuss/community/comm_disc_topic.tmpl
  POST       addPost()         discuss/community/comm_disc_topic.tmpl
  TOPIC      addTopic()        discuss/community/comm_disc_topic_new.tmpl
  SUMMARY    showSummary()     discuss/community/comm_disc_topic_sum.tmpl
  Admin      see handleAdminHandler()
  [no token] showDefault()     discuss/community/comm_section.tmpl
 
Overrides:
handleRequest in class GenericHandler

showDefault

protected void showDefault()
This method displays the default Discussion Page, which contains a list of categories to choose from along with choices on where to go.

Puts the following subs into the environment:

     categories_table      SortableTable with columns: id, title, 
                                 description
     num_posts_to_display  the number of posts to display on the 
                           topics page
 

showCategory

protected void showCategory()
This method displays the Discussion cateogory page, which shows a list of the topics in that category. The category to display the topics for is provided by the URL token which follows the CMCAT token that calls this method.

Puts the following subs into the environment:

   navigation     the html for the navigation sidebar
   category_info  SortableTable with columns: id, title, description, 
                          topic_count, post_count, last_post_date
   topics_table   SortableTable with columns: topicid, communityid, 
                          topicname, post_count, last_post_date
   num_posts_to_display  the number of posts to display on the 
                          topics page
 

showTopic

protected void showTopic()
This method displays the topic page, which contains a set of the posts for that topic. The URL tokens for this function must be the following:
Community?CMTOP+<topicID>+<numberOfPostsToDisplay>+<postStartNum>
where the topicID is the unique topic id number for the topic whose posts the page show display, the postStartNum is the post number to start on, and the numberOfPostsToDisplay is the number of posts to display on the page.

Note that this method displays the posts in descending order, so that a URL of Community?CMTOP+2+10+192 would display posts 183 to 192 from top to bottom on the first page, and the URL of Community?CMTOP+2+10+182 would display posts 173 to 182 from the top to the bottom of the page.

The defaults for these values are the latest post for postStartNum, and 10 for numberOfPostsToDisplay, so the URL Community?CMTOP+2 evaluates to Community?CMTOP+2+10+192, if 192 is the number of the latest post.

This method also inserts into steam_vars an array of urls to all the pages that would be generated to see all the posts for the current topic, at the current numberOfPostsToDisplay token. Thus, the first example above would provide an array of 20 urls which would point to each page needed to display all the posts. Note that The page designer, using the [loop ] expression, can display as many or all of these as he or she would like. See the steam documentation for more on this.

Puts the following subs into the environment:

     navigation      the html for the navigation sidebar
     category_info   SortableTable with columns: id, title, description, 
                          topic_count, post_count, last_post_date
     topic_info      SortableTable with columns: topicid, communityid, 
                          topicname, post_count, last_post_date 
     post_table      SortableTable with columns: postid, posttitle, 
                          postbody, postauthorfn, postauthorln, 
                          postemail, postdate
     post_links      Array of strings that provide the links to each
                          page of posts
     num_posts_to_display  the number of posts to display on the 
                            topics page
 

addTopic

protected void addTopic()
This method handles adding a topic to a category. The category to add the topic under is specified by the url token that follows the TOPIC token. This will add the topic specified, and display the 'add a first post template', whose actions are handled by the addPost method in this class.

Puts the following subs into the environment:

     category_info  SortableTable with columns: id, title, description, 
                          topic_count, post_count, last_post_date
     topic_info      SortableTable with columns: topicid, communityid, 
                          topicname, post_count, last_post_date, 
     error_msg       Message if topic could not be added
     num_posts_to_display  the number of posts to display on the 
                           topics page
 

addPost

protected void addPost()
This method handles adding a post to a topic. The topic to add the This will add a post using the form data passed to it, and then display The topic to add th the Topics page, displaying the post that was just added. post under is specified by the url token that follows the POST token. The last post that was displayed on the page is the last URL token. This allows us to know what the last post was before the user began to write the reply...

Puts the following subs into the environment:

     These are added only if there was an error adding the post:
     error_msg       an error explaining why post could not be added
     post_title      title entered for the failed post
     post_body       body entered for the failed post
     firstname       first name entered the for the failed post
     lastname        last name entered for the failed post
     email           email entered for the failed post
     num_posts_to_display  the number of posts to display on the 
                           topics page
 

showSummary

protected void showSummary()
This method shows a summary of posts for a given topic. The URL is as follows:
Community?SUMMARY+<topicID>+<displayOrder>
The order token may be either DATE, POST, or AUTHOR. Thus an example summary URL might look like: Community?SUMMARY+174+AUTHOR.

Puts the following subs into the environment:

     navigation            the html for the navigation sidebar
     post_summaries  SortableTable with columns: postid, posttitle, 
                             postauthorfn, postauthorln, postemail,
                             postdate
     topic_info      SortableTable with columns:  topicid, communityid, 
                             topicname
     category_info   SortableTable with columns: id, title, description, 
                          topic_count, post_count, last_post_date
     post_links      an array containing the post numbers to show at 
                          the bottom of the topics page when the
                          links for each post are followed
     num_posts_to_display  the number of posts to display on the 
                           topics page
 

insertTemplate

protected static void insertTemplate(HandlerData hd,
                                     java.lang.String key)
evaluate a template using the template path from the template hash and flush the template through hd.resp.
Parameters:
key - the key to use to get the template path from the hash

permPruneCategoriesTable

protected SortableTable permPruneCategoriesTable(SortableTable categoriesTable)
Permission prune the categories table, removing the categories for which this user does not have read permission. This is done by starting with a blank version of the table and adding the rows of only permissable categories.
Parameters:
categoriesTable - SortableTable containing the categories

permPruneTopicsTable

protected SortableTable permPruneTopicsTable(SortableTable topicsTable)

init

public boolean init(Log log)
The required init method, as defined in org.locomotive.loco.Handler. In this example, we load all the templates into a hashtable for easy access.
Overrides:
init in class GenericHandler
See Also:
org.locomotive.loco.Handler

shutdown

public boolean shutdown(Log log)
The required shutdown method, as defined in org.locomotive.loco.Handler. In this example, we don't actually need to do anything.
Overrides:
shutdown in class GenericHandler
See Also:
org.locomotive.loco.Handler#shutdown