private Object doGetVariable(String name) { return super.getVariable(name); }
public void include(String path) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) super.getVariable("request"); HttpServletResponse response = (HttpServletResponse) super.getVariable("response"); RequestDispatcher dispatcher = request.getRequestDispatcher(path); dispatcher.include(request, response); }
public void forward(String path) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) super.getVariable("request"); HttpServletResponse response = (HttpServletResponse) super.getVariable("response"); RequestDispatcher dispatcher = request.getRequestDispatcher(path); dispatcher.forward(request, response); }
public void redirect(String location) throws IOException { HttpServletResponse response = (HttpServletResponse) super.getVariable("response"); response.sendRedirect(location); } }
public Object getProperty(String property) { try { return binding.getVariable(property); } catch (MissingPropertyException e) { return super.getProperty(property); } }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { /** @todo we should check if we have the property with the metaClass instead of try/catch */ try { return super.getProperty(property); } catch (MissingPropertyException e) { return getVariable(property); } }
public Object get() { return script.getBinding().getVariable(variable); }
/** * @return a writer, an output stream, a markup builder or another requested object */ @Override public Object getVariable(String name) { lazyInit(); validateArgs(name, "No variable with"); return super.getVariable(name); }
Binding binding = getBinding(); if (binding != null && binding.hasVariable(name)) { return binding.getVariable(name);
public void testScriptWithDerivedBaseClass() throws Exception { Binding context = new Binding(); CompilerConfiguration config = new CompilerConfiguration(); config.setScriptBaseClass(DerivedScript.class.getName()); GroovyShell shell = new GroovyShell(context, config); Object result = shell.evaluate("x = 'abc'; doSomething(cheese)"); assertEquals("I like Cheddar", result); assertEquals("abc", context.getVariable("x")); }
Binding binding = getBinding(); if (binding != null && binding.hasVariable(name)) { return binding.getVariable(name);
private void lazyInit() { if (initialized) return; initialized = true; HttpServletResponse response = (HttpServletResponse) super.getVariable("response"); ServletOutput output = new ServletOutput(response); super.setVariable("out", output.getWriter()); super.setVariable("sout", output.getOutputStream()); MarkupBuilder builder = new MarkupBuilder(output.getWriter()); builder.setExpandEmptyElements(true); super.setVariable("html", builder); try { Class jsonBuilderClass = this.getClass().getClassLoader().loadClass("groovy.json.StreamingJsonBuilder"); Constructor writerConstructor = jsonBuilderClass.getConstructor(Writer.class); super.setVariable("json", writerConstructor.newInstance(output.getWriter())); } catch (Throwable t) { t.printStackTrace(); } // bind forward method MethodClosure c = new MethodClosure(this, "forward"); super.setVariable("forward", c); // bind include method c = new MethodClosure(this, "include"); super.setVariable("include", c); // bind redirect method c = new MethodClosure(this, "redirect"); super.setVariable("redirect", c); }
@Override public Object getVariable(String name) { try { return super.getVariable(name); } catch (MissingPropertyException e) { // ignore } return defaultValue; } };
private String eval(ShellSession session, String name, String def) { try { GroovyShell shell = getGroovyShell(session); Object ret = shell.getContext().getVariable(name); if (ret instanceof Closure) { log.log(Level.FINEST, "Invoking " + name + " closure"); Closure c = (Closure)ret; ret = c.call(); } else if (ret == null) { log.log(Level.FINEST, "No " + name + " will use empty"); return def; } return String.valueOf(ret); } catch (Exception e) { log.log(Level.SEVERE, "Could not get a " + name + " message, will use empty", e); return def; } }
@Override public Object getVariable(String name) { try { return super.getVariable(name); } catch (MissingPropertyException e) { // Original {@link Binding} doesn't have 'variable' for the given 'name'. // Try to resolve it as 'bean' from the given <code>beanFactory</code>. } if (GroovyScriptExecutingMessageProcessor.this.beanFactory == null) { throw new MissingPropertyException(name, this.getClass()); } try { return GroovyScriptExecutingMessageProcessor.this.beanFactory.getBean(name); } catch (NoSuchBeanDefinitionException e) { throw new MissingPropertyException(name, this.getClass(), e); } }
@Override public Object getVariable(String name) { if (name.equals("context")) { return proxy; } else { if (session != null) { try { Command<?> cmd = session.getCommand(name); if (cmd != null) { return new PipeLineClosure(new InvocationContextImpl<Object>(proxy), name, cmd); } } catch (CommandException ignore) { // Really ? } return super.getVariable(name); } else { return super.getVariable(name); } } } }
@Override public Object getVariable(String name) { try { return super.getVariable(name);
/** * @param name the name of the variable to lookup * @return the variable value */ @Override public Object getVariable(final String name) { return first.hasVariable(name) ? first.getVariable(name) : second.getVariable(name); }
/** * Overloaded to make variables appear as bean properties or via the subscript operator */ public Object getProperty(String property) { /** @todo we should check if we have the property with the metaClass instead of try/catch */ try { return super.getProperty(property); } catch (MissingPropertyException e) { return getVariable(property); } }
/** * @return a writer, an output stream, a markup builder or another requested object */ public Object getVariable(String name) { lazyInit(); validateArgs(name, "No variable with"); return super.getVariable(name); }