org.locomotive.module.pub
Class PublisherLib

java.lang.Object
  |
  +--org.locomotive.module.pub.PublisherLib

public class PublisherLib
extends java.lang.Object

This class provides a series of static methods which return Database information used by the Locomotive Publisher system.


Field Summary
static int APPROVED
           
static int CENSORED
          Constants used to denote the different statuses that a published page can be in:
static int NOT_YET_APPROVED
           
static int NYA_AND_APPR
           
 
Constructor Summary
PublisherLib()
           
 
Method Summary
static boolean changeStatus(java.sql.Connection conn, int page_id, int status)
          Changes the status of a page in the database.
static SortableTable getIndexTable(java.sql.Connection conn, int low_range, int high_range, int status)
          Returns a table containing index information of published pages between the two ranges inclusive, beginning with most recent page.
static int getMostRecentId(java.sql.Connection conn, int userid)
          Returns the most recently inserted page id of a user.
static int getNumPages(java.sql.Connection conn, int status)
          Returns the number of published pages in the database according to status.
static void getPageInfo(java.sql.Connection conn, int id, java.util.Hashtable hash_in)
          Returns all the fields of a user page (identified by its id) in a SortableTable.
static int getStatus(java.sql.Connection conn, int page_id)
          Changes the status of a page in the database.
static SortableTable getUserPageIndex(java.sql.Connection conn, int userid)
          Returns an index of pages of a single user.
static boolean insertImagesIntoPage(java.sql.Connection conn, int id, java.lang.String image_one, java.lang.String image_two)
          Inserts images into a page entry.
static boolean insertPage(java.sql.Connection conn, int userid, java.lang.String title, java.lang.String body_one, java.lang.String body_two, java.lang.String caption_one, java.lang.String caption_two, java.lang.String template)
          Creates a page entry into the database for the first time.
static boolean isOwner(java.sql.Connection conn, int id, int userid)
          Verifies if a user is the owner of this page or not.
static boolean reInsertPage(java.sql.Connection conn, int id, java.lang.String title, java.lang.String body_one, java.lang.String body_two, java.lang.String image_one, java.lang.String image_two, java.lang.String caption_one, java.lang.String caption_two, java.lang.String template)
          Re-inserts a page entry into the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENSORED

public static final int CENSORED
Constants used to denote the different statuses that a published page can be in:

NOT_YET_APPROVED

public static final int NOT_YET_APPROVED

APPROVED

public static final int APPROVED

NYA_AND_APPR

public static final int NYA_AND_APPR
Constructor Detail

PublisherLib

public PublisherLib()
Method Detail

insertPage

public static boolean insertPage(java.sql.Connection conn,
                                 int userid,
                                 java.lang.String title,
                                 java.lang.String body_one,
                                 java.lang.String body_two,
                                 java.lang.String caption_one,
                                 java.lang.String caption_two,
                                 java.lang.String template)
Creates a page entry into the database for the first time. Note that images are omitted because the images need the id of this entry first to be appended to their names.
Parameters:
conn - database connection
userid - page creator
title - title of page
body_one - first body text field
body_two - second body text field
caption_one - String caption for first image
caption_two - String caption for second image
template - String name of template file
Returns:
false if a database error occurs

insertImagesIntoPage

public static boolean insertImagesIntoPage(java.sql.Connection conn,
                                           int id,
                                           java.lang.String image_one,
                                           java.lang.String image_two)
Inserts images into a page entry. Must be done afterwards because the image name has to have the id name appended to it, and the id is not given until after an entry for the page has been made.
Parameters:
conn - database connection
id - page id
image_one - first image filename
image_two - second image filename
Returns:
false if a database error occurs

reInsertPage

public static boolean reInsertPage(java.sql.Connection conn,
                                   int id,
                                   java.lang.String title,
                                   java.lang.String body_one,
                                   java.lang.String body_two,
                                   java.lang.String image_one,
                                   java.lang.String image_two,
                                   java.lang.String caption_one,
                                   java.lang.String caption_two,
                                   java.lang.String template)
Re-inserts a page entry into the database.
Parameters:
id - id of page
body_one - first body text field
body_two - second body text field
image_one - name of first image file
image_two - name of second image file
caption_one - String caption for first image
caption_two - String caption for second image
template - String name of template file
Returns:
false if a database error occurs

getMostRecentId

public static int getMostRecentId(java.sql.Connection conn,
                                  int userid)
Returns the most recently inserted page id of a user.
Parameters:
conn - database connection
userid - userid of user
Returns:
page id, -1 if none exists

getPageInfo

public static void getPageInfo(java.sql.Connection conn,
                               int id,
                               java.util.Hashtable hash_in)
Returns all the fields of a user page (identified by its id) in a SortableTable.
Parameters:
conn - database connection
id - page id
hash_in - Hashtable to put these values in: id (page id) userid title modified (date) status (ie. NOT_YET_APPROVED) template (filename) body_one (text) body_two image_one (filename) image_two (filename) caption_one (text) caption_two

isOwner

public static boolean isOwner(java.sql.Connection conn,
                              int id,
                              int userid)
Verifies if a user is the owner of this page or not.
Parameters:
conn - database connection
id - page id
userid - id of user
Returns:
true if the user is the creator of this page

getNumPages

public static int getNumPages(java.sql.Connection conn,
                              int status)
Returns the number of published pages in the database according to status.
Parameters:
conn - database connection
status - constant indicating the status of the pages to count
Returns:
-1 if a database error occurs

getIndexTable

public static SortableTable getIndexTable(java.sql.Connection conn,
                                          int low_range,
                                          int high_range,
                                          int status)
Returns a table containing index information of published pages between the two ranges inclusive, beginning with most recent page.
Parameters:
conn - database connection
low_range - index 1 is the most recent page, the lowest range
high_range - should not exceed the number of published pages in the database
status - constant indicating the status of the pages to fetch
Returns:
SortableTable with the following columns: id (page id) modified (date) username (author) title

getUserPageIndex

public static SortableTable getUserPageIndex(java.sql.Connection conn,
                                             int userid)
Returns an index of pages of a single user.
Parameters:
conn - database connection
userid - id of user
Returns:
SortableTable with the following columns: id (page id) modified (date) username (author) title status

getStatus

public static int getStatus(java.sql.Connection conn,
                            int page_id)
Changes the status of a page in the database.
Parameters:
conn - database connection
page_id - id of the web page
Returns:
-2 if page does not exist

changeStatus

public static boolean changeStatus(java.sql.Connection conn,
                                   int page_id,
                                   int status)
Changes the status of a page in the database.
Parameters:
conn - database connection
page_id - id of the web page
status - status to change the page to
Returns:
false if a database error occurs