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.
- Trunk javadocs:
- Trunk source location: https://source.sakaiproject.org/svn/user/trunk/
Accessing the ToolManager
- You can use Spring Framework to inject the service or use the cover
- Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
- Add the ToolManager bean to the bean for YourAppClass
Code Block xml xml <bean id="org.sakaiproject.yourapp.logic.YourAppClass" class="org.sakaiproject.yourapp.logic.impl.YourAppClassImpl"> <property name="toolManager" ref="org.sakaiproject.tool.api.ToolManager" /> </bean>
- Add a variable and setter to YourAppClass to use the service in like so:
Code Block java java private ToolManager toolManager; public void setToolManager(ToolManager toolManager) { this.toolManager = toolManager; }
- Add the ToolManager bean to the bean for YourAppClass
- Using the Component Manager to get the service
- Note: This is not the recommended method, you should be using Spring to inject the service
- Use the CM cover to get the service
Code Block java java 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)
- Use the service variable to access the service and get the current context
Code Block java java 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:
Code Block java java Placement currentPlacement = toolManager.getCurrentPlacement();