ubbexport.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 1,595 行 · 第 1/5 页
JAVA
1,595 行
} println("createDate " + createDate); } return modifiedDate; } private static Date getForumModifiedDate( File forumDir, int forumNumber ) throws IOException { println( "Getting modified date for forum " + forumNumber + "..." ); // The modified date of this forum. Initialize it to now, although it // will be changed when the correct modified date is found. Date forumModifiedDate = new Date(); // Load the forumX.threads file. This file is a listing of threads ordered // from oldest to newest modified. File threadList = new File(forumDir, "forum" + forumNumber + ".threads"); // Convert that file listing to an array of strings String[] lines = fileToArray(threadList); // Loop through the array starting at the end (because the most recent // thread is at the end. We loop because we want to find a valid thread // listing and the file may contain invalid thread data. for( int i=lines.length-1; i>=0; i-- ) { // Tokenize the string FullStringTokenizer tokens = new FullStringTokenizer(lines[i],"|^|"); // The Julian date is the first token: try { double jDate = Double.parseDouble(tokens.nextToken()); //forumModifiedDate = (JulianDate.computeGregorianDate(jDate)).getTime(); forumModifiedDate = (new JulianDate(jDate)).getGregorianDate().getTime(); tokens.nextToken();tokens.nextToken();tokens.nextToken();tokens.nextToken(); //Date d = ubbThreadFormatter.parse(tokens.nextToken()); //getGregorianDate(jDate); //System.err.println("date was: " + forumModifiedDate.toString()); //System.err.println("time diff: " + // (forumModifiedDate.getTime() - d.getTime()) ); // At this point, we've found the correct date, so break out // of this loop break; } catch( Exception e ) {e.printStackTrace();} } System.out.println("forum mod date: " + forumNumber + " " + forumModifiedDate.toString()); return forumModifiedDate; /* BufferedReader listIn = new BufferedReader(new FileReader(threadList)); String threadLine = null; int threadCount = 0; while ((threadLine = listIn.readLine()) != null) { if( (threadCount++ % 50) == 0 ) { print("."); } FullStringTokenizer tokens = new FullStringTokenizer(threadLine, "|^|"); String jDate = tokens.nextToken(); // convert julian date: double julianDate = 0.0; try { julianDate = Double.parseDouble(jDate); } catch(Exception e) {} Date threadModDate = (JulianDate.computeGregorianDate(julianDate)).getTime(); String threadID = tokens.nextToken(); File threadFile = new File( forumDir, threadID+".cgi" ); if( threadFile.exists() ) { BufferedReader messages = new BufferedReader( new FileReader(threadFile) ); messages.readLine(); // skip the first line String message = null; while( (message=messages.readLine()) != null ) { FullStringTokenizer mTokens = new FullStringTokenizer(message,"||"); mTokens.nextToken(); mTokens.nextToken(); mTokens.nextToken(); String date = mTokens.nextToken(); date += " " + mTokens.nextToken(); Date d = new Date(0L); try { d = ubbMessageDateFormatter.parse(date); } catch( ParseException e ) { System.err.println("(getForumModifiedDate): unparseable date: " + date); } if( d.getTime() > modifiedDate.getTime() ) { modifiedDate = d; } } messages.close(); } System.err.println("\n"); System.err.println("for this thread,"); System.err.println("julian date: " + threadModDate.toString() ); System.err.println("old date: " + modifiedDate.toString() ); } listIn.close(); return modifiedDate; */ } private static Date getGregorianDate( double julianDate ) { double l = julianDate + 68569.0; double n = ( 4.0 * l ) / 146097.0; l = l - ( ((146097.0*n)+3.0)/4.0); double i = (4000.0 * (l+1.0))/1461001.0; l = l - ((1461.0*i)/4.0) + 31.0; double j = (80.0 * l) / 2447.0; double d = l - ((2447.0*j)/80.0); l = j/11.0; double m = j + 2.0 - (12.0*l); double y = 100.0 * (n-49.0) + i + l; System.err.println("\n"); System.err.println("l: " + l); System.err.println("n: " + n); System.err.println("i: " + i); System.err.println("j: " + j); System.err.println("d: " + d); System.err.println("m: " + m); System.err.println("y: " + y); return new Date();// l = jd + 68569// n = ( 4 * l ) / 146097// l = l - ( 146097 * n + 3 ) / 4// i = ( 4000 * ( l + 1 ) ) / 1461001// l = l - ( 1461 * i ) / 4 + 31// j = ( 80 * l ) / 2447// d = l - ( 2447 * j ) / 80// l = j / 11// m = j + 2 - ( 12 * l )// y = 100 * ( n - 49 ) + i + l } private static Date getThreadCreationDate( File forumDir, String threadID ) throws IOException { Date creationDate = null; File messageList = new File(forumDir, threadID+".cgi"); if( messageList.exists() ) { BufferedReader messages = new BufferedReader( new FileReader(messageList) ); // skip the first line messages.readLine(); String rootMessage = messages.readLine(); if( rootMessage == null ) { return null; } FullStringTokenizer mTokens = new FullStringTokenizer(rootMessage,"||"); // skip the first 3 tokens mTokens.nextToken(); mTokens.nextToken(); mTokens.nextToken(); String date = mTokens.nextToken(); date += " " + mTokens.nextToken(); try { creationDate = ubbMessageDateFormatter.parse(date); } catch( ParseException e ) { System.err.println("(getThreadCreationDate): unparseable date: " + date); } messages.close(); } return creationDate; } /** * Leads user through the process of selecting the UBBCGI directory. */ public static File getUbbCGIDirectory() { // Get user input for cgi directory println(" "); println("Enter the path to your UBBCGI directory. e.g. /home/ubb/ubbcgi:"); if (ubbcgiDir != null) { print("[" + ubbcgiDir + "] "); } print("> "); String path = readLine(); if (path.equals("") && ubbcgiDir != null) { path = ubbcgiDir; } println(" "); File ubbcgi = new File(path); //Test to see if this is actually the UBBCGI dir. We simply check if //there is a sub-dir called Members. if (ubbcgi.exists() && ubbcgi.isDirectory()) { File memberDir = new File(ubbcgi, "Members"); if (memberDir.exists() && memberDir.isDirectory()) { //Got all the way here, so set the current path as the default ubbcgiDir = path; return ubbcgi; } else { println("ERROR - the directory you entered exists but does not\n" + "seem to be the UBBCGI directory. Try again."); return getUbbCGIDirectory(); } } else { println("ERROR - the directory you entered was not found. Try again."); return getUbbCGIDirectory(); } } /** * Leads user through the process of selecting the UBB directory. */ public static File getUbbDirectory() { // Get user UBB directory println(" "); println("Enter the path to your UBB directory. e.g. /home/ubb/ubb or D:\\blah\\blah :"); if (ubbDir != null) { print("[" + ubbDir + "] "); } print("> "); String path = readLine(); if (path.equals("") && ubbDir != null) { path = ubbDir; } println(" "); File ubb = new File(path); //Test to see if this is actually the UBB dir. if (ubb.exists() && ubb.isDirectory()) { //Our test for being the UBB dir is that there is a subdirectory //and that at least one file ends with CGI. boolean isSubDir = false; boolean isCGI = false; File [] files = ubb.listFiles(); for (int i=0; i<files.length; i++) { if (files[i].isDirectory()) { isSubDir = true; } if (files[i].getName().endsWith(".cgi")) { isCGI = true; } } if (isSubDir && isCGI) { //Got all the way here, so set the current path as the default ubbDir = path; return ubb; } else { println("ERROR - the directory you entered exists but does not\n" + "seem to be the UBB directory. Try again."); return getUbbDirectory(); } } else { println("ERROR - the directory you entered was not found. Try again."); return getUbbDirectory(); } } public static void main(String [] args) throws IOException { println("\n"); println(" Jive UBB Export Tool " + TOOL_VERSION); println(" Copyright (c) 2001 CoolServlets Inc."); //Start main loop while (true) { println(" "); println("You are using UBB Version " + UBB_VERSION); println("Enter the number of the command you'd like to perform:"); println(" (1) Export all data from a UBB installation."); println(" (2) Export users data from a UBB installation."); println(" (3) Export a single forum from a UBB installation."); println(" (4) Learn more about this program."); println(" (5) Change UBB Version. "); println(" (6) Exit application."); print("> "); String response = readLine(); println(" "); try { int choice = Integer.parseInt(response); switch (choice) { case 1: fullExport(); break; case 2: userExport(); break; case 3: // Doesnt support UBB5 if (UBB_VERSION == 6) { forumExport(); } else { println("This option is only supported under UBB 6"); } break; case 4: printInfo(); break; case 5: changeVersion(); break; case 6: System.exit(0); default: println("ERROR - command not recognized. Please try again."); } } catch (NumberFormatException nfe) { println("ERROR - command not recognized. Please try again."); } } } public static void print(String string) { System.out.print(string); } public static void printInfo() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?