⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ubbexport.java

📁 jive 2.1.1 的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/**
 * $RCSfile: UBBExport.java,v $
 * $Revision: 1.4 $
 * $Date: 2001/06/19 18:33:56 $
 *
 * Copyright (C) 1999-2001 CoolServlets Inc. All rights reserved.
 * ===================================================================
 * The Jive Software License, Version 1.0
 * (Derived from Apache Software License Version 1.1)
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        Jive Software (http://www.jivesoftware.com)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Jive", "Jive Software, and "CoolServlets" must not be used
 *    to endorse or promote products derived from this software without
 *    prior written permission. For written permission, please
 *    contact info@jivesoftware.com.
 *
 * 5. Products derived from this software may not be called "Jive",
 *    nor may "Jive" appear in their name, without prior written
 *    permission of CoolServlets Inc.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL COOLSERVLETS INC. OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ===================================================================
 */

package com.jivesoftware.forum.tool;

import java.io.*;
import java.util.*;
import java.text.*;

import com.jivesoftware.util.JulianDate;
import com.jivesoftware.util.StringUtils;
import com.jivesoftware.util.FullStringTokenizer;
import com.jivesoftware.util.UnicodeFilterWriter;

import org.apache.oro.text.*;
import org.apache.oro.text.perl.*;
import org.apache.oro.text.regex.*;

/**
 * A utility to export UBB data in the Jive XML format.
 */
public class UBBExport {

    /**
     * Standard Jive XML date format (don't modify this, as this format
     * is exptected in the import and export classes).
     */
    public static final String XML_DATE_FORMAT = "yyyy/MM/dd HH:mm:ss.SS z";
    /**
     * The version number of the tool.
     */
    public static final String TOOL_VERSION = "0.5";
    /**
     * The version number of the Jive XML format that the tool uses.
     */
    public static final String XML_VERSION = "1.0";

    /**
     * A simple date formatter that will convert Date objects to the Jive
     * date format. For example: 1978/11/15 12:00:00.00 PST
     */
    private static SimpleDateFormat dateFormatter =
        new SimpleDateFormat(XML_DATE_FORMAT);

    private static SimpleDateFormat fileDateFormatter =
        new SimpleDateFormat("yyyy-MM-dd");

    private static SimpleDateFormat ubbFormatter =
        new SimpleDateFormat("MM-dd-yy");

    private static SimpleDateFormat ubbThreadFormatter =
        new SimpleDateFormat("yyyyMMddHHmm");

    private static SimpleDateFormat ubbMessageDateFormatter =
        new SimpleDateFormat("MM-dd-yy hh:mm a");

    private static String ubbcgiDir = null;
    private static String ubbDir = null;
    private static String usersFile = "ubbUsers-" + fileDateFormatter.format(new Date()) + ".xml";
    private static String fullFile = "ubbData-" + fileDateFormatter.format(new Date()) + ".xml";

	private static final String[] HTMLToUBBCode = {
        // Images
        "s%<IMG SRC=\"(\\S+?)\".*?>%[IMG]$1[/IMG]%isg",
        "s%<IMG SRC=\"(\\S+?)\".*?ALT=\"(.*?)\".*?>%[IMG SRC=$1]$2[/IMG]%isg",
        // Links
        "s%<A HREF=\"mailto:(\\S+?)\".*?>(.+?)</A>%[EMAIL=$1]$2[/EMAIL]%isg",
        "s%<A HREF=mailto:(\\S+?).*?>(.+?)</A>%[EMAIL=$1]$2[/EMAIL]%isg",
        "s%<A HREF=\"(\\S+?)\".*?>(.+?)</A>%[URL=$1]$2[/URL]%isg",
        "s%<A HREF=(\\S+?).*?>(.+?)</A>%[URL=$1]$2[/URL]%isg",
        // Quotes
        "s%<BLOCKQUOTE><FONT.*?>.*?by (.+?):</FONT><HR>(.+?)<HR></BLOCKQUOTE>%[QUOTE SRC=$1]$2[/QUOTE]%isg",
        "s%<BLOCKQUOTE><FONT.*?>quote:</FONT><HR>(.+?)<HR></BLOCKQUOTE>%[QUOTE]$1[/QUOTE]%isg"
	};

    // Static compiled regexp patterns
    // So when a filter is created we don't have to recompile the regexp
    // Set to a capacity of 100 unique patterns, this should be enough
    // for most users.
    private static PatternCacheLRU regexp = new PatternCacheLRU(100);
    private static Perl5Util perl = new Perl5Util(regexp);

    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("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) 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:
                        forumExport();
                        break;
                    case 4:
                        printInfo();
                        break;
                    case 5:
                        System.exit(0);
                    default:
                        println("ERROR - command not recognized. Please try again.");
                }
            }
            catch (NumberFormatException nfe) {
                println("ERROR - command not recognized. Please try again.");
            }
        }
    }

    private static String toUBBCode(String str) {
		String filtered = str;
		for (int i = 0; i < HTMLToUBBCode.length; i++) {
		    filtered = perl.substitute(HTMLToUBBCode[i],filtered);
		}
        filtered = StringUtils.replaceIgnoreCase(filtered,"<b>","[b]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"</b>","[/b]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"<i>","[i]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"</i>","[/i]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"<ol>","[list=1]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"</ol>","[/list]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"<ul>","[list]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"</ul>","[/list]");
        filtered = StringUtils.replaceIgnoreCase(filtered,"<li>","[*]");
		return filtered;
    }

    /**
     * Leads user through the process of selecting the UBB directory.
     */
    public static File getUbbDirectory() {
        println(" ");
        println("Enter the path to your UBB directory. e.g. /home/ubb/ubb:");
        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();
        }
    }

    /**
     * Leads user through the process of selecting the UBBCGI directory.
     */
    public static File getUbbCGIDirectory() {
        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();
        }
    }

    /**
     * Do an export of all forum data.
     */
    public static void fullExport() {
        File ubbDir = getUbbDirectory();
        File ubbCGIDir = getUbbCGIDirectory();

        //Get member info
        int memberCount = 0;
        File memberDir = new File(ubbCGIDir, "Members");
        File memberTotalFile = new File(memberDir, "membertotal.cgi");
        String [] memberTotal = fileToArray(memberTotalFile);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -