01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/facade/sakai/ContextSakaiImpl.java $
03: * $Id: ContextSakaiImpl.java 18229 2006-11-18 01:12:05Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.section.facade.sakai;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.sakaiproject.section.api.facade.manager.Context;
25: import org.sakaiproject.exception.IdUnusedException;
26: import org.sakaiproject.site.cover.SiteService;
27: import org.sakaiproject.tool.api.Placement;
28: import org.sakaiproject.tool.cover.ToolManager;
29:
30: /**
31: * Uses Sakai's ToolManager to determine the current context.
32: *
33: * @author <a href="mailto:jholtzman@berkeley.edu">Josh Holtzman</a>
34: *
35: */
36: public class ContextSakaiImpl implements Context {
37: private static final Log log = LogFactory
38: .getLog(ContextSakaiImpl.class);
39:
40: /**
41: * @inheritDoc
42: */
43: public String getContext(Object request) {
44: Placement placement = ToolManager.getCurrentPlacement();
45: if (placement == null) {
46: log.error("Placement is null");
47: }
48: return placement.getContext();
49: }
50:
51: public String getContextTitle(Object request) {
52: String siteContext = getContext(null);
53: String siteTitle = null;
54: try {
55: siteTitle = SiteService.getSite(siteContext).getTitle();
56: } catch (IdUnusedException e) {
57: log.error("Unable to get site for context " + siteContext);
58: siteTitle = siteContext; // Better than nothing???
59: }
60: return siteTitle;
61: }
62: }
|