blob: 3385b028c50585428cbf329d4d064efe6e3a8a81 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.lenya.cms.module;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
/**
* Module manager implementation.
*/
public class ModuleManagerImpl extends AbstractLogEnabled implements ModuleManager, ThreadSafe,
Configurable {
public String getBaseURI(String shortcut) throws ModuleException {
if (!this.module2src.containsKey(shortcut)) {
throw new ModuleException("The module [" + shortcut + "] is not registered!");
}
String baseUri;
if (this.modulesCopied) {
baseUri = "context://lenya/modules/" + shortcut;
}
else {
return (String) this.module2src.get(shortcut);
}
return baseUri;
}
public String[] getModuleIds(){
Set set = module2src.keySet();
return (String[]) set.toArray(new String[set.size()]);
}
private boolean modulesCopied = false;
private Map module2src = new HashMap();
public void configure(Configuration config) throws ConfigurationException {
Configuration modulesConfig = config.getChild("modules");
this.modulesCopied = modulesConfig.getAttributeAsBoolean("copy");
Configuration[] modules = modulesConfig.getChildren("module");
for (int i = 0; i < modules.length; i++) {
String shortcut = modules[i].getAttribute("shortcut");
String src = modules[i].getAttribute("src");
String uri = new File(src).toURI().toString();
this.module2src.put(shortcut, uri);
}
}
}