List of usage examples for org.apache.commons.jelly JellyContext setVariable
public void setVariable(String name, Object value)
From source file:com.viltgroup.xcp.jenkins.maven.XcpMavenSettings.java
public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath, FilePath generatedFilePath) {/*from w ww . j a va2s. c o m*/ XMLOutput output = null; try { // create directories if needed generatedFilePath.getParent().mkdirs(); // prepare output writer output = XMLOutput.createXMLOutput(generatedFilePath.write()); // load jelly template String templateLocation = String.format("/%s/template.jelly", XcpMavenSettings.class.getName().replace('.', '/')); URL templateURL = XcpMavenSettings.class.getResource(templateLocation); // generate settings.xml from template Jelly jelly = new Jelly(); jelly.setUrl(templateURL); Script script = jelly.compileScript(); // add xCP Designer path to the jelly context JellyContext context = new JellyContext(); context.setVariable("workspacePath", OSPathHacks.processFilePath(workspacePath)); context.setVariable("xcpDesignerPath", xcpDesignerPath); context.setVariable("xcpDesignerMavenPath", String.format("%s/maven", OSPathHacks.processFilePath(xcpDesignerPath))); context.setVariable("localRepositoryPath", OSPathHacks.processFilePath(localRepositoryPath)); script.run(context, output); output.flush(); } catch (IOException e) { throw new RuntimeException("Error generating xCP settings.xml file.", e); } catch (JellyTagException e) { throw new RuntimeException("Error generating xCP settings.xml file.", e); } catch (JellyException e) { throw new RuntimeException("Error generating xCP settings.xml file.", e); } catch (InterruptedException e) { throw new RuntimeException("Error generating xCP settings.xml file.", e); } finally { if (output != null) try { output.close(); } catch (IOException e) { } } }
From source file:com.marvelution.hudson.plugins.jirareporter.utils.IssueTextUtils.java
/** * Create the text content for a specific issue field * /*from w ww . ja v a 2s.c o m*/ * @param type the {@link Type} of text to create * @param build the {@link AbstractBuild} * @param site the {@link JIRASite} * @return the created text content */ public static String createFieldText(Type type, AbstractBuild<?, ?> build, JIRASite site) { final StringWriter writer = new StringWriter(); final XMLOutput output = XMLOutput.createXMLOutput(writer); final JellyContext context = new JellyContext(); context.setVariable("rootURL", Hudson.getInstance().getRootUrl()); context.setVariable("build", build); context.setVariable("site", site); try { Class.forName("jenkins.model.Jenkins"); context.setVariable("system", "Jenkins"); } catch (ClassNotFoundException e) { context.setVariable("system", "Hudson"); } context.setVariable("version", Hudson.getVersion().toString()); try { context.setVariable("environment", build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO))); } catch (Exception e) { context.setVariable("environment", Collections.emptyMap()); } // Utilize the Dozer Mapper and its convertors of the API V2 plugin to get the ChangeLog and TestResults try { context.setVariable("changelog", DozerUtils.getMapper().map(build.getChangeSet(), ChangeLog.class)); } catch (Exception e) { context.setVariable("changelog", new ChangeLog()); } try { context.setVariable("testresults", DozerUtils.getMapper().map(build, TestResult.class)); } catch (Exception e) { context.setVariable("testresults", new TestResult()); } try { context.runScript( HudsonPluginUtils.getPluginClassloader().getResource("fields/" + type.field(site) + ".jelly"), output); } catch (JellyException e) { LOGGER.log(Level.SEVERE, "Failed to create Text of type " + type.name(), e); throw new IllegalStateException("Cannot raise an issue if no text is available", e); } return writer.toString().trim(); }
From source file:com.cyclopsgroup.waterview.web.taglib.FormTag.java
static void setHideControls(boolean hideControls, JellyContext context) { context.setVariable(HIDE_CONTROLS, new Boolean(hideControls)); }
From source file:com.cloudbees.plugins.credentials.ContextMenuIconUtils.java
/** * Gets the qualified URL of the specified icon. * * @param icon the icon.//from w ww. j av a 2 s. c om * @return the qualified URL of the icon. */ @CheckForNull public static String getQualifiedUrl(@CheckForNull Icon icon) { if (icon == null) { return null; } try { Field iconType = Icon.class.getDeclaredField("iconType"); iconType.setAccessible(true); IconType type = (IconType) iconType.get(icon); switch (type) { case CORE: { return Functions.getResourcePath() + "/images/" + icon.getUrl(); } case PLUGIN: { return Functions.getResourcePath() + "/plugin/" + icon.getUrl(); } } return null; } catch (NoSuchFieldException e) { // ignore we'll use a JellyContext } catch (IllegalAccessException e) { // ignore we'll use a JellyContext } JellyContext ctx = new JellyContext(); ctx.setVariable("resURL", Functions.getResourcePath()); return icon.getQualifiedUrl(ctx); }
From source file:net.joinedminds.masserr.Functions.java
public static void initPageVariables(JellyContext context) { String rootURL = getRootUrl(); Functions h = new Functions(); context.setVariable("h", h); // The path starts with a "/" character but does not end with a "/" character. context.setVariable("rootURL", rootURL); context.setVariable("resURL", rootURL + RESOURCE_PATH); context.setVariable("imagesURL", rootURL + IMAGES_PATH); context.setVariable("selectedMainMenuItem", getParentMainMenu()); OAuthAuthentication authentication = AuthModule.getAuthentication(); if (authentication != null && authentication.isSignedIn()) { context.setVariable("authentication", authentication); }/*from w ww. ja v a2 s. c o m*/ }
From source file:com.cyclopsgroup.waterview.utils.TagSupportBase.java
/** * Set the resource for script//from w ww . j av a 2 s. c om * * @param resource Resource of script * @param context Context to set */ public static final void addScriptResource(URL resource, JellyContext context) { synchronized (context) { LinkedList scriptResources = (LinkedList) context.getVariable(SCRIPT_RESOURCE_NAME); if (scriptResources == null) { scriptResources = new LinkedList(); context.setVariable(SCRIPT_RESOURCE_NAME, scriptResources); } scriptResources.add(resource); } }
From source file:com.cyclopsgroup.waterview.web.taglib.BaseJellyFormControlTag.java
/** * Override method runScript in class BaseJellyFormControlTag * * @see com.cyclopsgroup.waterview.jelly.taglib.BaseJellyControlTag#runScript(org.apache.commons.jelly.Script, org.apache.commons.jelly.XMLOutput) *//*from ww w . j a va 2 s .co m*/ protected void runScript(Script script, XMLOutput output) throws Exception { FormTag.setHideControls(true, getContext()); String formContent = getBodyText(); FormTag.setHideControls(false, getContext()); if (formTag == null) { throw new JellyTagException("Form tag must be defined"); } JellyContext jc = new JellyContext(getContext()); jc.setVariable("formControl", this); jc.setVariable("formTag", formTag); jc.setVariable("form", formTag.getForm()); jc.setVariable("formContent", formContent); script.run(jc, output); }
From source file:com.cyclopsgroup.waterview.richweb.taglib.TreeChildrenTag.java
/** * Override or implement method of parent class or interface * * @see com.cyclopsgroup.waterview.jelly.AbstractTag#doTag(org.apache.avalon.framework.service.ServiceManager, org.apache.commons.jelly.XMLOutput) *//* ww w . j a va 2 s . co m*/ protected void doTag(ServiceManager serviceManager, XMLOutput output) throws Exception { TreeScriptTag treeScriptTag = (TreeScriptTag) findAncestorWithClass(TreeScriptTag.class); String var = treeScriptTag.getVar(); if (treeScriptTag == null) { throw new JellyTagException("TreeChildren must be in the TreeScript"); } TreeNode node = (TreeNode) getContext().getVariable(var); TreeNode[] children = node.getChildren(); RuntimeTree treeRuntime = (RuntimeTree) getContext().getVariable(RuntimeTree.NAME); for (int i = 0; i < children.length; i++) { TreeNode child = children[i]; JellyContext jc = new JellyContext(getContext()); jc.setVariable(var, treeRuntime.createRuntimeNode(child)); treeScriptTag.getBody().run(jc, output); } }
From source file:com.cyclopsgroup.waterview.web.taglib.BaseJellyTableControlTag.java
/** * Override method runScript in class BaseJellyTableControlTag * * @see com.cyclopsgroup.waterview.jelly.taglib.BaseJellyControlTag#runScript(org.apache.commons.jelly.Script, org.apache.commons.jelly.XMLOutput) *///from w w w.ja v a 2 s .c o m protected void runScript(Script script, XMLOutput output) throws Exception { invokeBody(XMLOutput.createDummyXMLOutput()); 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", data); jc.setVariable("tableControl", this); script.run(jc, output); }
From source file:com.latticeware.xecute.Engine.java
public Object execute(String script, Map<String, Object> env) throws UnsupportedEncodingException, JellyException { ByteArrayOutputStream baos = new ByteArrayOutputStream(5120); ByteArrayInputStream bais = new ByteArrayInputStream(script.getBytes()); XMLOutput xo = XMLOutput.createXMLOutput(baos); InputSource is = new InputSource(bais); JellyContext context = new JellyContext(); env.keySet().forEach((key) -> {// w w w. j a v a 2 s . c om context.setVariable(key, env.get(key)); }); context.runScript(is, xo); return baos.toString(); }