{
// FIXME: This should all be done by Jelly.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware( true );
XMLReader reader = factory.newSAXParser().getXMLReader();
XMLParser parser = new XMLParser( reader );
parser.setContext( context );
parser.setClassLoader( context.getClassLoader() );
Script script = null;
InputSource source = null;
if ( encoding != null )
{
InputStreamReader isr = null;
try
{
isr = new InputStreamReader( scriptInputStream, encoding );
source = new InputSource( isr );
}
finally
{
if ( isr != null )
{
try
{
isr.close();
}
catch ( IOException e )
{
log.debug( "WARNING: Cannot close stream!", e );
}
isr = null;
}
}
}
else
{
source = new InputSource( scriptInputStream );
}
if ( systemId != null )
{
source.setSystemId( systemId );
}
if ( log.isDebugEnabled() )
log.debug( "the system identifier to help resolve relative URLs : " + systemId );
script = parser.parse( source );
script = script.compile();
return script;
}