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 javax.servlet.ServletException;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpSession;
024: import javax.xml.bind.annotation.XmlTransient;
025:
026: import com.nabhinc.portal.core.PortalConstants;
027: import com.nabhinc.portal.core.PortalUtil;
028:
029: /**
030: *
031: *
032: * @author Padmanabh Dabke
033: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
034: */
035: public class PortalPageState {
036: public PortalPage portalPage = null;
037: private String pageURL = null;
038: // finalPageURL = pageURL + navState
039: private String finalPageURL = null;
040: public String localizedLabel = null;
041: public boolean isEditable = true;
042: public boolean isDeletable = true;
043: private transient Renderable ppCurrentRenderable = null;
044: private String viewURLPrefix = null;
045: public boolean needsPasswordCheck = false;
046: private String navState = PortalConstants.NAV_SELECTION_TOKEN;
047:
048: public PortalPageState(PortalPage page, String label,
049: String urlPrefix, HttpServletRequest request)
050: throws ServletException {
051: this .portalPage = page;
052: this .localizedLabel = label;
053: this .viewURLPrefix = urlPrefix;
054: this .isDeletable = page.isDeletable(request);
055: this .isEditable = page.isEditable(request);
056: if (page.isPasswordProtected()
057: && (!PortalUtil.isOwnerOrAdmin(request, page
058: .getOwnerName())))
059: this .needsPasswordCheck = true;
060: }
061:
062: @XmlTransient
063: public Renderable getCurrentRenderable() {
064: return this .ppCurrentRenderable;
065: }
066:
067: public void setCurrentRenderable(Renderable r) {
068: this .ppCurrentRenderable = r;
069: }
070:
071: public void setMaximizedPageMode(Renderable r, HttpSession session) {
072: this .pageURL = this .viewURLPrefix + this .portalPage.getIndex()
073: + "/" + PortalConstants.DISPLAY_MODE_MAXIMIZED + "/"
074: + r.getNumericId() + "/";
075: setCurrentRenderable(r);
076: setFinalPageURL(session);
077: }
078:
079: public void setNormalPageMode(HttpSession session) {
080: this .pageURL = this .viewURLPrefix + this .portalPage.getIndex()
081: + "/" + PortalConstants.DISPLAY_MODE_NORMAL + "/";
082: setCurrentRenderable(null);
083: setFinalPageURL(session);
084: }
085:
086: public void setDesktopPageMode(HttpSession session) {
087: this .pageURL = this .viewURLPrefix + this .portalPage.getIndex()
088: + "/" + PortalConstants.DISPLAY_MODE_DESKTOP + "/";
089: setCurrentRenderable(null);
090: setFinalPageURL(session);
091: }
092:
093: public String getPageURL() {
094: return this .finalPageURL;
095: }
096:
097: public void setNavigationState(String n, HttpSession session) {
098: if (!this .navState.equals(n)) {
099: this .navState = n;
100: setFinalPageURL(session);
101: }
102: }
103:
104: public String getNavigationState() {
105: return this .navState;
106: }
107:
108: private void setFinalPageURL(HttpSession session) {
109: this .finalPageURL = this .pageURL + this .navState + "/";
110: storeNavigationState(session);
111: }
112:
113: private void storeNavigationState(HttpSession session) {
114: session.setAttribute(
115: PortalConstants.PORTAL_PAGE_NAV_STATE_ATTRIB
116: + this .portalPage.getPortalApplication()
117: .getIdPrefix()
118: + this .portalPage.getIndex(), this .navState);
119: session.setAttribute(PortalConstants.PORTAL_PAGE_URL_ATTRIB
120: + this .portalPage.getPortalApplication().getIdPrefix()
121: + this .portalPage.getIndex(), this .pageURL);
122: }
123:
124: protected boolean restoreNavigationState(HttpSession session) {
125:
126: String nState = (String) session
127: .getAttribute(PortalConstants.PORTAL_PAGE_NAV_STATE_ATTRIB
128: + this .portalPage.getPortalApplication()
129: .getIdPrefix()
130: + this .portalPage.getIndex());
131: String pURL = (String) session
132: .getAttribute(PortalConstants.PORTAL_PAGE_URL_ATTRIB
133: + this .portalPage.getPortalApplication()
134: .getIdPrefix()
135: + this .portalPage.getIndex());
136: if (nState != null && pURL != null) {
137: this .navState = nState;
138: this .pageURL = pURL;
139: this .finalPageURL = this .pageURL + this .navState + "/";
140: return true;
141: }
142: return false;
143: }
144: }
|