001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-impl/impl/src/java/org/sakaiproject/portal/charon/handlers/GalleryHandler.java $
003: * $Id: GalleryHandler.java 29143 2007-04-19 01:10:38Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006, 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.portal.charon.handlers;
021:
022: import java.io.IOException;
023: import java.util.List;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import org.sakaiproject.component.cover.ServerConfigurationService;
029: import org.sakaiproject.exception.IdUnusedException;
030: import org.sakaiproject.exception.PermissionException;
031: import org.sakaiproject.portal.api.Portal;
032: import org.sakaiproject.portal.api.PortalHandlerException;
033: import org.sakaiproject.portal.api.PortalRenderContext;
034: import org.sakaiproject.portal.util.PortalSiteHelper;
035: import org.sakaiproject.site.api.Site;
036: import org.sakaiproject.site.api.SitePage;
037: import org.sakaiproject.site.cover.SiteService;
038: import org.sakaiproject.tool.api.Session;
039: import org.sakaiproject.tool.api.ToolException;
040:
041: /**
042: * Handler for the gallery parts of the portal
043: *
044: * @author ieb
045: * @since Sakai 2.4
046: * @version $Rev: 29143 $
047: *
048: */
049: public class GalleryHandler extends SiteHandler {
050:
051: private static final String INCLUDE_GALLERY_NAV = "include-gallery-nav";
052:
053: private static final String INCLUDE_GALLERY_LOGIN = "include-gallery-login";
054:
055: private PortalSiteHelper siteHelper = new PortalSiteHelper();
056:
057: public GalleryHandler() {
058: urlFragment = "gallery";
059: }
060:
061: @Override
062: public int doGet(String[] parts, HttpServletRequest req,
063: HttpServletResponse res, Session session)
064: throws PortalHandlerException {
065: if ((parts.length >= 2) && (parts[1].equals("gallery"))) {
066: try {
067: // recognize an optional page/pageid
068: String pageId = null;
069: if ((parts.length == 5) && (parts[3].equals("page"))) {
070: pageId = parts[4];
071: }
072:
073: // site might be specified
074: String siteId = null;
075: if (parts.length >= 3) {
076: siteId = parts[2];
077: }
078:
079: doGallery(req, res, session, siteId, pageId, req
080: .getContextPath()
081: + req.getServletPath());
082: return END;
083: } catch (Exception ex) {
084: throw new PortalHandlerException(ex);
085: }
086: } else {
087: return NEXT;
088: }
089: }
090:
091: public void doGallery(HttpServletRequest req,
092: HttpServletResponse res, Session session, String siteId,
093: String pageId, String toolContextPath)
094: throws ToolException, IOException {
095: // check to default site id
096: if (siteId == null) {
097: if (session.getUserId() == null) {
098: String forceLogin = req
099: .getParameter(Portal.PARAM_FORCE_LOGIN);
100: if (forceLogin == null
101: || "yes".equalsIgnoreCase(forceLogin)
102: || "true".equalsIgnoreCase(forceLogin)) {
103: portal.doLogin(req, res, session,
104: req.getPathInfo(), false);
105: return;
106: }
107: siteId = ServerConfigurationService.getGatewaySiteId();
108: } else {
109: siteId = SiteService.getUserSiteId(session.getUserId());
110: }
111: }
112:
113: // if no page id, see if there was a last page visited for this site
114: if (pageId == null) {
115: pageId = (String) session
116: .getAttribute(Portal.ATTR_SITE_PAGE + siteId);
117: }
118:
119: // find the site, for visiting
120: Site site = null;
121: try {
122: site = siteHelper.getSiteVisit(siteId);
123: } catch (IdUnusedException e) {
124: portal.doError(req, res, session, Portal.ERROR_GALLERY);
125: return;
126: } catch (PermissionException e) {
127: // if not logged in, give them a chance
128: if (session.getUserId() == null) {
129: portal.doLogin(req, res, session, req.getPathInfo(),
130: false);
131: } else {
132: portal.doError(req, res, session, Portal.ERROR_GALLERY);
133: }
134: return;
135: }
136:
137: // find the page, or use the first page if pageId not found
138: SitePage page = site.getPage(pageId);
139: if (page == null) {
140: // List pages = site.getOrderedPages();
141: List pages = siteHelper.getPermittedPagesInOrder(site);
142: if (!pages.isEmpty()) {
143: page = (SitePage) pages.get(0);
144: }
145: }
146: if (page == null) {
147: portal.doError(req, res, session, Portal.ERROR_GALLERY);
148: return;
149: }
150:
151: // store the last page visited
152: session.setAttribute(Portal.ATTR_SITE_PAGE + siteId, page
153: .getId());
154:
155: // form a context sensitive title
156: String title = ServerConfigurationService
157: .getString("ui.service")
158: + " : " + site.getTitle() + " : " + page.getTitle();
159:
160: // start the response
161: String siteType = portal.calcSiteType(siteId);
162: PortalRenderContext rcontext = portal.startPageContext(
163: siteType, title, site.getSkin(), req);
164:
165: // the 'little' top area
166: includeGalleryNav(rcontext, req, session, siteId, "gallery");
167:
168: includeWorksite(rcontext, res, req, session, site, page,
169: toolContextPath, "gallery");
170:
171: portal.includeBottom(rcontext);
172:
173: portal.sendResponse(rcontext, res, "gallery", null);
174: }
175:
176: protected void includeGalleryNav(PortalRenderContext rcontext,
177: HttpServletRequest req, Session session, String siteId,
178: String prefix) {
179: if (rcontext.uses(INCLUDE_GALLERY_NAV)) {
180:
181: boolean loggedIn = session.getUserId() != null;
182: boolean topLogin = ServerConfigurationService.getBoolean(
183: "top.login", true);
184:
185: // outer blocks and jump-to links
186: String accessibilityURL = ServerConfigurationService
187: .getString("accessibility.url");
188: rcontext
189: .put(
190: "galleryHasAccessibilityURL",
191: Boolean
192: .valueOf((accessibilityURL != null && accessibilityURL != "")));
193:
194: rcontext.put("galleryAccessibilityURL", accessibilityURL);
195: // rcontext.put("gallarySitAccessibility",
196: // Web.escapeHtml(rb.getString("sit_accessibility")));
197: // rcontext.put("gallarySitJumpcontent",
198: // Web.escapeHtml(rb.getString("sit_jumpcontent")));
199: // rcontext.put("gallarySitJumptools",
200: // Web.escapeHtml(rb.getString("sit_jumptools")));
201: // rcontext.put("gallarySitJumpworksite",
202: // Web.escapeHtml(rb.getString("sit_")));
203: rcontext.put("gallaryLoggedIn", Boolean.valueOf(loggedIn));
204:
205: try {
206: if (loggedIn) {
207: includeTabs(rcontext, req, session, siteId, prefix,
208: false);
209: } else {
210: includeGalleryLogin(rcontext, req, session, siteId);
211: }
212: } catch (Exception any) {
213: }
214: }
215:
216: }
217:
218: protected void includeGalleryLogin(PortalRenderContext rcontext,
219: HttpServletRequest req, Session session, String siteId)
220: throws IOException {
221: if (rcontext.uses(INCLUDE_GALLERY_LOGIN)) {
222: portal.includeLogin(rcontext, req, session);
223: }
224: }
225:
226: }
|