Child pages
  • Using the ToolManager Service
Skip to end of metadata
Go to start of metadata

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 Component Manager to get the service
    • Note: This is not the recommended method, you should be using Spring to inject the service
    1. Use the CM cover to get the service
      import org.sakaiproject.component.cover.ComponentManager;
      import org.sakaiproject.tool.api.ToolManager;
      ...
        private ToolManager toolManager;
      ...
          toolManager = (ToolManager) ComponentManager.get(ToolManager.class);
      

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();
      
  • No labels

4 Comments

  1. Is this tutorial still valid for 2.6 when there is K1 in place as well other major changes have been made since this tutorial was written in Oct 2006

    1. The services have not changed. K1 is just a repackaging of the code that has been around (but tweaked a bit) since version 2.2.

  2. I can not find the "sakai-tool-api 2.7" at https://source.sakaiproject.org/maven2/org/sakaiproject/sakai-tool-api/

    is this tutorial still valid for 2.7?

  3. The services have not changed significantly since Sakai 2.4 aside from some packaging changes (i.e. changes that affect the build but do not change the names of APIs or methods). Thus this is still correct all the way through Sakai 10.