001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.util.*;
009: import java.io.*;
010: import java.net.*;
011: import java.util.ArrayList;
012: import java.util.Hashtable;
013: import java.util.logging.Logger;
014: import java.util.logging.Level;
015:
016: import com.sun.portal.search.robot.RobotConfig;
017: import com.sun.portal.search.rdm.*;
018: import com.sun.portal.search.util.SearchConfig;
019: import com.sun.portal.search.soif.*;
020: import com.sun.portal.search.admin.resources.SearchResource;
021: import com.sun.portal.log.common.PortalLogger;
022: import com.sun.portal.log.common.PortalLogManager;
023:
024: public class CSConfig {
025: private static Logger debugLogger = PortalLogger
026: .getLogger(CSConfig.class);
027:
028: protected static String P_FILE = null;
029: protected static Properties csconfig = null;
030: protected static boolean inited = false;
031: protected static boolean searchInited = false;
032: static RobotConfig robotConf = null;
033: private static RDMTaxonomy taxonomy = null;
034: private static String taxonomyFileName = null;
035: protected static long taxFileLastModified = -1;
036: protected static String[] taxonomyList = null;
037: protected static String[] taxonomyLabelList = null;
038: protected static String server_root = null;
039: protected static String base = "/var/opt/SUNWportal";
040: protected static String uri = "/ps";
041: protected static String binDir = null;
042: protected static String libDir = null;
043: protected static String libPath = null;
044: protected static ResourceBundle rb = null;
045: protected static Locale locale = Locale.US;
046:
047: static void checkConfigRefresh() {
048: if (taxFileLastModified == -1) {
049: loadTaxonomy();
050: } else {
051: try {
052: File file = new File(taxonomyFileName);
053: long lastmodified = file.lastModified();
054: if (lastmodified <= taxFileLastModified) {
055: return;
056: }
057: loadTaxonomy();
058: } catch (Exception e) {
059: //ignore
060: }
061: }
062: }
063:
064: public static void loadTaxonomy() {
065: try {
066: taxonomyFileName = SearchConfig.getValue(SearchConfig.TAX);
067: File file = new File(taxonomyFileName);
068: taxFileLastModified = file.lastModified();
069: SOIFInputStream ss = new SOIFInputStream(taxonomyFileName);
070: taxonomy = new RDMTaxonomy(ss);
071: } catch (Exception e) {
072: taxonomy = new RDMTaxonomy("Search");
073: }
074: ArrayList taxList = new ArrayList();
075: try {
076: taxonomy.apply(RDM.RDM_TAX_PREORDER, new TaxListDumper(
077: taxList));
078: String a[] = { "a" };
079: if (taxList.size() == 0) {
080: taxonomyList = null;
081: taxonomyLabelList = null;
082: return;
083: }
084: taxonomyList = (String[]) taxList.toArray(a);
085: taxonomyLabelList = (String[]) taxList.toArray(a);
086:
087: String ident = null;
088:
089: try {
090: ResourceBundle rb = SearchResource
091: .getResourceBundle(locale);
092: ident = rb.getString("taxonomy.ident.text");
093: } catch (MissingResourceException e) {
094: debugLogger.log(Level.INFO, "PSSH_CSPSA0014",
095: CompassAdminConstants.RESOURCE_BUNDLE_FILE);
096: }
097: if (ident == null) {
098: ident = " "; //set default
099: }
100:
101: for (int i = 0; taxonomyLabelList != null
102: && i < taxonomyLabelList.length; i++) {
103: StringTokenizer st = new StringTokenizer(
104: taxonomyLabelList[i], ":");
105: String last = "";
106: int n = 0;
107: while (st.hasMoreTokens()) {
108: last = st.nextToken();
109: n++;
110: }
111: for (int j = 0; j < n - 1; j++) {
112: last = ident + last;
113: }
114: taxonomyLabelList[i] = last;
115: }
116: } catch (Exception e) {
117: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
118: .getMessage());
119: }
120:
121: }
122:
123: public static RDMTaxonomy getTaxonomy() {
124: checkConfigRefresh();
125: return taxonomy;
126: }
127:
128: public static String[] getTaxonomyNameList() {
129: checkConfigRefresh();
130: return taxonomyList;
131: }
132:
133: public static String[] getTaxonomyLabelList() {
134: checkConfigRefresh();
135: return taxonomyLabelList;
136: }
137:
138: /* XXX
139: hacking
140: */
141: public static String getBinPath() {
142: if (binDir != null) {
143: return binDir;
144: }
145: return "/opt/SUNWportal/bin";
146: }
147:
148: public static String getLibDir() {
149: if (libDir != null) {
150: return libDir;
151: }
152: return "/opt/SUNWportal/lib";
153: }
154:
155: public static String getLibPath() {
156: if (libPath != null) {
157: return libPath;
158: }
159: return "/opt/SUNWportal/lib";
160: }
161:
162: public static String getServerRoot() {
163: return server_root;
164: }
165:
166: /*
167: * mainly for cli
168: */
169: public static void setServerRoot(String root) {
170: server_root = root;
171: }
172:
173: public static void init(String root) {
174: server_root = root;
175: initConfig();
176: }
177:
178: public static void initSearch(String searchURL) {
179: debugLogger.log(Level.FINER, "PSSH_CSPSA0015", searchURL);
180: InputStream in;
181: if (searchInited)
182: return;
183: try {
184: URL command_url = new URL(searchURL);
185: URLConnection url_conn = command_url.openConnection();
186: in = url_conn.getInputStream();
187: } catch (Exception e) {
188: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
189: .getMessage());
190: return;
191: }
192: try {
193: byte buff[] = new byte[1024];
194: int n;
195: n = in.read(buff, 0, 1024); // don't care about what returns
196: while (n > 0) {
197: n = in.read(buff, 0, 1024);
198: }
199: } catch (Exception e) {
200: debugLogger.log(Level.INFO, "PSSH_CSPSA0016", e
201: .getMessage());
202: return;
203: }
204: searchInited = true;
205: }
206:
207: /**
208: * Initialize the logging
209: * @param serverRoot
210: */
211: public static void initLogging(String serverRoot) {
212: PortalLogManager manager = new PortalLogManager();
213: String searchLogConfigFile = serverRoot + File.separator
214: + SearchConfig.CONFDIR + File.separator
215: + PortalLogManager.SEARCH_LOG_CONFIG_FILENAME;
216: manager.init(SearchConfig.SEARCH_LOGGER, searchLogConfigFile);
217: }
218:
219: public static void initConfig() {
220: inited = true;
221: SearchConfig csidConf = SearchConfig.getSearchConfig();
222: if (csidConf == null) {
223: try {
224: SearchConfig.init(server_root + File.separator
225: + SearchConfig.CONFDIR + File.separator
226: + SearchConfig.SEARCH_CONF);
227: csidConf = SearchConfig.getSearchConfig();
228: } catch (Exception e) {
229: debugLogger.log(Level.INFO, "PSSH_CSPSA0017", e
230: .getMessage());
231: }
232: }
233: if (csidConf != null) {
234: binDir = csidConf.getValue(SearchConfig.BINDIR);
235: libDir = csidConf.getValue(SearchConfig.LIBDIR);
236: libPath = csidConf.getValue(SearchConfig.LIBPATH);
237: String debug = csidConf.getValue("admin-debug");
238: /*
239: if (debug != null) {
240: if (debug.equalsIgnoreCase("true")) {
241: CSDebug.setEnable(true);
242: }
243: else {
244: CSDebug.setEnable(false);
245: }
246: }
247: */
248: }
249: robotConf = new RobotConfig(server_root + File.separator
250: + "config");
251: try {
252: ImportConfig.init(server_root + File.separator
253: + SearchConfig.CONFDIR + File.separator
254: + ImportConfig.IMPORT_CONF);
255: } catch (Exception e) {
256: debugLogger.log(Level.INFO, "PSSH_CSPSA0018", e
257: .getMessage());
258: }
259:
260: }
261:
262: public static void setAdminLocale(Locale adminLocale) {
263: locale = adminLocale;
264: }
265:
266: public static Locale getAdminLocale() {
267: return locale;
268: }
269:
270: public static RobotConfig getRobotConfig() {
271: return robotConf;
272: }
273:
274: static public void main(String[] args) {
275: init(args[0]);
276: for (int i = 0; i < taxonomyList.length; i++) {
277: System.out.println(taxonomyLabelList[i] + "["
278: + taxonomyList[i] + "]");
279: }
280: }
281: }
|