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.robot;
007:
008: import com.sun.portal.log.common.PortalLogger;
009: import com.sun.portal.search.util.SearchLogger;
010:
011: import java.util.*;
012: import java.util.logging.Level;
013: import java.util.logging.Logger;
014: import java.io.*;
015: import java.net.*;
016:
017: public class ConverterConfig {
018:
019: ArrayList docs = null;
020: String converter_conf = null;
021: ArrayList pre_comment = null;
022:
023: static public void main(String[] args) {
024: ConverterConfig cc = new ConverterConfig(args[0]);
025: cc.updateFile();
026: }
027:
028: public ConverterConfig(String conf_dir) {
029: this .converter_conf = conf_dir + File.separator
030: + "convert.conf";
031: docs = new ArrayList();
032: parse_converter(this .converter_conf);
033: }
034:
035: void parse_converter(String file) {
036: String line = null;
037: BufferedReader in = null;
038: try {
039: in = new BufferedReader(new FileReader(file));
040: line = in.readLine();
041: } catch (IOException e) {
042: System.out.println("Exception:" + e.getMessage());
043: return;
044: }
045: boolean afterComment = false;
046: while (line != null) {
047: String nline = line.trim();
048: //System.out.println(nline);
049: if (nline.length() == 0) {
050: try {
051: line = in.readLine();
052: } catch (IOException e) {
053: break;
054: }
055: continue;
056: }
057: if (nline.startsWith("#")) {
058: this .addPreComment(nline);
059: try {
060: line = in.readLine();
061: } catch (IOException e) {
062: break;
063: }
064: continue;
065: }
066:
067: if (!nline.startsWith("DocType=")) {
068: SearchLogger.getLogger().log(Level.FINER,
069: "PSSH_CSPSR0001", nline);
070: } else {
071: DocType doc = new DocType();
072: StringTokenizer st = new StringTokenizer(nline
073: .substring(8), "@@");
074: int i = 0;
075: while (st.hasMoreTokens()) {
076: switch (i) {
077: case 0:
078: doc.desc = st.nextToken();
079: break;
080: case 1:
081: doc.type_nums = st.nextToken();
082: break;
083: case 2:
084: if (st.nextToken().trim().compareTo("1") == 0) {
085: doc.enabled = true;
086: }
087: break;
088: case 3:
089: doc.module = st.nextToken();
090: break;
091: case 4:
092: doc.args = st.nextToken();
093: break;
094: }
095: i++;
096: }
097: this .docs.add(doc);
098: }
099: try {
100: line = in.readLine();
101: } catch (IOException e) {
102: break;
103: }
104: }
105: }
106:
107: public void updateFile() {
108: PrintWriter out = null;
109: try {
110: FileOutputStream fout = new FileOutputStream(
111: this .converter_conf);
112: out = new PrintWriter(fout, true);
113: } catch (Exception e) {
114: System.out.println("[updateFile]Exception:"
115: + e.getMessage());
116: return;
117: }
118: for (int i = 0; pre_comment != null
119: && i < this .pre_comment.size(); i++) {
120: out.println("#" + (String) this .pre_comment.get(i));
121: }
122: for (int i = 0; i < this .docs.size(); i++) {
123: DocType doc = (DocType) this .docs.get(i);
124: out.print("DocType=" + doc.desc + "@@" + doc.type_nums
125: + "@@");
126: if (doc.enabled) {
127: out.print("1@@");
128: } else {
129: out.print("0@@");
130: }
131: if (doc.module != null) {
132: out.print(doc.module + "@@");
133: if (doc.args != null) {
134: out.print(doc.args + "@@");
135: }
136: }
137: out.println("");
138: }
139: out.close();
140: }
141:
142: public int numOfDocs() {
143: return this .docs.size();
144: }
145:
146: public void addPreComment(String comm) {
147: if (this .pre_comment == null) {
148: this .pre_comment = new ArrayList();
149: }
150: String comment = comm.substring(1);
151: this .pre_comment.add(comment);
152:
153: }
154:
155: public String getDocLabel(int index) {
156: if (index >= 0 && index < this .docs.size()) {
157: DocType doc = (DocType) docs.get(index);
158: return doc.desc;
159: //return doc.desc + "(" + doc.type_nums + ")";
160: }
161: return null;
162: }
163:
164: public void setDocEnable(int index, boolean enabled) {
165: if (index >= 0 && index < this .docs.size()) {
166: DocType doc = (DocType) docs.get(index);
167: doc.enabled = enabled;
168: }
169: }
170:
171: public boolean getDocEnable(int index) {
172: if (index >= 0 && index < this .docs.size()) {
173: DocType doc = (DocType) docs.get(index);
174: return doc.enabled;
175: }
176: return false;
177: }
178:
179: }
|