dbdataexport.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 887 行 · 第 1/3 页
JAVA
887 行
/** * $RCSfile: DbDataExport.java,v $ * $Revision: 1.7 $ * $Date: 2002/07/03 00:48:03 $ * * Copyright (C) 1999-2001 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum.database;import java.util.*;import java.text.*;import java.io.*;import com.jivesoftware.forum.*;import com.jivesoftware.forum.util.*;import com.jivesoftware.util.*;/** * Exports Jive data. Note, currently watches are not exported. */public class DbDataExport { /** * Standard Jive XML date format. */ private static final String XML_DATE_FORMAT = DbDataImport.XML_DATE_FORMAT; /** * XML version */ private static final String XML_VERSION = DbDataImport.XML_VERSION; /** * A simple date formatter that will convert Date objects to the Jive * date format. For example: 1978/01/17 21:17:33.83 CST */ private static SimpleDateFormat dateFormatter = new SimpleDateFormat(XML_DATE_FORMAT); /** * Jive permission types */ private static int [] permTypes = new int [] { ForumPermissions.CATEGORY_ADMIN, ForumPermissions.CREATE_ATTACHMENT, ForumPermissions.CREATE_MESSAGE, ForumPermissions.CREATE_THREAD, ForumPermissions.FORUM_ADMIN, ForumPermissions.GROUP_ADMIN, ForumPermissions.MODERATE_MESSAGES, ForumPermissions.MODERATE_THREADS, ForumPermissions.READ_FORUM, ForumPermissions.SYSTEM_ADMIN, ForumPermissions.USER_ADMIN }; /** * Jive permission names */ private static String [] permNames = new String [] { "CATEGORY_ADMIN", "CREATE_ATTACHMENT", "CREATE_MESSAGE", "CREATE_THREAD", "FORUM_ADMIN", "GROUP_ADMIN", "MODERATE_MESSAGES", "MODERATE_THREADS", "READ_FORUM", "SYSTEM_ADMIN", "USER_ADMIN" }; private File dataPath = new File(JiveGlobals.getJiveHome() + File.separator + "data" + File.separator); private DbForumFactory factory = null; private static DbDataExport exporter = null; private boolean running = false; private boolean exportIDs = false; private boolean exportUsers = true; private boolean exportGroups = true; private boolean exportForums = true; private boolean exportPerms = true; private Map forumList; private File exportFile; public static SimpleDateFormat EXPORT_FILE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd-HHmm"); /** * Returns an instance the singleton instance of DbDataExport. * * @param factory a DbForumFactory object which will be used to get all * Jive objects. */ public static synchronized DbDataExport getInstance(DbForumFactory factory) { if (exporter == null) { exporter = new DbDataExport(factory); } return exporter; } /** * Private access only since this class is a singleton. */ private DbDataExport(DbForumFactory factory) { this.factory = factory; exportIDs = false; exportUsers = true; exportGroups = true; exportForums = true; exportPerms = true; forumList = new HashMap(); exportFile = new File(dataPath, "jive-" + EXPORT_FILE_DATE_FORMAT.format(new Date()) + ".xml"); this.running = false; } /** * Returns true if there is an export process currently running. * * @return true if an export is running, false otherwise. */ public boolean isRunning() { return running; } /** * Sets if IDs should be exported with each object. Since Jive maintains IDs * for each of its objects (ie, forum IDs, message IDs, user IDs), exporting * the IDs might be useful if you want to import your data again and have * same IDs associated with objects. Most forums link to their content * in the following manner: http://yoursite/jive/forum.jsp?forum=5. If * your data is exported with IDs then re-imported, that link will remain * valid. Otherwise, when Jive imports the data a new ID will be auto- * generated and may not be the same as the old ID.<p> * * By default, IDs will not be exported. * * @param exportIDs true to indicate that IDs should be exported with each * Jive object, false to not export IDs. */ public void setExportIDs(boolean exportIDs) { if (!running) { this.exportIDs = exportIDs; } } /** * Indicates if IDs will be exported. * * @return true if IDs will be exported with each object, false otherwise. */ public boolean canExportIDs() { return exportIDs; } /** * Sets whether or not users should be exported. Users will be exported * by default. * * @param exportUsers true to indicate that user objects should be exported, * false to not export. */ public void setExportUsers(boolean exportUsers) { if (!running) { this.exportUsers = exportUsers; } } /** * Indicates if users will be exported. * * @return true if users will be exported, false otherwise. */ public boolean canExportUsers() { return exportUsers; } /** * Sets whether or not groups will be exported. Groups will be exported * by default. * * @param exportGroups true to indicate that groups should be exported, * false to not export. */ public void setExportGroups(boolean exportGroups) { if (!running) { this.exportGroups = exportGroups; } } /** * Indicates if groups will be exported. * * @return true if groups will be exported, false otherwise. */ public boolean canExportGroups() { return exportGroups; } /** * Sets whether or not forums will be exported. Forums will be exported * by default. * * @param exportForums true to indicate that forums should be exported, * false to not export. */ public void setExportForums(boolean exportForums) { if (!running) { this.exportForums = exportForums; } } /** * Indicates if forums will be exported. * * @return true if forums will be exported, false otherwise. */ public boolean canExportForums() { return exportForums; } /** * Sets whether or not permissions will be exported. This includes both * global and per-forum permission settings. By default all permissions * are exported. Note, if you choose to not export forums, only the system * admin privledges will be exported. * * @param exportPerms true to indicate that all permissions should be * exported, false to not export. */ public void setExportPerms(boolean exportPerms) { if (!running) { this.exportPerms = exportPerms; } } /** * Indicates if all permissions (that includes global and per-forum * permissions) will be exported. * * @return true if all permissions will be exported, false otherwise. */ public boolean canExportPerms() { return exportPerms; } /** * Adds a forum to the list of exported forums. The export tool will only * export forums included in the forum list and if exporting forums is * allowed. * * @param forum the forum you wish to export. */ public void addExportedForum(Forum forum) { if (!running) { Long forumID = new Long(forum.getID()); forumList.put(forumID, forumID); } } /** * Returns the list of forums being exported. * * @return the list of forums being exported. */ public List getExportedForums() { return Collections.unmodifiableList(new java.util.LinkedList(forumList.values())); } /** * Sets the filename Jive will use to export forum data to. Note, only * letters, numbers, "-", "_" and "." are allowed in the name of the file. * If invalid characters are detected, an IllegalArgumentException will * be thrown. * * @param filename the name of the file Jive will export data to. */ public void setFilename(String filename) throws IllegalArgumentException { if (running) { return; } if (filename == null) { throw new IllegalArgumentException("Invalid filename"); } // Do a check on the name of the file:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?