Source Code Cross Referenced for SearchModelImpl.java in  » Portal » Open-Portal » com » sun » portal » search » admin » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.search.admin.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.net.*;
010:        import java.util.*;
011:        import java.util.logging.Logger;
012:        import java.util.logging.Level;
013:
014:        import javax.servlet.http.HttpServletRequest;
015:
016:        import com.iplanet.jato.model.*;
017:        import com.iplanet.jato.util.*;
018:
019:        import com.sun.portal.search.admin.CSConfig;
020:        import com.sun.portal.search.util.SearchConfig;
021:        import com.sun.portal.search.util.OrderedMap;
022:        import com.sun.portal.search.util.PBlock;
023:        import com.sun.portal.log.common.PortalLogger;
024:
025:        import com.iplanet.am.console.base.model.AMModelBase;
026:        import com.iplanet.am.console.components.view.html.DynamicGUI;
027:
028:        /**
029:         *
030:         *
031:         *
032:         */
033:        public class SearchModelImpl extends AMModelBase implements  SearchModel {
034:            // Create a Logger for this class
035:            private static Logger debugLogger = PortalLogger
036:                    .getLogger(SearchModelImpl.class);
037:
038:            /** constructor
039:             *
040:             * @param req  HTTP Servlet Request
041:             * @param rbName  resource bundle name
042:             */
043:            public SearchModelImpl(HttpServletRequest req, String rbName) {
044:                super (req, rbName);
045:                init(req);
046:            }
047:
048:            /**
049:             * initializes
050:             */
051:            protected void init(HttpServletRequest req) {
052:                // initializing the SearchConfig object
053:                load();
054:            }
055:
056:            //////////////////////////////////////////////////////
057:            // Convenience accessors & mutators
058:            //////////////////////////////////////////////////////
059:            /**
060:             * not implemented
061:             */
062:            public String getServerStatus() {
063:                return "ON";
064:            }
065:
066:            /**
067:             * not implemented
068:             */
069:            public void setServerStatus(String value) {
070:                ;
071:            }
072:
073:            /**
074:             * returns server instance name
075:             */
076:            public String getServerInstanceName() {
077:                return (String) config.get(SearchConfig.INSTANCE_NAME);
078:            }
079:
080:            /**
081:             * sets server instance name
082:             */
083:            public void setServerInstanceName(String value) {
084:                config.put(SearchConfig.INSTANCE_NAME, value);
085:            }
086:
087:            /*
088:             * server Root from search.conf
089:             */
090:            public String getServerRoot() {
091:                return (String) config.get(SearchConfig.SERVER_ROOT);
092:            }
093:
094:            /* 
095:             * checking accessibility of directoryPath
096:             * - Name is the name of the serverModel form element
097:             * - value is the path of directory checked for accessibility
098:             */
099:            private void checkFileAccess(String name, String value)
100:                    throws Exception {
101:                if (value.trim().length() == 0) {
102:                    throw new Exception(name
103:                            + getLocalizedString("server.error.not_empty"));
104:                }
105:
106:                File f = new File(value);
107:                if (f.exists()) {
108:                    if (!f.isFile()) {
109:                        throw new Exception(name + " : '" + value + "' "
110:                                + getLocalizedString("server.error.not_file"));
111:                    }
112:                    if (!f.canRead()) {
113:                        throw new Exception(
114:                                name
115:                                        + " : '"
116:                                        + value
117:                                        + "' "
118:                                        + getLocalizedString("server.error.not_readible"));
119:                    }
120:                    if (!f.canWrite()) {
121:                        throw new Exception(
122:                                name
123:                                        + " : '"
124:                                        + value
125:                                        + "' "
126:                                        + getLocalizedString("server.error.not_writable"));
127:                    }
128:                } else {
129:                    File p = f.getParentFile();
130:                    if (p != null) {
131:                        String absPath = p.getAbsolutePath();
132:                        checkDirectoryAccess(name, absPath);
133:                    }
134:                }
135:            }
136:
137:            /* 
138:             * checking accessibility of directoryPath
139:             * - Name is the name of the serverModel form element
140:             * - value is the path of directory checked for accessibility
141:             */
142:            private void checkDirectoryAccess(String name, String value)
143:                    throws Exception {
144:                if (value.trim().length() == 0) {
145:                    throw new Exception(name + " "
146:                            + getLocalizedString("server.error.not_empty"));
147:                }
148:                File f = new File(value);
149:                if (f.exists()) {
150:                    if (!f.isDirectory()) {
151:                        throw new Exception(
152:                                name
153:                                        + " : '"
154:                                        + value
155:                                        + "' "
156:                                        + getLocalizedString("server.error.not_directory"));
157:                    }
158:                    if (!f.canRead()) {
159:                        throw new Exception(
160:                                name
161:                                        + " : '"
162:                                        + value
163:                                        + "' "
164:                                        + getLocalizedString("server.error.not_readible"));
165:                    }
166:                    if (!f.canWrite()) {
167:                        throw new Exception(
168:                                name
169:                                        + " : '"
170:                                        + value
171:                                        + "' "
172:                                        + getLocalizedString("server.error.not_writable"));
173:                    }
174:                } else {
175:                    throw new Exception(name + " : '" + value + "' "
176:                            + getLocalizedString("server.error.inexistant"));
177:                }
178:            }
179:
180:            /*
181:             * setting the serverRoot file path
182:             */
183:            public void setServerRoot(String value) throws Exception {
184:                checkDirectoryAccess(
185:                        getLocalizedString("server.error.root_path"), value);
186:                config.put(SearchConfig.SERVER_ROOT, value);
187:            }
188:
189:            public String getServerTmpFiles() {
190:                return (String) config.get(SearchConfig.TMPDIR);
191:            }
192:
193:            public void setServerTmpFiles(String value) throws Exception {
194:                checkDirectoryAccess(
195:                        getLocalizedString("server.error.tmp_files"), value);
196:                config.put(SearchConfig.TMPDIR, value);
197:            }
198:
199:            public String getServerDocSecurityMode() {
200:                return (String) config.get(SearchConfig.SECMODE);
201:            }
202:
203:            public void setServerDocSecurityMode(String value) {
204:                config.put(SearchConfig.SECMODE, value);
205:            }
206:
207:            public String getServerDocSecurityMgr() {
208:                return (String) config.get(SearchConfig.SECMGR);
209:            }
210:
211:            public void setServerDocSecurityMgr(String value) throws Exception {
212:                Class.forName(value);
213:                config.put(SearchConfig.SECMGR, value);
214:            }
215:
216:            public String getSearchRDMLog() {
217:                return (String) config.get(SearchConfig.RDM_LOGFN);
218:            }
219:
220:            public void setSearchRDMLog(String value) throws Exception {
221:                checkFileAccess(getLocalizedString("advancedLog.searchLog"),
222:                        value);
223:                config.put(SearchConfig.RDM_LOGFN, value);
224:            }
225:
226:            /**
227:             * getting boolean state of property disable-rdm-log in search.conf
228:             */
229:            public boolean getSearchLogState() {
230:                String stateStr = (String) (String) config
231:                        .get(SearchConfig.RDM_DISABLE_LOG);
232:                if (stateStr != null && stateStr.equals("true")) {
233:                    return true;
234:                } else {
235:                    return false;
236:                }
237:            }
238:
239:            /**
240:             * setting boolean state of property disable-rdm-log in search.conf
241:             */
242:            public void setSearchLogState(boolean value) {
243:                if (value) {
244:                    config.put(SearchConfig.RDM_DISABLE_LOG, "true");
245:                } else {
246:                    config.put(SearchConfig.RDM_DISABLE_LOG, "false");
247:                }
248:            }
249:
250:            public String getIndexMaintenanceLog() {
251:                return (String) config.get(SearchConfig.SENGINE_LOGFN);
252:            }
253:
254:            public void setIndexMaintenanceLog(String value) throws Exception {
255:                checkFileAccess(
256:                        getLocalizedString("advancedLog.indexMaintenance"),
257:                        value);
258:                config.put(SearchConfig.SENGINE_LOGFN, value);
259:            }
260:
261:            public String getRdMgrLog() {
262:                return (String) config.get(SearchConfig.RDMGR_LOGFN);
263:            }
264:
265:            public void setRdMgrLog(String value) throws Exception {
266:                checkFileAccess(getLocalizedString("advancedLog.rdManager"),
267:                        value);
268:                config.put(SearchConfig.RDMGR_LOGFN, value);
269:            }
270:
271:            public String getRdmDebugLog() {
272:                return (String) config.get(SearchConfig.DEBUG_LOGFN);
273:            }
274:
275:            public void setRdmDebugLog(String value) throws Exception {
276:                checkFileAccess(getLocalizedString("advancedLog.rdmDebug"),
277:                        value);
278:                config.put(SearchConfig.DEBUG_LOGFN, value);
279:            }
280:
281:            public String getRdmDebugLevel() {
282:                return (String) config.get(SearchConfig.DEBUG_LOGLV);
283:            }
284:
285:            public void setRdmDebugLevel(String value) {
286:                config.put(SearchConfig.DEBUG_LOGLV, value);
287:            }
288:
289:            //////////////////////////////////////////////////////
290:            // Model execution methods
291:            //////////////////////////////////////////////////////
292:
293:            /**
294:             *
295:             */
296:            public Object execute(ModelExecutionContext context)
297:                    throws ModelControlException {
298:                String operationName = null;
299:                if (context != null)
300:                    operationName = context.getOperationName();
301:                else
302:                    operationName = ModelExecutionContext.OPERATION_RETRIEVE;
303:
304:                Object result = null;
305:                if (operationName
306:                        .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
307:                    result = retrieve(context);
308:                }
309:
310:                return result;
311:            }
312:
313:            /**
314:             *
315:             */
316:            public Object retrieve(ModelExecutionContext context)
317:                    throws ModelControlException {
318:                // loading the Properties from the file search.conf
319:                load();
320:
321:                // Nothing useful to return
322:                return null;
323:            }
324:
325:            /**
326:             * loading the model from file
327:             */
328:            public void load() {
329:                // getting the ServerRoot directory
330:                String serverRoot = CSConfig.getServerRoot();
331:                if (serverRoot == null) {
332:                    serverRoot = ".";
333:                }
334:
335:                // opening the search.conf file
336:                String csidFilePath = serverRoot + csidFileRelativPath;
337:                try {
338:                    config = new OrderedMap();
339:                    BufferedReader r = new BufferedReader(
340:                            new InputStreamReader(new FileInputStream(
341:                                    csidFilePath), "UTF-8"));
342:                    int commentNb = 1;
343:                    String line;
344:                    String key;
345:                    String value;
346:                    while ((line = r.readLine()) != null) {
347:                        // test if comment generate a dummy comment entry
348:                        if (line.length() != 0) {
349:                            if (line.charAt(0) == '#') {
350:                                config.put(COMMENT + String.valueOf(commentNb),
351:                                        line);
352:                                commentNb++;
353:                            } else {
354:                                // this is an actual configuration attribut 
355:                                int pos = line.indexOf("=");
356:                                if (pos != -1) {
357:                                    key = line.substring(0, pos);
358:                                    value = line.substring(pos + 1).trim();
359:                                    if (value.startsWith("\"")
360:                                            && value.endsWith("\"")) {
361:                                        value = value.substring(1, value
362:                                                .length() - 1);
363:                                    }
364:                                } else {
365:                                    key = line;
366:                                    value = null;
367:                                }
368:                                config.put(key, value);
369:                            }
370:                        } else {
371:                            // assimilate empty line as a separator comment
372:                            config.put(COMMENT + String.valueOf(commentNb),
373:                                    line);
374:                            commentNb++;
375:                        }
376:                    }
377:                    commentNb++;
378:                } catch (IOException ioe) {
379:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", ioe
380:                            .getMessage());
381:                } catch (Exception e) {
382:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", e
383:                            .getMessage());
384:                }
385:            }
386:
387:            /**
388:             * storing the model in file search.conf
389:             */
390:            public void store() {
391:                String serverRoot = CSConfig.getServerRoot();
392:                String csidFilePath = serverRoot + csidFileRelativPath;
393:                try {
394:                    PrintWriter pw = new PrintWriter(new BufferedWriter(
395:                            new OutputStreamWriter(new FileOutputStream(
396:                                    csidFilePath), "UTF-8")));
397:                    // writing the configuration elements
398:                    String[] keysArray = config.getOrderedKeys();
399:                    String key = null;
400:                    String value = null;
401:                    for (int i = 0; i < keysArray.length; i++) {
402:                        key = keysArray[i];
403:                        value = (String) config.get(key);
404:                        if (!key.startsWith(COMMENT)) {
405:                            // strip out the dummy comment key for comments and empty lines
406:                            pw.print(key + "=" + PBlock.quotedString(value)
407:                                    + "\n");
408:                        } else {
409:                            pw.print(value + "\n");
410:                        }
411:                    }
412:                    pw.close();
413:                    // reinitializing the searchConfig from updated file
414:                    SearchConfig.init(csidFilePath);
415:                    // setting the "srv restart flag" so as admin page displays warning
416:                    // to restart server
417:                    needSrvRestart = true;
418:                } catch (IOException ioe) {
419:                    debugLogger.log(Level.INFO, "PSSH_CSPSAM0051",
420:                            new String[] { csidFilePath, ioe.getMessage() });
421:                } catch (Exception e) {
422:                    debugLogger
423:                            .log(Level.INFO, "PSSH_CSPSAM0011", csidFilePath);
424:                }
425:            }
426:
427:            /*
428:             * returns state flag requiring server restart
429:             * note :
430:             * - if admin changes back to the original config, the flag would
431:             *   still be on.
432:             *   this is kind of temporary solution, while looking into ways to 
433:             *   avoid having the admin warning message to restart the server all 
434:             *   together.
435:             * - the flag is being reset to false (static value) when server is restarted
436:             */
437:            public boolean needSrvRestart() {
438:                return needSrvRestart;
439:            }
440:
441:            public String getStringValue(String key) {
442:                return (String) config.get(key);
443:            }
444:
445:            public void setStringValue(String key, String value) {
446:                config.put(key, value);
447:            }
448:
449:            //////////////////////////////////////////////////////
450:            // Class variables
451:            //////////////////////////////////////////////////////
452:            private static boolean needSrvRestart = false;
453:            private static final String COMMENT = "__configComment_";
454:
455:            public static Map csidMap;
456:            public static final String csidFileRelativPath = File.separator
457:                    + "config" + File.separator + "search.conf";
458:
459:            //////////////////////////////////////////////////////
460:            // Member variables
461:            //////////////////////////////////////////////////////
462:            public String ServerStatus;
463:            public String ServerInstanceName;
464:            public String ServerName;
465:            public String ServerPort;
466:            public String ServerRoot;
467:            public String ServerErrorLog;
468:            public String ServerTmpFiles;
469:            private OrderedMap config;
470:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.