[Building Sakai] Writing a Helper

Matthew Buckett matthew.buckett at oucs.ox.ac.uk
Thu Apr 29 02:27:24 PDT 2010


On 28 April 2010 19:09,  <mizematr at notes.udayton.edu> wrote:
>
> Is there any documentation out there for writing a Sakai helper from
> scratch?  My googling has turned up little to nothing on the topic.

Are you wanting to write a helper to replace an existing one?
Or call an existing helper from a new tool?
Or just curious how helpers work?

I've written a new helper for handling some stuff from Site Info and
I've called existing helpers from tools, so can probably go a dig up
how I did it....

Ok, so to dispatch to a helper in a tool I did:

I have a path inside my tool that always passes the request through to a helper:

		ActiveTool tool = ActiveToolManager.getActiveTool("sakai.sitesetup");
		req.removeAttribute(ActiveTool.NATIVE_URL); // Forgot why I did this....
		tool.help(req, res, null, null);

Then to start the helper I stuff some stuff into the sakai session and
redirect to the path I've mapped to the helper:

		// This will actually be a tool session specific to this tool.
		HttpSession session = request.getSession();
		// Chuck the URL into the session so another controller can use it.
		session.setAttribute(ATTRIBUTE_URL, newSite.getName());
		
		// This is the URL the helper should send the browser to when done
		session.setAttribute(Tool.HELPER_DONE_URL, request.getContextPath()+
request.getServletPath()+getReturnPath());

		// Stash some stuff into the session so the helper can see it.
		session.setAttribute(SiteHelper.SITE_CREATE_SITE_TYPES, "project,course");
		session.setAttribute(SiteHelper.SITE_CREATE_SITE_TITLE, newSite.getTitle());

		// Then redirect/forward through to the path mapped to the helper.

My helper then has control and as long as it doesn't change the path
should continue working. When it's done it redirects the browser to
the Tool.HELPER_DONE_URL from the session:

	ToolSession sakaiSession = SessionManager.getCurrentToolSession();
	String url = (String) sakaiSession.getAttribute(Tool.HELPER_DONE_URL);
	response.sendRedirect(url);

Again the helper can pass results through the session if it wants to.

Some examples of helpers in the Sakai codebase are the login tool,
resources file picker, permissions manager and in newer releases
(2.6+) parts of Site Info have been refactored into helpers (choosing
participants to add and managing groups).

-- 
  Matthew Buckett
  VLE Developer, LTG, Oxford University Computing Services


More information about the sakai-dev mailing list