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

📄 ubbexport.java

📁 jive 2.1.1 的源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	                // in the loop
	                if( firstTime ) {
	                    out.write("<MessageList>");
	                    firstTime = false;
	                }
	                if (messageCount % 100 == 0) {
	                    print(".");
	                }
	                //Increment message count
	                messageCount++;

                    out.write("<Message>");
                    writeMessageXML(out,subject,creationDate,messageLine);
                    out.write("</Message>");
	            }

	            // if firstTime is false, that means we did print out a beginning
	            // <MessageList>, so we need to close it here
	            if( !firstTime ) {
	                out.write("</MessageList>");
	            }

	            out.write("</Message>");
	            //out.write("</MessageList>");
	            out.write("</Thread>");

            messages.close();
            }
        }
        listIn.close();

        out.write("</ThreadList>");

        out.write("</Forum>");

        return messageCount;
    }

    public static int writeUserXML(File memberDir, Writer out) {
        int userCount = 0;
        try {
            out.write("<UserList>");
            File [] files = memberDir.listFiles();
            for (int i=0; i<files.length; i++) {
                if (files[i].isFile()) {
                    String filename = files[i].getName();
                    //We know that all user files should be 8 characters in
                    //length and that they'll end in .cgi. This is a bit
                    //"hackish" but should work with the UBB file format.
                    if (filename.length() == 12 && filename.endsWith(".cgi")) {
                        String [] data = fileToArray(files[i]);
                        // check for invalid user data (some user files might
                        // be blank
                        if( data.length > 0 ) {
                            out.write("<User>");
                            out.write("<Username>");
                            out.write(StringUtils.escapeForXML(data[0]));
                            out.write("</Username><Password>");
                            String passwordHash = StringUtils.hash(data[1]);
                            out.write(passwordHash);
                            boolean emailVisible = data[11].equals("yes");
                            out.write("</Password><Email visible=\"" + emailVisible + "\">");
                            out.write(StringUtils.escapeForXML(data[2]));
                            out.write("</Email>");
                            String userCreationDate
                                = dateFormatter.format(ubbFormatter.parse(data[10]));
                            out.write("<CreationDate>");
                            out.write(userCreationDate);
                            out.write("</CreationDate><ModifiedDate>");
                            out.write(userCreationDate);
                            out.write("</ModifiedDate>");


                            //All other ubb data is set as properties. They are:
                            //URL, Occupation, Location, TotalPosts, Status,
                            //Interests, DateRegistered, Signature, ICQnumber,
                            //AllowMassMail
                            //url
                            out.write("<PropertyList>");
                            if (data[3] != null && !data[3].equals("")) {
                                out.write("<Property name=\"url\" ");
                                out.write("value=\"" + StringUtils.escapeForXML(data[3]) + "\"/>");
                            }
                            //occupation
                            if (data[5] != null && !data[5].equals("") ) {
                                out.write("<Property name=\"occupation\" ");
                                out.write("value=\"" + StringUtils.escapeForXML(data[5]) + "\"/>");
                            }
                            //location
                            if (data[6] != null && !data[6].equals("")) {
                                out.write("<Property name=\"location\" ");
                                out.write("value=\"" + StringUtils.escapeForXML(data[6]) + "\"/>");
                            }
                            //Fields past this value are optional and may not
                            //show up as blank lines in the file.
                            //signature
                            if (data.length > 12 && data[12] != null && !data[12].equals("")) {
                                out.write("<Property name=\"signature\" ");
                                out.write("value=\"" + StringUtils.escapeForXML(data[12]) + "\"/>");
                            }
                            //ICQNumber
                            if (data.length > 13 && data[13] != null && !data[13].equals("")) {
                                out.write("<Property name=\"ICQNumber\" ");
                                out.write("value=\"" + StringUtils.escapeForXML(data[13]) + "\"/>");
                            }
                            //AllowsEmail
                            if (data.length > 14 && data[14] != null && !data[14].equals("")) {
                                out.write("<Property name=\"allowsMassEmail\" ");
                                out.write("value=\"" + data[14].equals("yes") + "\"/>");
                            }
                            out.write("</PropertyList>");

                            out.write("</User>");
                            userCount++;
                            if (userCount % 50 == 0) {
                                print(".");
                            }
                        }
                    }
                }
            }
            out.write("</UserList>");
        }
        catch(Exception e) {
            println(e.toString());
            e.printStackTrace();
        }
        return userCount;
    }

    public static void forumExport() {
        File ubbDir = getUbbDirectory();
        File ubbCGIDir = getUbbCGIDirectory();

        //Get forum info
        int forumCount = 0;
        File forumsFile = new File(ubbCGIDir, "forums.cgi");
        String [] forumData = fileToArray(forumsFile);
        forumCount = forumData.length;

        int forumChoice;
        boolean done = false;
        while (!done) {
            println(" ");
            println("Enter the number corresponding to the forum that you'd like to export.");
            for (int i=0; i<forumCount; i++) {
                FullStringTokenizer tokens = new FullStringTokenizer(forumData[i],"|");
                tokens.nextToken();
                String forumName = tokens.nextToken();
                for (int j=0; j < 6; j++) {
                    tokens.nextToken();
                }
                int forumID = Integer.parseInt(tokens.nextToken());
                println(" (" + (i+1) + ") Forum #" + forumID + " --  " + forumName);
            }
            print("> ");
            String response = readLine();
            println(" ");/*
            try {
                int choice = Integer.parseInt(response);
                switch (choice) {
                    case 1:
                        println("Starting data export...");
                        //Output data to file.
                        //Write data as UTF-8 so that extended chars turn out correctly.
                        try {
                            BufferedWriter out = new BufferedWriter(
                                new OutputStreamWriter(
                                    new FileOutputStream(xmlName),
                                    "UTF-8"
                                ),
                                262144
                            );

                            out.write("<?xml version=\"1.0\"?>");
                            out.write("<!DOCTYPE Jive SYSTEM \"jive.dtd\">");
                            out.write("<Jive version=\"" + XML_VERSION + "\" exportDate=\"" +
                                    jiveFormatter.format(new Date()) + "\">"
                            );

                            print("Exporting user data...");
                            int userCount = writeUserXML(memberDir, out);
                            out.flush();
                            println("\nFinished exporting " + userCount + " users.");

                            //Export all forums
                            for (int i=0; i<forumCount; i++) {
                                FullStringTokenizer tokens = new FullStringTokenizer(forumData[i],"|");
                                tokens.nextToken();
                                String forumName = tokens.nextToken();
                                for (int j=0; j < 6; j++) {
                                    tokens.nextToken();
                                }
                                int forumID = Integer.parseInt(tokens.nextToken());
                                print("Exporting \"" + forumName + "\"...");
                                File forumDir = new File(ubbDir, "Forum" + forumID);
                                int messageCount = writeForumXML(forumDir, forumID, out);
                                println("\nFinished exporting " + messageCount + " messages.");
                            }

                            out.write("</Jive>");
                            out.close();

                        }
                        catch(Exception e) {
                            e.printStackTrace();
                        }

                        done = true;
                        break;
                    case 2:
                        done = true;
                        break;
                     default:
                        println("ERROR - command not recognized. Please try again.");
                }
            }
            catch (NumberFormatException nfe) {
                println("ERROR - command not recognized. Please try again.");
            }
            */
        }
    }

    /**
     * Reads a text file and returns it as an array of Strings.
     */
    public static String [] fileToArray(File file) {
        try {
            BufferedReader in = new BufferedReader(new FileReader(file));
            String line = null;
            ArrayList buffer = new ArrayList();
            while ((line = in.readLine()) != null) {
                buffer.add(line);
            }
            String [] results = new String[buffer.size()];
            for (int i=0; i<results.length; i++) {
                results[i] = (String)buffer.get(i);
            }
            in.close();
            return results;
        }
        catch (Exception e) {
            e.printStackTrace();
            return new String [] { };
        }
    }

    public static void printInfo() {
        println("The UBB export tool will convert your UBB data into the Jive");
        println("XML format. You can choose to export all of your data, or only");
        println("select parts of it. Find updated versions of this tool on the");
        println("Jive website -- http://www.jivesoftware.com");
        println(" ");
        println("The two important pieces of information you'll need to know ");
        println("are the locations of your UBB (data) and UBBCGI (program) ");
        println("directories. Consult your UBB documentation if you are unsure");
        println("where they are.");
    }

    public static void println(String line) {
        System.out.println(line);
    }

    public static void print(String string) {
        System.out.print(string);
    }

    public static String readLine() {
        try {
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            return in.readLine();
        }
        catch (Exception e) {
            return "";
        }
    }

    /**
     *  Converts the HTML &lt;br&gt; and &lt;p&gt; tags into actual newline
     *  characters.
     */
    public static String convertHTMLToNewlines(String string) {
        string = StringUtils.replaceIgnoreCase(string, "<br>", "\n");
        return StringUtils.replaceIgnoreCase(string, "<p>", "\n\n");
    }
}

⌨️ 快捷键说明

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