3

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?

Virgílio Santos
  • 412
  • 2
  • 13

1 Answers1

4

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.

Aaron Zeckoski
  • 5,016
  • 8
  • 25
  • 48
  • Great, it seems to be what I was looking for at first, but I will stick with the tool based configuration for now. The first method it really a better way and the second I think I would never realize just looking around the services (or will, but will take big time). I will test the code later and if it's not working I can edit the answer, thank you! =) – Virgílio Santos Aug 13 '14 at 19:38