KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mvnforum > phpbb2mvnforum > PHPBBToMvnForum


1 package org.mvnforum.phpbb2mvnforum;
2 import java.io.File JavaDoc;
3 import java.io.FileOutputStream JavaDoc;
4 import java.io.PrintStream JavaDoc;
5 import java.sql.*;
6
7 import net.myvietnam.mvncore.exception.CreateException;
8 import net.myvietnam.mvncore.exception.DatabaseException;
9 import net.myvietnam.mvncore.exception.DuplicateKeyException;
10 import net.myvietnam.mvncore.exception.ForeignKeyNotFoundException;
11 import net.myvietnam.mvncore.exception.ObjectNotFoundException;
12
13 import org.mvnforum.util.DBUtils;
14 import org.mvnforum.util.Phpbb2MvnforumConfig;
15
16
17 //==============================================================================
18
// The JavaReference.com Software License, Version 1.0
19
// Copyright (c) 2002-2005 JavaReference.com. All rights reserved.
20
//
21
//
22
// Redistribution and use in source and binary forms, with or without
23
// modification, are permitted provided that the following conditions
24
// are met:
25
//
26
// 1. Redistributions of source code must retain the above copyright notice,
27
// this list of conditions and the following disclaimer.
28
//
29
// 2. Redistributions in binary form must reproduce the above copyright notice,
30
// this list of conditions and the following disclaimer in the documentation
31
// and/or other materials provided with the distribution.
32
//
33
// 3. The end-user documentation included with the redistribution, if any, must
34
// include the following acknowlegement:
35
//
36
// "This product includes software developed by the Javareference.com
37
// (http://www.javareference.com/)."
38
//
39
// Alternately, this acknowlegement may appear in the software itself, if and
40
// wherever such third-party acknowlegements normally appear.
41
//
42
// 4. The names "JavaReference" and "Javareference.com", must not be used to
43
// endorse or promote products derived from this software without prior written
44
// permission. For written permission, please contact webmaster@javareference.com.
45
//
46
// 5. Products derived from this software may not be called "Javareference" nor may
47
// "Javareference" appear in their names without prior written permission of
48
// Javareference.com.
49
//
50
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
51
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
52
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
53
// JAVAREFERENCE.COM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
54
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
56
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
57
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
58
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
59
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60
//
61
//================================================================================
62
// Software from this site consists of contributions made by various individuals
63
// on behalf of Javareference.com. For more information on Javareference.com,
64
// please see http://www.javareference.com
65
//================================================================================
66

67
68 /**
69  * @author anandh
70  */

71 public class PHPBBToMvnForum {
72     Connection phpbb_c = null;
73     Connection mvnforum_c = null;
74     PrintStream JavaDoc sqlout = null;
75
76
77     /**
78      * @param phphost
79      * @param phpdb
80      * @param phpuser
81      * @param phppass
82      * @param mvnhost
83      * @param mvndb
84      * @param mvnuser
85      * @param mvnpass
86      * @param ostream
87      */

88     public PHPBBToMvnForum(String JavaDoc phphost, String JavaDoc phpdb, String JavaDoc phpuser, String JavaDoc phppass,
89                            String JavaDoc mvnhost, String JavaDoc mvndb, String JavaDoc mvnuser, String JavaDoc mvnpass,
90                            PrintStream JavaDoc ostream) throws Exception JavaDoc {
91         
92         if(ostream == null)
93             throw new Exception JavaDoc("Outputstream is null.");
94         
95         String JavaDoc phpurl = "jdbc:mysql://" + phphost + "/" + phpdb;
96         String JavaDoc mvnurl = "jdbc:mysql://" + mvnhost + "/" + mvndb;
97     
98         try
99         {
100             Class.forName("com.mysql.jdbc.Driver").newInstance();
101         }
102         catch (Exception JavaDoc E)
103         {
104             System.err.println("Unable to load driver.");
105             E.printStackTrace();
106         }
107          
108        phpbb_c = DriverManager.getConnection(phpurl, phpuser, phppass);
109        
110        if((mvnhost == null) || (mvndb == null) ||(mvnuser == null) ||(mvnpass == null))
111        {
112             mvnforum_c = null;
113        }
114        else
115        {
116             mvnforum_c = DriverManager.getConnection(mvnurl, mvnuser, mvnpass);
117        }
118        
119        sqlout = ostream;
120     }
121         
122     /**
123      * Performs Conversion of phpbb database to mvnforum database
124      *
125      *
126      */

127     public void convert() {
128         try
129         {
130             System.out.println("Conversion started...");
131             //Migrator.migrateusers(sqlout, int gender);
132
Migrator.migratecategories(sqlout);
133             Migrator.migrateforums(sqlout);
134             //Migrator.migrateposts(sqlout);
135
//Migrator.migratethreads(sqlout);
136
//Migrator.migrateprivatemessages(sqlout);
137
DBUtils.writeXmlFile(DBUtils.getDomDocument(), Phpbb2MvnforumConfig.EXPORT_XML);
138             System.out.println("Conversion complete...");
139         }
140         catch (SQLException E)
141         {
142             System.out.println("Exception during conversion...");
143             System.out.println("SQLException: " + E.getMessage());
144             System.out.println("SQLState: " + E.getSQLState());
145             System.out.println("VendorError: " + E.getErrorCode());
146         } catch (DatabaseException e) {
147             // TODO Auto-generated catch block
148
e.printStackTrace();
149         } catch (CreateException e) {
150             // TODO Auto-generated catch block
151
e.printStackTrace();
152         } catch (DuplicateKeyException e) {
153             // TODO Auto-generated catch block
154
e.printStackTrace();
155         } catch (ForeignKeyNotFoundException e) {
156             // TODO Auto-generated catch block
157
e.printStackTrace();
158         } catch (ObjectNotFoundException e) {
159             // TODO Auto-generated catch block
160
e.printStackTrace();
161         }
162
163         
164         try
165         {
166             phpbb_c.close();
167             if(mvnforum_c != null)
168             {
169                 mvnforum_c.close();
170             }
171         }
172         catch (SQLException e)
173         {
174             e.printStackTrace();
175         }
176         
177         sqlout.close();
178     }
179
180     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
181         
182         String JavaDoc phphost = Phpbb2MvnforumConfig.PHP_HOST;
183         String JavaDoc phpdb = Phpbb2MvnforumConfig.PHP_DB;
184         String JavaDoc phpuser = Phpbb2MvnforumConfig.PHP_USER;
185         String JavaDoc phppass = Phpbb2MvnforumConfig.PHP_PASS;
186         String JavaDoc mvnhost = Phpbb2MvnforumConfig.MVN_HOST;
187         String JavaDoc mvndb = Phpbb2MvnforumConfig.MVN_DB;
188         String JavaDoc mvnuser = Phpbb2MvnforumConfig.MVN_USER;
189         String JavaDoc mvnpass = Phpbb2MvnforumConfig.MVN_PASS;
190         String JavaDoc filename = Phpbb2MvnforumConfig.FILE_NAME;
191         
192         PrintStream JavaDoc ostream = System.out;
193         
194         if(filename != null)
195         {
196             File JavaDoc f = new File JavaDoc(filename);
197             FileOutputStream JavaDoc fout = new FileOutputStream JavaDoc(f);
198             ostream = new PrintStream JavaDoc(fout, true);
199         }
200                 
201         (new PHPBBToMvnForum(phphost, phpdb, phpuser, phppass,
202                             mvnhost, mvndb, mvnuser, mvnpass,
203                             ostream)).convert();
204     }
205 }
206
Popular Tags