Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
when transforming an imported jelly file an exception is thrown:
Use case;
import.jelly:
<?xml version="1.0" encoding="ISO-8859-1"?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" >
<x:transform xslt="import.xsl">
<j:import inherit="true" uri="imported.jelly"/>
</x:transform>
</j:jelly>
imported.jelly:
<?xml version="1.0" encoding="ISO-8859-1"?>
<j:jelly xmlns:j="jelly:core">
<root/>
</j:jelly>
imported.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="root">
<html></html>
</xsl:template>
</xsl:stylesheet>
The exception is:
[snip] <j:import> could not import script
at org.apache.commons.jelly.tags.xml.TransformTag.doTag
(TransformTag.java:204)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135)
at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233)
at org.apache.commons.jelly.tags.core.JellyTag.doTag(JellyTag.java:91)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.JellyContext.runScript
(JellyContext.java:623)
at org.apache.commons.jelly.JellyContext.runScript
(JellyContext.java:529)
[snip]
[snip] <j:import> could not import script
at
org.apache.commons.jelly.tags.xml.TransformTag$TagBodyXMLReader.doInvokeBody
(TransformTag.java:527)
at
org.apache.commons.jelly.tags.xml.TransformTag$TagBodyXMLReader.parse
(TransformTag.java:482)
at org.apache.commons.jelly.tags.xml.TransformTag.doTag
(TransformTag.java:190)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:135)
at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:233)
at org.apache.commons.jelly.tags.core.JellyTag.doTag(JellyTag.java:91)
at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:279)
at org.apache.commons.jelly.JellyContext.runScript
(JellyContext.java:623)
at org.apache.commons.jelly.JellyContext.runScript
(JellyContext.java:529)
[snip]
Root cause
Exception in thread "main"
This script works:
import2.jelly:
<?xml version="1.0" encoding="ISO-8859-1"?>
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" >
<j:import inherit="true" uri="imported.jelly"/>
</j:jelly>
After some investigation I found the following:
The root cause of this exception is an ArrayIndexOutOfBoundsException in
xalan. (Unfortunately you can not see this root exception in the stacktrace.
I had to use the debugger...)
My first guess was that is due to inproper setup of the
TransformContentHandler. This is right because the nested import tag does
not fire startDocument() and endDocument() events that the xalan content
handler depends on to setup itself.
This works with import and content that needs parsing.
in TagBodyXMLReader
/**
- Actually invoke the tag body to generate the SAX events
* - @throws SAXException -
- Any SAX exception, possibly wrapping another exception.
*/
private void doInvokeBody() throws SAXException {
tryUnknown macro: { if (this.shouldParseBody()) { XMLReader anXMLReader = XMLReaderFactory.createXMLReader(); anXMLReader.setContentHandler(this.xmlOutput); anXMLReader.setProperty (LEXICAL_HANDLER_PROPERTY,this.xmlOutput); StringWriter writer = new StringWriter(); this.tag.invokeBody(XMLOutput.createXMLOutput(writer)); Reader reader = new StringReader(writer.toString()); anXMLReader.parse(new InputSource(reader)); } else { this.xmlOutput.startDocument(); this.tag.invokeBody(this.xmlOutput); this.xmlOutput.endDocument(); } }catch (Exception ex)
{ throw new SAXException(ex); }}