Getter methods in jPublishContext

Florian Gnägi <[email protected]> Mon, 2 Dec 2002 11:47:07 +0100
Newsgroups gmane.comp.java.jpublish.devel
Organization OLAT-Zentrum Universität Zürich
Message-ID <00af01c299f0$308bbc20$9f703c82@zipcfg>
Hi all

I added convenience getter methods for the jPublishContext to get the current page, session, request etc. I find coding with this methods much saver since one does not have to use strings or constants in the actions. This is also better for refactoring (eclipse's refactoring features are sooo helpful!), automatic code completion and gives more readable and more compact code. 

What do you think?

Sincerly
-florian

Florian Gnägi <[email protected]>
http://www.olat-zentrum.unizh.ch

Center for Computing Services
OLAT-Zentrum
University of Zurich                Phone: +41 1 63 56788
Winterthurerstrasse 190
CH-8057 Zuerich                  FAX:   +41 1 63 54505
jpublishContext-patch.txt (text/plain, 3.1 KB)
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.jpublish.util.CharacterEncodingMap;
import org.jpublish.util.DateUtilities;
import org.jpublish.util.NumberUtilities;
import org.jpublish.util.URLUtilities;
import com.anthonyeden.lib.log.Logger;



	/**
	 * Convenience methods for getting objects stored in the jPublish context
	 */
	
	/** Get the current HTTP-request object
	 * @return The HTTP servlet request or null if not available
	 */
	public HttpServletRequest getRequest() {
		return (HttpServletRequest) get(JPUBLISH_REQUEST);
	}
	
	/** Get the current HTTP-response object
	 * @return The HTTP servlet response or null if not available
	 */
	public HttpServletResponse getResponse() {
		return (HttpServletResponse) get(JPUBLISH_RESPONSE);
	}
	
	/** Get the current HTTP session object
	 * @return The HTTP session or null if not available
	 */
	public HttpSession getSession() {
		return (HttpSession) get(JPUBLISH_SESSION);
	}
	
	/** Get the current servlet context
	 * @return The servlet context or null if not available
	 */
	public ServletContext getApplication() {
		return (ServletContext) get(JPUBLISH_APPLICATION);
	}
	
	/** Get the jPublish character encoding map
	 * @return The character encoding map or null if not available
	 */
	public CharacterEncodingMap getCharacterEncodingMap() {
		return (CharacterEncodingMap) get (JPUBLISH_CHARACTER_ENCODING_MAP);
	}
	
	/** Get the jPublish URL utilities
	 * @return The URL utilities or null if not available
	 */
	public URLUtilities getUrlUtilities() {
		return (URLUtilities) get(JPUBLISH_URL_UTILITIES);
	}
	
	/** Get the jPublish date utilities
	 * @return The date utilities or null if not available
	 */
	public DateUtilities getDateUtilities() {
		return (DateUtilities) get(JPUBLISH_DATE_UTILITIES);
	}
	
	/** Get the jPublish number utilities
	 * @return The number utilities or null if not available
	 */
	public NumberUtilities getNumberUtilities() {
		return (NumberUtilities) get (JPUBLISH_NUMBER_UTILITIES);
	}
	
	/** Get the jPublish Logger
	 * @return The logger or null if not available
	 */
	public Logger getSyslog() {
		return (Logger) get (JPUBLISH_SYSLOG);
	}
	
	/** Get the current jPublish page
	 * @return The current page or null if not available
	 */
	public Page getPage() {
		return (Page) get (JPUBLISH_PAGE);
	}
	
	/** names used to store objects in the jPublish context */
	public static final String JPUBLISH_REQUEST = "request";
	public static final String JPUBLISH_RESPONSE = "response";
	public static final String JPUBLISH_SESSION = "session";
	public static final String JPUBLISH_APPLICATION = "application";
	public static final String JPUBLISH_CHARACTER_ENCODING_MAP = "characterEncodingMap";
	public static final String JPUBLISH_URL_UTILITIES = "urlUtilities";
	public static final String JPUBLISH_DATE_UTILITIES = "dateUtilities";
	public static final String JPUBLISH_NUMBER_UTILITIES = "numberUtilities";
	public static final String JPUBLISH_SYSLOG = "syslog";		
	public static final String JPUBLISH_SITE = "site";
	public static final String JPUBLISH_PAGE = "page";