* @return a <code>Configuration</code> value
* @exception ConfigurationException if an error occurs
* @exception ContextException if an error occurs
*/
public Configuration configure(ExcaliburComponentManager startupManager) throws ConfigurationException, ContextException {
Parser p = null;
Configuration roleConfig = null;
try {
this.configurationFile.refresh();
p = (Parser)startupManager.lookup(Parser.ROLE);
SAXConfigurationHandler b = new SAXConfigurationHandler();
InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/cocoon.roles").openStream();
InputSource is = new InputSource(inputStream);
is.setSystemId(this.configurationFile.getSystemId());
p.setContentHandler(b);
p.parse(is);
roleConfig = b.getConfiguration();
} catch (Exception e) {
getLogger().error("Could not configure Cocoon environment", e);
throw new ConfigurationException("Error trying to load configurations", e);
} finally {
if (p != null) startupManager.release(p);
}
DefaultRoleManager drm = new DefaultRoleManager();
drm.setLogger(getLogger());
drm.configure(roleConfig);
roleConfig = null;
try {
p = (Parser)startupManager.lookup(Parser.ROLE);
SAXConfigurationHandler b = new SAXConfigurationHandler();
InputSource is = this.configurationFile.getInputSource();
p.setContentHandler(b);
p.parse(is);
this.configuration = b.getConfiguration();
} catch (Exception e) {
getLogger().error("Could not configure Cocoon environment", e);
throw new ConfigurationException("Error trying to load configurations",e);
} finally {
if (p != null) startupManager.release(p);
}
Configuration conf = this.configuration;
if (getLogger().isDebugEnabled()) {
getLogger().debug("Root configuration: " + conf.getName());
}
if (! "cocoon".equals(conf.getName())) {
throw new ConfigurationException("Invalid configuration file\n" + conf.toString());
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Configuration version: " + conf.getAttribute("version"));
}
if (!Constants.CONF_VERSION.equals(conf.getAttribute("version"))) {
throw new ConfigurationException("Invalid configuration schema version. Must be '" + Constants.CONF_VERSION + "'.");
}
String userRoles = conf.getAttribute("user-roles", "");
if (!"".equals(userRoles)) {
try {
p = (Parser)startupManager.lookup(Parser.ROLE);
SAXConfigurationHandler b = new SAXConfigurationHandler();
org.apache.cocoon.environment.Context context =
(org.apache.cocoon.environment.Context) this.context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
URL url = context.getResource(userRoles);
InputSource is = new InputSource(new BufferedInputStream(url.openStream()));
is.setSystemId(this.configurationFile.getSystemId());
p.setContentHandler(b);
p.parse(is);
roleConfig = b.getConfiguration();
} catch (Exception e) {
getLogger().error("Could not configure Cocoon environment", e);
throw new ConfigurationException("Error trying to load configurations", e);
} finally {