001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/PHPBBToMvnForum.java,v 1.14 2007/01/15 10:27:35 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.14 $
005: * $Date: 2007/01/15 10:27:35 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author:
039: */
040: package org.mvnforum.phpbb2mvnforum;
041:
042: import java.io.File;
043: import java.io.FileOutputStream;
044: import java.io.PrintStream;
045: import java.sql.*;
046:
047: import net.myvietnam.mvncore.exception.CreateException;
048: import net.myvietnam.mvncore.exception.DatabaseException;
049: import net.myvietnam.mvncore.exception.DuplicateKeyException;
050: import net.myvietnam.mvncore.exception.ForeignKeyNotFoundException;
051: import net.myvietnam.mvncore.exception.ObjectNotFoundException;
052:
053: import org.mvnforum.util.DBUtils;
054: import org.mvnforum.util.Phpbb2MvnforumConfig;
055:
056: //==============================================================================
057: // The JavaReference.com Software License, Version 1.0
058: // Copyright (c) 2002-2005 JavaReference.com. All rights reserved.
059: //
060: //
061: // Redistribution and use in source and binary forms, with or without
062: // modification, are permitted provided that the following conditions
063: // are met:
064: //
065: // 1. Redistributions of source code must retain the above copyright notice,
066: // this list of conditions and the following disclaimer.
067: //
068: // 2. Redistributions in binary form must reproduce the above copyright notice,
069: // this list of conditions and the following disclaimer in the documentation
070: // and/or other materials provided with the distribution.
071: //
072: // 3. The end-user documentation included with the redistribution, if any, must
073: // include the following acknowlegement:
074: //
075: // "This product includes software developed by the Javareference.com
076: // (http://www.javareference.com/)."
077: //
078: // Alternately, this acknowlegement may appear in the software itself, if and
079: // wherever such third-party acknowlegements normally appear.
080: //
081: // 4. The names "JavaReference" and "Javareference.com", must not be used to
082: // endorse or promote products derived from this software without prior written
083: // permission. For written permission, please contact webmaster@javareference.com.
084: //
085: // 5. Products derived from this software may not be called "Javareference" nor may
086: // "Javareference" appear in their names without prior written permission of
087: // Javareference.com.
088: //
089: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
090: // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
091: // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
092: // JAVAREFERENCE.COM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
093: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
094: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
095: // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
096: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
097: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
098: // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
099: //
100: //================================================================================
101: // Software from this site consists of contributions made by various individuals
102: // on behalf of Javareference.com. For more information on Javareference.com,
103: // please see http://www.javareference.com
104: //================================================================================
105:
106: /**
107: * @author anandh
108: */
109: public class PHPBBToMvnForum {
110:
111: Connection phpbb_c = null;
112:
113: Connection mvnforum_c = null;
114:
115: PrintStream sqlout = null;
116:
117: /**
118: * @param phphost
119: * @param phpdb
120: * @param phpuser
121: * @param phppass
122: * @param mvnhost
123: * @param mvndb
124: * @param mvnuser
125: * @param mvnpass
126: * @param ostream
127: */
128: public PHPBBToMvnForum(String phphost, String phpdb,
129: String phpuser, String phppass, String mvnhost,
130: String mvndb, String mvnuser, String mvnpass,
131: PrintStream ostream) throws Exception {
132:
133: if (ostream == null) {
134: throw new IllegalArgumentException("Outputstream is null.");
135: }
136:
137: String phpurl = "jdbc:mysql://" + phphost + "/" + phpdb;
138: String mvnurl = "jdbc:mysql://" + mvnhost + "/" + mvndb;
139:
140: try {
141: Class.forName("com.mysql.jdbc.Driver").newInstance();
142: } catch (Exception e) {
143: System.err.println("Unable to load driver.");
144: e.printStackTrace();
145: }
146:
147: phpbb_c = DriverManager.getConnection(phpurl, phpuser, phppass);
148:
149: if ((mvnhost == null) || (mvndb == null) || (mvnuser == null)
150: || (mvnpass == null)) {
151: mvnforum_c = null;
152: } else {
153: mvnforum_c = DriverManager.getConnection(mvnurl, mvnuser,
154: mvnpass);
155: }
156:
157: sqlout = ostream;
158: }
159:
160: /**
161: * Performs Conversion of phpbb database to mvnforum database
162: */
163: public void convert() {
164: try {
165: System.out.println("Conversion started...");
166: //Migrator.migrateusers(sqlout, int gender);
167: Migrator.migrateCategories(sqlout);
168: Migrator.migrateForums(sqlout);
169: //Migrator.migrateposts(sqlout);
170: //Migrator.migratethreads(sqlout);
171: //Migrator.migrateprivatemessages(sqlout);
172: DBUtils.writeXmlFile(DBUtils.getDomDocument(),
173: Phpbb2MvnforumConfig.EXPORT_XML);
174: System.out.println("Conversion complete...");
175: } catch (SQLException e) {
176: System.out.println("Exception during conversion...");
177: System.out.println("SQLException: " + e.getMessage());
178: System.out.println("SQLState: " + e.getSQLState());
179: System.out.println("VendorError: " + e.getErrorCode());
180: } catch (DatabaseException e) {
181: e.printStackTrace();
182: } catch (CreateException e) {
183: e.printStackTrace();
184: } catch (DuplicateKeyException e) {
185: e.printStackTrace();
186: } catch (ForeignKeyNotFoundException e) {
187: e.printStackTrace();
188: } catch (ObjectNotFoundException e) {
189: e.printStackTrace();
190: }
191:
192: try {
193: phpbb_c.close();
194: if (mvnforum_c != null) {
195: mvnforum_c.close();
196: }
197: } catch (SQLException e) {
198: e.printStackTrace();
199: }
200:
201: sqlout.close();
202: }
203:
204: public static void main(String[] args) {
205:
206: try {
207: String phphost = Phpbb2MvnforumConfig.PHP_HOST;
208: String phpdb = Phpbb2MvnforumConfig.PHP_DB;
209: String phpuser = Phpbb2MvnforumConfig.PHP_USER;
210: String phppass = Phpbb2MvnforumConfig.PHP_PASS;
211: String mvnhost = Phpbb2MvnforumConfig.MVN_HOST;
212: String mvndb = Phpbb2MvnforumConfig.MVN_DB;
213: String mvnuser = Phpbb2MvnforumConfig.MVN_USER;
214: String mvnpass = Phpbb2MvnforumConfig.MVN_PASS;
215: String filename = Phpbb2MvnforumConfig.FILE_NAME;
216:
217: Class.forName("com.mysql.jdbc.Driver");
218:
219: PrintStream ostream = System.out;
220:
221: if (filename != null) {
222: File f = new File(filename);
223: FileOutputStream fout = new FileOutputStream(f);
224: ostream = new PrintStream(fout, true);
225: }
226:
227: PHPBBToMvnForum phpbb2mvnforum = new PHPBBToMvnForum(
228: phphost, phpdb, phpuser, phppass, mvnhost, mvndb,
229: mvnuser, mvnpass, ostream);
230: phpbb2mvnforum.convert();
231: } catch (Exception e) {
232: e.printStackTrace();
233: }
234: }
235: }
|