Source Code Cross Referenced for LuceneCommandLineReindexer.java in  » Forum » JForum-2.1.8 » net » jforum » tools » search » 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 » Forum » JForum 2.1.8 » net.jforum.tools.search 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.jforum.tools.search;
002:
003:        import jargs.gnu.CmdLineParser;
004:
005:        import java.text.ParseException;
006:        import java.text.SimpleDateFormat;
007:        import java.util.Date;
008:
009:        import net.jforum.ConfigLoader;
010:        import net.jforum.ForumStartup;
011:        import net.jforum.search.LuceneReindexArgs;
012:        import net.jforum.search.LuceneReindexer;
013:        import net.jforum.search.LuceneSettings;
014:        import net.jforum.search.SearchFacade;
015:        import net.jforum.util.preferences.ConfigKeys;
016:        import net.jforum.util.preferences.SystemGlobals;
017:
018:        import org.apache.commons.lang.StringUtils;
019:        import org.apache.log4j.xml.DOMConfigurator;
020:
021:        /**
022:         * @author Rafael Steil
023:         * @version $Id: LuceneCommandLineReindexer.java,v 1.1 2007/09/01 15:10:32 rafaelsteil Exp $
024:         */
025:        public class LuceneCommandLineReindexer {
026:            private LuceneReindexArgs reindexerArgs;
027:            private boolean recreate;
028:            private String path;
029:
030:            public static void main(String[] args) {
031:                LuceneCommandLineReindexer reindexer = new LuceneCommandLineReindexer();
032:                reindexer.init(args);
033:
034:                System.out.println("*** INITIALIZING \n");
035:                System.out
036:                        .println("** At any time, press CTRL+C to stop the process \n");
037:
038:                reindexer.start();
039:
040:                System.out.println("*** FINISHED ");
041:            }
042:
043:            private void start() {
044:                LuceneReindexer reindexer = new LuceneReindexer(
045:                        (LuceneSettings) SystemGlobals
046:                                .getObjectValue(ConfigKeys.LUCENE_SETTINGS),
047:                        this .reindexerArgs, this .recreate);
048:
049:                reindexer.startProcess();
050:            }
051:
052:            private void init(String[] args) {
053:                this .parseCmdArgs(args);
054:
055:                DOMConfigurator.configure(this .path + "/WEB-INF/log4j.xml");
056:
057:                ConfigLoader.startSystemglobals(this .path);
058:
059:                SystemGlobals.loadQueries(SystemGlobals
060:                        .getValue(ConfigKeys.SQL_QUERIES_GENERIC));
061:                SystemGlobals.loadQueries(SystemGlobals
062:                        .getValue(ConfigKeys.SQL_QUERIES_DRIVER));
063:
064:                ConfigLoader.createLoginAuthenticator();
065:                ConfigLoader.loadDaoImplementation();
066:
067:                SearchFacade.init();
068:
069:                ForumStartup.startDatabase();
070:            }
071:
072:            private void parseCmdArgs(String[] args) {
073:                StringBuffer description = new StringBuffer(512);
074:                description
075:                        .append("\n*** Going to reindex using the following options: \n");
076:
077:                CmdLineParser parser = new CmdLineParser();
078:
079:                CmdLineParser.Option recreateOption = parser
080:                        .addBooleanOption("recreateIndex");
081:                CmdLineParser.Option typeOption = parser
082:                        .addStringOption("type");
083:                CmdLineParser.Option pathOption = parser
084:                        .addStringOption("path");
085:                CmdLineParser.Option firstPostIdOption = parser
086:                        .addIntegerOption("firstPostId");
087:                CmdLineParser.Option lastPostIdOption = parser
088:                        .addIntegerOption("lastPostId");
089:                CmdLineParser.Option fromDateOption = parser
090:                        .addStringOption("fromDate");
091:                CmdLineParser.Option toDateOption = parser
092:                        .addStringOption("toDate");
093:                CmdLineParser.Option avoidDuplicatedOption = parser
094:                        .addBooleanOption("avoidDuplicatedRecords");
095:
096:                try {
097:                    parser.parse(args);
098:                } catch (CmdLineParser.OptionException e) {
099:                    System.out.println(e.getMessage());
100:                    this .printUsage();
101:                }
102:
103:                if (parser.getRemainingArgs().length > 0) {
104:                    this .printUsage();
105:                }
106:
107:                // Type
108:                String type = (String) parser.getOptionValue(typeOption);
109:
110:                if (StringUtils.isEmpty(type)
111:                        || (!type.equals("date") && !type.equals("message"))) {
112:                    System.out
113:                            .println("*** --type should be either date or message");
114:                    this .printUsage();
115:                }
116:
117:                description.append("\t-> Searching by ").append(type).append(
118:                        '\n');
119:
120:                // Path
121:                this .path = (String) parser.getOptionValue(pathOption);
122:
123:                if (StringUtils.isEmpty(this .path)) {
124:                    System.out
125:                            .println("*** --path is a required option. It should point to the root directory where JForum is installed");
126:                    this .printUsage();
127:                }
128:
129:                description.append("\t->App path: ").append(path).append('\n');
130:
131:                // FirstPostId and LastPostId
132:                int firstPostId = ((Integer) parser.getOptionValue(
133:                        firstPostIdOption, new Integer(0))).intValue();
134:                int lastPostId = ((Integer) parser.getOptionValue(
135:                        lastPostIdOption, new Integer(0))).intValue();
136:
137:                if ("message".equals(type)) {
138:                    if (firstPostId == 0 || lastPostId == 0
139:                            || lastPostId <= firstPostId) {
140:                        System.out
141:                                .println("*** --firstPostId and --lastPostId are required fields when --type=message. "
142:                                        + "Also, --lastPostId should be greater than --firstPostId");
143:                        this .printUsage();
144:                    }
145:
146:                    description.append("\t-> From Post #").append(firstPostId)
147:                            .append(" to Post #").append(lastPostId).append(
148:                                    '\n');
149:                }
150:
151:                // FromDate and ToDate
152:                Date fromDate = null;
153:                Date toDate = null;
154:
155:                if ("date".equals(type)) {
156:                    fromDate = this .parseDate((String) parser
157:                            .getOptionValue(fromDateOption));
158:                    toDate = this .parseDate((String) parser
159:                            .getOptionValue(toDateOption));
160:
161:                    if (fromDate == null || toDate == null) {
162:                        System.out
163:                                .println("*** --fromDate and --toDate are required fields when --type=date");
164:                        this .printUsage();
165:                    }
166:
167:                    description.append("\t-> From date ").append(fromDate)
168:                            .append(" to ").append(toDate).append('\n');
169:                }
170:
171:                // Recreate
172:                this .recreate = ((Boolean) parser.getOptionValue(
173:                        recreateOption, Boolean.FALSE)).booleanValue();
174:                description.append("\t->Recreate the index? ").append(
175:                        this .recreate ? "Yes" : "No").append('\n');
176:
177:                // AvoidDuplicatedRecords
178:                boolean avoidDuplicated = ((Boolean) parser.getOptionValue(
179:                        avoidDuplicatedOption, Boolean.FALSE)).booleanValue();
180:                description.append("\t->Avoid duplicated records? ").append(
181:                        avoidDuplicated ? "Yes" : "No").append('\n');
182:
183:                this .reindexerArgs = new LuceneReindexArgs(fromDate, toDate,
184:                        firstPostId, lastPostId, avoidDuplicated, "date"
185:                                .equals(type) ? LuceneReindexArgs.TYPE_DATE
186:                                : LuceneReindexArgs.TYPE_MESSAGE);
187:
188:                System.out.println(description);
189:            }
190:
191:            private Date parseDate(String s) {
192:                Date date = null;
193:
194:                if (!StringUtils.isEmpty(s)) {
195:                    try {
196:                        date = new SimpleDateFormat("dd/MM/yyyy").parse(s);
197:                    } catch (ParseException e) {
198:                    }
199:                }
200:
201:                return date;
202:            }
203:
204:            private void printUsage() {
205:                System.out.println("\nUsage: LuceneCommandLineReindexer \n"
206:                        + " --path full_path_to_JForum_root_directory \n"
207:                        + " --type {date|message} \n"
208:                        + " --firstPostId a_id \n" + " --lastPostId a_id \n"
209:                        + " --fromDate dd/MM/yyyy \n"
210:                        + " --toDate dd/MM/yyyy \n" + " [--recreateIndex]\n"
211:                        + " [--avoidDuplicatedRecords]");
212:                System.exit(1);
213:            }
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.