?? importjive.java
字號(hào):
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/jive/ImportJive.java,v 1.4 2004/06/27 01:20:40 skoehler Exp $
* $Author: skoehler $
* $Revision: 1.4 $
* $Date: 2004/06/27 01:20:40 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding mvnForum MUST remain intact
* in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the
* footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Igor Manic imanic@users.sourceforge.net
*/
package com.mvnforum.admin.importexport.jive;
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.digester.Digester;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;
import com.mvnforum.MVNForumConfig;
import com.mvnforum.admin.CategoryXML;
import com.mvnforum.admin.ImportWebHelper;
import com.mvnforum.admin.importexport.SetParentRule;
import net.myvietnam.mvncore.exception.*;
/**
* @author <a href="mailto:imanic@users.sourceforge.net">Igor Manic</a>
* @version $Revision: 1.4 $, $Date: 2004/06/27 01:20:40 $
* <br/>
* <code>ImportJive</code> class encapsulates processing
* of Jive's XMLs, and imports all the data into MVN Forum database.
* For details see {@link #importXml(File, HttpServletRequest, HttpServletResponse, int, String, Calendar, String, boolean, Vector, int)}
* <br/>
* This class cannot be instantiated.
*/
public class ImportJive extends ImportWebHelper {
/** Message log. */
private static Log log = LogFactory.getLog(ImportJive.class);
/** Cannot instantiate. */
private ImportJive() {
}
// =================================================================
// ===================== MAIN PUBLIC METHODS =======================
// =================================================================
/**
* This method performs processing of Jive's XML backup file <code>importFile</code>
* and imports the data into the MVN Forum system. It clears the database
* and files, does neccessary setup (including startup of message output),
* and calls {@link #processXml(File, Calendar)} to do actual processing.<br/>
*
* @param importFile Jive XML file to be imported.
* @param request Current session's <code>HttpServletRequest</code> object.
* @param response Current session's <code>HttpServletResponse</code> object.
* @param logonMemberID MemberID of user who is logged in, and who initiated import process.
* @param logonMemberName MemberName of user who is logged in, and who initiated import process.
* @param importTime The moment when import process was started.
* @param importIP From this IP address admin requested import.
* @param clearIfError Should it clear/reset the database in case of error.
* @param otherFieldValues Vector of name/value pairs of other form fields (like
* <code>RootCategory</code>, <code>ForumPasswords</code>)
* @param messageLevel What messages should be written to output during the process.
* For details see {@link com.mvnforum.MVNForumConstant#MESSAGE_LEVEL_ALL_MESSAGES},
* {@link com.mvnforum.MVNForumConfig#MESSAGE_LEVEL_IMPORTANT_MESSAGES} and
* {@link com.mvnforum.MVNForumConfig#MESSAGE_LEVEL_ONLY_ERRORS}.
*
* @exception ImportException If there is an error during the process. See {@link net.myvietnam.mvncore.exception.ImportException}.
*
*/
public static void importXml(File importFile,
HttpServletRequest request, HttpServletResponse response,
int logonMemberID, String logonMemberName,
Calendar importTime, String importIP, boolean clearIfError,
Vector otherFieldValues, int messageLevel)
throws ImportException {
for (int i=0; i<otherFieldValues.size()-1; i+=2) {
String name=(String)otherFieldValues.get(i);
String value=(String)otherFieldValues.get(i+1);
if (name!=null) {
if (name.equals("ForumPasswords")) JiveXML.allForumsPassword=value;
else if (name.equals("RootCategory")) JiveXML.rootCategoryName=value;
else if (name.equals("RootCategoryDesc")) JiveXML.rootCategoryDesc=value;
else if (name.equals("JiveGuest")) JiveXML.guestName=value;
else if (name.equals("JiveAdmin")) JiveXML.adminName=value;
//else ignore
}
}
try {
response.setContentType("text/html; charset=utf-8");
setOutputHtmlWriter(response.getWriter());
setMessageOutputLevel(messageLevel);
startHtml(request);
clearDatabase();
clearFiles(request.getSession().getServletContext());
} catch (DatabaseException e) {
handleFatalError("Database error while clearing previous contents.",
e, clearIfError, request);
} catch (IOException e) {
handleFatalError("I/O error while clearing previous contents.",
e, clearIfError, request);
}
try {
processXml(importFile, importTime);
handleSuccess(request);
} catch (ImportException e) {
handleFatalError(e.getMessage(), e.getException(),
clearIfError, request);
} catch (IOException e) {
handleFatalError("I/O error while reading XML file.",
e, clearIfError, request);
} catch (SAXException e) {
if (e.getException()==null) {
handleFatalError("Error while parsing uploaded XML file.",
e, clearIfError, request);
} else {
handleFatalError("Error while parsing uploaded XML file.",
e.getException(), clearIfError, request);
}
} finally {
/* Don't delete this XML since this method was maybe started from the
* command-line, which means this file is not temporary (uploaded)
* //if ((importFile!=null) && (importFile.exists())) importFile.delete();
* Anyway, if neccessary, this XML will be deleted in the caller (WebHandler)
*/
}
}
// =================================================================
// ================== MAIN PROCESSING XML METHOD ===================
// =================================================================
/**
* This method performs actual processing of Jive's XML file <code>inputFile</code>
* and imports the data into the MVN Forum system.<br/>
* Don't use this method directly. Instead, you should use
* {@link #importXml(File, HttpServletRequest, HttpServletResponse, int, String, Calendar, String, boolean, Vector, int)}.
*
* @param inputFile Jive XML file to be imported.
* @param importTime The moment when import process was started.
*
* @exception IOException If there is an I/O error while processing XML file.
* @exception SAXException If there is an error while parsing XML file.
* @exception ImportException If there is an error while adding some default values to database.
*
*/
protected static void processXml(File inputFile, Calendar importTime)
throws IOException, SAXException, ImportException {
addImportantMessage("Starting migration of data...");
//SAXParserFactory factory=SAXParserFactory.newInstance();
Digester digester=new Digester();
//should try new Digester(SAXParser), or Digester(XMLReader)
digester.setValidating(true);
digester.setNamespaceAware(true);
/* =================================================================
* This is the main part of file - XML processing rules for Digester
* =================================================================
*
* note: since SetTopRule is firing the desired method at the end of
* the XML element matching the pattern, I had to implement my own
* SetParentRule which does exactly the same thing (calls desired
* child's method with a parent object as an argument). The difference
* is that it is firing the "setParent" method at the beginning of the
* corresponding XML element, thus leaving me the chance to, for example,
* create messages as they arrive from the XML parser, not waiting the
* end of the whole document (!!!), because I can't add a message, unless
* I already added it's parent messages, thread, forum and category.
*/
/* First, I'll create root object of class JiveXML.
* It's constructor will create default contents of the database, including
* admin member (with MemberID=1, MemberName=JiveXML.adminName, MemberPassword="admin").
* Later, if I find Jive's admin, I'll just rewrite this default's admin data.
* JiveXML constructor will also create a root category,
* to which I am going to put all forums from Jive.
*/
digester.addObjectCreate("Jive", JiveXML.class);
digester.addSetProperties("Jive", "xmlversion", "jiveXmlVersion");
digester.addSetProperties("Jive", "exportDate", "jiveExportDate");
/* For each Jive user, create MVN Forum member. */
digester.addObjectCreate("Jive/UserList/User", JiveUserXML.class);
//todo Igor: check what this is about: digester.addSetProperties("Jive/UserList/User", "id", "userId");
digester.addCallMethod("Jive/UserList/User", "addJiveUser", 9);
digester.addCallParam("Jive/UserList/User/Username", 0);
digester.addCallParam("Jive/UserList/User/Password", 1);
digester.addCallParam("Jive/UserList/User/Email", 2);
digester.addCallParam("Jive/UserList/User/Email", 3, "visible");
digester.addCallParam("Jive/UserList/User/Name", 4);
digester.addCallParam("Jive/UserList/User/Name", 5, "visible");
digester.addCallParam("Jive/UserList/User/CreationDate", 6);
digester.addCallParam("Jive/UserList/User/ModifiedDate", 7);
digester.addCallParam("Jive/UserList/User/RewardPoints", 8);
ImportJive.addMessage("All Jive/UserList/User/PropertyList/Property will be ignored.");
/* For each Jive group, create MVN Forum group.
* -> Jive/GroupList/Group/PropertyList/Property is not imported
* -> Jive/GroupList/Group/AdministratorList/Username - only the
* first one will be imported (as GroupOwner)
*/
digester.addObjectCreate("Jive/GroupList/Group", JiveGroupXML.class);
/* addJiveGroup will be fired at the end of the <Group> XML element. */
digester.addCallMethod("Jive/GroupList/Group", "addJiveGroup");
//todo Igor: check what this is about: digester.addSetProperties("Jive/GroupList/Group", "id", "groupId");
digester.addCallMethod("Jive/GroupList/Group/Name", "setGroupName", 0);
digester.addCallMethod("Jive/GroupList/Group/Description", "setGroupDescription", 0);
digester.addCallMethod("Jive/GroupList/Group/CreationDate", "setGroupCreationDate", 0);
digester.addCallMethod("Jive/GroupList/Group/ModifiedDate", "setGroupModifiedDate", 0);
digester.addCallMethod("Jive/GroupList/Group/AdministratorList/Username", "setGroupOwnerName", 0);
ImportJive.addMessage("All Jive/GroupList/Group/PropertyList/Property will be ignored.");
ImportJive.addMessage("All Jive/GroupList/Group/AdministratorList/Username will be ignored, except for the first one (to become GroupOwner).");
/* addJiveGroupMember must first call addJiveGroup to create this group,
* since it's not yet created (didn't get to the end of the <Group> XML element).
*/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -