Reader reader = null;
try
{
String resource = doc.getAbsolutePath();
Parser parser = doxia.getParser( renderingContext.getParserId() );
// TODO: DOXIA-111: the filter used here must be checked generally.
if ( renderingContext.getAttribute( "velocity" ) != null )
{
try
{
SiteResourceLoader.setResource( resource );
Context vc = createVelocityContext( sink, siteContext );
StringWriter sw = new StringWriter();
velocity.getEngine().mergeTemplate( resource, siteContext.getInputEncoding(), vc, sw );
reader = new StringReader( sw.toString() );
if ( parser.getType() == Parser.XML_TYPE && siteContext.isValidate() )
{
reader = validate( reader, resource );
}
}
catch ( Exception e )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().error( "Error parsing " + resource + " as a velocity template, using as text.", e );
}
else
{
getLogger().error( "Error parsing " + resource + " as a velocity template, using as text." );
}
}
}
else
{
switch ( parser.getType() )
{
case Parser.XML_TYPE:
reader = ReaderFactory.newXmlReader( doc );
if ( siteContext.isValidate() )
{