List of usage examples for org.apache.commons.jelly JellyContext setVariable
public void setVariable(String name, Object value)
From source file:jenkins.scm.api.metadata.AvatarMetadataAction.java
/** * Helper method to resolve the icon image url. * * @param iconClassName the icon class name. * @param size the size string, e.g. {@code 16x16}, {@code 24x24}, etc. * @return the icon image url or {@code null} *//* w w w . jav a2s .co m*/ @CheckForNull protected final String avatarIconClassNameImageOf(@CheckForNull String iconClassName, @NonNull String size) { if (StringUtils.isNotBlank(iconClassName)) { String spec = null; if ("16x16".equals(size)) { spec = "icon-sm"; } else if ("24x24".equals(size)) { spec = "icon-md"; } else if ("32x32".equals(size)) { spec = "icon-lg"; } else if ("48x48".equals(size)) { spec = "icon-xlg"; } if (spec != null) { Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " " + spec); if (icon != null) { JellyContext ctx = new JellyContext(); ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH); return icon.getQualifiedUrl(ctx); } } } return null; }
From source file:com.cyclopsgroup.waterview.web.taglib.SelectTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//*from ww w . j a v a 2 s . c o m*/ protected void processTag(XMLOutput output) throws Exception { FieldTag fieldTag = (FieldTag) requireParent(FieldTag.class); options = ListOrderedMap.decorate(new HashMap()); invokeBody(output); if (getItems() != null) { Iterator i = Collections.EMPTY_LIST.iterator(); if (TypeUtils.isIteratable(getItems())) { i = TypeUtils.iterate(getItems()); } else if (getItems() instanceof Map) { i = ((Map) getItems()).entrySet().iterator(); } while (i.hasNext()) { Object item = i.next(); SelectOption option = null; if (item instanceof SelectOption) { option = (SelectOption) item; } else if (item instanceof Map.Entry) { Map.Entry e = (Map.Entry) item; String name = TypeUtils.toString(e.getKey()); option = new DefaultSelectOption(name, TypeUtils.toString(e.getValue())); } else { String name = TypeUtils.toString(item); option = new DefaultSelectOption(name, name); } addOption(option); } } JellyEngine je = (JellyEngine) getServiceManager().lookup(JellyEngine.ROLE); final Script script = je.getScript("/waterview/FormSelectInput.jelly"); Script s = new Script() { public Script compile() throws JellyException { return this; } public void run(JellyContext context, XMLOutput output) throws JellyTagException { context.setVariable("selectTag", SelectTag.this); script.run(context, output); } }; fieldTag.setBodyScript(s); }
From source file:com.cyclopsgroup.waterview.navigator.impl.DefaultNavigatorService.java
/** * Overwrite or implement method in DefaultNavigatorHome * * @see org.apache.avalon.framework.activity.Initializable#initialize() *//*from w w w .ja v a2 s . co m*/ public void initialize() throws Exception { pathIndex = new Hashtable(); parentPathIndex = new MultiHashMap(); pageIndex = new Hashtable(); rootNode = new DefaultNavigatorNode(this, "/", null); rootNode.getAttributes().set(DefaultNavigatorNode.PAGE_NAME, "/Index.jelly"); rootNode.getAttributes().set(DefaultNavigatorNode.TITLE_NAME, "%waterview.navigation.start"); addNode(rootNode); JellyContext jc = new JellyContext(); jc.setVariable(DefaultNavigatorService.class.getName(), this); jc.registerTagLibrary("http://waterview.cyclopsgroup.com/navigator", new NavigatorTagLibrary()); for (Enumeration en = getClass().getClassLoader().getResources(path); en.hasMoreElements();) { URL resource = (URL) en.nextElement(); getLogger().info("Reading navigation from " + resource); jc.runScript(resource, XMLOutput.createDummyXMLOutput()); } populateNode(rootNode); }
From source file:com.cyclopsgroup.waterview.jelly.ScriptFrame.java
/** * Override or implement method of parent class or interface * * @see com.cyclopsgroup.waterview.Frame#display(com.cyclopsgroup.waterview.Page, com.cyclopsgroup.waterview.PageRuntime) *///from w w w . ja v a 2 s . co m public void display(Page page, PageRuntime runtime) throws Exception { JellyEngine je = (JellyEngine) runtime.getServiceManager().lookup(JellyEngine.ROLE); JellyContext jc = new JellyContext(je.getGlobalContext()); JellyEngine.passVariables(runtime.getPageContext(), jc); runtime.getPageContext().put(JellyEngine.JELLY_CONTEXT, jc); jc.setVariable(Page.NAME, page); jc.setVariable(PageRuntime.NAME, runtime); XMLOutput output = XMLOutput.createXMLOutput(runtime.getOutput()); runtime.getPageContext().put(JellyEngine.JELLY_OUTPUT, output); script.run(jc, output); output.flush(); }
From source file:com.cyclopsgroup.waterview.jelly.ScriptLayout.java
/** * Override or implement method of parent class or interface * * @see com.cyclopsgroup.waterview.Layout#render(com.cyclopsgroup.waterview.PageRuntime, com.cyclopsgroup.waterview.Page) *//*from ww w. jav a 2 s . c o m*/ public synchronized void render(PageRuntime runtime, Page page) throws Exception { if (getModule() != null) { getModule().execute(runtime, runtime.getPageContext()); } JellyContext jellyContext = (JellyContext) runtime.getPageContext().get(JellyEngine.JELLY_CONTEXT); XMLOutput output = (XMLOutput) runtime.getPageContext().get(JellyEngine.JELLY_OUTPUT); jellyContext.setVariable(Page.NAME, page); jellyContext.setVariable(NAME, this); jellyContext.setVariable(JellyEngine.RENDERING, Boolean.TRUE); script.run(jellyContext, output); jellyContext.setVariable(Page.NAME, null); jellyContext.setVariable(NAME, null); jellyContext.setVariable(JellyEngine.RENDERING, null); }
From source file:com.cyclopsgroup.waterview.web.taglib.RenderTreeChildrenTag.java
/** * Overwrite or implement method processTag() * * @see com.cyclopsgroup.waterview.utils.TagSupportBase#processTag(org.apache.commons.jelly.XMLOutput) *//* w w w . j a v a 2s. c o m*/ protected void processTag(XMLOutput output) throws Exception { TreeTag tree = (TreeTag) getContext().getVariable(TreeTag.TREE_TAG); RuntimeTreeNode runtimeNode = (RuntimeTreeNode) getContext().getVariable(TreeTag.CURRENT_RUNTIME_NODE); JellyContext jc = new JellyContext(getContext()); Node[] nodes = runtimeNode.getChildrenNodes(); for (int i = 0; i < nodes.length; i++) { RuntimeTreeNode node = (RuntimeTreeNode) nodes[i]; jc.setVariable(tree.getVar(), tree.isRuntime() ? node : node.getContent()); jc.setVariable(TreeTag.CURRENT_RUNTIME_NODE, node); tree.getBody().run(jc, output); } }
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) *//* www . j a va2 s .com*/ 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.JellyPageRenderer.java
/** * Override method render in super class of JellyPageRenderer * //from w ww.j a va 2 s . c o m * @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(); } } }
From source file:com.cyclopsgroup.waterview.jelly.JellyEngine.java
/** * Init global context/*from ww w . j av a 2 s . c o m*/ * * @throws Exception Throw it out */ private void initGlobalContext() throws Exception { JellyContext jc = new JellyContext(); jc.setVariable(SERVICE_MANAGER, serviceManager); jc.setVariable(ROLE, this); TagLibrary deftaglib = new TagLibrary(); deftaglib.registerPackage((TagPackage) Class.forName(DEFINITION_TAG_PACKAGE).newInstance()); jc.registerTagLibrary(DEFINITION_TAGLIB_URL, deftaglib); Enumeration e = getClass().getClassLoader().getResources("META-INF/cyclopsgroup/waterview.xml"); while (e.hasMoreElements()) { URL resource = (URL) e.nextElement(); getLogger().info("Load definition from " + resource); jc.runScript(resource, XMLOutput.createDummyXMLOutput()); } globalContext = new JellyContext(); globalContext.setVariables(initProperties); for (Iterator i = tagLibraries.keySet().iterator(); i.hasNext();) { String uri = (String) i.next(); TagLibrary taglib = (TagLibrary) tagLibraries.get(uri); globalContext.registerTagLibrary(uri, taglib); } globalContext.setVariable(SERVICE_MANAGER, serviceManager); globalContext.setVariable(ROLE, this); }
From source file:hudson.widgets.RenderOnDemandClosure.java
/** * Renders the captured fragment.//from w w w . ja va 2 s . c o m */ @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); } } }; }