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.model;
007:
008: import java.io.*;
009: import java.util.*;
010: import java.util.logging.Level;
011: import java.util.logging.Logger;
012:
013: import javax.servlet.http.HttpServletRequest;
014:
015: import com.iplanet.jato.model.*;
016:
017: import com.sun.portal.search.admin.CSConfig;
018: import com.sun.portal.search.util.SearchConfig;
019: import com.sun.portal.log.common.PortalLogger;
020: import com.iplanet.am.console.base.model.AMModelBase;
021: import com.iplanet.am.console.components.view.html.DynamicGUI;
022:
023: /**
024: *
025: *
026: *
027: */
028: public class AdvancedLogModelImpl extends AMModelBase implements
029: AdvancedLogModel {
030: // Create a Logger for this class
031: private static Logger debugLogger = PortalLogger
032: .getLogger(AdvancedLogModelImpl.class);
033:
034: /** constructor
035: *
036: * @param req HTTP Servlet Request
037: * @param rbName resource bundle name
038: */
039: public AdvancedLogModelImpl(HttpServletRequest req, String rbName) {
040: super (req, rbName);
041: init(req);
042: }
043:
044: /** initializes */
045: protected void init(HttpServletRequest req) {
046: load();
047: }
048:
049: public String getSearchRDMLog() {
050: return SearchConfig.getValue(SearchConfig.RDM_LOGFN);
051: }
052:
053: public void setSearchRDMLog(String value) {
054: debugLogger.log(Level.FINER, "PSSH_CSPSAM0001", value);
055: SearchConfig.setValue(SearchConfig.RDM_LOGFN, value);
056: }
057:
058: /**
059: * getting boolean state of property disable-rdm-log in search.conf
060: */
061: public boolean getSearchLogState() {
062: String stateStr = (String) SearchConfig
063: .getValue(SearchConfig.RDM_DISABLE_LOG);
064: if (stateStr != null && stateStr.equals("true")) {
065: debugLogger.log(Level.FINER, "PSSH_CSPSAM0002",
066: new String[] { SearchConfig.RDM_DISABLE_LOG,
067: stateStr });
068: return true;
069: } else {
070: return false;
071: }
072: }
073:
074: /**
075: * setting boolean state of property disable-rdm-log in search.conf
076: */
077: public void setSearchLogState(boolean value) {
078: if (value) {
079: debugLogger
080: .log(Level.FINER, "PSSH_CSPSAM0003", new String[] {
081: SearchConfig.RDM_DISABLE_LOG, "true" });
082: SearchConfig.setValue(SearchConfig.RDM_DISABLE_LOG, "true");
083: } else {
084: debugLogger.log(Level.FINER, "PSSH_CSPSAM0003",
085: new String[] { SearchConfig.RDM_DISABLE_LOG,
086: "false" });
087: SearchConfig
088: .setValue(SearchConfig.RDM_DISABLE_LOG, "false");
089: }
090: }
091:
092: public String getIndexMaintenanceLog() {
093: return SearchConfig.getValue(SearchConfig.SENGINE_LOGFN);
094: }
095:
096: public void setIndexMaintenanceLog(String value) {
097: SearchConfig.setValue(SearchConfig.SENGINE_LOGFN, value);
098: }
099:
100: public String getRdMgrLog() {
101: return SearchConfig.getValue(SearchConfig.RDMGR_LOGFN);
102: }
103:
104: public void setRdMgrLog(String value) {
105: SearchConfig.setValue(SearchConfig.RDMGR_LOGFN, value);
106: }
107:
108: public String getRdmDebugLog() {
109: return SearchConfig.getValue(SearchConfig.DEBUG_LOGFN);
110: }
111:
112: public void setRdmDebugLog(String value) {
113: SearchConfig.setValue(SearchConfig.DEBUG_LOGFN, value);
114: }
115:
116: public String getRdmDebugLevel() {
117: return SearchConfig.getValue(SearchConfig.DEBUG_LOGLV);
118: }
119:
120: public void setRdmDebugLevel(String value) {
121: SearchConfig.setValue(SearchConfig.DEBUG_LOGLV, value);
122: }
123:
124: ////////////////////////////////////////////////////////////////////////////////
125: // Model execution methods
126: ////////////////////////////////////////////////////////////////////////////////
127:
128: /**
129: *
130: *
131: */
132: public Object execute(ModelExecutionContext context)
133: throws ModelControlException {
134: String operationName = null;
135: if (context != null) {
136: operationName = context.getOperationName();
137: } else {
138: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
139: }
140: Object result = null;
141: if (operationName
142: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
143: result = retrieve(context);
144: }
145:
146: return result;
147: }
148:
149: /**
150: * 1. reads extract the location of the search.conf file
151: * 2. open the search.conf
152: * 3. populate AdvancedLogModelImpl object
153: *
154: */
155: public Object retrieve(ModelExecutionContext context)
156: throws ModelControlException {
157: // loading the Properties from the file search.conf
158: debugLogger.finer("PSSH_CSPSAM0004");
159: load();
160:
161: return null;
162: }
163:
164: /**
165: * loading the model from file
166: */
167: public void load() {
168: // getting the ServerRoot directory
169: String serverRoot = CSConfig.getServerRoot();
170: if (serverRoot == null) {
171: serverRoot = ".";
172: }
173:
174: // opening the search.conf file
175: String csidFilePath = serverRoot + csidFileRelativPath;
176: try {
177: debugLogger.log(Level.FINER, "PSSH_CSPSAM0005",
178: csidFilePath);
179: // init the SearchConfig object
180: SearchConfig.init(csidFilePath);
181: } catch (Exception e) {
182: debugLogger.log(Level.INFO, "PSSH_CSPSAM0006", e
183: .getMessage());
184: }
185:
186: }
187:
188: /**
189: * storing the model in file search.conf
190: */
191: public void store() {
192: String serverRoot = CSConfig.getServerRoot();
193: String csidFilePath = serverRoot + csidFileRelativPath;
194: debugLogger.log(Level.FINER, "PSSH_CSPSAM0007", csidFilePath);
195: try {
196: // writing the file "search.conf"
197: FileWriter fw = new FileWriter(csidFilePath);
198: // writing the header
199: fw.write(SearchConfig.SEARCH_CONF_HEADER);
200: // writing the configuration elements
201: StringBuffer sb = new StringBuffer();
202: HashMap map = SearchConfig.getMap();
203: Iterator keysIterator = map.keySet().iterator();
204: String key = null;
205: String value = null;
206: while (keysIterator.hasNext()) {
207: key = (String) keysIterator.next();
208: value = (String) map.get(key);
209: debugLogger.log(Level.FINER, "PSSH_CSPSAM0008",
210: new String[] { key, value });
211: sb.append(key);
212: sb.append("=");
213: sb.append(value);
214: sb.append("\n");
215: }
216: debugLogger.log(Level.FINER, "PSSH_CSPSAM0009",
217: csidFilePath);
218: fw.write(sb.toString());
219: debugLogger.log(Level.FINER, "PSSH_CSPSAM0010",
220: csidFilePath);
221: fw.close();
222: } catch (Exception e) {
223: debugLogger.log(Level.FINER, "PSSH_CSPSAM0011", e
224: .getMessage());
225: }
226: }
227:
228: public static final String csidFileRelativPath = File.separator
229: + "config" + File.separator + SearchConfig.SEARCH_CONF;
230: }
|