@Override
@SuppressWarnings("unchecked")
public void init() throws ServletException
{
// Run in servlet container, load config from config.xml.
ResourceLookup webInfLookup = new ResourceLookup(new PrefixDecoratorLocator(
new ServletContextLocator(getServletContext()), "/WEB-INF/"));
try
{
config = DcsConfig.deserialize(webInfLookup.getFirst("dcs-config.xml"));
}
catch (Exception e)
{
throw new ServletException("Could not read 'config.xml' resource.", e);
}
// Initialize XSLT
initXslt(config, webInfLookup);
// Load component suite. Use classpath too (for JUnit tests).
try
{
List<IResourceLocator> resourceLocators = Lists.newArrayList();
resourceLocators.add(new PrefixDecoratorLocator(new ServletContextLocator(
getServletContext()), "/WEB-INF/suites/"));
if (Boolean.getBoolean(ENABLE_CLASSPATH_LOCATOR)) resourceLocators
.add(Location.CONTEXT_CLASS_LOADER.locator);
ResourceLookup suitesLookup = new ResourceLookup(resourceLocators);
IResource suiteResource = suitesLookup
.getFirst(config.componentSuiteResource);
if (suiteResource == null)
{
throw new Exception(
"Suite file not found in servlet context's /WEB-INF/suites: "
+ config.componentSuiteResource);
}
componentSuite = ProcessingComponentSuite.deserialize(suiteResource,
suitesLookup);
}
catch (Exception e)
{
throw new ServletException("Could initialize component suite.", e);
}
// Initialize defaults.
if (componentSuite.getAlgorithms().size() == 0)
{
throw new ServletException("Component suite has no algorithms.");
}
defaultAlgorithmId = componentSuite.getAlgorithms().get(0).getId();
// Initialize controller
final List<Class<? extends IProcessingComponent>> cachedComponentClasses = Lists
.newArrayListWithExpectedSize(2);
if (config.cacheDocuments)
{
cachedComponentClasses.add(IDocumentSource.class);
}
if (config.cacheClusters)
{
cachedComponentClasses.add(IClusteringAlgorithm.class);
}
controller = ControllerFactory.createCachingPooling(cachedComponentClasses
.toArray(new Class [cachedComponentClasses.size()]));
List<IResourceLocator> locators = Lists.newArrayList();
locators.add(new PrefixDecoratorLocator(new ServletContextLocator(
getServletContext()), "/WEB-INF/resources/"));
if (Boolean.getBoolean(ENABLE_CLASSPATH_LOCATOR)) locators
.add(Location.CONTEXT_CLASS_LOADER.locator);