Index: JellyContext.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
retrieving revision 1.50
diff -u -r1.50 JellyContext.java
--- JellyContext.java 5 Feb 2004 22:32:30 -0000 1.50
+++ JellyContext.java 17 Feb 2004 16:00:14 -0000
@@ -74,6 +74,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
JellyContext represents the Jelly context.
@@ -496,6 +497,26 @@
return script.compile();
}
+ /**
+ * Attempts to parse the script from the given InputSource using the
+ * {@link #getResource} method then returns the compiled script.
+ */
+ public Script compileScript(InputSource source) throws JellyException {
+ XMLParser parser = getXMLParser();
+ parser.setContext(this);
+
+ Script script = null;
+ try {
+ script = parser.parse(source);
+ } catch (IOException e) {
+ throw new JellyException("Could not parse Jelly script",e);
+ } catch (SAXException e) {
+ throw new JellyException("Could not parse Jelly script",e);
+ }
+
+ return script.compile();
+ }
+
/**
* @return a thread pooled XMLParser to avoid the startup overhead
* of the XMLParser
@@ -538,6 +559,16 @@
}
/**
+ * Parses the script from the given InputSource then compiles it and runs it.
+ *
+ * @return the new child context that was used to run the script
+ */
+ public JellyContext runScript(InputSource source, XMLOutput output) throws JellyException {
+ return runScript(source, output, JellyContext.DEFAULT_EXPORT,
+ JellyContext.DEFAULT_INHERIT);
+ }
+
+ /**
* Parses the script from the given uri using the
* JellyContext.getResource() API then compiles it and runs it.
*
@@ -601,11 +632,21 @@
*/
public JellyContext runScript(URL url, XMLOutput output,
boolean export, boolean inherit) throws JellyException {
- Script script = compileScript(url);
+ return runScript(new InputSource(url.toString()), output, export, inherit);
+ }
+
+ /**
+ * Parses the script from the given InputSource then compiles it and runs it.
+ *
+ * @return the new child context that was used to run the script
+ */
+ public JellyContext runScript(InputSource source, XMLOutput output,
+ boolean export, boolean inherit) throws JellyException {
+ Script script = compileScript(source);
URL newJellyContextURL = null;
try {
- newJellyContextURL = getJellyContextURL(url);
+ newJellyContextURL = getJellyContextURL(source);
} catch (MalformedURLException e) {
throw new JellyException(e.toString());
}
@@ -622,7 +663,7 @@
}
if (log.isDebugEnabled() ) {
- log.debug( "About to run script: " + url );
+ log.debug( "About to run script: " + source.getSystemId() );
log.debug( "root context URL: " + newJellyContext.rootURL );
log.debug( "current context URL: " + newJellyContext.currentURL );
}
@@ -874,6 +915,16 @@
*/
protected URL getJellyContextURL(URL url) throws MalformedURLException {
String text = url.toString();
+ int idx = text.lastIndexOf('/');
+ text = text.substring(0, idx + 1);
+ return new URL(text);
+ }
+
+ /**
+ * Strips off the name of a script to create a new context URL
+ */
+ protected URL getJellyContextURL(InputSource source) throws MalformedURLException {
+ String text = source.getSystemId();
int idx = text.lastIndexOf('/');
text = text.substring(0, idx + 1);
return new URL(text);