// Remove the /
path = path.substring( 1 );
// Handle locale request
SiteRenderingContext context;
Map documents;
File generatedSiteDirectory;
String localeWanted = null;
for ( Iterator it = localesList.iterator(); it.hasNext(); )
{
Locale locale = (Locale) it.next();
if ( path.startsWith( locale.getLanguage() + "/" ) )
{
localeWanted = locale.toString();
path = path.substring( locale.getLanguage().length() + 1 );
}
}
if ( localeWanted == null )
{
DoxiaBean defaultDoxiaBean = (DoxiaBean) 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 = (DoxiaBean) 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 = (DocumentRenderer) 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 locateDocuments = siteRenderer.locateDocumentFiles( context );
if ( locateDocuments.containsKey( path ) )
{
DocumentRenderer renderer = (DocumentRenderer) locateDocuments.get( path );
renderer.renderDocument( servletResponse.getWriter(), siteRenderer, context );
}
}
catch ( RendererException e )
{
throw new ServletException( e );
}
List originalSiteDirectories = new ArrayList( context.getSiteDirectories() );
for ( Iterator i = originalSiteDirectories.iterator(); i.hasNext(); )
{
File dir = (File) i.next();
context.addSiteDirectory( dir );
}
}
else
{
filterChain.doFilter( servletRequest, servletResponse );