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.util.logging.Logger;
010: import java.util.logging.Level;
011: import java.io.*;
012: import com.sun.portal.search.util.PBlock;
013: import com.sun.portal.search.util.OrderedMap;
014: import com.sun.portal.log.common.PortalLogger;
015:
016: public class filterConfigurator {
017: private static Logger debugLogger = PortalLogger
018: .getLogger(filterConfigurator.class);
019:
020: static void readFilterToArray() {
021: outFilterConf = new ArrayList();
022: try {
023: BufferedReader br = new BufferedReader(new FileReader(
024: server_root + File.separator + "config"
025: + File.separator + "filter.conf"));
026: String line = null;
027: while ((line = br.readLine()) != null) {
028: outFilterConf.add(line);
029: }
030: } catch (Exception e) {
031: debugLogger.log(Level.INFO, "PSSH_CSPSA0040", new String[] {
032: e.getMessage(), server_root, File.separator, });
033: }
034: // end of readFilterToArray
035: }
036:
037: public static String getFilterConfVars(String type, String fnName,
038: String attrName, String defaultValue) {
039:
040: String line = null;
041: for (int i = 0; i < outFilterConf.size(); i++) {
042: line = (String) outFilterConf.get(i);
043: if (line.startsWith(type)) {
044: Map map = new HashMap();
045: try {
046: PBlock.str2pblock(line.substring(type.length()),
047: map);
048: String fn = (String) map.get("fn");
049: if (fn != null && fn.equalsIgnoreCase(fnName)) {
050: return (String) map.get(attrName);
051: }
052: } catch (Exception e) {/*ignore*/
053: }
054: }
055: }
056: return defaultValue;
057: }
058:
059: public static void setFilterConfVars(String type, String fnName,
060: String attrName, String setVal) {
061: String line = null;
062: for (int i = 0; i < outFilterConf.size(); i++) {
063: line = (String) outFilterConf.get(i);
064: if (line.startsWith(type)) {
065: OrderedMap map = null;
066: try {
067: map = PBlock.str2pblock(line);
068: } catch (Exception e) {
069: continue;
070: }
071:
072: String fn = (String) map.get("fn");
073: if (fn != null && fn.equalsIgnoreCase(fnName)) {
074: map.put(attrName, setVal);
075: String newLine = null;
076: try {
077: newLine = PBlock.pblock2str(map);
078: } catch (Exception e) {
079: }
080:
081: /* Iterator it = map.keySet().iterator();
082: StringBuffer sb = new StringBuffer(type);
083: while (it.hasNext()) {
084: String key = (String) it.next();
085: String value = (String) map.get(key);
086: sb.append(" " + key + "=" + value);
087: }
088: String newLine = sb.toString();
089:
090: */
091: if (newLine != null) {
092: outFilterConf.remove(i);
093: outFilterConf.add(i, newLine);
094: }
095: return;
096: }
097: }
098: }
099: }
100:
101: public static void updateFilterConf() {
102: try {
103: FileOutputStream fout = new FileOutputStream(server_root
104: + File.separator + "config" + File.separator
105: + "filter.conf");
106: PrintWriter out = new PrintWriter(fout, true);
107: for (int i = 0; i < outFilterConf.size(); i++) {
108: out.println((String) outFilterConf.get(i));
109: }
110: out.close();
111: } catch (Exception E) {
112: debugLogger.info("PSSH_CSPSA0041");
113: }
114:
115: }
116:
117: public static ArrayList outFilterConf = new ArrayList();
118:
119: private static String server_root = CSConfig.getServerRoot();
120:
121: }
|