|
From: <jt...@hy...> - 2007-03-22 20:30:07
|
Author: jtravis Date: 2007-03-22 12:29:58 -0800 (Thu, 22 Mar 2007) New Revision: 3822 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3822 Modified: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy Log: Cleanup tabs, simplify, provide helpers Modified: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-22 20:29:33 UTC (rev 3821) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-22 20:29:58 UTC (rev 3822) @@ -9,11 +9,14 @@ import org.hyperic.hq.ui.util.ContextUtils import org.hyperic.hq.ui.util.RequestUtils +import org.hyperic.hq.ui.rendit.helpers.LiveDataHelper +import org.hyperic.hq.ui.rendit.helpers.ResourceHelper + import groovy.text.SimpleTemplateEngine import java.io.File -public abstract class BaseController - extends Expando +abstract class BaseController + extends Expando { Log log = LogFactory.getLog(this.getClass()) String action @@ -32,7 +35,10 @@ def setPluginDir(File pluginDir) { this.pluginDir = pluginDir } - + + def getResourceHelper() { return new ResourceHelper(getUser()) } + def getLiveDataHelper() { return new LiveDataHelper(getUser()) } + /** * Retreives the currently logged-in user */ @@ -40,10 +46,10 @@ if (this.user != null) return this.user - def sessId = RequestUtils.getSessionId(invokeArgs.request) - def ctx = invokeArgs.request.session.servletContext + def sessId = RequestUtils.getSessionId(invokeArgs.request) + def ctx = invokeArgs.request.session.servletContext - this.user = ContextUtils.getAuthzBoss(ctx).getCurrentSubject(sessId) + this.user = ContextUtils.getAuthzBoss(ctx).getCurrentSubject(sessId) } /** @@ -54,25 +60,33 @@ * current action will be used * args: A map of key/value pairs to send to the .gsp to use when * rendering + * + * Examples: + * To render the file 'listView.gsp' to the browser + * > render file:'listView' + * + * To render the current action to the browser and pass in parameters + * needed by the .gsp + * > render args:[userName:'Jeff', favouriteDrink:'Vodka'] + * */ - protected def render(args) { + protected void render(args) { args = (args == null) ? [:] : args - def gspArgs = args.remove("args") - def gspFile = args.remove("file") - def useAction - - if (gspFile == null) - useAction = action - else - useAction = gspFile + def gspArgs = args.remove("args") + def gspFile = args.remove("file") + def useAction + + if (gspFile == null) + useAction = action + else + useAction = gspFile - def targFile = new File(pluginDir, useAction + ".gsp") - targFile.withReader { reader -> - def eng = new SimpleTemplateEngine(false) - def template = eng.createTemplate(reader) - def outStream = invokeArgs.response.outputStream - def outWriter = new OutputStreamWriter(outStream) - template.make(gspArgs).writeTo(outWriter) - } - } + new File(pluginDir, useAction + '.gsp').withReader { reader -> + def eng = new SimpleTemplateEngine(false) + def template = eng.createTemplate(reader) + def outStream = invokeArgs.response.outputStream + def outWriter = new OutputStreamWriter(outStream) + template.make(gspArgs).writeTo(outWriter) + } + } } Modified: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-22 20:29:33 UTC (rev 3821) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-22 20:29:58 UTC (rev 3822) @@ -8,7 +8,7 @@ * RenditServer. It has the responsibility of locating the controllers, * setting up the environment, and invoking the request. */ -public class Dispatcher { +class Dispatcher { private Log log = LogFactory.getLog(Dispatcher.class); private File pluginDir @@ -37,7 +37,6 @@ } def invoke() { - log.info "Controller name is $controllerName" def controller = Class.forName(controllerName, true, this.class.classLoader).newInstance() @@ -50,7 +49,10 @@ throw new IllegalArgumentException("Unknown action [$action]") } + def start = System.currentTimeMillis() runner(invokeArgs.request.parameterMap) + log.info """Executed $controllerName:$action in + ${System.currentTimeMillis() - start} ms""" } } |