org.locomotive.module.pub
Class PublisherServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.locomotive.loco.servlet.LocoServlet
                    |
                    +--org.locomotive.module.pub.PublisherServlet

public class PublisherServlet
extends LocoServlet

This class is the main Servlet for the Locomotive Personal Website Publisher. This example module of the Locomotive allows users to create and design their own website by filling out text fields, inserting images, and arranging all of the HTML elements in a pre-arranged lay-out determined by the template selected by the user. The Locomotive stores all of the necessary information (text strings, images, which template is used, etc.) and automatically dynamically creates the page for viewing when the Servlet string is parsed to determine the specific user's page. This module also displays an index of published webpages, beginning with the most recent. NOTE: The image path (image_path) variable below must be modified All templates for the Publisher Module are in the templates/pub dir. The tokens and their corresponding methods are:

 Token          Method              Template
 [no token]     showMain()          pub/main.tmpl
 index          showDefaultIndex()  pub/index.tmpl
 approve        showApprove()       pub/approve.tmpl
 censor         showCensor()        pub/censor.tmpl
 create         showCreate()        pub/create.tmpl
 preview        showPreview()       pub/preview.tmpl 
 final          showFinal()         pub/final.tmpl
 

See Also:
Serialized Form

Field Summary
static int num_listings_per_index_page
          Constant used to determine how many page listings to show per index page.
static java.lang.String PUB_ADMIN
          Permission that allows a user to allow or censor newly user-created web pages.
 
Fields inherited from class org.locomotive.loco.servlet.LocoServlet
conn, DEBUG, ERROR, form_data, NORMAL, req, resp, session, steam_vars, url_tokens, user, WARNING
 
Constructor Summary
PublisherServlet()
           
 
Method Summary
static boolean fileRename(java.io.File oldfile, java.io.File newfile)
          This method is a workaround because the renameTo doesn't work on NFS mounted file systems I'd still consider it a bug -- a Java application or servlet has no idea whether a given path is a "single filesystem" or is NFS-mounted.
protected  void getPermissions()
          Prepares the PermissionSet object for permission checking.
 void init(javax.servlet.ServletConfig config)
          The required init method, as defined in org.locomotive.loco.Servlet.
 void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          main entry point called by RequestManager for each new request.
protected  void showApprove()
          Displays a page showing the list of not-yet-approved published pages.
protected  void showCensor()
          Displays a page showing the list of censored published pages.
protected  void showCreate()
          Displays the page used to create a web page.
protected  void showDefaultIndex()
          Shows the index of published pages that are not-yet-approved and approved.
protected  void showFinal()
          Displays the final published version of a page.
protected  boolean showIndex(int status)
          Displays a page showing a list of published pages.
protected  void showMain()
          Displays the main start page for this module.
protected  void showOwn()
          Shows the index of published pages owned by a user.
protected  void showPreview()
          Displays a preview of a published page.
 boolean shutdown(Log log)
          The required shutdown method, as defined in org.locomotive.loco.Servlet.
 
Methods inherited from class org.locomotive.loco.servlet.LocoServlet
displayPage, displayString, handleException, log, logEvent, sayBadURL, setup
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

num_listings_per_index_page

public static final int num_listings_per_index_page
Constant used to determine how many page listings to show per index page.

PUB_ADMIN

public static final java.lang.String PUB_ADMIN
Permission that allows a user to allow or censor newly user-created web pages.
Constructor Detail

PublisherServlet

public PublisherServlet()
Method Detail

service

public void service(javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse resp)
             throws javax.servlet.ServletException,
                    java.io.IOException
main entry point called by RequestManager for each new request.
Overrides:
service in class LocoServlet
Tags copied from class: LocoServlet
See Also:
LocoServlet.setup(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), javax.servlet.http.HttpServlet.html#service

showMain

protected void showMain()
                 throws java.io.IOException
Displays the main start page for this module. If the user has the PUB_ADMIN permission, then they are given links to the approval and censored index pages.

showIndex

protected boolean showIndex(int status)
                     throws java.io.IOException
Displays a page showing a list of published pages. The number token represents which range of pages to display. No number token will simply default to the first page of indexes.
Parameters:
status - status of pages we want to see an index for
Returns:
true if no error occurs and the index is not empty

showOwn

protected void showOwn()
                throws java.io.IOException
Shows the index of published pages owned by a user.

showDefaultIndex

protected void showDefaultIndex()
                         throws java.io.IOException
Shows the index of published pages that are not-yet-approved and approved. This is to be viewed by all.

showApprove

protected void showApprove()
                    throws java.io.IOException
Displays a page showing the list of not-yet-approved published pages. User must have the "PUB_ADMIN" permission to see this index. Token number decides which page of the index to display.

showCensor

protected void showCensor()
                   throws java.io.IOException
Displays a page showing the list of censored published pages. User must have the "PUB_ADMIN" permission to see this index. Token number decides which page of the index to display.

showCreate

protected void showCreate()
                   throws java.io.IOException
Displays the page used to create a web page.

showPreview

protected void showPreview()
                    throws java.io.IOException
Displays a preview of a published page. Essentially the same as showing the final version of the page, except with the addition of 'Modify' and 'Publish' buttons so that the user has the option to do more editing before actually publishing the page for public viewing.

showFinal

protected void showFinal()
                  throws java.io.IOException
Displays the final published version of a page. If the page is censored, only users with PUB_ADMIN permission can see the page. The token indicates the id of the page to display.

getPermissions

protected void getPermissions()
                       throws java.io.IOException
Prepares the PermissionSet object for permission checking.

init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
The required init method, as defined in org.locomotive.loco.Servlet.
Overrides:
init in class javax.servlet.GenericServlet

shutdown

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

fileRename

public static boolean fileRename(java.io.File oldfile,
                                 java.io.File newfile)
This method is a workaround because the renameTo doesn't work on NFS mounted file systems I'd still consider it a bug -- a Java application or servlet has no idea whether a given path is a "single filesystem" or is NFS-mounted. and is such a distinction "100% Pure Java"? Just what is, for the purposes of Java, a filesystem? Will this method fail when moving files to floppies on Macs or Windoze? Zip drives? Partitioned hard disks with aliases / shortcuts / symlinks between them? Returning a boolean is totally weak (worse yet, it's totally C); if this method is going to fail across NFS, a specific Exception would allow for more robust handling. If nothing else, the JDK javadocs should indicate the limits of this method. I too lost a lot of time discovering and working around this problem, and I'd like to see File.move(File) and File.copy(File) methods that work across NFS-mounted volumes.
See Also:
method,