System.err.println("Jelly " + Jelly.getJellyVersion()); System.err.println(" compiled: " + Jelly.getJellyBuildDate()); System.err.println(""); System.exit(1); XMLOutput.createXMLOutput(System.out); Jelly jelly = new Jelly(); jelly.setScript(scriptFile); final Script script = jelly.compileScript(); final JellyContext context = jelly.getJellyContext(); context.setVariable("args", args); context.setVariable("commandLine", cmdLine);
public void setUp(String scriptName) throws Exception { this.context = new JellyContext(); this.xmlOutput = XMLOutput.createDummyXMLOutput(); this.jelly = new Jelly(); String script = scriptName; URL url = this.getClass().getResource(script); if ( url == null ) { throw new Exception( "Could not find Jelly script: " + script + " in package of class: " + this.getClass().getName() ); } this.jelly.setUrl(url); }
/** * The context to use */ public JellyContext getJellyContext() throws MalformedURLException { if (context == null) { // take off the name off the URL String text = getUrl().toString(); int idx = text.lastIndexOf('/'); text = text.substring(0, idx + 1); context = new JellyContext(getRootContext(), new URL(text)); } return context; }
/** * Sets the script URL to use as an absolute URL or a relative filename */ public void setScript(String script) throws MalformedURLException { setUrl(resolveURL(script)); }
public void testInvalidXML1Validation() throws Exception { // with validation setUp("invalidScript1.jelly"); jelly.setValidateXML(true); try { Script script = jelly.compileScript(); fail("Invalid scripts should throw JellyException on parse"); } catch (JellyException e) { } }
/** * A script should fail to parse if it declares tags that don't exist. */ public void testNonexistentTags() throws Exception { setUp("nonexistentTags1.jelly"); try { Script script = jelly.compileScript(); fail("Scripts should throw JellyException when it declares a nonexistent tag."); } catch (JellyException e) { } }
if (! loadedProperties) { loadedProperties = true; loadJellyProperties(); parser.setContext(getJellyContext()); } catch (MalformedURLException e) { throw new JellyException(e.toString()); parser.setDefaultNamespaceURI(this.defaultNamespaceURI); parser.setValidating(this.validateXML); script = parser.parse(getUrl()); script = script.compile(); if (log.isDebugEnabled()) { log.debug("Compiled script: " + getUrl());
/** * CDATA sections should be retained in the output. * * @throws Exception */ public void testCData() throws Exception { Jelly jelly = new Jelly(); jelly.setScript("file:src/test/org/apache/commons/jelly/test/xml/testCData.jelly"); Script script = jelly.compileScript(); JellyContext context = new JellyContext(); script.run(context, XMLOutput.createDummyXMLOutput()); String output = (String) context.getVariable("foo"); assertTrue("'foo' is not null", output != null); String golden = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; golden += "<!DOCTYPE foo [\n"; golden += " <!ELEMENT foo (#PCDATA)>\n"; golden += "]><foo></foo>"; assertEquals("output should contain the CDATA section", golden, output); }
public void setUp() throws Exception { super.setUp(); jelly = new Jelly(); context = new JellyContext(); xmlOutput = XMLOutput.createDummyXMLOutput(); }
protected void setUpScript(String scriptname) throws Exception { URL url = this.getClass().getResource(scriptname); if(null == url) { throw new Exception( "Could not find Jelly script: " + scriptname + " in package of class: " + getClass().getName() ); } jelly.setUrl(url); String exturl = url.toExternalForm(); int lastSlash = exturl.lastIndexOf("/"); String extBase = exturl.substring(0,lastSlash+1); URL baseurl = new URL(extBase); context.setCurrentURL(baseurl); }
public void testNamespaceDefined() throws Exception { jelly.setDefaultNamespaceURI("jelly:core"); Script script = jelly.compileScript(); script.run(context,xmlOutput); assertTrue("should have set 'usedDefaultNamespace' variable", context.getVariable("usedDefaultNamespace") != null); }
/** * Loads the properties from the given input stream */ protected void loadProperties(InputStream is) throws IOException { JellyContext theContext = getJellyContext(); Properties props = new Properties(); props.load(is); Enumeration propsEnum = props.propertyNames(); while (propsEnum.hasMoreElements()) { String key = (String) propsEnum.nextElement(); String value = props.getProperty(key); // @todo we should parse the value in case its an Expression theContext.setVariable(key, value); } } }
public void testNamespaceNotDefined() throws Exception { Script script = jelly.compileScript(); script.run(context,xmlOutput); assertTrue("should not have set 'usedDefaultNamespace' variable", context.getVariable("usedDefaultNamespace") == null); } }
if (! loadedProperties) { loadedProperties = true; loadJellyProperties(); parser.setContext(getJellyContext()); } catch (MalformedURLException e) { throw new JellyException(e.toString()); parser.setDefaultNamespaceURI(this.defaultNamespaceURI); parser.setValidating(this.validateXML); script = parser.parse(getUrl()); script = script.compile(); if (log.isDebugEnabled()) { log.debug("Compiled script: " + getUrl());
/** * Sets the script URL to use as an absolute URL or a relative filename */ public void setScript(String script) throws MalformedURLException { setUrl(resolveURL(script)); }
public void testParserCache1() throws Exception { // without validation, should // not fail because validation is disabled setUp("invalidScript1.jelly"); jelly.setValidateXML(false); Script script = jelly.compileScript(); script.run(context,xmlOutput); assertTrue("should have set 'foo' variable to 'bar'", context.getVariable("foo").equals("bar")); // if I enable xml validation, the script should fail // despite the cache jelly.setValidateXML(true); try { script = jelly.compileScript(); fail("Invalid scripts should throw JellyException on parse, despite the cache"); } catch (JellyException e) { } }
public void setUp() throws Exception { super.setUp(); jelly = new Jelly(); context = new JellyContext(); xmlOutput = XMLOutput.createDummyXMLOutput(); }
protected void setUpScript(String scriptname) throws Exception { URL url = this.getClass().getResource(scriptname); if(null == url) { throw new Exception( "Could not find Jelly script: " + scriptname + " in package of class: " + getClass().getName() ); } jelly.setUrl(url); String exturl = url.toExternalForm(); int lastSlash = exturl.lastIndexOf("/"); String extBase = exturl.substring(0,lastSlash+1); URL baseurl = new URL(extBase); context.setCurrentURL(baseurl); }
public void testParserCache2() throws Exception { // no default namespace setUp("nsFilterTest.jelly"); Script script = jelly.compileScript(); script.run(context,xmlOutput); assertTrue("should have no var when default namspace is not set", context.getVariable("usedDefaultNamespace") == null); // now we have a default namespace, so we // should see a variable, despite the XMLParser cache jelly.setDefaultNamespaceURI("jelly:core"); script = jelly.compileScript(); script.run(context,xmlOutput); assertTrue("should have var when default namspace is set", context.getVariable("usedDefaultNamespace").equals("true")); } }
/** * Loads the properties from the given input stream */ protected void loadProperties(InputStream is) throws IOException { JellyContext theContext = getJellyContext(); Properties props = new Properties(); props.load(is); Enumeration propsEnum = props.propertyNames(); while (propsEnum.hasMoreElements()) { String key = (String) propsEnum.nextElement(); String value = props.getProperty(key); // @todo we should parse the value in case its an Expression theContext.setVariable(key, value); } } }