01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.module;
19:
20: import java.io.File;
21: import java.util.HashMap;
22: import java.util.Map;
23: import java.util.Set;
24:
25: import org.apache.avalon.framework.configuration.Configurable;
26: import org.apache.avalon.framework.configuration.Configuration;
27: import org.apache.avalon.framework.configuration.ConfigurationException;
28: import org.apache.avalon.framework.logger.AbstractLogEnabled;
29: import org.apache.avalon.framework.thread.ThreadSafe;
30:
31: /**
32: * Module manager implementation.
33: */
34: public class ModuleManagerImpl extends AbstractLogEnabled implements
35: ModuleManager, ThreadSafe, Configurable {
36:
37: public String getBaseURI(String shortcut) throws ModuleException {
38: if (!this .module2src.containsKey(shortcut)) {
39: throw new ModuleException("The module [" + shortcut
40: + "] is not registered!");
41: }
42:
43: String baseUri;
44: if (this .modulesCopied) {
45: baseUri = "context://lenya/modules/" + shortcut;
46: } else {
47: return (String) this .module2src.get(shortcut);
48: }
49: return baseUri;
50: }
51:
52: public String[] getModuleIds() {
53: Set set = module2src.keySet();
54: return (String[]) set.toArray(new String[set.size()]);
55: }
56:
57: private boolean modulesCopied = false;
58: private Map module2src = new HashMap();
59:
60: public void configure(Configuration config)
61: throws ConfigurationException {
62: Configuration modulesConfig = config.getChild("modules");
63: this .modulesCopied = modulesConfig
64: .getAttributeAsBoolean("copy");
65:
66: Configuration[] modules = modulesConfig.getChildren("module");
67: for (int i = 0; i < modules.length; i++) {
68: String shortcut = modules[i].getAttribute("shortcut");
69: String src = modules[i].getAttribute("src");
70: String uri = new File(src).toURI().toString();
71: this.module2src.put(shortcut, uri);
72: }
73:
74: }
75:
76: }
|