* @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 {
SAXParser p = null;
Configuration roleConfig = null;
try {
this.configurationFile.refresh();
p = (SAXParser)startupManager.lookup(SAXParser.ROLE);
SAXConfigurationHandler b = new SAXConfigurationHandler();
InputStream inputStream = ClassUtils.getResource("org/apache/cocoon/cocoon.roles").openStream();
InputSource is = new InputSource(inputStream);
is.setSystemId(this.configurationFile.getURI());
p.parse(is, b);
roleConfig = b.getConfiguration();
} catch (Exception e) {
throw new ConfigurationException("Error trying to load configurations", e);
} finally {
if (p != null) startupManager.release((Component)p);
}
DefaultRoleManager drm = new DefaultRoleManager();
drm.enableLogging(getLogger().getChildLogger("roles"));
drm.configure(roleConfig);
roleConfig = null;
try {
p = (SAXParser)startupManager.lookup(SAXParser.ROLE);
SAXConfigurationHandler b = new SAXConfigurationHandler();
InputSource is = SourceUtil.getInputSource(this.configurationFile);
p.parse(is, b);
this.configuration = b.getConfiguration();
} catch (Exception e) {
throw new ConfigurationException("Error trying to load configurations",e);
} finally {
if (p != null) startupManager.release((Component)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 = (SAXParser)startupManager.lookup(SAXParser.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);
if (url == null) {
throw new ConfigurationException("User-roles configuration '"+userRoles+"' cannot be found.");
}
InputSource is = new InputSource(new BufferedInputStream(url.openStream()));
is.setSystemId(this.configurationFile.getURI());
p.parse(is, b);
roleConfig = b.getConfiguration();
} catch (Exception e) {
throw new ConfigurationException("Error trying to load user-roles configuration", e);
} finally {
startupManager.release((Component)p);