001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.model;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import javax.portlet.ActionRequest;
026: import javax.servlet.ServletContext;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.xml.bind.annotation.XmlAttribute;
029: import javax.xml.bind.annotation.XmlTransient;
030:
031: import com.nabhinc.portal.core.PortalConstants;
032: import com.nabhinc.portal.core.SessionCache;
033:
034: /**
035: *
036: *
037: * @author Padmanabh Dabke
038: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
039: */
040: public abstract class BaseCompositeRenderable extends BaseRenderable
041: implements CompositeRenderable {
042:
043: @XmlAttribute(name="selectedWindowId")
044: private String bcrSelectedWindowId = null;
045: protected transient String bprComponentTemplate = "wide_portlet.jsp";
046:
047: @XmlTransient
048: public String getComponentTemplate() {
049: return bprComponentTemplate;
050: }
051:
052: public void setComponentTemplate(String t) {
053: this .bprComponentTemplate = t;
054: }
055:
056: public String getSelectedPortletWindowId() {
057: return this .bcrSelectedWindowId;
058: }
059:
060: public void setSelectedPortletWindowId(String wId) {
061: this .bcrSelectedWindowId = wId;
062: }
063:
064: public BaseCompositeRenderable() {
065:
066: }
067:
068: public BaseCompositeRenderable(PortalPage parent) {
069: super (parent);
070: }
071:
072: public void setPortalPage(PortalPage p) {
073: super .setPortalPage(p);
074: Iterator<Renderable> iter = getComponents();
075: while (iter.hasNext())
076: iter.next().setPortalPage(p);
077: }
078:
079: public void setIdPrefix(String prefix) {
080: super .setIdPrefix(prefix);
081: Iterator<Renderable> iter = getComponents();
082: while (iter.hasNext())
083: iter.next().setIdPrefix(prefix);
084: }
085:
086: private void setTitleAndBorderWidth(ActionRequest req,
087: String borderParam, String titleParam, Renderable p) {
088: if (req.getParameter(borderParam) != null)
089: p.setBorderWidth(0);
090: if (req.getParameter(titleParam) != null)
091: p.setTitleShown(false);
092:
093: }
094:
095: protected Renderable createRenderable(String pName,
096: ActionRequest req, String borderParam, String titleParam) {
097: if (pName != null && pName.trim().length() > 0) {
098: if (pName.startsWith("page:")) {
099: String templateFilePath = pName.substring(5);
100: String modelClass = PortalConfiguration.getInstance()
101: .lookupModelClass(templateFilePath);
102: if (modelClass == null)
103: throw new RuntimeException(
104: "Invalid portal configuration. Could not look up model class for template "
105: + templateFilePath);
106: try {
107: Renderable r = (Renderable) Class.forName(
108: modelClass).newInstance();
109: r.setTemplate(templateFilePath);
110: setTitleAndBorderWidth(req, borderParam,
111: titleParam, r);
112: return r;
113: } catch (Exception e) {
114: throw new RuntimeException(
115: "Invalid portal configuration. Could not create instance of model class "
116: + modelClass, e);
117: }
118: } else {
119: return createPortletWindow(pName, req, borderParam,
120: titleParam);
121:
122: }
123: } else {
124: return null;
125: }
126: }
127:
128: protected PortletWindow createPortletWindow(String pName,
129: ActionRequest req, String borderParam, String titleParam) {
130: PortletWindow pWindow = new PortletWindow(this .getPortalPage(),
131: pName);
132: setTitleAndBorderWidth(req, borderParam, titleParam, pWindow);
133: return pWindow;
134: }
135:
136: public void modify(ActionRequest req) {
137:
138: String newPageName = req.getParameter("pagename");
139: if (newPageName != null && (!newPageName.trim().equals(""))) {
140: getPortalPage().setName(newPageName);
141: }
142: setRefreshSeconds(Integer.parseInt(req.getParameter("refresh")));
143:
144: }
145:
146: public void setRenderAttributes(HttpServletRequest request,
147: SessionCache sCache) {
148: request.setAttribute(
149: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE, this );
150: }
151:
152: public void computeTemplatePath(ServletContext servletContext,
153: String appPath, String theme) {
154: super .computeTemplatePath(servletContext, appPath, theme);
155: Iterator<Renderable> components = getComponents();
156: if (components != null) {
157: while (components.hasNext()) {
158: components.next().computeTemplatePath(servletContext,
159: appPath, theme);
160: }
161: }
162: }
163:
164: public List<PortletWindow> getPortletWindowList() {
165: List<PortletWindow> windowList = new ArrayList<PortletWindow>();
166: addPortletWindows(windowList);
167: return windowList;
168: }
169:
170: public void addPortletWindows(List<PortletWindow> windowList) {
171: Iterator<Renderable> components = getComponents();
172: while (components.hasNext()) {
173: components.next().addPortletWindows(windowList);
174: }
175: }
176:
177: public PortletWindow getDefaultPortletWindow() {
178: List<PortletWindow> windowList = getPortletWindowList();
179: if (windowList.size() > 0)
180: return windowList.get(0);
181: else
182: return null;
183: }
184: }
|