01: /*
02: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU General Public License
06: * as published by the Free Software Foundation; either version 2
07: * of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU General Public License for more details.
13: *
14: * You should have received a copy of the GNU General Public License
15: * along with this program; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: *
18: */
19: package com.nabhinc.portlet.image;
20:
21: import javax.portlet.ActionRequest;
22: import javax.portlet.ActionResponse;
23: import javax.portlet.PortletMode;
24: import javax.portlet.PortletModeException;
25: import javax.portlet.PortletException;
26: import javax.portlet.PortletSecurityException;
27:
28: import com.nabhinc.portal.api.EntityLockedException;
29: import com.nabhinc.portal.api.PortalInformationStoreLocator;
30: import com.nabhinc.portal.container.ActionRequestImpl;
31: import com.nabhinc.portal.container.PortalInterface;
32: import com.nabhinc.portal.core.PortalConstants;
33: import com.nabhinc.portal.model.PortalApplication;
34: import com.nabhinc.portal.model.PortalApplicationView;
35: import com.nabhinc.portlet.base.BasePortlet;
36: import com.nabhinc.portlet.image.ImageConfig;
37: import com.nabhinc.ws.core.WebServiceSecurityException;
38:
39: /**
40: * Sample portlet demonstrating how portlet config can be used to save
41: * portlet specific data. The portlet is designed to display an Image with
42: * path and size edit facility.
43: *
44: * @author Padmanabh Dabke
45: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
46: */
47: public class ImagePortlet extends BasePortlet {
48: public void init(ImageConfig config) throws PortletException {
49: }
50:
51: public void processAction(ActionRequest aReq, ActionResponse aRes)
52: throws PortletException {
53:
54: PortalApplication portalApp = ((PortalApplicationView) aReq
55: .getAttribute(PortalConstants.CURRENT_PORTAL_APP_VIEW))
56: .getPortalApplication();
57: synchronized (portalApp) {
58: PortalInterface pi = ((ActionRequestImpl) aReq)
59: .getPortalInterface();
60: ImageConfig blockState = (ImageConfig) pi
61: .getPortletWindowConfig();
62: if (blockState == null) {
63: blockState = new ImageConfig();
64: pi.setPortletWindowConfig(blockState);
65: }
66: blockState.setHeight(aReq.getParameter("image_height"));
67: blockState.setWidth(aReq.getParameter("image_width"));
68: blockState.setSource(aReq.getParameter("logo_image"));
69: blockState.setTitle(aReq.getParameter("image_title"));
70: try {
71: PortalInformationStoreLocator
72: .getPortalInformationStore()
73: .savePortalApplication(portalApp, true);
74: } catch (EntityLockedException e) {
75: throw new PortletException(
76: "You changes could not be persisted since the psite is locked by another user.");
77: } catch (WebServiceSecurityException e) {
78: throw new PortletSecurityException(e);
79: } catch (Exception e) {
80:
81: }
82:
83: try {
84: aRes.setPortletMode(PortletMode.VIEW);
85: } catch (PortletModeException e) { // this will never be thrown
86: e.printStackTrace();
87: }
88: }
89: }
90:
91: }
|