?? importjive.java
字號:
digester.addCallMethod("Jive/GroupList/Group/MemberList/Username", "addJiveGroupMember", 0);
/* For each Jive forum, create MVN Forum forum.
* -> Jive/ForumList/Forum/FilterList/Filter is not imported
* -> Jive/ForumList/Forum/PropertyList/Property is not imported
*/
digester.addObjectCreate("Jive/ForumList/Forum", JiveForumXML.class);
/* addJiveForum will be fired at the end of the <Forum> XML element. */
digester.addCallMethod("Jive/ForumList/Forum", "addJiveForum");
//todo Igor: check what this is about: digester.addSetProperties("Jive/ForumList/Forum", "id", "forumId");
digester.addCallMethod("Jive/ForumList/Forum/Name", "setForumName", 0);
digester.addCallMethod("Jive/ForumList/Forum/Description", "setForumDescription", 0);
digester.addCallMethod("Jive/ForumList/Forum/CreationDate", "setForumCreationDate", 0);
digester.addCallMethod("Jive/ForumList/Forum/ModifiedDate", "setForumModifiedDate", 0);
ImportJive.addMessage("All Jive/ForumList/Forum/FilterList/Filter will be ignored.");
ImportJive.addMessage("All Jive/ForumList/Forum/PropertyList/Property will be ignored.");
/* addJiveForumUser must first call addJiveForum to create this forum,
* since it's not yet created (didn't get to the end of the <Forum> XML element).
*/
digester.addCallMethod("Jive/ForumList/Forum/PermissionList/UserPermissionList/UserPermission", "addJiveForumUser", 3);
digester.addCallParam("Jive/ForumList/Forum/PermissionList/UserPermissionList/UserPermission", 0, "usertype");
digester.addCallParam("Jive/ForumList/Forum/PermissionList/UserPermissionList/UserPermission", 1, "username");
digester.addCallParam("Jive/ForumList/Forum/PermissionList/UserPermissionList/UserPermission", 2, "permission");
/* addJiveForumGroup must first call addJiveForum to create this forum,
* since it's not yet created (didn't get to the end of the <Forum> XML element).
*/
digester.addCallMethod("Jive/ForumList/Forum/PermissionList/GroupPermissionList/GroupPermission", "addJiveForumGroup", 2);
digester.addCallParam("Jive/ForumList/Forum/PermissionList/GroupPermissionList/GroupPermission", 0, "groupname");
digester.addCallParam("Jive/ForumList/Forum/PermissionList/GroupPermissionList/GroupPermission", 1, "permission");
/* For each Jive thread, create MVN Forum thread.
* -> Jive/ForumList/Forum/ThreadList/Thread/PropertyList/Property is not imported
*/
digester.addObjectCreate("Jive/ForumList/Forum/ThreadList/Thread", JiveThreadXML.class);
//digester.addSetTop("Jive/ForumList/Forum/ThreadList/Thread", "setParentForum");
SetParentRule threadParentRule = new SetParentRule("setParentForum");
digester.addRule("Jive/ForumList/Forum/ThreadList/Thread", threadParentRule);
/* addJiveThread will be fired at the end of the <Thread> XML element. */
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread", "addJiveThread");
//todo Igor: check what this is about: digester.addSetProperties("Jive/ForumList/Forum/ThreadList/Thread", "id", "threadId");
/* this doesn't work here since it will be fired only after we start processing first message:
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/Message/Username", "setUsername", 0);
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/Message/Subject", "setTopic", 0);
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/Message/Body", "setBody", 0); */
/* We consider the thread is created by the author of the first message. But, when
* we come to <Message> element, we'll already have JiveMessageXML on top of Digester
* stack. Thus, here we'll handle thread parameters we know now, and other parameters
* will be known and given to JiveThreadXML object when we come to processing the
* first Message of the thread (which always exists).
* This applies to rules matching Message/Username, Message/Subject and Message/Body.
* They will not only set corresponding JiveMessageXML fields, but also parent
* JiveThreadXML fields if it is the first message in a thread.
* One more problem is about thread watches - these Watch elements are parsed before
* the first message. But, to enter thread watch into the database, we need to have
* already created thread. And that's not possible before we process the first message.
* So, all thread watches will be remembered in JiveThreadXML, and when we process the
* first message, we'll then setup all the fields of JiveThreadXML, create the thread,
* and then add all thread watches we remembered.
*/
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/CreationDate", "setCreationDate", 0);
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/ModifiedDate", "setModifiedDate", 0);
ImportJive.addMessage("All Jive/ForumList/Forum/ThreadList/Thread/PropertyList/Property will be ignored.");
digester.addCallMethod("Jive/ForumList/Forum/ThreadList/Thread/WatchList/Watch", "addJiveThreadWatch", 3);
digester.addCallParam("Jive/ForumList/Forum/ThreadList/Thread/WatchList/Watch", 0, "type");
digester.addCallParam("Jive/ForumList/Forum/ThreadList/Thread/WatchList/Watch", 1, "expirable");
digester.addCallParam("Jive/ForumList/Forum/ThreadList/Thread/WatchList/Watch/Username", 2);
/* For each Jive message, create MVN Forum post.
* -> * /Message/PropertyList/Property is not imported
*/
digester.addObjectCreate("*/Message", JiveMessageXML.class);
//digester.addSetTop("*/Message", "setParentThreadOrPost");
SetParentRule messageParentRule = new SetParentRule("setParentThreadOrPost");
digester.addRule("*/Message", messageParentRule);
/* addJiveMessage will be fired at the end of the <Message> XML element. */
digester.addCallMethod("*/Message", "addJiveMessage");
//todo Igor: check what this is about: digester.addSetProperties("*/Message", "id", "postId");
digester.addCallMethod("*/Message/Subject", "setPostSubject", 0);
digester.addCallMethod("*/Message/Body", "setPostBody", 0);
digester.addCallMethod("*/Message/Username", "setPostUsername", 0);
digester.addCallMethod("*/Message/CreationDate", "setPostCreationDate", 0);
digester.addCallMethod("*/Message/ModifiedDate", "setPostModifiedDate", 0);
ImportJive.addMessage("All */Message/PropertyList/Property will be ignored.");
/* At this point, on top of stack we have only the root JiveXML object */
digester.addCallMethod("Jive/UserPermissionList/UserPermission", "addJiveUserPermission", 3);
digester.addCallParam("Jive/UserPermissionList/UserPermission", 0, "usertype");
digester.addCallParam("Jive/UserPermissionList/UserPermission", 1, "username");
digester.addCallParam("Jive/UserPermissionList/UserPermission", 2, "permission");
/* addJiveForumGroup must first call addJiveForum to create this forum,
* since it's not yet created (didn't get to the end of the <Forum> XML element).
*/
digester.addCallMethod("Jive/GroupPermissionList/GroupPermission", "addJiveGroupPermission", 2);
digester.addCallParam("Jive/GroupPermissionList/GroupPermission", 0, "groupname");
digester.addCallParam("Jive/GroupPermissionList/GroupPermission", 1, "permission");
/* ==================================================================
* This was the main part of file - XML processing rules for Digester
* ==================================================================
*/
digester.parse(inputFile);
//now add some default permissions for guests and registered members (if they don't exist yet)
try {
for (int j=0; j<JiveXML.addDefaultPermissionsToGuests.length; j++) {
try {
JiveXML.addGuestMemberPermission(Integer.toString(JiveXML.addDefaultPermissionsToGuests[j]));
} catch (DuplicateKeyException e) {
/* Ignore if we doubled some permissions.
* Because we convert each Jive permission into the list of
* MVN Forum permissions (can be more than one), some permissions
* could be generated twice, or more times.
*/
}
}
for (int j=0; j<JiveXML.addDefaultPermissionsToMembers.length; j++) {
try {
JiveXML.addRegisteredMembersGroupPermission(Integer.toString(JiveXML.addDefaultPermissionsToMembers[j]));
} catch (DuplicateKeyException e) {
/* Ignore if we doubled some permissions.
* Because we convert each Jive permission into the list of
* MVN Forum permissions (can be more than one), some permissions
* could be generated twice, or more times.
*/
}
}
} catch (DatabaseException e) {
log.error("Database error while adding default permissions.", e);
throw new ImportException("Error while adding default permissions to guests and registered members.", e);
} catch (CreateException e) {
log.error("Create data error while adding default permissions.", e);
throw new ImportException("Error while adding default permissions to guests and registered members.", e);
} catch (ForeignKeyNotFoundException e) {
log.error("Foreign key not found error while adding default permissions.", e);
throw new ImportException("Error while adding default permissions to guests and registered members.", e);
}
if (JiveXML.foundAdminUser) {
ImportJive.addImportantMessage("IMPORTANT: Jive user \""+JiveXML.adminName+
"\" kept all his data (including password), and has SYSTEM_ADMIN "+
"permissions - even if he didn't have them in Jive!!!");
} else {
ImportJive.addImportantMessage("SYSTEM_ADMIN user with a name \""+
JiveXML.adminName+"\" and password \"admin\" was created. "+
"For your security, you should first change that password.");
}
}
/**
* Adds <code>message</code> to the output stream that was setup in
* {@link #importXml(File, HttpServletRequest, HttpServletResponse, int, String, Calendar, String, boolean, Vector, int)}.
* <br/>This method was made public to be available to Jive XML processing classes.
*
* @param message Message to be written to output.
* @see com.mvnforum.admin.ImportWebHelper#addMessage(java.lang.String)
*
*/
public static void addMessage(String message) {
ImportWebHelper.addMessage(message);
}
/**
* Adds important (bold) <code>message</code> to the output stream that was setup in
* {@link #importXml(File, HttpServletRequest, HttpServletResponse, int, String, Calendar, String, boolean, Vector, int)}.
* <br/>This method was made public to be available to Jive XML processing classes.
*
* @param message Message to be written to output.
* @see com.mvnforum.admin.ImportWebHelper#addImportantMessage(java.lang.String)
*
*/
public static void addImportantMessage(String message) {
ImportWebHelper.addImportantMessage(message);
}
public static void createDefaultGuestMember() throws DuplicateKeyException,
ObjectNotFoundException, CreateException, DatabaseException, ForeignKeyNotFoundException {
if ((JiveXML.guestName==null) || (JiveXML.guestName.length()<=0)) {
JiveXML.guestName=MVNForumConfig.getDefaultGuestName();
}
//addImportantMessage("Adding \""+JiveXML.guestName+"\" virtual guest member.");
ImportWebHelper.createDefaultGuestMember(JiveXML.guestName);
}
public static void createDefaultAdminMember() throws ObjectNotFoundException,
CreateException, DatabaseException, DuplicateKeyException, ForeignKeyNotFoundException {
if ((JiveXML.adminName==null) || (JiveXML.adminName.length()<=0)) {
JiveXML.adminName="Admin";
}
//addImportantMessage("Adding \""+JiveXML.adminName+"\" member with SYSTEM_ADMIN permissions.");
ImportWebHelper.createDefaultAdminMember(JiveXML.adminName);
}
public static void createDefaultRegisteredMembersGroup() throws CreateException,
DuplicateKeyException, ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
//addMessage("Adding default group of \"Registered Members\".");
ImportWebHelper.createDefaultRegisteredMembersGroup(JiveXML.adminName);
}
public static void createDefaultRanks() throws CreateException,
DuplicateKeyException, ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
//addMessage("Adding default rank titles.");
ImportWebHelper.createDefaultRanks();
}
public static void createRootCategory() throws CreateException,
DuplicateKeyException, ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
/* Each MVN category can have any number of it's own forums.
* Also, MVN supports (sub)categories in each category.
* Jive's forums are the same as MVN's forums, but Jive doesn't have categories at all.
* That means that all Jive's forums will be translated into MVN's forums that
* have to be put down into the one and only MVN category I must create here.
*/
addMessage("Adding category \""+JiveXML.rootCategoryName+"\" where all Jive forums will be stored in.");
CategoryXML categoryXML=new CategoryXML();
categoryXML.addCategory(JiveXML.rootCategoryName, JiveXML.rootCategoryDesc,
null /*categoryCreationDate*/, null /*categoryModifiedDate*/,
null /*categoryOrder*/, null /*categoryOption*/, null /*categoryStatus*/);
JiveXML.rootCategoryID=categoryXML.getCategoryID();
addImportantMessage("All ForumPasswords will be set to \""+JiveXML.allForumsPassword+"\".");
}
private static void handleSuccess(HttpServletRequest request) {
addSuccessMessage();
endHtml();
}
//it's possible I called this method with e==null
private static void handleFatalError(String message, Exception e,
boolean clearIfError, HttpServletRequest request)
throws ImportException {
if (e==null) log.error(message);
else log.error(message, e);
if ((e==null) || (e.getMessage()==null)) addErrorMessage(message);
else addErrorMessage(message+"<br/>Cause: "+e.getMessage());
//try to clear the database and rollback to valid empty state with admin member
ImportWebHelper.addFinalErrorHandling(request, clearIfError);
endHtml();
if (e==null) throw new ImportException(message);
else throw new ImportException(message, e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -