List of usage examples for org.apache.commons.jelly XMLOutput flush
public void flush() throws IOException
From source file:com.cyclopsgroup.waterview.jelly.JellyPanel.java
/** * Override or implement method of parent class or interface * * @see com.cyclopsgroup.waterview.spi.Panel#render(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.spi.View[]) *///from ww w . j ava 2 s . c o m public void render(RuntimeData data, View[] views) throws Exception { JellyEngine je = (JellyEngine) data.getServiceManager().lookup(JellyEngine.ROLE); JellyContext jc = je.createJellyContext(data.getRequestContext()); jc.setVariable(VIEWS_NAME, views); runModule(data, new JellyContextAdapter(jc)); try { XMLOutput output = XMLOutput.createXMLOutput(data.getOutput()); script.run(jc, output); output.flush(); } catch (Exception e) { data.getOutput().println("<pre>"); e.printStackTrace(data.getOutput()); data.getOutput().println("</pre>"); } finally { data.getOutput().flush(); } }
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(); return "<p>" + outputStream.toString() + " </p>"; }
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 ww.j a v a2s. c o 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.viltgroup.xcp.jenkins.maven.XcpMavenSettings.java
public static void generateFile(String workspacePath, String xcpDesignerPath, String localRepositoryPath, FilePath generatedFilePath) {//from ww w . j ava 2 s. 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.cyclopsgroup.waterview.jelly.JellyView.java
/** * Overwrite or implement method render() * @see com.cyclopsgroup.waterview.spi.View#render(com.cyclopsgroup.waterview.RuntimeData, com.cyclopsgroup.waterview.Context) *///from w w w. ja va2 s . c o m public void render(RuntimeData data, Context viewContext) throws Exception { runModule(data, viewContext); JellyEngine je = (JellyEngine) data.getServiceManager().lookup(JellyEngine.ROLE); JellyContext jellyContext = je.createJellyContext(viewContext); XMLOutput output = XMLOutput.createXMLOutput(data.getOutput()); try { script.run(jellyContext, output); } catch (Exception e) { data.getOutput().print("<div>"); e.printStackTrace(data.getOutput()); data.getOutput().println("</div>"); } finally { output.flush(); } }
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 a v a2 s. c om 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:org.apache.commons.jelly.demos.HomepageBuilder.java
public void buildPage(String template, JellyContext ctx) { // try { ////from ww w .j a v a 2 s.c o m // Embedded embedded = new Embedded(); // embedded.setOutputStream(new FileOutputStream("out.html")); // //embedded.setVariable("some-var","some-object"); // // embedded.setScript("file:///anoncvs/jakarta-commons-sandbox/jelly/sample.jelly"); // //or one can do. // //embedded.setScript(scriptAsInputStream); // // boolean bStatus=embedded.execute(); // if(!bStatus) //if error // { // System.out.println(embedded.getErrorMsg()); // } // // } catch (Exception e) { // e.printStackTrace(); // } try { OutputStream output = new FileOutputStream("demopage.html"); JellyContext context = new JellyContext(); context.setVariable("name", nameField.getText()); context.setVariable("background", colorField.getText()); context.setVariable("url", urlField.getText()); Vector v = new Vector(); Enumeration items = listModel.elements(); while (items.hasMoreElements()) { v.add(items.nextElement()); } context.setVariable("hobbies", v); XMLOutput xmlOutput = XMLOutput.createXMLOutput(output); context.runScript(resolveURL("src/test/org/apache/commons/jelly/demos/" + template), xmlOutput); xmlOutput.flush(); System.out.println("Finished merging template"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.codehaus.mojo.AbstractJellyMojo.java
/** * Execute the .jelly script associated with the concrete class *//* ww w . j av a 2 s.c o m*/ public void execute() throws MojoExecutionException { try { final String scriptName = this.getClass().getSimpleName() + ".jelly"; if (scriptName == null || scriptName.equals("")) throw new MojoExecutionException("script name unspecified"); URL fileName = this.getClass().getResource(scriptName); if (fileName == null) throw new MojoExecutionException(scriptName + " not found"); setParams(); // add plugin's parameters to the groovy context JellyContext context = new JellyContext(); if (params != null) { Iterator i = params.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); context.setVariable(key, params.get(key)); } } XMLOutput xmlOutput = XMLOutput.createXMLOutput(System.out); context.runScript(fileName, xmlOutput); xmlOutput.flush(); } catch (Exception e) { throw new MojoExecutionException("Mojo error occurred:", e); } }
From source file:org.wyona.yanel.impl.resources.usecase.UsecaseResource.java
/** * Generate jelly view.//from w ww .j av a 2 s . c o m */ private InputStream getJellyInputStream(String viewID, String viewTemplate, boolean XMLoutput) throws UsecaseException { try { if (log.isDebugEnabled()) log.debug("viewTemplate: " + viewTemplate); Repository repo = this.getRealm().getRepository(); JellyContext jellyContext = new JellyContext(); jellyContext.setVariable("resource", this); jellyContext.setVariable("yanel.back2context", PathUtil.backToContext(realm, getPath())); jellyContext.setVariable("yanel.back2realm", PathUtil.backToRealm(getPath())); jellyContext.setVariable("yanel.globalHtdocsPath", PathUtil.getGlobalHtdocsPath(this)); jellyContext.setVariable("yanel.resourcesHtdocsPath", PathUtil.getResourcesHtdocsPathURLencoded(this)); jellyContext.setVariable("yanel.reservedPrefix", this.getYanel().getReservedPrefix()); //jellyContext.setVariable("request", request); ByteArrayOutputStream jellyResultStream = new ByteArrayOutputStream(); XMLOutput jellyOutput = XMLOutput.createXMLOutput(jellyResultStream, XMLoutput); InputStream templateInputStream; String templatePublicId; String templateSystemId; if (viewTemplate.startsWith("/")) { if (log.isDebugEnabled()) log.debug( "Accessing view template directly from the repo (no protocol specified). View Template: " + viewTemplate); // for backwards compatibility. when not using a protocol templateInputStream = repo.getNode(viewTemplate).getInputStream(); templatePublicId = "yanelrepo:" + viewTemplate; /*XXX HACK the following does not work: Jelly wants URLs => protocol must be registered by the JVM! templateSystemId = "yanelrepo:"+viewTemplate; */ templateSystemId = "file:///yanelrepo" + viewTemplate; } else { if (log.isDebugEnabled()) log.debug( "Accessing view template through the source-resolver (protocol specified). View Template: " + viewTemplate); SourceResolver resolver = new SourceResolver(this); Source templateSource = resolver.resolve(viewTemplate, null); templateInputStream = ((StreamSource) templateSource).getInputStream(); templatePublicId = templateSource.getSystemId(); /*XXX HACK the following does not work: Jelly wants URLs => protocol must be registered by the JVM! templateSystemId = templateSource.getSystemId(); */ templateSystemId = "file:///" + viewTemplate.replaceFirst(":", "/"); } InputSource inputSource = new InputSource(templateInputStream); inputSource.setPublicId(templatePublicId); inputSource.setSystemId(templateSystemId); jellyContext.runScript(inputSource, jellyOutput); //XXX should we close templateInputStream here?!? jellyOutput.flush(); byte[] result = jellyResultStream.toByteArray(); //System.out.println(new String(result, "utf-8")); return new ByteArrayInputStream(result); } catch (Exception e) { String errorMsg = "Error creating 'jelly' view '" + viewID + "' of usecase resource: " + getName() + ": " + e; log.error(errorMsg, e); throw new UsecaseException(errorMsg, e); } }