1 5 6 package org.javabb.migration.betweendbs; 7 import java.sql.Connection ; 8 import java.sql.DriverManager ; 9 import java.sql.SQLException ; 10 import java.text.DateFormat ; 11 import java.text.SimpleDateFormat ; 12 import java.util.Date ; 13 14 import org.springframework.web.util.HtmlUtils; 15 16 public abstract class Jbb_Convert { 17 18 private static String phpbb_url = "jdbc:mysql://localhost:3306/javabb3?unicode=true"; 20 private static String phpbb_user = "root"; 21 private static String phpbb_pass = "root"; 22 23 24 private static String javabb_url = "jdbc:postgresql://localhost/javabb"; 25 private static String javabb_user = "postgres"; 26 private static String javabb_pass = "postgres"; 27 private static String javabb_driver = "org.postgresql.Driver"; 28 29 protected String sql = ""; 30 31 private static DateFormat df = new SimpleDateFormat ("yyyyMMddHHmmss"); 32 33 34 protected Connection getDbOrigin() throws ClassNotFoundException , SQLException { 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 getDbDest() throws ClassNotFoundException , SQLException { 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 51 public abstract void convert() throws Exception ; 52 53 59 public String toJbbCode(String phpBBCode) { 60 phpBBCode = phpBBCode == null ? "": phpBBCode; 61 phpBBCode = HtmlUtils.htmlUnescape(phpBBCode); 62 String 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 75 public String convertIP(String hexCode) { 76 77 if (hexCode.length() != 8) 78 return "127.0.0.1"; 79 80 StringBuffer ip = new StringBuffer (); 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 JBB_TIMESTAMP_FORMAT = "yyyyMMddHHmmss"; 94 public String long2timestamp(long pre) { 95 if (df == null) 96 df = new SimpleDateFormat (JBB_TIMESTAMP_FORMAT); 97 98 return df.format(new Date (pre)); 99 } 100 101 public static void convertJbb_badwords() throws ClassNotFoundException , SQLException { 102 new Jbb_badwords().convert(); 103 } 104 105 public static void convertJbb_category() throws ClassNotFoundException , SQLException { 106 new Jbb_category().convert(); 107 } 108 109 public static void convertJbb_emoticon() throws ClassNotFoundException , SQLException { 110 new Jbb_emoticon().convert(); 111 } 112 113 public static void convertJbb_forum() throws ClassNotFoundException , SQLException { 114 new Jbb_forum().convert(); 115 } 116 117 public static void convertJbb_posts() throws ClassNotFoundException , SQLException { 118 new Jbb_posts().convert(); 119 } 120 121 public static void convertJbb_topics() throws ClassNotFoundException , SQLException { 122 new Jbb_topics().convert(); 123 } 124 125 public static void convertJbb_users() throws ClassNotFoundException , SQLException { 126 new Jbb_users().convert(); 127 } 128 129 public static void convertJbb_post_text() throws ClassNotFoundException , SQLException { 130 new Jbb_post_text().convert(); 131 } 132 } 133 | Popular Tags |