Source Code Cross Referenced for ImportAgent.java in  » Portal » Open-Portal » com » sun » portal » search » admin » mbeans » tasks » 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.mbeans.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.sun.portal.search.admin.mbeans.tasks;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import java.util.logging.*;
006:        import java.net.*;
007:        import java.lang.*;
008:        import java.text.*;
009:
010:        import com.sun.portal.admin.server.AdminServerUtil;
011:        import com.sun.portal.admin.server.mbeans.PSResource;
012:        import com.sun.portal.admin.common.context.PortalDomainContext;
013:        import com.sun.portal.admin.common.context.PSConfigContext;
014:        import com.sun.portal.admin.common.PSMBeanException;
015:
016:        import com.iplanet.sso.*;
017:
018:        import com.sun.portal.search.util.*;
019:        import com.sun.portal.search.admin.mbeans.*;
020:
021:        import com.sun.portal.util.Platform;
022:
023:        public class ImportAgent {
024:
025:            public final static String CHARACTER_SET = "character-set";
026:            public final static String DATABASE = "database";
027:            public final static String DESTINATION_DATABASE = "destination-database";
028:            public final static String ENABLED = "enabled";
029:            public final static String ID = "id";
030:            public final static String INPUT_FILE = "input-file";
031:            public final static String INPUT_FILE_EXISTS = "input-file-exists";
032:            public final static String INSTANCE = "instance";
033:            public final static String IS_COMPASS301X = "is-compass301x";
034:            public final static String IS_SEARCH_QUERY = "is-search-query";
035:            public final static String IS_SSL = "is-ssl";
036:            public final static String LAST_COLLECTION_TIME = "last-collection-time";
037:            public final static String NAME = "name";
038:            public final static String NICKNAME = "nickname";
039:            public final static String PASSWORD = "password";
040:            public final static String PORT = "port";
041:            public final static String SCOPE = "scope";
042:            public final static String SERVER = "server";
043:            public final static String TIMEOUT = "timeout";
044:            public final static String URI = "uri";
045:            public final static String USER = "user";
046:            public final static String VIEW_ATTRIBUTES = "view-attributes";
047:            public final static String VIEW_HITS = "view-hits";
048:
049:            private final static String CSID = "x-catalog://host:port/nickname";
050:
051:            private final static String INTERNAL_AGENT_TYPE = "agent-type";
052:            private final static String INTERNAL_CHARSET = "charset";
053:            private final static String INTERNAL_CSID = "csid";
054:            private final static String INTERNAL_DESTINATION_CSID = "destination-csid";
055:            private final static String INTERNAL_EMAIL = "email";
056:            private final static String INTERNAL_ENABLE = "enable";
057:            private final static String INTERNAL_ID = "id";
058:            private final static String INTERNAL_INSTANCE_NAME = "instance-name";
059:            private final static String INTERNAL_IS_COMPASS = "is-compass";
060:            private final static String INTERNAL_IS_SSL = "is-ssl";
061:            private final static String INTERNAL_LOCAL_DB = "local-db";
062:            private final static String INTERNAL_NAME = "name";
063:            private final static String INTERNAL_NICKNAME = "nickname";
064:            private final static String INTERNAL_PASSWORD = "password";
065:            private final static String INTERNAL_QL_COMPASS = "compass";
066:            private final static String INTERNAL_QL_GATHERER = "gatherer";
067:            private final static String INTERNAL_QL_SEARCH = "search";
068:            private final static String INTERNAL_RDM_QUERY_LANGUAGE = "rdm-query-language";
069:            private final static String INTERNAL_SCOPE = "scope";
070:            private final static String INTERNAL_SEARCH_DB = "search-db";
071:            private final static String INTERNAL_SEARCH_URI = "search-uri";
072:            private final static String INTERNAL_SERVER_PORT = "server";
073:            private final static String INTERNAL_SRCFILE = "srcfile";
074:            private final static String INTERNAL_TIMEOUT = "timeout";
075:            private final static String INTERNAL_TIME_STAMP = "last-collection-time";
076:            private final static String INTERNAL_USER = "user";
077:            private final static String INTERNAL_USE_RDM_INCOMING = "use-rdm-incoming";
078:            private final static String INTERNAL_US_AUTH = "use-auth";
079:            private final static String INTERNAL_VIEW_ATTRIBUTES = "view-attributes";
080:            private final static String INTERNAL_VIEW_HITS = "view-hits";
081:            private final static String INTERNAL_VIEW_ORDER = "view-order";
082:
083:            private final static String[] compareFields = { INTERNAL_CSID,
084:                    INTERNAL_LOCAL_DB, INTERNAL_SRCFILE,
085:                    INTERNAL_RDM_QUERY_LANGUAGE, INTERNAL_VIEW_ATTRIBUTES,
086:                    INTERNAL_SCOPE };
087:
088:            private String searchServerID = null;
089:            private String psDir = null;
090:            private String searchServerRoot = null;
091:            private static Logger logger = null;
092:
093:            private HashMap importAgents = null;
094:            private int importAgentID = 0;
095:            private Process importmgrProcess = null;
096:
097:            public ImportAgent(String searchServerID, String psDir,
098:                    String searchServerRoot, Logger logger) {
099:                this .searchServerID = searchServerID;
100:                this .psDir = psDir;
101:                this .searchServerRoot = searchServerRoot;
102:                this .logger = logger;
103:
104:                importAgents = new HashMap();
105:                importAgentID = 0;
106:                try {
107:                    String fileName = searchServerRoot + File.separator
108:                            + "config" + File.separator + "import.conf";
109:                    BufferedReader br = new BufferedReader(
110:                            new InputStreamReader(
111:                                    new FileInputStream(fileName), "UTF-8"));
112:                    HashMap agent = null;
113:                    boolean inTag = false;
114:                    String line = "";
115:                    while ((line = br.readLine()) != null) {
116:                        line = line.trim();
117:                        if (inTag) {
118:                            if (line.startsWith("</Import>")) {
119:                                String id = (String) agent.get("id");
120:                                if (id != null) {
121:                                    int currentID = Integer.parseInt(id);
122:                                    if (currentID > importAgentID) {
123:                                        importAgentID = currentID;
124:                                    }
125:                                    importAgents.put(id, agent);
126:                                    inTag = false;
127:                                }
128:                            } else if (!line.equals("")
129:                                    && !line.startsWith("#")) {
130:                                PBlock.str2pblock(line, agent);
131:                            }
132:                        } else if (line.startsWith("<Import ")
133:                                && line.endsWith(">")) {
134:                            agent = new HashMap();
135:                            PBlock.str2pblock(line.substring(8,
136:                                    line.length() - 1), agent);
137:                            inTag = true;
138:                        }
139:                    }
140:                } catch (Exception e) {
141:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
142:                }
143:                importmgrProcess = null;
144:            }
145:
146:            public ArrayList getAll(List attributes) throws PSMBeanException {
147:                ArrayList data = new ArrayList();
148:
149:                Iterator i = importAgents.keySet().iterator();
150:                while (i.hasNext()) {
151:                    String key = (String) i.next();
152:                    HashMap map = (HashMap) importAgents.get(key);
153:
154:                    try {
155:                        Properties p = getAttributes(attributes, map);
156:                        data.add(p);
157:                    } catch (Exception e) {
158:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
159:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
160:                                .toString(), e);
161:                    }
162:                }
163:
164:                return data;
165:            }
166:
167:            public Properties get(String id, List attributes)
168:                    throws PSMBeanException {
169:                HashMap map = (HashMap) importAgents.get(id);
170:                if (map == null) {
171:                    String message = "Unknown import agent: " + id;
172:                    Object tokens[] = { message };
173:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
174:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
175:                }
176:
177:                try {
178:                    return getAttributes(attributes, map);
179:                } catch (Exception e) {
180:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
181:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
182:                            .toString(), e);
183:                }
184:            }
185:
186:            public void create(String fileName, String destinationDatabase)
187:                    throws PSMBeanException {
188:                HashMap map = new HashMap();
189:                map.put(INTERNAL_ID, Integer.toString(++importAgentID));
190:                map.put(INTERNAL_ENABLE, "true");
191:                map.put(INTERNAL_DESTINATION_CSID, CSID);
192:                map.put(INTERNAL_SRCFILE, fileName);
193:                map.put(INTERNAL_LOCAL_DB, destinationDatabase);
194:
195:                if (!addImportAgent(map)) {
196:                    String message = "Duplicated import agent: " + fileName;
197:                    Object tokens[] = { message };
198:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
199:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
200:                }
201:
202:                try {
203:                    update();
204:                } catch (Exception e) {
205:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
206:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
207:                            .toString(), e);
208:                }
209:            }
210:
211:            public void create(Properties p, String destinationDatabase)
212:                    throws PSMBeanException {
213:                String compass301x = getCreateValue(p, IS_COMPASS301X, "false");
214:
215:                HashMap map = new HashMap();
216:
217:                map.put(INTERNAL_ID, Integer.toString(++importAgentID));
218:
219:                map.put(INTERNAL_ENABLE, "true");
220:                map.put(INTERNAL_DESTINATION_CSID, CSID);
221:
222:                map.put(INTERNAL_NICKNAME, getCreateValue(p, NICKNAME, ""));
223:
224:                map.put(INTERNAL_LOCAL_DB, destinationDatabase);
225:
226:                map.put(INTERNAL_CHARSET, getCreateValue(p, CHARACTER_SET, ""));
227:
228:                String id = (getCreateValue(p, IS_SSL, "false").equals("true")) ? "x-catalogs"
229:                        : "x-catalog";
230:                id = id + "://" + getCreateValue(p, SERVER, "server");
231:                id = id + ":" + getCreateValue(p, PORT, "80");
232:                id = id + "/" + getCreateValue(p, INSTANCE, "instance");
233:                map.put(INTERNAL_CSID, id);
234:
235:                if (compass301x.equals("true")) {
236:                    map.put(INTERNAL_USE_RDM_INCOMING, "true");
237:                } else {
238:                    map.put(INTERNAL_SEARCH_URI, getCreateValue(p, URI, ""));
239:                    map
240:                            .put(INTERNAL_SEARCH_DB, getCreateValue(p,
241:                                    DATABASE, ""));
242:                }
243:
244:                map.put(INTERNAL_USER, getCreateValue(p, USER, ""));
245:                map.put(INTERNAL_PASSWORD, getCreateValue(p, PASSWORD, ""));
246:
247:                if (getCreateValue(p, IS_SEARCH_QUERY, "false").equals("true")) {
248:                    if (compass301x.equals("true")) {
249:                        map.put(INTERNAL_RDM_QUERY_LANGUAGE,
250:                                INTERNAL_QL_COMPASS);
251:                    } else {
252:                        map
253:                                .put(INTERNAL_RDM_QUERY_LANGUAGE,
254:                                        INTERNAL_QL_SEARCH);
255:                    }
256:                    map.put(INTERNAL_SCOPE, getCreateValue(p, SCOPE, ""));
257:                    map.put(INTERNAL_VIEW_ATTRIBUTES, getCreateValue(p,
258:                            VIEW_ATTRIBUTES, ""));
259:                    map.put(INTERNAL_VIEW_HITS,
260:                            getCreateValue(p, VIEW_HITS, ""));
261:                } else {
262:                    map.put(INTERNAL_RDM_QUERY_LANGUAGE, INTERNAL_QL_GATHERER);
263:                }
264:
265:                map.put(INTERNAL_TIME_STAMP, getCreateValue(p,
266:                        LAST_COLLECTION_TIME, ""));
267:                map.put(INTERNAL_TIMEOUT, getCreateValue(p, TIMEOUT, ""));
268:
269:                if (!addImportAgent(map)) {
270:                    String message = "Duplicated import agent: " + id;
271:                    Object tokens[] = { message };
272:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
273:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
274:                }
275:
276:                try {
277:                    update();
278:                } catch (Exception e) {
279:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
280:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
281:                            .toString(), e);
282:                }
283:            }
284:
285:            public void delete(List ids) throws PSMBeanException {
286:                for (int index = 0; index < ids.size(); index++) {
287:                    importAgents.remove((String) ids.get(index));
288:                }
289:
290:                try {
291:                    update();
292:                } catch (Exception e) {
293:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
294:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
295:                            .toString(), e);
296:                }
297:            }
298:
299:            public void edit(String id, String fileName,
300:                    String destinationDatabase) throws PSMBeanException {
301:                HashMap map = (HashMap) importAgents.get(id);
302:                if (map == null) {
303:                    String message = "Import agent " + id + " not found";
304:                    Object tokens[] = { message };
305:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
306:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
307:                }
308:
309:                map.remove(INTERNAL_CSID);
310:                map.remove(INTERNAL_NICKNAME);
311:                map.remove(INTERNAL_PASSWORD);
312:                map.remove(INTERNAL_RDM_QUERY_LANGUAGE);
313:                map.remove(INTERNAL_SCOPE);
314:                map.remove(INTERNAL_SEARCH_DB);
315:                map.remove(INTERNAL_SEARCH_URI);
316:                map.remove(INTERNAL_TIMEOUT);
317:                map.remove(INTERNAL_TIME_STAMP);
318:                map.remove(INTERNAL_USER);
319:                map.remove(INTERNAL_USE_RDM_INCOMING);
320:                map.remove(INTERNAL_VIEW_ATTRIBUTES);
321:                map.remove(INTERNAL_VIEW_HITS);
322:
323:                map.put(INTERNAL_SRCFILE, fileName);
324:                if (destinationDatabase != null) {
325:                    map.put(INTERNAL_LOCAL_DB, destinationDatabase);
326:                }
327:
328:                try {
329:                    update();
330:                } catch (Exception e) {
331:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
332:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
333:                            .toString(), e);
334:                }
335:            }
336:
337:            public void edit(String id, Properties p, String destinationDatabase)
338:                    throws PSMBeanException {
339:                String compass301x = (p.containsKey(IS_COMPASS301X)) ? p
340:                        .getProperty(IS_COMPASS301X) : "false";
341:
342:                HashMap map = (HashMap) importAgents.get(id);
343:                if (map == null) {
344:                    String message = "Import agent " + id + " not found";
345:                    Object tokens[] = { message };
346:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
347:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
348:                }
349:
350:                map.remove(INTERNAL_SRCFILE);
351:
352:                setEditValue(map, INTERNAL_NICKNAME, p, NICKNAME);
353:
354:                map.put(INTERNAL_LOCAL_DB, destinationDatabase);
355:
356:                setEditValue(map, INTERNAL_CHARSET, p, CHARACTER_SET);
357:
358:                String protocol = "";
359:                String server = "";
360:                String port = "";
361:                String instance = "";
362:
363:                String currentValue = (String) map.get(INTERNAL_CSID);
364:                if (currentValue != null && !currentValue.equals("")) {
365:                    try {
366:                        URL url = new URL(currentValue.replaceFirst(
367:                                "x-catalog", "http"));
368:                        protocol = (url.getProtocol().equals("https")) ? "x-catalogs"
369:                                : "x-catalog";
370:                        server = url.getHost();
371:                        port = new Integer(url.getPort()).toString();
372:                        instance = url.getFile();
373:                    } catch (Exception e) {
374:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
375:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
376:                                .toString(), e);
377:                    }
378:                }
379:
380:                boolean needUpdate = false;
381:                if (p.containsKey(IS_SSL)) {
382:                    protocol = (p.getProperty(IS_SSL).equals("true")) ? "x-catalogs"
383:                            : "x-catalog";
384:                    needUpdate = true;
385:                }
386:                if (p.containsKey(SERVER)) {
387:                    server = p.getProperty(SERVER);
388:                    needUpdate = true;
389:                }
390:                if (p.containsKey(PORT)) {
391:                    port = p.getProperty(PORT);
392:                    needUpdate = true;
393:                }
394:                if (p.containsKey(INSTANCE)) {
395:                    instance = p.getProperty(INSTANCE);
396:                    needUpdate = true;
397:                }
398:                if (needUpdate) {
399:                    String csid = protocol + "://" + server;
400:                    if (!port.equals("")) {
401:                        csid = csid + ":" + port;
402:                    }
403:                    if (!instance.equals("")) {
404:                        csid = csid + "/" + instance;
405:                    }
406:                    map.put(INTERNAL_CSID, csid);
407:                }
408:
409:                if (compass301x.equals("true")) {
410:                    map.put(INTERNAL_USE_RDM_INCOMING, "true");
411:                    map.remove(INTERNAL_SEARCH_URI);
412:                    map.remove(INTERNAL_SEARCH_DB);
413:                } else {
414:                    map.remove(INTERNAL_USE_RDM_INCOMING);
415:                    setEditValue(map, INTERNAL_SEARCH_URI, p, URI);
416:                    setEditValue(map, INTERNAL_SEARCH_DB, p, DATABASE);
417:                }
418:
419:                setEditValue(map, INTERNAL_USER, p, USER);
420:                setEditValue(map, INTERNAL_PASSWORD, p, PASSWORD);
421:
422:                if (p.containsKey(IS_SEARCH_QUERY)) {
423:                    if (p.getProperty(IS_SEARCH_QUERY).equals("true")) {
424:                        if (compass301x.equals("true")) {
425:                            map.put(INTERNAL_RDM_QUERY_LANGUAGE,
426:                                    INTERNAL_QL_COMPASS);
427:                        } else {
428:                            map.put(INTERNAL_RDM_QUERY_LANGUAGE,
429:                                    INTERNAL_QL_SEARCH);
430:                        }
431:                        setEditValue(map, INTERNAL_SCOPE, p, SCOPE);
432:                        setEditValue(map, INTERNAL_VIEW_ATTRIBUTES, p,
433:                                VIEW_ATTRIBUTES);
434:                        setEditValue(map, INTERNAL_VIEW_HITS, p, VIEW_HITS);
435:                    } else {
436:                        map.put(INTERNAL_RDM_QUERY_LANGUAGE,
437:                                INTERNAL_QL_GATHERER);
438:                        map.remove(INTERNAL_SCOPE);
439:                        map.remove(INTERNAL_VIEW_ATTRIBUTES);
440:                        map.remove(INTERNAL_VIEW_HITS);
441:                    }
442:                }
443:
444:                setEditValue(map, INTERNAL_TIME_STAMP, p, LAST_COLLECTION_TIME);
445:                setEditValue(map, INTERNAL_TIMEOUT, p, TIMEOUT);
446:
447:                try {
448:                    update();
449:                } catch (Exception e) {
450:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
451:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
452:                            .toString(), e);
453:                }
454:            }
455:
456:            public void enable(List ids) throws PSMBeanException {
457:                for (int index = 0; index < ids.size(); index++) {
458:                    String id = (String) ids.get(index);
459:                    HashMap map = (HashMap) importAgents.get(id);
460:                    if (map == null) {
461:                        String message = "Import agent " + id + " not found";
462:                        Object tokens[] = { message };
463:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
464:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
465:                    }
466:                    map.put(INTERNAL_ENABLE, "true");
467:                }
468:
469:                try {
470:                    update();
471:                } catch (Exception e) {
472:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
473:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
474:                            .toString(), e);
475:                }
476:            }
477:
478:            public void disable(List ids) throws PSMBeanException {
479:                for (int index = 0; index < ids.size(); index++) {
480:                    String id = (String) ids.get(index);
481:                    HashMap map = (HashMap) importAgents.get(id);
482:                    if (map == null) {
483:                        String message = "Import agent " + id + " not found";
484:                        Object tokens[] = { message };
485:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
486:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
487:                    }
488:                    map.put(INTERNAL_ENABLE, "false");
489:                }
490:
491:                try {
492:                    update();
493:                } catch (Exception e) {
494:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
495:                    throw new PSMBeanException("PSALI_CSPACCSH0001", e
496:                            .toString(), e);
497:                }
498:            }
499:
500:            public void run() throws PSMBeanException {
501:                if (importmgrProcess != null) {
502:                    try {
503:                        int exitCode = importmgrProcess.exitValue();
504:                        importmgrProcess = null;
505:                    } catch (IllegalThreadStateException itse) {
506:                        // This means import agent run has not completed yet.
507:                    } catch (Exception e) {
508:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
509:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
510:                                .toString(), e);
511:                    }
512:                }
513:
514:                if (importmgrProcess == null) {
515:                    try {
516:                        String commands[] = {
517:                                psDir + File.separator + "lib" + File.separator
518:                                        + "importmgr",
519:                                "-c",
520:                                searchServerRoot + File.separator + "config"
521:                                        + File.separator + "search.conf", CSID,
522:                                "run", "all" };
523:
524:                        String[] envs = null;
525:                        if (isWindows()) {
526:                            envs = new String[6];
527:                        } else {
528:                            envs = new String[5];
529:                        }
530:                        envs[0] = "PATH=" + psDir + File.separator + "lib"
531:                                + ":" + psDir + File.separator + "bin";
532:                        envs[1] = "LD_LIBRARY_PATH=" + psDir + File.separator
533:                                + "lib:" + psDir + File.separator + "lib"
534:                                + File.separator + "filter:" + File.separator
535:                                + "usr" + File.separator + "lib"
536:                                + File.separator + "mps:" + File.separator
537:                                + "usr" + File.separator + "lib"
538:                                + File.separator + "lwp";
539:                        envs[2] = "CAT_SERVER_ROOT=" + searchServerRoot;
540:                        envs[3] = "CS_CONFIG_PATH=" + searchServerRoot
541:                                + File.separator + "config";
542:                        envs[4] = "CS_LOGDIR=" + searchServerRoot
543:                                + File.separator + "logs";
544:                        if (isWindows()) {
545:                            String key = "COMSPEC";
546:                            String value = null;
547:                            try {
548:                                value = getEnvVar(key);
549:                            } catch (Exception ex) {
550:                            }
551:                            if (value == null || value.trim().equals("")) {
552:                                String winDir = (System.getProperty("os.name")
553:                                        .equals("Windows XP")) ? "C:\\WINDOWS"
554:                                        : "C:\\WINNT";
555:                                value = winDir + "\\system32\\cmd.exe";
556:                            }
557:                            envs[0] = "PATH=" + psDir + File.separator + "lib"
558:                                    + ";" + psDir + File.separator + "bin"
559:                                    + ";" + psDir + File.separator + "lib"
560:                                    + File.separator + "filter" + ";" + psDir
561:                                    + File.separator + ".." + File.separator
562:                                    + "share" + File.separator + "lib";
563:                            envs[5] = key + "=" + value;
564:                        }
565:                        if (isHpux()) {
566:                            envs[1] = "SHLIB_PATH=" + psDir + File.separator
567:                                    + "lib:" + psDir + File.separator + "lib"
568:                                    + File.separator + "filter:"
569:                                    + File.separator + "opt" + File.separator
570:                                    + "sun" + File.separator + "private"
571:                                    + File.separator + "lib";
572:                        }
573:
574:                        Runtime rt = Runtime.getRuntime();
575:                        importmgrProcess = rt.exec(commands, envs);
576:                    } catch (Exception e) {
577:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
578:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
579:                                .toString(), e);
580:                    }
581:                } else {
582:                    String message = "Import agents are already running";
583:                    Object tokens[] = { message };
584:                    logger.log(Level.INFO, "PSSH_CSPSAMB0001", tokens);
585:                    throw new PSMBeanException("PSALI_CSPACCSH0001");
586:                }
587:            }
588:
589:            public boolean stillRunning() throws PSMBeanException {
590:                if (importmgrProcess != null) {
591:                    try {
592:                        int exitCode = importmgrProcess.exitValue();
593:                        importmgrProcess = null;
594:                        return false;
595:                    } catch (IllegalThreadStateException itse) {
596:                        return true;
597:                    } catch (Exception e) {
598:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
599:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
600:                                .toString(), e);
601:                    }
602:                } else {
603:                    return false;
604:                }
605:            }
606:
607:            private void update() throws Exception {
608:                String fileName = searchServerRoot + File.separator + "config"
609:                        + File.separator + "import.conf";
610:                FileOutputStream fos = new FileOutputStream(fileName);
611:                PrintWriter pw = new PrintWriter(new BufferedWriter(
612:                        new OutputStreamWriter(fos, "UTF-8")), true);
613:                pw
614:                        .println("# Written automatically by importmgr -- DO NOT EDIT");
615:
616:                Iterator i1 = importAgents.keySet().iterator();
617:                while (i1.hasNext()) {
618:                    HashMap map = (HashMap) importAgents
619:                            .get((String) i1.next());
620:
621:                    pw.println("<Import id=" + (String) map.get("id") + ">");
622:
623:                    Iterator i2 = map.keySet().iterator();
624:                    while (i2.hasNext()) {
625:                        String key = (String) i2.next();
626:                        if (key.compareToIgnoreCase("id") != 0) {
627:                            pw
628:                                    .println(key
629:                                            + "="
630:                                            + PBlock.quotedString((String) map
631:                                                    .get(key)) + "");
632:                        }
633:                    }
634:
635:                    pw.println("</Import>");
636:                    pw.println();
637:                }
638:                pw.close();
639:            }
640:
641:            private boolean addImportAgent(HashMap map) {
642:                Iterator i = importAgents.keySet().iterator();
643:                while (i.hasNext()) {
644:                    HashMap m = (HashMap) importAgents.get((String) i.next());
645:
646:                    boolean match = true;
647:                    for (int index = 0; index < compareFields.length; index++) {
648:                        String key = compareFields[index];
649:                        String value1 = (String) map.get(key);
650:                        String value2 = (String) m.get(key);
651:                        if ((value1 == null && value1 != null)
652:                                || (value1 != null && value2 == null)
653:                                || (value1 != null && value2 != null && !value1
654:                                        .equals(value2))) {
655:                            match = false;
656:                        }
657:                    }
658:                    if (match) {
659:                        return false;
660:                    }
661:                }
662:
663:                ArrayList al = new ArrayList();
664:                i = map.keySet().iterator();
665:                while (i.hasNext()) {
666:                    String key = (String) i.next();
667:                    String value = (String) map.get(key);
668:                    if (value == null || value.equals("")
669:                            || value.equals("\"\"")) {
670:                        al.add(key);
671:                    }
672:                }
673:                for (int index = 0; index < al.size(); index++) {
674:                    map.remove(al.get(index));
675:                }
676:
677:                importAgents.put((String) map.get(INTERNAL_ID), map);
678:                return true;
679:            }
680:
681:            private String getCreateValue(Properties p, String key,
682:                    String defaultValue) {
683:                if (p.containsKey(key)) {
684:                    return p.getProperty(key);
685:                } else {
686:                    return defaultValue;
687:                }
688:            }
689:
690:            private void setEditValue(HashMap map, String field, Properties p,
691:                    String key) {
692:                if (p.containsKey(key)) {
693:                    map.put(field, p.getProperty(key));
694:                }
695:            }
696:
697:            private Properties getAttributes(List attributes, HashMap map)
698:                    throws Exception {
699:                if (attributes.size() == 0) {
700:                    attributes.add(CHARACTER_SET);
701:                    attributes.add(DATABASE);
702:                    attributes.add(DESTINATION_DATABASE);
703:                    attributes.add(ENABLED);
704:                    attributes.add(ID);
705:                    attributes.add(INPUT_FILE);
706:                    attributes.add(INPUT_FILE_EXISTS);
707:                    attributes.add(INSTANCE);
708:                    attributes.add(IS_COMPASS301X);
709:                    attributes.add(IS_SEARCH_QUERY);
710:                    attributes.add(IS_SSL);
711:                    attributes.add(LAST_COLLECTION_TIME);
712:                    attributes.add(NAME);
713:                    attributes.add(NICKNAME);
714:                    attributes.add(PASSWORD);
715:                    attributes.add(PORT);
716:                    attributes.add(SCOPE);
717:                    attributes.add(SERVER);
718:                    attributes.add(TIMEOUT);
719:                    attributes.add(URI);
720:                    attributes.add(USER);
721:                    attributes.add(VIEW_ATTRIBUTES);
722:                    attributes.add(VIEW_HITS);
723:                }
724:
725:                Properties p = new Properties();
726:                for (int index = 0; index < attributes.size(); index++) {
727:                    String attribute = (String) attributes.get(index);
728:                    if (attribute.equals(CHARACTER_SET)) {
729:                        String value = (String) map.get(INTERNAL_CHARSET);
730:                        p.setProperty(CHARACTER_SET, (value != null) ? value
731:                                : "");
732:                    } else if (attribute.equals(DATABASE)) {
733:                        String value = (String) map.get(INTERNAL_SEARCH_DB);
734:                        p.setProperty(DATABASE, (value != null) ? value : "");
735:                    } else if (attribute.equals(DESTINATION_DATABASE)) {
736:                        String value = (String) map.get(INTERNAL_LOCAL_DB);
737:                        p.setProperty(DESTINATION_DATABASE,
738:                                (value != null) ? value : "");
739:                    } else if (attribute.equals(ENABLED)) {
740:                        String value = (String) map.get(INTERNAL_ENABLE);
741:                        p.setProperty(ENABLED, (value != null) ? value : "");
742:                    } else if (attribute.equals(ID)) {
743:                        String value = (String) map.get(INTERNAL_ID);
744:                        p.setProperty(ID, (value != null) ? value : "");
745:                    } else if (attribute.equals(INPUT_FILE)) {
746:                        String value = (String) map.get(INTERNAL_SRCFILE);
747:                        p.setProperty(INPUT_FILE, (value != null) ? value : "");
748:                    } else if (attribute.equals(INPUT_FILE_EXISTS)) {
749:                        String value = (String) map.get(INTERNAL_SRCFILE);
750:                        if (value != null) {
751:                            File f = new File(value);
752:                            if (f.exists()) {
753:                                p.setProperty(INPUT_FILE_EXISTS, "true");
754:                            } else {
755:                                p.setProperty(INPUT_FILE_EXISTS, "false");
756:                            }
757:                        } else {
758:                            p.setProperty(INPUT_FILE_EXISTS, "");
759:                        }
760:                    } else if (attribute.equals(INSTANCE)) {
761:                        String instance = "";
762:                        String value = (String) map.get(INTERNAL_CSID);
763:                        if (value != null && !value.equals("")) {
764:                            value = value.replaceFirst("x-catalog", "http");
765:                            try {
766:                                URL url = new URL(value);
767:                                instance = url.getFile().replaceFirst("/", "");
768:                            } catch (Exception e) {
769:                                String message = "Badly formed CSID: " + value
770:                                        + ", " + e.toString();
771:                                Object tokens[] = { message };
772:                                logger.log(Level.INFO, "PSSH_CSPSAMB0001",
773:                                        tokens);
774:                            }
775:                        }
776:                        p.setProperty(INSTANCE, instance);
777:                    } else if (attribute.equals(IS_COMPASS301X)) {
778:                        String value = (String) map
779:                                .get(INTERNAL_USE_RDM_INCOMING);
780:                        p.setProperty(IS_COMPASS301X, (value != null) ? value
781:                                : "false");
782:                    } else if (attribute.equals(IS_SEARCH_QUERY)) {
783:                        String value = (String) map
784:                                .get(INTERNAL_RDM_QUERY_LANGUAGE);
785:                        if (value == null || value.equals("")) {
786:                            p.setProperty(IS_SEARCH_QUERY, "false");
787:                        } else {
788:                            p.setProperty(IS_SEARCH_QUERY, (value
789:                                    .equals(INTERNAL_QL_GATHERER)) ? "false"
790:                                    : "true");
791:                        }
792:                    } else if (attribute.equals(IS_SSL)) {
793:                        String isSSL = "false";
794:                        String value = (String) map.get(INTERNAL_CSID);
795:                        if (value != null && !value.equals("")) {
796:                            if (value.indexOf("x-catalogs") == -1) {
797:                                isSSL = "false";
798:                            } else {
799:                                isSSL = "true";
800:                            }
801:                        }
802:                        p.setProperty(IS_SSL, isSSL);
803:                    } else if (attribute.equals(LAST_COLLECTION_TIME)) {
804:                        String value = (String) map.get(INTERNAL_TIME_STAMP);
805:                        p.setProperty(LAST_COLLECTION_TIME,
806:                                (value != null) ? value : "");
807:                    } else if (attribute.equals(NAME)) {
808:                        String id = (String) map.get(INTERNAL_CSID);
809:                        String nickName = (String) map.get(INTERNAL_NICKNAME);
810:                        if (id != null) {
811:                            if (nickName == null) {
812:                                p.setProperty(NAME, id);
813:                            } else {
814:                                p.setProperty(NAME, nickName);
815:                            }
816:                        } else {
817:                            String fileName = (String) map
818:                                    .get(INTERNAL_SRCFILE);
819:                            if (fileName != null) {
820:                                if (nickName == null) {
821:                                    p.setProperty(NAME, fileName);
822:                                } else {
823:                                    p.setProperty(NAME, nickName);
824:                                }
825:                            } else {
826:                                p.setProperty(NAME, "");
827:                            }
828:                        }
829:                    } else if (attribute.equals(NICKNAME)) {
830:                        String value = (String) map.get(INTERNAL_NICKNAME);
831:                        p.setProperty(NICKNAME, (value != null) ? value : "");
832:                    } else if (attribute.equals(PASSWORD)) {
833:                        String value = (String) map.get(INTERNAL_PASSWORD);
834:                        p.setProperty(PASSWORD, (value != null) ? value : "");
835:                    } else if (attribute.equals(PORT)) {
836:                        String port = "";
837:                        String value = (String) map.get(INTERNAL_CSID);
838:                        if (value != null && !value.equals("")) {
839:                            value = value.replaceFirst("x-catalog", "http");
840:                            try {
841:                                URL url = new URL(value);
842:                                port = new Integer(url.getPort()).toString();
843:                            } catch (Exception e) {
844:                                String message = "Badly formed CSID: " + value
845:                                        + ", " + e.toString();
846:                                Object tokens[] = { message };
847:                                logger.log(Level.INFO, "PSSH_CSPSAMB0001",
848:                                        tokens);
849:                            }
850:                        }
851:                        p.setProperty(PORT, port);
852:                    } else if (attribute.equals(SCOPE)) {
853:                        String value = (String) map.get(INTERNAL_SCOPE);
854:                        p.setProperty(SCOPE, (value != null) ? value : "");
855:                    } else if (attribute.equals(SERVER)) {
856:                        String server = "";
857:                        String value = (String) map.get(INTERNAL_CSID);
858:                        if (value != null && !value.equals("")) {
859:                            value = value.replaceFirst("x-catalog", "http");
860:                            try {
861:                                URL url = new URL(value);
862:                                server = url.getHost();
863:                            } catch (Exception e) {
864:                                String message = "Badly formed CSID: " + value
865:                                        + ", " + e.toString();
866:                                Object tokens[] = { message };
867:                                logger.log(Level.INFO, "PSSH_CSPSAMB0001",
868:                                        tokens);
869:                            }
870:                        }
871:                        p.setProperty(SERVER, server);
872:                    } else if (attribute.equals(TIMEOUT)) {
873:                        String value = (String) map.get(INTERNAL_TIMEOUT);
874:                        p.setProperty(TIMEOUT, (value != null) ? value : "");
875:                    } else if (attribute.equals(URI)) {
876:                        String value = (String) map.get(INTERNAL_SEARCH_URI);
877:                        p.setProperty(URI, (value != null) ? value : "");
878:                    } else if (attribute.equals(USER)) {
879:                        String value = (String) map.get(INTERNAL_USER);
880:                        p.setProperty(USER, (value != null) ? value : "");
881:                    } else if (attribute.equals(VIEW_ATTRIBUTES)) {
882:                        String value = (String) map
883:                                .get(INTERNAL_VIEW_ATTRIBUTES);
884:                        p.setProperty(VIEW_ATTRIBUTES, (value != null) ? value
885:                                : "");
886:                    } else if (attribute.equals(VIEW_HITS)) {
887:                        String value = (String) map.get(INTERNAL_VIEW_HITS);
888:                        p.setProperty(VIEW_HITS, (value != null) ? value : "");
889:                    }
890:                }
891:
892:                return p;
893:            }
894:
895:            private String getEnvVar(String Str) throws Exception {
896:                Process p = null;
897:                Runtime r = Runtime.getRuntime();
898:                p = r.exec("cmd.exe /c set");
899:                BufferedReader br = new BufferedReader(new InputStreamReader(p
900:                        .getInputStream()));
901:                String line;
902:                while ((line = br.readLine()) != null) {
903:                    int idx = line.indexOf('=');
904:                    String key = line.substring(0, idx);
905:                    String value = line.substring(idx + 1);
906:                    if (key.equalsIgnoreCase(Str))
907:                        return value;
908:                }
909:                return null;
910:            }
911:
912:            private boolean isWindows() {
913:                String osName = Platform.name;
914:                if (osName.startsWith("windows")) {
915:                    return true;
916:                } else {
917:                    return false;
918:                }
919:            }
920:
921:            private boolean isHpux() {
922:                String osName = Platform.name;
923:                if (osName.startsWith("HP-UX")) {
924:                    return true;
925:                } else {
926:                    return false;
927:                }
928:            }
929:
930:        }
ww_w_.__j__av__a2__s__.co___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.