001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-impl/impl/src/java/org/sakaiproject/portal/charon/handlers/PresenceHandler.java $
003: * $Id: PresenceHandler.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:
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.sakaiproject.exception.IdUnusedException;
028: import org.sakaiproject.exception.PermissionException;
029: import org.sakaiproject.portal.api.Portal;
030: import org.sakaiproject.portal.api.PortalHandlerException;
031: import org.sakaiproject.site.api.Site;
032: import org.sakaiproject.site.cover.SiteService;
033: import org.sakaiproject.tool.api.ActiveTool;
034: import org.sakaiproject.tool.api.Placement;
035: import org.sakaiproject.tool.api.Session;
036: import org.sakaiproject.tool.api.ToolException;
037: import org.sakaiproject.tool.cover.ActiveToolManager;
038: import org.sakaiproject.util.Web;
039:
040: /**
041: *
042: * @author ieb
043: * @since Sakai 2.4
044: * @version $Rev: 29143 $
045: *
046: */
047: public class PresenceHandler extends BasePortalHandler {
048: public PresenceHandler() {
049: urlFragment = "presence";
050: }
051:
052: @Override
053: public int doGet(String[] parts, HttpServletRequest req,
054: HttpServletResponse res, Session session)
055: throws PortalHandlerException {
056:
057: if ((parts.length >= 3) && (parts[1].equals("presence"))) {
058: try {
059: doPresence(req, res, session, parts[2], req
060: .getContextPath()
061: + req.getServletPath()
062: + Web.makePath(parts, 1, 3), Web.makePath(
063: parts, 3, parts.length));
064: return END;
065: } catch (Exception ex) {
066: throw new PortalHandlerException(ex);
067: }
068: } else {
069: return NEXT;
070: }
071: }
072:
073: public void doPresence(HttpServletRequest req,
074: HttpServletResponse res, Session session, String siteId,
075: String toolContextPath, String toolPathInfo)
076: throws ToolException, IOException {
077: // permission check - visit the site
078: Site site = null;
079: try {
080: site = SiteService.getSiteVisit(siteId);
081: } catch (IdUnusedException e) {
082: portal.doError(req, res, session, Portal.ERROR_WORKSITE);
083: return;
084: } catch (PermissionException e) {
085: // if not logged in, give them a chance
086: if (session.getUserId() == null) {
087: portal.doLogin(req, res, session, req.getPathInfo(),
088: false);
089: } else {
090: portal
091: .doError(req, res, session,
092: Portal.ERROR_WORKSITE);
093: }
094: return;
095: }
096:
097: // get the skin for the site
098: String skin = site.getSkin();
099:
100: // find the tool registered for this
101: ActiveTool tool = ActiveToolManager
102: .getActiveTool("sakai.presence");
103: if (tool == null) {
104: portal.doError(req, res, session, Portal.ERROR_WORKSITE);
105: return;
106: }
107:
108: // form a placement based on the site and the fact that this is that
109: // site's presence...
110: // Note: the placement is transient, but will always have the same id
111: // and context based on the siteId
112: Placement placement = new org.sakaiproject.util.Placement(
113: siteId + "-presence", tool.getId(), tool, null, siteId,
114: null);
115:
116: portal.forwardTool(tool, req, res, placement, skin,
117: toolContextPath, toolPathInfo);
118: }
119:
120: }
|