001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * Created on 29/11/2004 22:53:28
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.repository;
044:
045: import java.io.IOException;
046: import java.util.HashMap;
047: import java.util.Map;
048: import java.util.Properties;
049:
050: import net.jforum.ConfigLoader;
051: import net.jforum.JForumExecutionContext;
052:
053: import org.apache.log4j.Logger;
054:
055: /**
056: * @author Rafael Steil
057: * @version $Id: ModulesRepository.java,v 1.11 2006/08/20 22:47:38 rafaelsteil Exp $
058: */
059: public class ModulesRepository {
060: private static final Logger logger = Logger
061: .getLogger(ModulesRepository.class);
062:
063: private static Map cache = new HashMap();
064: private static final String ENTRIES = "entries";
065:
066: /**
067: * Loads all modules mapping.
068: *
069: * @param baseDir The directory where the file "modulesMapping.properties"
070: * is placed.
071: * @throws IOException
072: */
073: public static void init(String baseDir) {
074: cache.put(ENTRIES, ConfigLoader.loadModulesMapping(baseDir));
075: }
076:
077: public static int size() {
078: return cache.size();
079: }
080:
081: /**
082: * Gets the fully qualified name of some given module name.
083: *
084: * @param moduleName The module's name to get its class name
085: * @return The class name associated to the module name passed
086: * as argument, or <code>null</code> if not found.
087: */
088: public static String getModuleClass(String moduleName) {
089: Properties p = (Properties) cache.get(ENTRIES);
090:
091: if (p == null) {
092: logger.error("Null modules. Askes moduleName: "
093: + moduleName
094: + ", url="
095: + JForumExecutionContext.getRequest()
096: .getQueryString());
097: return null;
098: }
099:
100: return p.getProperty(moduleName);
101: }
102: }
|