1 5 6 package org.javabb.migration.phpbb; 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/javabb07?unicode=true"; 20 private static String phpbb_user = "root"; 21 private static String phpbb_pass = ""; 22 protected static String phpbb_prefix = "forumjf_"; 23 24 25 30 31 32 private static String javabb_url = "jdbc:postgresql://localhost/javabb"; 33 private static String javabb_user = "postgres"; 34 private static String javabb_pass = ""; 35 private static String javabb_driver = "org.postgresql.Driver"; 36 37 protected String sql = ""; 38 39 private static DateFormat df = new SimpleDateFormat ("yyyyMMddHHmmss"); 40 41 47 protected Connection getPhpBBConnection() throws ClassNotFoundException , SQLException { 48 Class.forName("com.mysql.jdbc.Driver"); 49 System.out.println("Retrieving phpBB connection"); 50 return DriverManager.getConnection(phpbb_url, phpbb_user, phpbb_pass); 51 } 52 53 59 protected Connection getJavaBBConnection() throws ClassNotFoundException , SQLException { 60 Class.forName(javabb_driver); 61 System.out.println("Retrieving javaBB connection"); 62 return DriverManager.getConnection(javabb_url, javabb_user, javabb_pass); 63 } 64 65 69 public abstract void convert() throws Exception ; 70 71 77 public String toJbbCode(String phpBBCode) { 78 phpBBCode = phpBBCode == null ? "": phpBBCode; 79 phpBBCode = HtmlUtils.htmlUnescape(phpBBCode); 80 String ret = phpBBCode.replaceAll( 81 "\\[(/)?(b|u|i|list|quote|code|img|url)(?::\\w+)?(=\"?[^\":]+\"?)?(:\\w)?(?::\\w+)?\\]", 82 "[$1$2$3]" 83 ); 84 return ret; 85 } 86 87 93 public String convertIP(String hexCode) { 94 95 if (hexCode.length() != 8) 96 return "127.0.0.1"; 97 98 StringBuffer ip = new StringBuffer (); 99 100 ip.append(Integer.parseInt(hexCode.substring(0,2), 16)); 101 ip.append("."); 102 ip.append(Integer.parseInt(hexCode.substring(2,4), 16)); 103 ip.append("."); 104 ip.append(Integer.parseInt(hexCode.substring(4,6), 16)); 105 ip.append("."); 106 ip.append(Integer.parseInt(hexCode.substring(6,8), 16)); 107 108 return ip.toString(); 109 } 110 111 private static final String JBB_TIMESTAMP_FORMAT = "yyyyMMddHHmmss"; 112 public String long2timestamp(long pre) { 113 if (df == null) 114 df = new SimpleDateFormat (JBB_TIMESTAMP_FORMAT); 115 116 return df.format(new Date (pre)); 117 } 118 119 public static void convertJbb_badwords() throws ClassNotFoundException , SQLException { 120 new Jbb_badwords().convert(); 121 } 122 123 public static void convertJbb_category() throws ClassNotFoundException , SQLException { 124 new Jbb_category().convert(); 125 } 126 127 public static void convertJbb_emoticon() throws ClassNotFoundException , SQLException { 128 new Jbb_emoticon().convert(); 129 } 130 131 public static void convertJbb_forum() throws ClassNotFoundException , SQLException { 132 new Jbb_forum().convert(); 133 } 134 135 public static void convertJbb_posts() throws ClassNotFoundException , SQLException { 136 new Jbb_posts().convert(); 137 } 138 139 public static void convertJbb_topics() throws ClassNotFoundException , SQLException { 140 new Jbb_topics().convert(); 141 } 142 143 public static void convertJbb_users() throws ClassNotFoundException , SQLException { 144 new Jbb_users().convert(); 145 } 146 } 147 | Popular Tags |