List of usage examples for org.apache.commons.jelly JellyContext JellyContext
public JellyContext()
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 2s . c om*/ context.setVariable(key, env.get(key)); }); context.runScript(is, xo); return baos.toString(); }
From source file:com.hp.test.framework.runner.Runallthetests.java
@BeforeTest public void pres(ITestContext ctx) throws JellyException, FileNotFoundException { context = new JellyContext(); context.setVariable("xpath", new XpathSupport()); context.setVariable("env", System.getProperties()); context.setVariable("outcome", Boolean.TRUE); // Map<String,String> suiteName_list = ctx.getCurrentXmlTest().getTestParameters(); // for(String a:suiteName_list.keySet()) // System.out.println("key"+a+"value"+suiteName_list.get(a)); }
From source file:com.viltgroup.xcp.jenkins.maven.XcpMavenSettings.java
public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath, FilePath generatedFilePath) {/*from w w w.j a v a 2s .c om*/ 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 * /* ww w .j av a 2s . com*/ * @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.groupon.jenkins.buildsetup.GithubRepoAction.java
public String getHtml(ProjectConfigInfo projectConfigInfo) throws IOException, ClassNotFoundException, JellyException { String name = getClass().getName().replace('.', '/').replace('$', '/') + "/" + "index.jelly"; URL actionTemplate = getClass().getClassLoader().getResource(name); JellyContext context = new JellyContext(); context.setVariable("p", projectConfigInfo); context.setVariable("it", this); OutputStream outputStream = new ByteArrayOutputStream(); XMLOutput output = XMLOutput.createXMLOutput(outputStream); context.runScript(actionTemplate, output); output.flush();//from w ww. ja va2s . c o m return "<p>" + outputStream.toString() + " </p>"; }
From source file:com.cloudbees.hudson.plugins.folder.FolderIcon.java
protected String iconClassNameImageOf(String size) { String iconClassName = getIconClassName(); if (StringUtils.isNotBlank(iconClassName)) { String spec = null;//from w ww .j ava 2 s .c o m 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.navigator.impl.DefaultNavigatorHome.java
/** * Overwrite or implement method in DefaultNavigatorHome * * @see org.apache.avalon.framework.activity.Initializable#initialize() *//*w w w . j a v a2 s. c om*/ 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, "Start"); addNode(rootNode); JellyContext jc = new JellyContext(); jc.setVariable(getClass().getName(), this); jc.registerTagLibrary("http://waterview.cyclopsgroup.com/navigator", new NavigatorTagLibrary()); for (Enumeration en = getClass().getClassLoader() .getResources("META-INF/cyclopsgroup/waterview-navigation.xml"); en.hasMoreElements();) { URL resource = (URL) en.nextElement(); getLogger().info("Reading navigation from " + resource); jc.runScript(resource, XMLOutput.createDummyXMLOutput()); } populateNode(rootNode); }
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 ww. j av a 2 s . 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.navigator.impl.DefaultNavigatorService.java
/** * Overwrite or implement method in DefaultNavigatorHome * * @see org.apache.avalon.framework.activity.Initializable#initialize() *//*from w w w. ja v a 2s .c o 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.cloudbees.plugins.credentials.ContextMenuIconUtils.java
/** * Gets the qualified URL of the specified icon. * * @param icon the icon.// w w w .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); }