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.io.IOException;
022:
023: import javax.servlet.ServletContext;
024: import javax.servlet.ServletException;
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027: import javax.xml.bind.annotation.XmlAttribute;
028: import javax.xml.bind.annotation.XmlTransient;
029:
030: import com.nabhinc.portal.core.PortalConstants;
031: import com.nabhinc.portal.core.PortalUtil;
032:
033: /**
034: *
035: *
036: * @author Padmanabh Dabke
037: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
038: */
039: public abstract class BaseRenderable implements Renderable {
040:
041: @XmlAttribute(name="id")
042: private int numericId = -1;
043:
044: /**
045: * Unique ID generated by concatenating PortalApplication name+id and the
046: * numeric ID that is unique within the PortalApplication.
047: */
048: @XmlTransient
049: protected String id = null;
050:
051: @XmlAttribute(name="refreshSeconds")
052: private int refreshSeconds = -1;
053:
054: @XmlTransient
055: protected PortalPage portalPage = null;
056:
057: @XmlAttribute(name="template")
058: protected String template = null;
059:
060: @XmlAttribute(name="show-title")
061: protected boolean showTitle = true;
062:
063: @XmlAttribute(name="border-width")
064: protected int borderWidth = 1;
065:
066: protected transient String templatePath = null;
067:
068: @XmlTransient
069: public String getId() {
070: return id;
071: }
072:
073: public BaseRenderable() {
074: }
075:
076: public BaseRenderable(PortalPage parent) {
077: setPortalPage(parent);
078: }
079:
080: public void setId(String id) {
081: this .id = id;
082: }
083:
084: @XmlTransient
085: public int getNumericId() {
086: return numericId;
087: }
088:
089: public void setNumericId(int numericId) {
090: this .numericId = numericId;
091: }
092:
093: @XmlTransient
094: public PortalPage getPortalPage() {
095: return portalPage;
096: }
097:
098: public void setPortalPage(PortalPage portalPage) {
099: this .portalPage = portalPage;
100: if (this .numericId == -1)
101: this .numericId = portalPage.getPortalApplication()
102: .getNextID();
103: this .id = portalPage.getPortalApplication().getIdPrefix()
104: + this .numericId;
105: portalPage.addRenderable(this );
106: }
107:
108: public void setIdPrefix(String prefix) {
109: this .id = portalPage.getPortalApplication().getIdPrefix()
110: + this .numericId;
111: }
112:
113: @XmlTransient
114: public int getRefreshSeconds() {
115: return refreshSeconds;
116: }
117:
118: public void setRefreshSeconds(int refreshSeconds) {
119: if (refreshSeconds <= 0)
120: refreshSeconds = -1;
121: this .refreshSeconds = refreshSeconds;
122: }
123:
124: @XmlTransient
125: public String getTemplate() {
126: return this .template;
127: }
128:
129: public void setTemplate(String t) {
130: this .template = t;
131: }
132:
133: @XmlTransient
134: public int getBorderWidth() {
135: return this .borderWidth;
136: }
137:
138: public void setBorderWidth(int w) {
139: this .borderWidth = w;
140: }
141:
142: @XmlTransient
143: public boolean isTitleShown() {
144: return this .showTitle;
145: }
146:
147: public void setTitleShown(boolean fl) {
148: this .showTitle = fl;
149: }
150:
151: public void render(HttpServletRequest request,
152: HttpServletResponse response) throws IOException,
153: ServletException {
154: Object currentR = request
155: .getAttribute(PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE);
156: try {
157: request.setAttribute(
158: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE, this );
159: request.getRequestDispatcher(this .templatePath).include(
160: request, response);
161: } finally {
162: if (currentR != null)
163: request.setAttribute(
164: PortalConstants.CURRENT_RENDERABLE_ATTRIBUTE,
165: currentR);
166: }
167: }
168:
169: public void setPortletTemplate(String template) {
170: // Default implementation is no-op
171: }
172:
173: public String getContentBelowMainMenu() {
174: return "<div id=\"spacer\"> </div>";
175: }
176:
177: public void computeTemplatePath(ServletContext servletContext,
178: String appPath, String theme) {
179: this .templatePath = PortalUtil.getTemplatePath(servletContext,
180: appPath, theme, this .template);
181: }
182:
183: public String getTemplatePath() {
184: return this.templatePath;
185: }
186:
187: }
|