KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > migration > betweendbs > Jbb_Convert


1 /**
2  * Script de migração phpBB -> JavaBB
3  * @author Lucas Teixeira - lucas@javabb.org
4  */

5
6 package org.javabb.migration.betweendbs;
7 import java.sql.Connection JavaDoc;
8 import java.sql.DriverManager JavaDoc;
9 import java.sql.SQLException JavaDoc;
10 import java.text.DateFormat JavaDoc;
11 import java.text.SimpleDateFormat JavaDoc;
12 import java.util.Date JavaDoc;
13
14 import org.springframework.web.util.HtmlUtils;
15
16 public abstract class Jbb_Convert {
17     
18     //TODO Get all this references from an external resource
19
private static String JavaDoc phpbb_url = "jdbc:mysql://localhost:3306/javabb3?unicode=true";
20     private static String JavaDoc phpbb_user = "root";
21     private static String JavaDoc phpbb_pass = "root";
22     
23     /* POSTGRESQL */
24     private static String JavaDoc javabb_url = "jdbc:postgresql://localhost/javabb";
25     private static String JavaDoc javabb_user = "postgres";
26     private static String JavaDoc javabb_pass = "postgres";
27     private static String JavaDoc javabb_driver = "org.postgresql.Driver";
28     
29     protected String JavaDoc sql = "";
30         
31     private static DateFormat JavaDoc df = new SimpleDateFormat JavaDoc("yyyyMMddHHmmss");
32         
33
34     protected Connection JavaDoc getDbOrigin() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
35         Class.forName(javabb_driver);
36         System.out.println("Retrieving javaBB connection");
37         return DriverManager.getConnection(javabb_url, javabb_user, javabb_pass);
38     }
39
40
41     protected Connection JavaDoc getDbDest() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
42         Class.forName("com.mysql.jdbc.Driver");
43         System.out.println("Retrieving phpBB connection");
44         return DriverManager.getConnection(phpbb_url, phpbb_user, phpbb_pass);
45     }
46     
47     /**
48      * Convert the table data
49      * @return
50      */

51     public abstract void convert() throws Exception JavaDoc;
52     
53     /**
54      * Convert the hashed bbcode from phpbb to an clean bbcode to javaBB
55      * @param phpBBCode the dirty bbcode
56      * @return the bbcode w/out hashes
57      * @author Ronald Tetsuo Miura - ronald.tetsuo@gmail.com
58      */

59     public String JavaDoc toJbbCode(String JavaDoc phpBBCode) {
60         phpBBCode = phpBBCode == null ? "": phpBBCode;
61         phpBBCode = HtmlUtils.htmlUnescape(phpBBCode);
62         String JavaDoc ret = phpBBCode.replaceAll(
63                         "\\[(/)?(b|u|i|list|quote|code|img|url)(?::\\w+)?(=\"?[^\":]+\"?)?(:\\w)?(?::\\w+)?\\]",
64                         "[$1$2$3]"
65                      );
66         return ret;
67     }
68     
69     /**
70      * Convert the hashed ip from phpbb to an clean ip
71      * @param hexCode the phpbb ip representation
72      * @return the ip well formatted
73      * @author Flávio Bianchi - flavio@javafree.com.br
74      */

75     public String JavaDoc convertIP(String JavaDoc hexCode) {
76         
77         if (hexCode.length() != 8)
78             return "127.0.0.1";
79         
80         StringBuffer JavaDoc ip = new StringBuffer JavaDoc();
81         
82         ip.append(Integer.parseInt(hexCode.substring(0,2), 16));
83         ip.append(".");
84         ip.append(Integer.parseInt(hexCode.substring(2,4), 16));
85         ip.append(".");
86         ip.append(Integer.parseInt(hexCode.substring(4,6), 16));
87         ip.append(".");
88         ip.append(Integer.parseInt(hexCode.substring(6,8), 16));
89         
90         return ip.toString();
91     }
92     
93     private static final String JavaDoc JBB_TIMESTAMP_FORMAT = "yyyyMMddHHmmss";
94     public String JavaDoc long2timestamp(long pre) {
95         if (df == null)
96             df = new SimpleDateFormat JavaDoc(JBB_TIMESTAMP_FORMAT);
97         
98         return df.format(new Date JavaDoc(pre));
99     }
100     
101     public static void convertJbb_badwords() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
102         new Jbb_badwords().convert();
103     }
104     
105     public static void convertJbb_category() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
106         new Jbb_category().convert();
107     }
108     
109     public static void convertJbb_emoticon() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
110         new Jbb_emoticon().convert();
111     }
112     
113     public static void convertJbb_forum() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
114         new Jbb_forum().convert();
115     }
116     
117     public static void convertJbb_posts() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
118         new Jbb_posts().convert();
119     }
120     
121     public static void convertJbb_topics() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
122         new Jbb_topics().convert();
123     }
124     
125     public static void convertJbb_users() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
126         new Jbb_users().convert();
127     }
128     
129     public static void convertJbb_post_text() throws ClassNotFoundException JavaDoc, SQLException JavaDoc {
130         new Jbb_post_text().convert();
131     }
132 }
133
Popular Tags