| java.lang.Object org.jamwiki.servlets.ServletUtil
ServletUtil | public class ServletUtil (Code) | | Utility methods useful when processing JAMWiki servlet requests.
|
Method Summary | |
protected static String | cachedContent(String context, Locale locale, String virtualWiki, String topicName, boolean cook) Retrieve the content of a topic from the cache, or if it is not yet in
the cache then add it to the cache.
Parameters: context - The servlet context for the topic being retrieved. | protected static String | checkForSpam(HttpServletRequest request, String topicName, String contents) This is a utility method that will check topic content for spam, and
return null if no matching values are found, or if a spam
pattern is found then that pattern will be returned. | public static WikiUserAuth | currentUser() Retrieve the current WikiUserAuth from Acegi
SecurityContextHolder . | public static Watchlist | currentWatchlist(HttpServletRequest request, String virtualWiki) Retrieve the current logged-in user's watchlist from the session. | public static String | getIpAddress(HttpServletRequest request) Duplicate the functionality of the request.getRemoteAddr() method, but
for IPv6 addresses strip off any local interface information (anything
following a "%").
Parameters: request - the HTTP request object. | protected static Topic | initializeTopic(String virtualWiki, String topicName) Initialize topic values for a Topic object. | protected static boolean | isEditable(String virtualWiki, String topicName, WikiUserAuth user) Determine if a user has permission to edit a topic.
Parameters: virtualWiki - The virtual wiki name for the topic in question. Parameters: topicName - The name of the topic in question. Parameters: user - The current Wiki user, or null if there isno current user. | protected static boolean | isMoveable(String virtualWiki, String topicName, WikiUserAuth user) Determine if a user has permission to move a topic.
Parameters: virtualWiki - The virtual wiki name for the topic in question. Parameters: topicName - The name of the topic in question. Parameters: user - The current Wiki user, or null if there isno current user. | protected static boolean | isTopic(HttpServletRequest request, String value) Examine the request object, and see if the requested topic or page
matches a given value.
Parameters: request - The servlet request object. Parameters: value - The value to match against the current topic or page name. | protected static void | loadCategoryContent(ModelAndView next, String virtualWiki, String topicName) Utility method for adding categories associated with the current topic
to the ModelAndView object. | protected static void | loadDefaults(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) This method ensures that values required for rendering a JSP page have
been loaded into the ModelAndView object. | public static Pagination | loadPagination(HttpServletRequest request, ModelAndView next) Create a Pagination object and load all necessary values into the
request for processing by a JSP.
Parameters: request - The servlet request object. Parameters: next - A ModelAndView object corresponding to the page beingconstructed. | public static Iterator | processMultipartRequest(HttpServletRequest request, String uploadDirectory, long maxFileSize) Utility method for parsing a multipart servlet request. | protected static void | redirect(ModelAndView next, String virtualWiki, String destination) Modify the current ModelAndView object to create a Spring redirect
response, meaning that the view name becomes "redirect:" followed by
the redirection target.
Parameters: next - The current ModelAndView object, which will be reset bythis method. Parameters: virtualWiki - The virtual wiki name for the page being redirectedto. Parameters: destination - The topic or page name that is the redirectiontarget. | public static Locale | retrieveUserLocale(HttpServletRequest request) Users can specify a default locale in their preferences, so determine
if the current user is logged-in and has chosen a locale. | public static VirtualWiki | retrieveVirtualWiki(String virtualWikiName) Given a virtual wiki name, return a VirtualWiki object.
If there is no virtual wiki available with the given name then the
default virtual wiki is returned.
Parameters: virtualWikiName - The name of the virtual wiki that is beingretrieved. | protected static Vector | validateSystemSettings(Properties props) Validate that vital system properties, such as database connection settings,
have been specified properly.
Parameters: props - The property object to validate against. | protected static ModelAndView | viewError(HttpServletRequest request, Throwable t) Utility method used when redirecting to an error page.
Parameters: request - The servlet request object. Parameters: t - The exception that is the source of the error. | protected static ModelAndView | viewLogin(HttpServletRequest request, WikiPageInfo pageInfo, String topic, WikiMessage messageObject) Utility method used when redirecting to a login page.
Parameters: request - The servlet request object. Parameters: pageInfo - The current WikiPageInfo object, which containsinformation needed for rendering the final JSP page. Parameters: topic - The topic to be redirected to. | protected static void | viewTopic(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName) Utility method used when viewing a topic.
Parameters: request - The current servlet request object. Parameters: next - The current Spring ModelAndView object. Parameters: pageInfo - The current WikiPageInfo object, which containsinformation needed for rendering the final JSP page. Parameters: topicName - The topic being viewed. | protected static void | viewTopic(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, WikiMessage pageTitle, Topic topic, boolean sectionEdit) Utility method used when viewing a topic. |
PARAMETER_PAGE_INFO | final public static String PARAMETER_PAGE_INFO(Code) | | |
PARAMETER_TOPIC_OBJECT | final public static String PARAMETER_TOPIC_OBJECT(Code) | | |
cachedContent | protected static String cachedContent(String context, Locale locale, String virtualWiki, String topicName, boolean cook)(Code) | | Retrieve the content of a topic from the cache, or if it is not yet in
the cache then add it to the cache.
Parameters: context - The servlet context for the topic being retrieved. Maybe null if the cook parameter is set tofalse . Parameters: locale - The locale for the topic being retrieved. May benull if the cook parameter is set tofalse . Parameters: virtualWiki - The virtual wiki for the topic being retrieved. Parameters: topicName - The name of the topic being retrieved. Parameters: cook - A parameter indicating whether or not the content should beparsed before it is added to the cache. Stylesheet content (CSS) is notparsed, but most other content is parsed. The parsed or unparsed (depending on the cook parameter) topic content. |
checkForSpam | protected static String checkForSpam(HttpServletRequest request, String topicName, String contents) throws Exception(Code) | | This is a utility method that will check topic content for spam, and
return null if no matching values are found, or if a spam
pattern is found then that pattern will be returned. It will also log
information about the offending spam and user to the logs.
Parameters: request - The current servlet request. Parameters: topicName - The name of the current topic being edited. Parameters: contents - The text for the current topic that the user is trying toadd. null if nothing in the topic content matches a currentspam pattern, or the text that matches a spam pattern if one is found. |
currentUser | public static WikiUserAuth currentUser() throws AuthenticationCredentialsNotFoundException(Code) | | Retrieve the current WikiUserAuth from Acegi
SecurityContextHolder . If the current user is not
logged-in then this method will return an empty WikiUserAuth
object.
The current logged-in WikiUserAuth , or an emptyWikiUserAuth if there is no user currently logged in.This method will never return null . throws: AuthenticationCredentialsNotFoundException - If authenticationcredentials are unavailable. |
currentWatchlist | public static Watchlist currentWatchlist(HttpServletRequest request, String virtualWiki) throws Exception(Code) | | Retrieve the current logged-in user's watchlist from the session. If
there is no watchlist return an empty watchlist.
Parameters: request - The servlet request object. Parameters: virtualWiki - The virtual wiki for the watchlist being parsed. The current logged-in user's watchlist, or an empty watchlistif there is no watchlist in the session. |
getIpAddress | public static String getIpAddress(HttpServletRequest request)(Code) | | Duplicate the functionality of the request.getRemoteAddr() method, but
for IPv6 addresses strip off any local interface information (anything
following a "%").
Parameters: request - the HTTP request object. The IP address that the request originated from, or 0.0.0.0 ifthe originating address cannot be determined. |
initializeTopic | protected static Topic initializeTopic(String virtualWiki, String topicName) throws Exception(Code) | | Initialize topic values for a Topic object. This method will check to
see if a topic with the specified name exists, and if it does exist
then that topic will be returned. Otherwise a new topic will be
initialized, setting initial parameters such as topic name, virtual
wiki, and topic type.
Parameters: virtualWiki - The virtual wiki name for the topic beinginitialized. Parameters: topicName - The name of the topic being initialized. A new topic object with basic fields initialized, or if a topicwith the given name already exists then the pre-existing topic isreturned. throws: Exception - Thrown if any error occurs while retrieving orinitializing the topic object. |
isEditable | protected static boolean isEditable(String virtualWiki, String topicName, WikiUserAuth user) throws Exception(Code) | | Determine if a user has permission to edit a topic.
Parameters: virtualWiki - The virtual wiki name for the topic in question. Parameters: topicName - The name of the topic in question. Parameters: user - The current Wiki user, or null if there isno current user. true if the user is allowed to edit the topic,false otherwise. |
isMoveable | protected static boolean isMoveable(String virtualWiki, String topicName, WikiUserAuth user) throws Exception(Code) | | Determine if a user has permission to move a topic.
Parameters: virtualWiki - The virtual wiki name for the topic in question. Parameters: topicName - The name of the topic in question. Parameters: user - The current Wiki user, or null if there isno current user. true if the user is allowed to move the topic,false otherwise. |
isTopic | protected static boolean isTopic(HttpServletRequest request, String value)(Code) | | Examine the request object, and see if the requested topic or page
matches a given value.
Parameters: request - The servlet request object. Parameters: value - The value to match against the current topic or page name. true if the value matches the current topic orpage name, false otherwise. |
loadCategoryContent | protected static void loadCategoryContent(ModelAndView next, String virtualWiki, String topicName) throws Exception(Code) | | Utility method for adding categories associated with the current topic
to the ModelAndView object. This method adds a hashmap of category
names and sort keys to the session that can then be retrieved for
display during rendering.
Parameters: next - The current ModelAndView object used to return renderinginformation. Parameters: virtualWiki - The virtual wiki name for the topic being rendered. Parameters: topicName - The name of the topic that is being rendered. |
loadDefaults | protected static void loadDefaults(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception(Code) | | This method ensures that values required for rendering a JSP page have
been loaded into the ModelAndView object. Examples of values that
may be handled by this method include topic name, username, etc.
Parameters: request - The current servlet request object. Parameters: next - The current ModelAndView object. Parameters: pageInfo - The current WikiPageInfo object, containing basic pagerendering information. |
loadPagination | public static Pagination loadPagination(HttpServletRequest request, ModelAndView next)(Code) | | Create a Pagination object and load all necessary values into the
request for processing by a JSP.
Parameters: request - The servlet request object. Parameters: next - A ModelAndView object corresponding to the page beingconstructed. A Pagination object constructed from parameters found in therequest object. |
processMultipartRequest | public static Iterator processMultipartRequest(HttpServletRequest request, String uploadDirectory, long maxFileSize) throws Exception(Code) | | Utility method for parsing a multipart servlet request. This method returns
an iterator of FileItem objects that corresponds to the request.
Parameters: request - The servlet request containing the multipart request. Parameters: uploadDirectory - The directory into which files will be uploaded. Parameters: maxFileSize - The maximum allowed file size in bytes. Returns an iterator of FileItem objects the corresponds to the request. throws: Exception - Thrown if any problems occur while processing the request. |
redirect | protected static void redirect(ModelAndView next, String virtualWiki, String destination) throws Exception(Code) | | Modify the current ModelAndView object to create a Spring redirect
response, meaning that the view name becomes "redirect:" followed by
the redirection target.
Parameters: next - The current ModelAndView object, which will be reset bythis method. Parameters: virtualWiki - The virtual wiki name for the page being redirectedto. Parameters: destination - The topic or page name that is the redirectiontarget. An example might be "Special:Login". |
retrieveUserLocale | public static Locale retrieveUserLocale(HttpServletRequest request)(Code) | | Users can specify a default locale in their preferences, so determine
if the current user is logged-in and has chosen a locale. If not, use
the default locale from the request object.
Parameters: request - The request object for the HTTP request. Either the user's default locale (for logged-in users) or thelocale specified in the request if no default locale is available. |
retrieveVirtualWiki | public static VirtualWiki retrieveVirtualWiki(String virtualWikiName)(Code) | | Given a virtual wiki name, return a VirtualWiki object.
If there is no virtual wiki available with the given name then the
default virtual wiki is returned.
Parameters: virtualWikiName - The name of the virtual wiki that is beingretrieved. A VirtualWiki object. If there is no virtualwiki available with the given name then the default virtual wiki isreturned. |
validateSystemSettings | protected static Vector validateSystemSettings(Properties props)(Code) | | Validate that vital system properties, such as database connection settings,
have been specified properly.
Parameters: props - The property object to validate against. A Vector of WikiMessage objects containing any errors encountered,or an empty Vector if no errors are encountered. |
viewError | protected static ModelAndView viewError(HttpServletRequest request, Throwable t)(Code) | | Utility method used when redirecting to an error page.
Parameters: request - The servlet request object. Parameters: t - The exception that is the source of the error. Returns a ModelAndView object corresponding to the error page display. |
viewLogin | protected static ModelAndView viewLogin(HttpServletRequest request, WikiPageInfo pageInfo, String topic, WikiMessage messageObject) throws Exception(Code) | | Utility method used when redirecting to a login page.
Parameters: request - The servlet request object. Parameters: pageInfo - The current WikiPageInfo object, which containsinformation needed for rendering the final JSP page. Parameters: topic - The topic to be redirected to. Valid examples are"Special:Admin", "StartingPoints", etc. Parameters: messageObject - A WikiMessage object to be displayed on the loginpage. Returns a ModelAndView object corresponding to the login pagedisplay. throws: Exception - Thrown if any error occurs during processing. |
viewTopic | protected static void viewTopic(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, String topicName) throws Exception(Code) | | Utility method used when viewing a topic.
Parameters: request - The current servlet request object. Parameters: next - The current Spring ModelAndView object. Parameters: pageInfo - The current WikiPageInfo object, which containsinformation needed for rendering the final JSP page. Parameters: topicName - The topic being viewed. This value must be a validtopic that can be loaded as a org.jamwiki.model.Topic object. throws: Exception - Thrown if any error occurs during processing. |
viewTopic | protected static void viewTopic(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo, WikiMessage pageTitle, Topic topic, boolean sectionEdit) throws Exception(Code) | | Utility method used when viewing a topic.
Parameters: request - The current servlet request object. Parameters: next - The current Spring ModelAndView object. Parameters: pageInfo - The current WikiPageInfo object, which containsinformation needed for rendering the final JSP page. Parameters: pageTitle - The title of the page being rendered. Parameters: topic - The Topic object for the topic being displayed. Parameters: sectionEdit - Set to true if edit links should be displayedfor each section of the topic. throws: Exception - Thrown if any error occurs during processing. |
|
|