// Remove the /
path = path.substring( 1 );
// Handle locale request
SiteRenderingContext context;
Map<String, DocumentRenderer> documents;
File generatedSiteDirectory;
String localeWanted = null;
for ( Locale locale : localesList )
{
if ( path.startsWith( locale.getLanguage() + "/" ) )
{
localeWanted = locale.toString();
path = path.substring( locale.getLanguage().length() + 1 );
}
}
if ( localeWanted == null )
{
DoxiaBean defaultDoxiaBean = i18nDoxiaContexts.get( "default" );
if ( defaultDoxiaBean == null )
{
throw new ServletException( "No doxia bean found for the default locale" );
}
context = defaultDoxiaBean.getContext();
documents = defaultDoxiaBean.getDocuments();
generatedSiteDirectory = defaultDoxiaBean.getGeneratedSiteDirectory();
}
else
{
DoxiaBean i18nDoxiaBean = i18nDoxiaContexts.get( localeWanted );
if ( i18nDoxiaBean == null )
{
throw new ServletException( "No doxia bean found for the locale " + localeWanted );
}
context = i18nDoxiaBean.getContext();
documents = i18nDoxiaBean.getDocuments();
generatedSiteDirectory = i18nDoxiaBean.getGeneratedSiteDirectory();
}
// ----------------------------------------------------------------------
// Handle report and documents
// ----------------------------------------------------------------------
if ( documents.containsKey( path ) )
{
try
{
DocumentRenderer renderer = documents.get( path );
renderer.renderDocument( servletResponse.getWriter(), siteRenderer, context );
if ( renderer instanceof ReportDocumentRenderer )
{
ReportDocumentRenderer reportDocumentRenderer = (ReportDocumentRenderer) renderer;
if ( reportDocumentRenderer.isExternalReport() )
{
try
{
filterChain.doFilter( servletRequest, servletResponse );
}
catch ( Exception e )
{
throw new ServletException( e );
}
}
}
}
catch ( RendererException e )
{
throw new ServletException( e );
}
}
else if ( generatedSiteDirectory != null && generatedSiteDirectory.exists() )
{
context.getSiteDirectories().clear();
context.addSiteDirectory( generatedSiteDirectory );
try
{
Map<String, DocumentRenderer> locateDocuments = siteRenderer.locateDocumentFiles( context );
if ( locateDocuments.containsKey( path ) )
{
DocumentRenderer renderer = locateDocuments.get( path );
renderer.renderDocument( servletResponse.getWriter(), siteRenderer, context );
}
}
catch ( RendererException e )
{
throw new ServletException( e );
}
List<File> originalSiteDirectories = new ArrayList<File>( context.getSiteDirectories() );
for ( File dir : originalSiteDirectories )
{
context.addSiteDirectory( dir );
}
}
else
{
filterChain.doFilter( servletRequest, servletResponse );