001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.demo.preferences;
018:
019: import java.io.IOException;
020: import java.text.MessageFormat;
021: import java.util.ResourceBundle;
022:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.GenericPortlet;
026: import javax.portlet.PortletConfig;
027: import javax.portlet.PortletContext;
028: import javax.portlet.PortletException;
029: import javax.portlet.PortletRequestDispatcher;
030: import javax.portlet.PortletSession;
031: import javax.portlet.RenderRequest;
032: import javax.portlet.RenderResponse;
033:
034: /**
035: * <p>
036: * PreferencePortlet
037: * </p>
038: *
039: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
040: * @version $Id: PreferencePortlet.java 516448 2007-03-09 16:25:47Z ate $
041: *
042: */
043: public class PreferencePortlet extends GenericPortlet {
044:
045: /**
046: * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
047: */
048: protected void doView(RenderRequest request, RenderResponse response)
049: throws PortletException, IOException {
050: PortletContext context = getPortletContext();
051: ResourceBundle resource = getPortletConfig().getResourceBundle(
052: request.getLocale());
053:
054: request.setAttribute("viewMessage", resource
055: .getString("preference.label.MyModeIsView"));
056:
057: PortletRequestDispatcher rd = context
058: .getRequestDispatcher("/WEB-INF/demo/preference/pref-view.jsp");
059: rd.include(request, response);
060: }
061:
062: /**
063: * @see javax.portlet.GenericPortlet#init()
064: */
065: public void init(PortletConfig config) throws PortletException {
066: // System.out.println("Initializing Preference portlet example. ");
067: super .init(config);
068: }
069:
070: /**
071: * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
072: */
073: public void processAction(ActionRequest request,
074: ActionResponse response) throws PortletException,
075: IOException {
076: ResourceBundle resource = getPortletConfig().getResourceBundle(
077: request.getLocale());
078: // Integer iCount = (Integer) request.getAttribute("org.apache.jetspeed.invocationCount");
079: Integer iCount = (Integer) request.getPortletSession()
080: .getAttribute("org.apache.jetspeed.invocationCount");
081: if (iCount == null) {
082: iCount = new Integer(0);
083: }
084:
085: int count = iCount.intValue();
086: count++;
087:
088: response.setRenderParameter("invocationCount", String
089: .valueOf(count));
090:
091: MessageFormat format = new MessageFormat(resource
092: .getString("preference.label.processActionIWasInvoked"));
093: String[] patterns = { Integer.toString(count) };
094: response.setRenderParameter("invokeMessage", format
095: .format(patterns));
096: request.getPortletSession().setAttribute(
097: "org.apache.jetspeed.invocationCount",
098: new Integer(count), PortletSession.PORTLET_SCOPE);
099: // System.out.println(resource.getString("preference.label.IWasInvoked"));
100: }
101:
102: }
|