Dashboard > WG: Programmer's Cafe > ... > Sakai Framework Tips > Using the ToolManager Service
  WG: Programmer's Cafe Log In | Signup View a printable version of the current page.  
  Using the ToolManager Service
Added by Aaron Zeckoski, last edited by Aaron Zeckoski on Oct 27, 2006  (view change)
Labels: 
(None)

Information

This explains basic usage of the Sakai ToolManager Service. This service is used to find out things like the current location of the current user (Site, etc.) and information about Sakai tools.

Accessing the ToolManager

  • You can use Spring Framework to inject the service or use the cover
  1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
    1. Add the ToolManager bean to the bean for YourAppClass
      <bean id="org.sakaiproject.yourapp.logic.YourAppClass"
      		class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl">
      	<property name="toolManager"
      		ref="org.sakaiproject.tool.api.ToolManager" />
      </bean>
    2. Add a variable and setter to YourAppClass to use the service in like so:
      private ToolManager toolManager;
      public void setToolManager(ToolManager toolManager) {
      	this.toolManager = toolManager;
      }
  2. Using the cover to get the service
    • Note: This is not the recommended method, you should be using Spring to inject the service
    1. Setup a variable to hold the instance from the cover
      private ToolManager toolManager;
    2. Get access to the service using the cover
      toolManager = org.sakaiproject.tool.cover.ToolManager.getInstance();

Getting the current context for the current request (current user most likely)

  • Use this to tie data to a specific use of a tool in an area (probably a site or a section)
  1. Use the service variable to access the service and get the current context
    String currentContext = toolManager.getCurrentPlacement().getContext();
    • Note: The current context is probably the current site Id but do not depend on this
    • Note: If you just need the current Placement then you can do this:
      Placement currentPlacement = toolManager.getCurrentPlacement();

Site running on a free Atlassian Confluence Open Source Project License granted to Sakai Foundation. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.5 Build:#811 Jul 25, 2007) - Bug/feature request - Contact Administrators