001: /*
002: * Created on Mar 20, 2003
003: */
004: package net.sf.jportlet.portlet;
005:
006: import java.io.IOException;
007:
008: import java.util.Locale;
009:
010: /**
011: * The <code>PortletAdapter</code> provides a default implementation for the
012: * {@link net.sf.jportlet.portlet.Portlet} interface.
013: * <p>
014: * It is recommended not to extend the {@link net.sf.jportlet.portlet.Portlet} interface directly.
015: * Rather, a portlet should derive from this or any other derived class,
016: * because changes in the Portlet interface are then mostly likely to be catched
017: * by the default implementation, rather than breaking your portlet implementation
018: *
019: * @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
020: */
021: public class PortletAdapter extends Portlet {
022: //~ Methods ----------------------------------------------------------------
023:
024: /**
025: * Renders the portlet in {@link net.sf.jportlet.portlet.Portlet.Model.CONFIGURE} mode
026: * @param request
027: * @param response
028: * @throws PortletException
029: * @throws IOException
030: */
031: protected void doConfigure(PortletRequest request,
032: PortletResponse response) throws PortletException,
033: IOException {
034: }
035:
036: /**
037: * Renders the portlet in {@link net.sf.jportlet.portlet.Portlet.Model.EDIT} mode
038: * @param request
039: * @param response
040: * @throws PortletException
041: * @throws IOException
042: */
043: protected void doEdit(PortletRequest request,
044: PortletResponse response) throws PortletException,
045: IOException {
046: }
047:
048: /**
049: * Renders the portlet in {@link net.sf.jportlet.portlet.Portlet.Model.HELP} mode
050: * @param request
051: * @param response
052: * @throws PortletException
053: * @throws IOException
054: */
055: protected void doHelp(PortletRequest request,
056: PortletResponse response) throws PortletException,
057: IOException {
058: }
059:
060: /**
061: * Renders the portlet in {@link net.sf.jportlet.portlet.Portlet.Model.VIEW} mode
062: * @param request
063: * @param response
064: * @throws PortletException
065: * @throws IOException
066: */
067: protected void doView(PortletRequest request,
068: PortletResponse response) throws PortletException,
069: IOException {
070: }
071:
072: /**
073: * @see net.sf.jportlet.portlet.Portlet#getLastModified(net.sf.jportlet.portlet.PortletRequest)
074: */
075: public long getLastModified(PortletRequest request) {
076: return -1;
077: }
078:
079: public PortletLog getLog() {
080: return getPortletContext().getLog();
081: }
082:
083: /**
084: * @return PortletContext
085: */
086: public PortletContext getPortletContext() {
087: return getPortletConfig().getPortletContext();
088: }
089:
090: /**
091: * Returns the value of a localized text.
092: * This method call {@link PortletContext#getText(java.lang.String, java.util.Locale)}
093: */
094: public String getText(String key, Locale locale) {
095: getLog().debug("getText(" + key + "," + locale + ")");
096: return getPortletContext().getText(key, locale);
097: }
098:
099: /**
100: * Include a file into the {@link PortletResponse}.
101: * This method call {@link PortletContext#include(java.lang.String, net.sf.jportlet.portlet.PortletRequest, net.sf.jportlet.portlet.PortletResponse)}
102: */
103: public void include(String path, PortletRequest request,
104: PortletResponse response) throws PortletException,
105: IOException {
106: getPortletContext().include(path, request, response);
107: }
108:
109: /**
110: * @see net.sf.jportlet.portlet.Portlet#login(net.sf.jportlet.portlet.PortletRequest)
111: */
112: public void login(PortletRequest request) throws PortletException {
113: }
114:
115: /**
116: * @see net.sf.jportlet.portlet.Portlet#logout(net.sf.jportlet.portlet.PortletRequest)
117: */
118: public void logout(PortletRequest request) throws PortletException {
119: }
120:
121: public void service(PortletRequest request, PortletResponse response)
122: throws PortletException, IOException {
123: Mode mode = request.getMode();
124:
125: if (mode == Mode.VIEW) {
126: doView(request, response);
127: } else if (mode == Mode.EDIT) {
128: doEdit(request, response);
129: } else if (mode == Mode.CONFIGURE) {
130: doConfigure(request, response);
131: } else if (mode == Mode.HELP) {
132: doHelp(request, response);
133: } else {
134: throw new PortletException("Mode not supported: " + mode);
135: }
136: }
137: }
|