Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

  1. Using Spring to get the service for your class (e.g. YourAppClass) (recommended)
    1. 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>
      
    2. 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;
      }
      
  2. Using the cover Component Manager 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 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;
      
      Get access to the service using the cover
      Code Block
      javajava
      
      ...
          toolManager = (ToolManager) org.sakaiproject.tool.cover.ComponentManager.get(ToolManager.getInstance(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 Placement context
    Code Block
    java
    java
    Site site = null;
    try {
    	siteString currentContext = siteService.getSite(toolManager.getCurrentPlacement().getContext());
    } catch (Exception e) {
    	// assume we are not in a site then
    	throw new RuntimeException("Cannot get the current site placement");
    }
    return site.getId();
    );
    
    • Note: The current context is probably the current site Id but do not depend on this
    • Note: If you just need the current Placement reference (which may be the current site reference which is probably the current site Id) then you can do this:
      Code Block
      java
      java
      StringPlacement currentPlacementRefcurrentPlacement = toolManager.getCurrentPlacement().getContext();