001: //=============================================================================
002: //=== Copyright (C) 2001-2007 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.gast.gui.panels.migration.oldinst;
025:
026: import java.io.File;
027: import java.io.IOException;
028: import jeeves.constants.ConfigFile;
029: import org.fao.gast.lib.Lib;
030: import org.fao.gast.lib.Resource;
031: import org.jdom.Document;
032: import org.jdom.Element;
033: import org.jdom.JDOMException;
034:
035: //=============================================================================
036:
037: public class OldConfigLib {
038: //---------------------------------------------------------------------------
039: //---
040: //--- Constructor
041: //---
042: //---------------------------------------------------------------------------
043:
044: public OldConfigLib(String appPath) throws JDOMException,
045: IOException {
046: webPath = appPath + "/web/";
047:
048: String cfgFile = "/web/WEB-INF/config.xml";
049:
050: if (!new File(appPath + cfgFile).exists()) {
051: webPath = appPath + "/";
052: cfgFile = "/WEB-INF/config.xml";
053: }
054:
055: config = Lib.xml.load(appPath + cfgFile);
056: dbmsElem = retrieveDbms(config);
057: appHandElem = config.getRootElement().getChild(
058: ConfigFile.Child.APP_HANDLER);
059: }
060:
061: //---------------------------------------------------------------------------
062: //---
063: //--- API methods
064: //---
065: //---------------------------------------------------------------------------
066:
067: public String getHandlerProp(String name) {
068: return findInHandler(name);
069: }
070:
071: //---------------------------------------------------------------------------
072:
073: public Resource createResource() throws Exception {
074: return new Resource(webPath, dbmsElem);
075: }
076:
077: //---------------------------------------------------------------------------
078: //---
079: //--- Private methods
080: //---
081: //---------------------------------------------------------------------------
082:
083: private Element retrieveDbms(Document config) {
084: Element resources = config.getRootElement().getChild(
085: ConfigFile.Child.RESOURCES);
086:
087: for (Object res : resources
088: .getChildren(ConfigFile.Resources.Child.RESOURCE)) {
089: Element resource = (Element) res;
090: String enabled = resource.getAttributeValue("enabled");
091:
092: if ("true".equals(enabled))
093: return resource;
094: }
095:
096: //--- we should not arrive here
097:
098: return null;
099: }
100:
101: //---------------------------------------------------------------------------
102:
103: private String findInHandler(String paramName) {
104: for (Object o : appHandElem.getChildren("param")) {
105: Element param = (Element) o;
106:
107: String name = param.getAttributeValue("name");
108: String value = param.getAttributeValue("value");
109:
110: if (paramName.equals(name))
111: return value;
112: }
113:
114: return null;
115: }
116:
117: //---------------------------------------------------------------------------
118: //---
119: //--- Variables
120: //---
121: //---------------------------------------------------------------------------
122:
123: // private String appPath;
124: private String webPath;
125: private Document config;
126: private Element dbmsElem;
127: private Element appHandElem;
128: }
129:
130: //=============================================================================
|