List of usage examples for org.apache.commons.jelly JellyContext JellyContext
public JellyContext(JellyContext parent)
From source file:com.cyclopsgroup.waterview.web.taglib.JellyFormControlTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//*w w w. ja v a2 s . c om*/ protected void processTag(XMLOutput output) throws Exception { requireAttribute("script"); invokeBody(XMLOutput.createDummyXMLOutput()); if (formTag == null) { throw new JellyTagException("Form tag must be defined"); } JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); Script script = je.getScript(getScript()); JellyContext jc = new JellyContext(getContext()); jc.setVariable("formTag", formTag); jc.setVariable("form", formTag.getForm()); script.run(jc, output); }
From source file:com.cyclopsgroup.waterview.web.taglib.TreeTag.java
protected void processTag(XMLOutput output) throws Exception { requireAttribute("var"); requireAttribute("root"); RuntimeTreeNode runtimeNode;// ww w . jav a 2 s.c o m runtime = false; if (getRoot() instanceof RuntimeTreeNode) { runtimeNode = (RuntimeTreeNode) getRoot(); runtime = true; } else { //TODO not supported yet throw new UnsupportedOperationException(); } JellyContext jc = new JellyContext(getContext()); renderTag(runtimeNode, jc, output); }
From source file:com.cyclopsgroup.waterview.jelly.taglib.JellyScriptTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//*from www .j ava2s .com*/ protected void processTag(XMLOutput output) throws Exception { requireAttribute("type"); requireAttribute("path"); Script script = null; if (StringUtils.equals(getType(), "system")) { JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); script = je.getScript(getPath()); } else if (StringUtils.equals(getType(), "classpath")) { URL resource = getClass().getClassLoader().getResource(getPath()); if (resource != null) { script = context.compileScript(resource); } } else if (StringUtils.equals(getType(), "file")) { File file = new File(getPath()); if (file.exists()) { script = context.compileScript(file.toURL()); } } else { throw new JellyTagException("Type must be system|classpath|file, default value is system"); } if (script == null) { throw new FileNotFoundException("Resource " + getPath() + " is not found in " + getType()); } JellyContext jc = new JellyContext(getContext()); if (script != null) { script.run(jc, output); output.flush(); } }
From source file:com.cyclopsgroup.waterview.web.taglib.JellyTableControlTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) */// ww w . j a v a 2 s. com protected void processTag(XMLOutput output) throws Exception { requireAttribute("script"); invokeBody(XMLOutput.createDummyXMLOutput()); JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); Script s = je.getScript(getScript()); if (tableTag == null) { throw new JellyException("One table must be defined"); } if (data == null) { throw new JellyException("Tabular data must be included"); } JellyContext jc = new JellyContext(getContext()); jc.setVariable("tableTag", tableTag); jc.setVariable("table", tableTag.getTable()); jc.setVariable("tabularData", getData()); s.run(jc, output); }
From source file:hudson.widgets.RenderOnDemandClosure.java
/** * Renders the captured fragment.// w w w . j a v a 2 s . c om */ @JavaScriptMethod public HttpResponse render() { return new HttpResponse() { public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { try { new DefaultScriptInvoker() { @Override protected JellyContext createContext(StaplerRequest req, StaplerResponse rsp, Script script, Object it) { JellyContext context = super.createContext(req, rsp, script, it); for (int i = bodyStack.length - 1; i > 0; i--) {// exclude bodyStack[0] context = new JellyContext(context); context.setVariable("org.apache.commons.jelly.body", bodyStack[i]); } try { AdjunctsInPage.get().assumeIncluded(adjuncts); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to resurrect adjunct context", e); } catch (SAXException e) { LOGGER.log(Level.WARNING, "Failed to resurrect adjunct context", e); } return context; } @Override protected void exportVariables(StaplerRequest req, StaplerResponse rsp, Script script, Object it, JellyContext context) { super.exportVariables(req, rsp, script, it, context); context.setVariables(variables); req.setAttribute("currentDescriptorByNameUrl", currentDescriptorByNameUrl); } }.invokeScript(req, rsp, bodyStack[0], null); } catch (JellyTagException e) { LOGGER.log(Level.WARNING, "Failed to evaluate the template closure", e); throw new IOException("Failed to evaluate the template closure", e); } } }; }
From source file:com.cyclopsgroup.waterview.web.taglib.FieldTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//* ww w . ja va2s . c om*/ protected void processTag(XMLOutput output) throws Exception { requireAttribute("name"); FormTag formTag = (FormTag) requireInside(FormTag.class); formTag.addFieldTag(this); if (formTag.isFormNew()) { field = new Field(getName(), TypeUtils.getType(getType())); field.setTitle(getTitle()); field.setRequired(isRequired()); field.setPassword(isPassword()); if (!isPassword()) { field.setValue((String) getValue()); } formTag.getForm().addField(field); } else { field = formTag.getForm().getField(getName()); } invokeBody(output); if (!FormTag.isControlsHidden(getContext())) { if (getBodyScript() == null) { JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); setBodyScript(je.getScript("/waterview/FormField.jelly")); } JellyContext jc = new JellyContext(context); jc.setVariable("field", field); jc.setVariable("fieldTag", this); jc.setVariable("form", formTag.getForm()); jc.setVariable("formTag", formTag); jc.setVariable("formControl", formTag.getParent()); getBodyScript().run(jc, output); } }
From source file:com.cyclopsgroup.waterview.jelly.JellyEngine.java
/** * Create new Jelly context with all variables in given context * /*from w w w . j a va2 s . c o m*/ * @param context Given clib context * @return JellyContext object */ public JellyContext createJellyContext(com.cyclopsgroup.waterview.Context context) { JellyContext jc = new JellyContext(getGlobalContext()); for (Iterator i = context.keys(); i.hasNext();) { String name = (String) i.next(); Object value = context.get(name); jc.setVariable(name, value); } jc.setVariable(com.cyclopsgroup.waterview.Context.NAME, context); return jc; }
From source file:com.cyclopsgroup.waterview.jelly.valves.DeterminePageValve.java
private Page loadPage(Script script, JellyEngine jellyEngine) throws JellyTagException { JellyContext jc = new JellyContext(jellyEngine.getGlobalContext()); script.run(jc, XMLOutput.createDummyXMLOutput()); return (Page) jc.getVariable(Page.NAME); }
From source file:com.cyclopsgroup.waterview.jelly.DeterminePageValve.java
private Page loadPage(Script script) throws JellyTagException { JellyContext jc = new JellyContext(jelly.getGlobalContext()); script.run(jc, XMLOutput.createDummyXMLOutput()); return (Page) jc.getVariable(Page.NAME); }
From source file:com.cyclopsgroup.waterview.jelly.JellyPageRenderer.java
/** * Override method render in super class of JellyPageRenderer * //w w w . ja va 2 s . c om * @see com.cyclopsgroup.waterview.PageRenderer#render(com.cyclopsgroup.cyclib.Context, java.lang.String, java.lang.String, com.cyclopsgroup.waterview.UIRuntime) */ public void render(Context context, String packageName, String module, UIRuntime runtime) throws Exception { XMLOutput jellyOutput = (XMLOutput) context.get("jellyOutput"); if (jellyOutput == null) { jellyOutput = XMLOutput.createXMLOutput(runtime.getOutput()); context.put("jellyOutput", jellyOutput); } JellyContext jc = new JellyContext(initialJellyContext); for (Iterator i = context.keys(); i.hasNext();) { String name = (String) i.next(); jc.setVariable(name, context.get(name)); } String scriptPath = getScriptPath(packageName, module); Script script = getScript(scriptPath); synchronized (script) { try { script.run(jc, jellyOutput); runtime.getOutput().flush(); } catch (Exception e) { throw e; } finally { jc.getVariables().clear(); } } }