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


001:        package com.sun.portal.search.autoclassify;
002:
003:        import java.util.*;
004:        import java.util.logging.Logger;
005:        import java.util.logging.Level;
006:        import java.io.*;
007:        import com.sun.portal.search.rdm.*;
008:        import com.sun.portal.search.soif.*;
009:        import com.sun.portal.search.util.Getopt;
010:        import com.sun.portal.search.util.DateParser;
011:        import com.sun.portal.search.util.*;
012:        import com.sun.portal.search.admin.util.DBUtil;
013:        import com.sun.portal.log.common.PortalLogger;
014:        import com.iplanet.am.util.AdminUtils;
015:        import java.security.AccessController;
016:        import com.sun.identity.security.EncryptAction;
017:        import java.text.MessageFormat;
018:
019:        /** <p>Title: Autoclassify</p>
020:         * <p>Description: </p>
021:         * <p>Copyright: Copyright (c) 2002</p>
022:         * <p>Company: Sun Microsystems</p>
023:         * @author unascribed
024:         * @version 1.0
025:         */
026:
027:        public class Autoclassify {
028:
029:            class CreateClassMap implements  RDMCallback {
030:                Map classMap = null;
031:
032:                public CreateClassMap(Map classmap) {
033:                    classMap = classmap;
034:                }
035:
036:                public void callback(Object parm1) throws java.lang.Exception {
037:                    RDMClassification c = (RDMClassification) parm1;
038:                    if (c.getId() == "ROOT") {
039:                        return;
040:                    }
041:                    String rule = c.getMatchingRule();
042:                    if (rule == null) {
043:                        return;
044:                    }
045:                    HashMap map = new HashMap();
046:                    map.put("RULE", rule.trim());
047:                    classMap.put(c.getId(), map);
048:
049:                }
050:            }
051:
052:            AutoclassifyContext context = null;
053:            String server_root = ".";
054:            String logDir = null;
055:            String taxPath = null;
056:            String backupTaxPath = null;
057:            Date since = null;
058:            Date dbSince = null;
059:            Date startAt = new Date();
060:            String rdmServer = null;
061:            Map newTaxMap = null;
062:            Map oldTaxMap = null;
063:            Map results = new HashMap();
064:            HeartBeat heartbeat = null;
065:            RDStore rdstore = null;
066:            public boolean securityMode = false;
067:            String user = null;
068:            String password = null;
069:
070:            // Create a logger for this class
071:            private static Logger debugLogger = PortalLogger
072:                    .getLogger(Autoclassify.class);
073:
074:            /**
075:             * @param appContext Application Context
076:             * @param server_root The path of instance server root
077:             * @param lastRun An override timestamp
078:             * @param rdmServer rdmserver url
079:             * @throws Exception
080:             */
081:            public Autoclassify(AutoclassifyContext appContext,
082:                    String server_root, Date lastRun, String rdmServer)
083:                    throws Exception {
084:                this .server_root = server_root;
085:                context = appContext;
086:                logDir = server_root + File.separator + "logs";
087:
088:                taxPath = server_root + File.separator + "config"
089:                        + File.separator + "taxonomy.rdm";
090:                since = lastRun;
091:                this .rdmServer = rdmServer;
092:                since = lastRun;
093:                String lockFilePath = SearchConfig
094:                        .getValue(AutoclassifyConfig.NAME_LOCKFILE);
095:                if (lockFilePath == null) {
096:                    lockFilePath = logDir + File.separator
097:                            + "autoclassify.lock";
098:                }
099:                String secMode = SearchConfig.getValue(SearchConfig.SECMODE);
100:                if (secMode != null && secMode.toLowerCase().equals("on")) {
101:                    securityMode = true;
102:                    user = AdminUtils.getAdminDN();
103:                    password = (String) AccessController
104:                            .doPrivileged(new EncryptAction(new String(
105:                                    AdminUtils.getAdminPassword())));
106:                }
107:                heartbeat = new HeartBeat(lockFilePath);
108:                heartbeat.start();
109:                // Start the logging
110:                try {
111:                    SearchLogger.init(SearchConfig.AUTOCLASSIFY_LOGGER,
112:                            server_root);
113:                    debugLogger = SearchLogger.getLogger();
114:                } catch (Exception e) {
115:                    println(getLocalizedString("loggingInitFailure",
116:                            new Object[] { e.getMessage() }));
117:                    return;
118:                }
119:            }
120:
121:            /** A houskeeping procedure before the process terminated */
122:            public void shutdown() {
123:                heartbeat.Stop();
124:                for (; heartbeat.isAlive();) {
125:                }
126:                /*        if (heartbeat.isAlive()) {
127:                 heartbeat.interrupt();
128:                 }*/
129:            }
130:
131:            Map readTaxToMap(String path, boolean getLastRun) throws Exception {
132:                Map map = new HashMap();
133:                try {
134:                    SOIFInputStream sIn = new SOIFInputStream(path);
135:                    RDMTaxonomy tax = new RDMTaxonomy(sIn);
136:                    if (getLastRun) {
137:                        String lastRunStr = tax.getSOIF().getValue("LastRun");
138:                        //println("LastRun=" + lastRunStr);
139:                        if (lastRunStr != null) {
140:                            try {
141:                                dbSince = AutoclassifyConfig.formatter
142:                                        .parse(lastRunStr);
143:                            } catch (Exception e) {
144:                                debugLogger.log(Level.SEVERE,
145:                                        "PSSH_CSPSACY0001", e.getMessage());
146:                            }
147:                        }
148:                    }
149:                    RDMClassification root = tax
150:                            .find(RDMTaxonomy.RDM_TAXONOMY_ROOT);
151:                    CreateClassMap cm = new CreateClassMap(map);
152:                    root.apply(RDM.RDM_TAX_INORDER, cm);
153:                    //System.out.println("Read classification:" + map.size());
154:                } catch (Exception e) {
155:                    debugLogger.log(Level.INFO, "PSSH_CSPSACY0001", e
156:                            .getMessage());
157:                }
158:                return map;
159:            }
160:
161:            private void backupTaxonomy(String taxPath, String backupPath)
162:                    throws Exception {
163:                SOIFInputStream sis = new SOIFInputStream(taxPath);
164:                SOIFOutputStream sos = new SOIFOutputStream(backupPath);
165:                SOIF s = null;
166:                while ((s = sis.readSOIF()) != null) { // until the End-Of-Stream
167:
168:                    // If it's @TAXONOMY then put lastrun at it
169:                    if (s.getSchemaName().equalsIgnoreCase(RDM.A_SN_RDM_TAX)) {
170:                        s.insert("LastRun", AutoclassifyConfig.formatter
171:                                .format(startAt));
172:                    }
173:                    sos.write(s);
174:                }
175:                sis.close();
176:                sos.close();
177:            }
178:
179:            private void resetTaxonomyMap(Map map) {
180:                if (map == null) {
181:                    return;
182:                }
183:                Iterator it = map.keySet().iterator();
184:                while (it.hasNext()) {
185:                    String key = (String) it.next();
186:                    Map nc = (Map) newTaxMap.get(key);
187:                    nc.remove("USETIMESTAMP");
188:                }
189:            }
190:
191:            static String getLocalizedString(String key) {
192:                try {
193:                    return getLocalizedString(key, AutoclassifyConfig
194:                            .getResourceBundle());
195:                } catch (Exception e) {
196:                }
197:                return key;
198:            }
199:
200:            static String getLocalizedString(String key, Object[] objs) {
201:                String pattern = getLocalizedString(key);
202:                if (objs != null && objs.length > 0) {
203:                    MessageFormat mf = new MessageFormat("");
204:                    mf.applyPattern(getLocalizedString(key));
205:                    return mf.format(objs);
206:                } else {
207:                    return getLocalizedString(key);
208:                }
209:            }
210:
211:            String getLocalizedUIString(String key) {
212:                if (this .context == null) {
213:                    return key;
214:                }
215:                return getLocalizedString(key, context.getResourceBundle());
216:            }
217:
218:            void indexResult(String dbName, String soifPath) {
219:                String cmd = this .server_root + File.separator
220:                        + "run-cs-cli rdmgr -m -q -p stdout -y " + dbName + " "
221:                        + soifPath;
222:                Runtime rt = Runtime.getRuntime();
223:                try {
224:                    Process process = DBUtil.exec(cmd);
225:                    BufferedReader buf = new BufferedReader(
226:                            new InputStreamReader(process.getInputStream()));
227:                    String outLine = null;
228:                    while ((outLine = buf.readLine()) != null) {
229:                        println(outLine);
230:                    }
231:                    //process.waitFor() == 0;
232:                } catch (Exception e) {
233:                    // XXX Not logging exceptions? XXX
234:                    println("rt.exec Exception:" + e.getMessage());
235:                }
236:            }
237:
238:            String indexResults(String dbName, String soifPath) {
239:                StringBuffer sb = new StringBuffer();
240:                String cmd = this .server_root + File.separator
241:                        + "run-cs-cli rdmgr -m -q -p stdout -y " + dbName + " "
242:                        + soifPath;
243:                Runtime rt = Runtime.getRuntime();
244:                try {
245:                    Process process = DBUtil.exec(cmd);
246:                    BufferedReader buf = new BufferedReader(
247:                            new InputStreamReader(process.getInputStream()));
248:                    String outLine = null;
249:                    while ((outLine = buf.readLine()) != null) {
250:                        //println(outLine);
251:                        sb.append(outLine + "\n");
252:                    }
253:                    //process.waitFor() == 0;
254:                } catch (Exception e) {
255:                    // XXX Not logging exceptions? XXX
256:                    //println("rt.exec Exception:" + e.getMessage());
257:                    sb.append(e.getMessage());
258:                }
259:                return sb.toString();
260:            }
261:
262:            /** Running the document classification for given database
263:             * @param dbName database name
264:             * @throws Exception
265:             */
266:            public String doAutoclassify(String serverRoot, String dbName,
267:                    String dbPath, int hashTableSize) throws Exception {
268:
269:                StringBuffer sb = new StringBuffer();
270:
271:                sb.append(getLocalizedUIString("classify_database") + dbName
272:                        + "\n");
273:                //println(getLocalizedUIString("classify_database") + dbName);
274:                //CSLog.log(0,1, getLocalizedString("classify_database") + dbName);
275:                backupTaxPath = serverRoot + File.separator + "db"
276:                        + File.separator + dbName + File.separator
277:                        + "taxonomy.classifed";
278:                try {
279:                    if (newTaxMap == null) {
280:                        newTaxMap = readTaxToMap(taxPath, false);
281:                    } else {
282:                        this .resetTaxonomyMap(newTaxMap);
283:                    }
284:                    oldTaxMap = readTaxToMap(backupTaxPath, true);
285:                    if (since != null) {
286:                        sb.append(getLocalizedUIString("overridelastrunat")
287:                                + context.dateTimeFormat(since) + "\n");
288:                        //println(getLocalizedUIString("overridelastrunat") + context.dateTimeFormat(since));
289:                        dbSince = since;
290:                    } else if (dbSince != null) {
291:                        sb.append(getLocalizedUIString("lastrunat")
292:                                + context.dateTimeFormat(dbSince) + "\n");
293:                        //println(getLocalizedUIString("lastrunat") + context.dateTimeFormat(dbSince));
294:                    } else {
295:                        sb.append(getLocalizedUIString("firsttimerun") + "\n");
296:                        //println(getLocalizedUIString("firsttimerun"));
297:                    }
298:
299:                    rdstore = new RDStore(hashTableSize, dbPath);
300:
301:                    Iterator it = oldTaxMap.keySet().iterator();
302:                    while (it.hasNext()) {
303:                        Object key = it.next();
304:                        Map oc = (Map) oldTaxMap.get(key);
305:                        Map nc = (Map) newTaxMap.get(key);
306:                        if (nc != null) {
307:                            String newRule = (String) nc.get("RULE");
308:                            String oldRule = (String) oc.get("RULE");
309:                            if (newRule.compareToIgnoreCase(oldRule) != 0) {
310:                                oc.put("DELETED", "true");
311:                            } else {
312:                                nc.put("USETIMESTAMP", "true");
313:                            }
314:                        } else {
315:                            oc.put("DELETED", "true");
316:                        }
317:                        //System.out.println(key);
318:                    }
319:                    sb.append(getLocalizedUIString("removeclass") + "\n");
320:                    //println(getLocalizedUIString("removeclass"));
321:                    it = oldTaxMap.keySet().iterator();
322:                    while (it.hasNext()) {
323:                        String key = (String) it.next();
324:                        Map nc = (Map) oldTaxMap.get(key);
325:                        String needDelete = (String) nc.get("DELETED");
326:                        if (needDelete != null && needDelete.equals("true")) {
327:                            this .getRemoveClassificationRDs(dbName, key);
328:                        }
329:                    }
330:                    sb.append(getLocalizedUIString("addclass") + "\n");
331:                    //println("");
332:                    //println(getLocalizedUIString("addclass"));
333:                    it = newTaxMap.keySet().iterator();
334:                    while (it.hasNext()) {
335:                        String key = (String) it.next();
336:                        Map nc = (Map) newTaxMap.get(key);
337:                        String useTimeStamp = (String) nc.get("USETIMESTAMP");
338:                        String Rule = (String) nc.get("RULE");
339:                        if (Rule != null & Rule.length() > 0) {
340:                            if (useTimeStamp != null
341:                                    && useTimeStamp.equals("true")) {
342:                                getRDs(dbName, key, Rule, dbSince, this .startAt);
343:                            } else {
344:                                getRDs(dbName, key, Rule, null, this .startAt);
345:                            }
346:                        }
347:                    }
348:                    sb.append(getLocalizedUIString("indexingresult") + "\n");
349:                    //println("");
350:                    //println(getLocalizedUIString("indexingresult"));
351:                    String tmpsoif = serverRoot + File.separator + "tmp"
352:                            + File.separator + "result.soif";
353:                    int count = rdstore.CreateSOIF(tmpsoif);
354:                    if (count > 0) {
355:                        sb.append(indexResults(dbName, tmpsoif));
356:                    }
357:                    rdstore.close();
358:                    backupTaxonomy(taxPath, backupTaxPath);
359:                    //CSLog.log(0,1, count + getLocalizedString("numberrdupdated") );
360:                } catch (HeartBeatFailureException e) {
361:                    throw e;
362:                } catch (Exception e) {
363:                    throw e;
364:                    //System.out.println("Exception:" + e);
365:                }
366:
367:                return sb.toString();
368:            }
369:
370:            /** Running the document classification for given database
371:             * @param dbName database name
372:             * @throws Exception
373:             */
374:            public void doAutoClassify(String dbName, String dbPath,
375:                    int hashTableSize) throws Exception {
376:                println(getLocalizedUIString("classify_database") + dbName);
377:                debugLogger.log(Level.FINEST, "PSSH_CSPSACY0002", new Object[] {
378:                        getLocalizedUIString("classify_database"), dbName });
379:                backupTaxPath = this .server_root + File.separator + "db"
380:                        + File.separator + dbName + File.separator
381:                        + "taxonomy.classifed";
382:                try {
383:                    if (newTaxMap == null) {
384:                        newTaxMap = readTaxToMap(taxPath, false);
385:                    } else {
386:                        this .resetTaxonomyMap(newTaxMap);
387:                    }
388:                    oldTaxMap = readTaxToMap(backupTaxPath, true);
389:                    if (since != null) {
390:                        println(getLocalizedUIString("overridelastrunat")
391:                                + context.dateTimeFormat(since));
392:                        dbSince = since;
393:                    } else if (dbSince != null) {
394:                        println(getLocalizedUIString("lastrunat")
395:                                + context.dateTimeFormat(dbSince));
396:                    } else {
397:                        println(getLocalizedUIString("firsttimerun"));
398:                    }
399:
400:                    rdstore = new RDStore(hashTableSize, dbPath);
401:
402:                    Iterator it = oldTaxMap.keySet().iterator();
403:                    while (it.hasNext()) {
404:                        Object key = it.next();
405:                        Map oc = (Map) oldTaxMap.get(key);
406:                        Map nc = (Map) newTaxMap.get(key);
407:                        if (nc != null) {
408:                            String newRule = (String) nc.get("RULE");
409:                            String oldRule = (String) oc.get("RULE");
410:                            if (newRule.compareToIgnoreCase(oldRule) != 0) {
411:                                oc.put("DELETED", "true");
412:                            } else {
413:                                nc.put("USETIMESTAMP", "true");
414:                            }
415:                        } else {
416:                            oc.put("DELETED", "true");
417:                        }
418:                        //System.out.println(key);
419:                    }
420:                    println(getLocalizedUIString("removeclass"));
421:                    it = oldTaxMap.keySet().iterator();
422:                    while (it.hasNext()) {
423:                        String key = (String) it.next();
424:                        Map nc = (Map) oldTaxMap.get(key);
425:                        String needDelete = (String) nc.get("DELETED");
426:                        if (needDelete != null && needDelete.equals("true")) {
427:                            this .getRemoveClassificationRDs(dbName, key);
428:                        }
429:                    }
430:                    println("");
431:                    println(getLocalizedUIString("addclass"));
432:                    it = newTaxMap.keySet().iterator();
433:                    while (it.hasNext()) {
434:                        String key = (String) it.next();
435:                        Map nc = (Map) newTaxMap.get(key);
436:                        String useTimeStamp = (String) nc.get("USETIMESTAMP");
437:                        String Rule = (String) nc.get("RULE");
438:                        if (Rule != null & Rule.length() > 0) {
439:                            if (useTimeStamp != null
440:                                    && useTimeStamp.equals("true")) {
441:                                getRDs(dbName, key, Rule, dbSince, this .startAt);
442:                            } else {
443:                                getRDs(dbName, key, Rule, null, this .startAt);
444:                            }
445:                        }
446:                    }
447:                    println("");
448:                    println(getLocalizedUIString("indexingresult"));
449:                    int count = rdstore.CreateSOIF("result.soif");
450:                    if (count > 0) {
451:                        indexResult(dbName, "result.soif");
452:                    }
453:                    rdstore.close();
454:                    backupTaxonomy(taxPath, backupTaxPath);
455:                    debugLogger.log(Level.FINEST, "PSSH_CSPSACY0001",
456:                            (count + getLocalizedString("numberrdupdated")));
457:                } catch (HeartBeatFailureException e) {
458:                    throw e;
459:                } catch (Exception e) {
460:                    debugLogger
461:                            .log(Level.SEVERE, "Error getting document:" + e);
462:                }
463:
464:            }
465:
466:            private void removeAutoClassification(SOIF s, String className) {
467:                boolean in_class = false;
468:                boolean in_rd_auto_class = false;
469:                AVPair AVs = s.getAVPair(AutoclassifyConfig.NAME_CLASSIFIED);
470:                for (int i = 0; AVs != null && i <= AVs.getMaxIndex(); i++) {
471:                    String c = AVs.getValue(i);
472:                    if (c == null) {
473:                        continue;
474:                    }
475:                    if (c.compareToIgnoreCase(className) == 0) {
476:                        in_rd_auto_class = true;
477:                        AVs.remove(i);
478:                        AVs.squeeze();
479:                        if (AVs.getMaxIndex() == 0) {
480:                            AVs.insert("", 0);
481:                        }
482:                        break;
483:                    }
484:                }
485:                if (in_rd_auto_class) {
486:                    AVs = s.getAVPair(RDM.A_SN_RDM_CLASS);
487:                    for (int i = 0; AVs != null && i <= AVs.getMaxIndex(); i++) {
488:                        String c = AVs.getValue(i);
489:                        if (c == null) {
490:                            continue;
491:                        }
492:                        if (c.compareToIgnoreCase(className) == 0) {
493:                            AVs.remove(i);
494:                            AVs.squeeze();
495:                            if (AVs.getMaxIndex() == 0) {
496:                                AVs.insert("", 0);
497:                            }
498:                            break;
499:                        }
500:                    }
501:                }
502:            }
503:
504:            private void appendValueToSOIF(SOIF s, String name, String value) {
505:                AVPair AVs = s.getAVPair(name);
506:                if (AVs != null) {
507:                    AVs.insert(value, AVs.getMaxIndex() + 1);
508:                } else {
509:                    s.insert(name, value);
510:                }
511:            }
512:
513:            private void addingAutoClassification(SOIF s, String className) {
514:                boolean in_class = false;
515:                boolean in_rd_auto_class = false;
516:                AVPair AVs = s.getAVPair(RDM.A_SN_RDM_CLASS);
517:                for (int i = 0; AVs != null && i <= AVs.getMaxIndex(); i++) {
518:                    String c = AVs.getValue(i);
519:                    if (c == null) {
520:                        continue;
521:                    }
522:                    if (c.compareToIgnoreCase(className) == 0) {
523:                        in_class = true;
524:                        break;
525:                    }
526:                }
527:                AVs = s.getAVPair(AutoclassifyConfig.NAME_CLASSIFIED);
528:                for (int i = 0; AVs != null && i <= AVs.getMaxIndex(); i++) {
529:                    String c = AVs.getValue(i);
530:                    if (c == null) {
531:                        continue;
532:                    }
533:                    if (c.compareToIgnoreCase(className) == 0) {
534:                        in_rd_auto_class = true;
535:                        break;
536:                    }
537:                }
538:                if (!in_class) {
539:                    if (in_rd_auto_class) {
540:                        /* manually removed, don't add */
541:                    } else {
542:                        /* need to add to both rd_auto_classification & classification */
543:                        appendValueToSOIF(s,
544:                                AutoclassifyConfig.NAME_CLASSIFIED, className);
545:                        appendValueToSOIF(s, RDM.A_SN_RDM_CLASS, className);
546:                    }
547:                }
548:            }
549:
550:            void getRemoveClassificationRDs(String dbName, String className)
551:                    throws java.lang.Exception {
552:                // will need a timestamp if the update was not done at end
553:                String query = "Classification = \"" + className + "\"";
554:                //Search s = new Search(query,RDM.A_SN_RDM_CLASS + "," + AutoclassifyConfig.NAME_CLASSIFIED,"",1,10000,"search", dbName, rdmServer, (ssoToken != null ? ssoToken.toString():"")) ;
555:                //s.doQuery();
556:                RemoteSearch search = new RemoteSearch(query,
557:                        RDM.A_SN_RDM_CLASS + ","
558:                                + AutoclassifyConfig.NAME_CLASSIFIED, "search",
559:                        dbName, rdmServer, user, password);
560:
561:                SOIFInputStream rs = search.getResult();
562:                SOIF soif;
563:                int count = 0;
564:                for (soif = rs.readSOIF(); soif != null; soif = rs.readSOIF(), count++) {
565:                    String urlStr = soif.getURL();
566:
567:                    SOIF rd = rdstore.getRD(urlStr);
568:                    if (rd != null) {
569:                        removeAutoClassification(rd, className);
570:                    } else {
571:                        removeAutoClassification(soif, className);
572:                        rdstore.putRD(soif);
573:                    }
574:                }
575:                print("(-" + count + ")");
576:            }
577:
578:            void getRDs(String dbName, String className, String rule,
579:                    Date since, Date till) throws java.lang.Exception {
580:                StringBuffer query = new StringBuffer("(" + rule + ")");
581:                if (since != null) {
582:                    query.append(" <and> RD-Last-Changed >\"");
583:                    query.append(AutoclassifyConfig.formatter.format(since));
584:                    query.append("\"");
585:                }
586:                if (till != null) {
587:                    query.append(" <and> RD-Last-Changed <=\"");
588:                    query.append(AutoclassifyConfig.formatter.format(till));
589:                    query.append("\"");
590:                }
591:                //Search s = new Search(query.toString(),RDM.A_SN_RDM_CLASS + "," + AutoclassifyConfig.NAME_CLASSIFIED,"",1,10000,"search", dbName, searchURLStr, (ssoToken != null ? ssoToken.toString():"")) ;
592:                RemoteSearch search = new RemoteSearch(query.toString(),
593:                        RDM.A_SN_RDM_CLASS + ","
594:                                + AutoclassifyConfig.NAME_CLASSIFIED, "search",
595:                        dbName, rdmServer, user, password);
596:                //s.doQuery();
597:                //print("(+" + s.getHitCount() + ")");
598:                SOIFInputStream rs = search.getResult();
599:                SOIF soif;
600:                int count = 0;
601:                for (soif = rs.readSOIF(); soif != null; soif = rs.readSOIF(), count++) {
602:                    String urlStr = soif.getURL();
603:
604:                    SOIF rd = rdstore.getRD(urlStr);
605:                    if (rd != null) {
606:                        addingAutoClassification(rd, className);
607:                    } else {
608:                        addingAutoClassification(soif, className);
609:                        rdstore.putRD(soif);
610:                    }
611:                }
612:                print("(+" + count + ")");
613:            }
614:
615:            static String[] split(String str, String deli) {
616:                StringTokenizer st = new StringTokenizer(str, deli);
617:                ArrayList list = new ArrayList();
618:                int index = 0;
619:                while (st.hasMoreTokens()) {
620:                    list.add(st.nextToken());
621:                }
622:                return (String[]) list.toArray(new String[0]);
623:            }
624:
625:            /** A function return a locale by a given String
626:             * in following format "Language_Country"
627:             * @param localStr The locale in a string form
628:             * @return locale represented by the given string
629:             */
630:            public static Locale stringToLocale(String localStr) {
631:                StringTokenizer st = new StringTokenizer(localStr, "_");
632:                String[] codes = split(localStr, "_");
633:                if (codes.length >= 2) {
634:                    return new Locale(codes[0], codes[1]);
635:                }
636:                return Locale.getDefault();
637:            }
638:
639:            /** Application levle log
640:             * @param msg Message to log
641:             */
642:            public static void log(String msg) {
643:            }
644:
645:            /** output message to stdout in utf-8 encoding
646:             * @param msg Message to print
647:             */
648:            public static void print(String msg) {
649:                try {
650:                    byte[] bytes = msg.getBytes("UTF-8");
651:                    System.out.write(bytes);
652:                } catch (Exception e) {
653:                    // ignore
654:                }
655:            }
656:
657:            /** output message to stdout in utf-8 encoding with tailing new line
658:             * @param msg String to print
659:             */
660:            public static void println(String msg) {
661:                print(msg);
662:                System.out.println();
663:            }
664:
665:            /** get string from given resource bundle.
666:             * @param key key for the value
667:             * @param rb resource bundle to use
668:             * @return return the string value, or key if it doesn't exist.
669:             */
670:            public static String getLocalizedString(String key,
671:                    ResourceBundle rb) {
672:                if (rb != null) {
673:                    try {
674:                        return rb.getString(key);
675:                    } catch (MissingResourceException e) {
676:                    }
677:                }
678:                return key;
679:            }
680:
681:            /** Main entry for Autoclassify
682:             * @param args
683:             * @throws Exception
684:             */
685:            public static void main(String[] args) {
686:                Autoclassify ac = null;
687:                String taxFilePath = null;
688:                String configFilePath = null;
689:                String backupTaxFilePath = null;
690:                String runSince = null;
691:                String serverUrl = null;
692:                String server_root = ".";
693:                String[] selectDBs = null;
694:                Date lastRun = null;
695:
696:                try {
697:                    // getting resource boundle
698:                    ResourceBundle rb = AutoclassifyConfig.getResourceBundle();
699:                    ResourceBundle UIrb = rb;
700:                    AutoclassifyContext context = new AutoclassifyContext();
701:                    context.setResourceBundle(UIrb);
702:
703:                    Getopt opt = new Getopt(args, "t:s:l:d:");
704:                    while (opt.optInd < args.length) {
705:                        char c = (char) opt.getopt();
706:                        switch (c) {
707:                        case 't':
708:                            runSince = opt.optArg;
709:                            break;
710:                        case 's':
711:                            serverUrl = opt.optArg;
712:                            break;
713:                        case 'l':
714:                            Locale UIlocale = stringToLocale(opt.optArg);
715:                            UIrb = ResourceBundle.getBundle(
716:                                    AutoclassifyConfig.RESOURCE_BUNDLE_FILE,
717:                                    UIlocale);
718:                            context.setResourceBundle(UIrb);
719:                            context.setUILocale(UIlocale);
720:                            break;
721:                        case 'd':
722:                            selectDBs = split(opt.optArg, ":");
723:                            break;
724:                        default:
725:                            println(getLocalizedString("usage", rb));
726:                            return;
727:                        }
728:
729:                    }
730:                    if (serverUrl == null) {
731:                        println(getLocalizedString("usage", rb));
732:                        return;
733:                    }
734:
735:                    if (runSince != null) {
736:                        lastRun = DateParser.parse(runSince);
737:                    }
738:                    SearchConfig.init(server_root + File.separator
739:                            + SearchConfig.CONFDIR + File.separator
740:                            + SearchConfig.SEARCH_CONF);
741:
742:                    ac = new Autoclassify(context, server_root, lastRun,
743:                            serverUrl);
744:                    String tempDBPath = SearchConfig
745:                            .getValue(AutoclassifyConfig.NAME_DBFILE);
746:                    if (tempDBPath == null) {
747:                        tempDBPath = server_root + File.separator + "tmp"
748:                                + File.separator
749:                                + AutoclassifyConfig.DEFAULT_DBFILE_NAME;
750:                    }
751:                    String rdInMemory = SearchConfig
752:                            .getValue(AutoclassifyConfig.NAME_HASHTABLE_SIZE);
753:                    int hashTableSize = AutoclassifyConfig.DEFAULT_HASHTABLE_SIZE;
754:                    if (rdInMemory != null) {
755:                        try {
756:                            hashTableSize = Integer.parseInt(rdInMemory);
757:                        } catch (Exception e) {
758:                            //ignor
759:                        }
760:                    }
761:                    println(ac.getLocalizedUIString("prompt_started"));
762:                    debugLogger.log(Level.INFO, "PSSH_CSPSACY0001",
763:                            getLocalizedString("prompt_started"));
764:
765:                    debugLogger
766:                            .log(
767:                                    Level.FINEST,
768:                                    "PSSH_CSPSACY0002",
769:                                    new Object[] {
770:                                            getLocalizedString("security_mode"),
771:                                            (ac.securityMode ? getLocalizedString("security_on")
772:                                                    : getLocalizedString("security_off")) });
773:                    String[] dbs = DBUtil.getDBStringArray(server_root); // get available database list
774:                    if (selectDBs == null) {
775:                        selectDBs = dbs;
776:                    }
777:                    for (int i = 0; i < selectDBs.length; i++) {
778:                        ac.doAutoClassify(selectDBs[i], tempDBPath,
779:                                hashTableSize);
780:                    }
781:                    println("");
782:                    println(ac.getLocalizedUIString("prompt_stopped"));
783:                    debugLogger.log(Level.INFO, "PSSH_CSPSACY0001",
784:                            getLocalizedString("prompt_stopped"));
785:
786:                } catch (Exception e) {
787:                    println(e.getMessage());
788:                    debugLogger.log(Level.FINEST, "PSSH_CSPSACY0001", e
789:                            .getMessage());
790:                    e.printStackTrace();
791:
792:                }
793:                if (ac != null) {
794:                    ac.shutdown();
795:                }
796:                System.exit(0);
797:            }
798:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.