|
From: <jt...@hy...> - 2007-03-22 00:23:25
|
Author: jtravis Date: 2007-03-21 16:23:21 -0800 (Wed, 21 Mar 2007) New Revision: 3807 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3807 Added: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/ 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 Removed: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/rendit/ 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 Modified: trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java Log: Move the rendit_sys files to the correct package (under UI) Modified: trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java 2007-03-21 23:47:43 UTC (rev 3806) +++ trunk/src/org/hyperic/hq/ui/rendit/RenditServer.java 2007-03-22 00:23:21 UTC (rev 3807) @@ -95,7 +95,7 @@ b.setVariable("invokeArgs", new InvocationBindings(path, plugin.getPluginDir(), req, resp)); - plugin.run("org/hyperic/hq/rendit/dispatcher.groovy", b); + plugin.run("org/hyperic/hq/ui/rendit/dispatcher.groovy", b); } public static final RenditServer getInstance() { Copied: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit (from rev 3802, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/rendit) Deleted: 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/rendit/BaseController.groovy 2007-03-21 19:22:00 UTC (rev 3802) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-22 00:23:21 UTC (rev 3807) @@ -1,59 +0,0 @@ -package org.hyperic.hq.rendit - -import java.io.OutputStreamWriter - -import org.apache.commons.logging.Log -import org.apache.commons.logging.LogFactory - -import groovy.text.SimpleTemplateEngine -import java.io.File - -public abstract class BaseController - extends Expando -{ - Log log = LogFactory.getLog(this.getClass()) - String action - File pluginDir - def invokeArgs - - private void setAction(String action) { - this.action = action - } - - def setInvokeArgs(def args) { - this.invokeArgs = args - } - - def setPluginDir(File pluginDir) { - this.pluginDir = pluginDir - } - - /** - * Render a .gsp. - * - * This method takes a map of arguments. Valid arguments include: - * file: The file to render. If not specified, the name of the - * current action will be used - * args: A map of key/value pairs to send to the .gsp to use when - * rendering - */ - protected def render(args) { - 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) - } - } -} Copied: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy (from rev 3806, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/rendit/BaseController.groovy) =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy (rev 0) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-22 00:23:21 UTC (rev 3807) @@ -0,0 +1,78 @@ +package org.hyperic.hq.ui.rendit + +import java.io.OutputStreamWriter + +import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + +import org.hyperic.hq.authz.server.session.AuthzSubject +import org.hyperic.hq.ui.util.ContextUtils +import org.hyperic.hq.ui.util.RequestUtils + +import groovy.text.SimpleTemplateEngine +import java.io.File + +public abstract class BaseController + extends Expando +{ + Log log = LogFactory.getLog(this.getClass()) + String action + File pluginDir + def invokeArgs + private AuthzSubject user + + private void setAction(String action) { + this.action = action + } + + def setInvokeArgs(def args) { + this.invokeArgs = args + } + + def setPluginDir(File pluginDir) { + this.pluginDir = pluginDir + } + + /** + * Retreives the currently logged-in user + */ + protected AuthzSubject getUser() { + if (this.user != null) + return this.user + + def sessId = RequestUtils.getSessionId(invokeArgs.request) + def ctx = invokeArgs.request.session.servletContext + + this.user = ContextUtils.getAuthzBoss(ctx).getCurrentSubject(sessId) + } + + /** + * Render a .gsp. + * + * This method takes a map of arguments. Valid arguments include: + * file: The file to render. If not specified, the name of the + * current action will be used + * args: A map of key/value pairs to send to the .gsp to use when + * rendering + */ + protected def 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 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) + } + } +} Deleted: 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/rendit/dispatcher.groovy 2007-03-21 19:22:00 UTC (rev 3802) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-22 00:23:21 UTC (rev 3807) @@ -1,63 +0,0 @@ -package org.hyperic.hq.rendit - -import org.apache.commons.logging.Log -import org.apache.commons.logging.LogFactory - -/** - * The Dispatcher is the direct invocation target called from the HQ - * RenditServer. It has the responsibility of locating the controllers, - * setting up the environment, and invoking the request. - */ -public class Dispatcher { - private Log log = LogFactory.getLog(Dispatcher.class); - - private File pluginDir - private String controllerName - private String action - private def invokeArgs - - private String capitalize(String s) { - if (s.length() == 0) - return s; - return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); - } - - def Dispatcher(def invokeArgs) { - def path = invokeArgs.requestPath - - if (path.size() < 3) { - throw new IllegalArgumentException("Path must have at least 3 " + - "components"); - } - - pluginDir = invokeArgs.pluginDir - controllerName = capitalize(path[1]) + "Controller" - action = path[2] - this.invokeArgs = invokeArgs - } - - def invoke() { - def controller - - try { - controller = Class.forName(controllerName, true, - this.class.classLoader).newInstance() - } catch(Exception e) { - throw new IllegalArgumentException("Unknown controller " + - "[$controller]") - } - - controller.setAction(action) - controller.setPluginDir(pluginDir) - controller.setInvokeArgs(invokeArgs) - - def runner = controller."$action" - if (runner == null) { - throw new IllegalArgumentException("Unknown action [$action]") - } - - runner(invokeArgs.request.parameterMap) - } -} - -new Dispatcher(invokeArgs).invoke() Copied: trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy (from rev 3806, trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/rendit/dispatcher.groovy) =================================================================== --- trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy (rev 0) +++ trunk/src/org/hyperic/hq/ui/rendit/rendit_sys/org/hyperic/hq/ui/rendit/dispatcher.groovy 2007-03-22 00:23:21 UTC (rev 3807) @@ -0,0 +1,57 @@ +package org.hyperic.hq.ui.rendit + +import org.apache.commons.logging.Log +import org.apache.commons.logging.LogFactory + +/** + * The Dispatcher is the direct invocation target called from the HQ + * RenditServer. It has the responsibility of locating the controllers, + * setting up the environment, and invoking the request. + */ +public class Dispatcher { + private Log log = LogFactory.getLog(Dispatcher.class); + + private File pluginDir + private String controllerName + private String action + private def invokeArgs + + private String capitalize(String s) { + if (s.length() == 0) + return s; + return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); + } + + def Dispatcher(def invokeArgs) { + def path = invokeArgs.requestPath + + if (path.size() < 3) { + throw new IllegalArgumentException("Path must have at least 3 " + + "components"); + } + + pluginDir = invokeArgs.pluginDir + controllerName = capitalize(path[1]) + "Controller" + action = path[2] + this.invokeArgs = invokeArgs + } + + def invoke() { + log.info "Controller name is $controllerName" + def controller = Class.forName(controllerName, true, + this.class.classLoader).newInstance() + + controller.setAction(action) + controller.setPluginDir(pluginDir) + controller.setInvokeArgs(invokeArgs) + + def runner = controller."$action" + if (runner == null) { + throw new IllegalArgumentException("Unknown action [$action]") + } + + runner(invokeArgs.request.parameterMap) + } +} + +new Dispatcher(invokeArgs).invoke() |