Search code examples
sakai

How to get the current tool SitePage and/or its Properties?


With the ToolManager I can get the the current placement, the context and of course, the Site through the SiteService. But I want to get the current SitePage properties the user is currently accessing.

This doubt can be extended to the current Tool properties with a little more emphasis considering that once I have the Tool I could not find any methods covering the its properties.

I could get the tool properties and I'm using it (it is by instance) through Properties got with sitepage.getTool(TOOLID).getConfig(). To save a property, I'm using the ToolConfiguration approach and saving the data after editing with the ToolConfiguration.save() method. Is it the correct approach?


Solution

  • You can do this by getting the current tool session and then working your way backward from that. Here is a method that should do it.

    public SitePage findCurrentPage() {
      SitePage sp = null;
      ToolSession ts = SessionManager.getCurrentToolSession();
      if (ts != null) {
        ToolConfiguration tool = SiteService.findTool(ts.getPlacementId());
        if (tool != null) {
          String sitePageId = tool.getPageId();
          sp = s.getPage(sitePageId);
        }
      }
      return sp;
    }
    

    Alternatively, you could use the current tool to work your way to it but I think this method is harder.

    String toolId = toolManager.getCurrentTool().getId();
    String context = toolManager.getCurrentPlacement().getContext();
    Site s = siteService.getSite( context );
    ToolConfiguration tc = s.getTool(toolId);
    String sitePageId = tc.getPageId();
    SitePage sp = s.getPage(sitePageId);
    

    NOTE: I have not tested this code to make sure it works.