{
IOUtil.close( outStream );
IOUtil.close( inStream );
}
WebAppContext webapp = new WebAppContext();
webapp.setContextPath( "/" );
webapp.setResourceBase( tempWebappDirectory.getAbsolutePath() );
webapp.setAttribute( DoxiaFilter.SITE_RENDERER_KEY, siteRenderer );
webapp.getInitParams().put( "org.mortbay.jetty.servlet.Default.useFileMappedBuffer", "false" );
// For external reports
project.getReporting().setOutputDirectory( tempWebappDirectory.getAbsolutePath() );
for ( MavenReportExecution mavenReportExecution : getReports() )
{
mavenReportExecution.getMavenReport().setReportOutputDirectory( tempWebappDirectory );
}
List<MavenReportExecution> filteredReports = filterReports( getReports() );
List localesList = siteTool.getAvailableLocales( locales );
webapp.setAttribute( DoxiaFilter.LOCALES_LIST_KEY, localesList );
// Default is first in the list
Locale defaultLocale = (Locale) localesList.get( 0 );
Locale.setDefault( defaultLocale );
try
{
Map i18nDoxiaContexts = new HashMap();
for ( Iterator it = localesList.iterator(); it.hasNext(); )
{
Locale locale = (Locale) it.next();
SiteRenderingContext i18nContext = createSiteRenderingContext( locale );
i18nContext.setInputEncoding( getInputEncoding() );
i18nContext.setOutputEncoding( getOutputEncoding() );
Map i18nDocuments = locateDocuments( i18nContext, filteredReports, locale );
DoxiaBean doxiaBean;
if ( defaultLocale.equals( locale ) )
{
doxiaBean = new DoxiaBean( i18nContext, i18nDocuments, generatedSiteDirectory );
}
else
{
doxiaBean = new DoxiaBean( i18nContext, i18nDocuments, new File( generatedSiteDirectory, locale
.getLanguage() ) );
}
i18nDoxiaContexts.put( locale.getLanguage(), doxiaBean );
if ( defaultLocale.equals( locale ) )
{
i18nDoxiaContexts.put( "default", doxiaBean );
}
if ( defaultLocale.equals( locale ) )
{
siteRenderer.copyResources( i18nContext, new File( siteDirectory, "resources" ),
tempWebappDirectory );
}
else
{
siteRenderer.copyResources( i18nContext, new File( siteDirectory, "resources" ),
new File( tempWebappDirectory, locale.getLanguage() ) );
}
}
webapp.setAttribute( DoxiaFilter.I18N_DOXIA_CONTEXTS_KEY, i18nDoxiaContexts );
}
catch ( Exception e )
{
throw new MojoExecutionException( "Unable to set up webapp", e );
}