upgrade.jsp
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· JSP 代码 · 共 883 行 · 第 1/3 页
JSP
883 行
return isSkinPropUpdated; } public void setUpdateJiveHome(boolean updateJiveHome) { this.updateJiveHome = updateJiveHome; } public boolean isJiveHomeUpdated() { return isJiveHomeUpdated; } public void setUpdateGatewayFile(boolean updateGatewayFile) { this.updateGatewayFile = updateGatewayFile; } public boolean isGatewayFileUpdated() { return isGatewayFileUpdated; } public void setBackupGatewayFile(boolean backupGatewayFile) { this.backupGatewayFile = backupGatewayFile; } public void setUpdateFilter(boolean updateFilter) { this.updateFilter = updateFilter; } public boolean isFilterUpdated() { return isFilterUpdated; } public void setUpdateCategories(boolean updateCategories) { this.updateCategories = updateCategories; } public boolean isCategoriesUpdated() { return isCategoriesUpdated; } // private instance of this class private static Upgrade upgrade = null; private ForumFactory forumFactory; // constructor is private since this is a singleton private Upgrade(ForumFactory forumFactory) { this.forumFactory = forumFactory; } public static synchronized Upgrade getInstance(ForumFactory forumFactory) { if (upgrade == null) { upgrade = new Upgrade(forumFactory); } return upgrade; } public void doUpgrade() { if (isRunning) { return; } else { isRunning = true; } TaskEngine.addTask(new UpgradeThread()); } private class UpgradeThread implements Runnable { public UpgradeThread() {} public void run() { if (updateHSQL) { Connection con = null; try { con = ConnectionManager.getConnection(); java.sql.Statement stmt = con.createStatement(); for (int i=0; i<HSQL_QUERIES.length; i++) { try { stmt.executeUpdate(HSQL_QUERIES[i]); } catch (Exception e2) { e2.printStackTrace(); } } isHSQLUpdated = true; } catch (Exception e) { e.printStackTrace(); } finally { try { con.close(); } catch (Exception e) {} } } if (updateUserProp) { List oldPList = new ArrayList(); List newPList = new ArrayList(); for (Iterator iter=oldUserProps.keySet().iterator(); iter.hasNext();) { String oldProp = (String)iter.next(); oldPList.add(oldProp); } for (Iterator iter=oldUserProps.values().iterator(); iter.hasNext();) { String newProp = (String)iter.next(); newPList.add(newProp); } String[] oldPropList = (String[])oldPList.toArray(new String[0]); String[] newPropList = (String[])newPList.toArray(new String[0]); UserManager userManager = forumFactory.getUserManager(); for (Iterator iter=userManager.users(); iter.hasNext();) { try { User user = (User)iter.next(); for (int i=0; i<oldPropList.length; i++) { String oldPropertyValue = user.getProperty(oldPropList[i]); String newPropertyValue = user.getProperty(newPropList[i]); if (oldPropertyValue != null) { if (newPropertyValue == null) { user.setProperty(newPropList[i], oldPropertyValue); user.deleteProperty(oldPropList[i]); } else { user.deleteProperty(oldPropList[i]); } } } } catch (Exception e) { e.printStackTrace(); } } isUserPropUpdated = true; } if (updateSkinProp) { // Update skin properties. Don't overwrite the old ones. // Loop through all properties for (Iterator iter=skinProps.keySet().iterator(); iter.hasNext();) { String propName = (String)iter.next(); // We won't overwrite current values, so only update the prop if // it's not found: if (JiveGlobals.getJiveProperty(propName) == null) { JiveGlobals.setJiveProperty(propName, (String)skinProps.get(propName)); } } isSkinPropUpdated = true; } if (updateJiveHome) { // Check perms on attachment dirs File jiveHome = new File(JiveGlobals.getJiveHome()); File attachDir = new File(jiveHome, "attachments"); File imagesDir = new File(attachDir, "images"); if (attachDir.exists()) { try { if (attachDir.canRead() && attachDir.canWrite() && attachDir.canWrite() && imagesDir.canRead()) { isJiveHomeUpdated = true; } } catch (Exception e) { e.printStackTrace(); } } } if (updateGatewayFile) { // Delete the old gateways.xml file (optionally back it up) File jiveHome = new File(JiveGlobals.getJiveHome()); File gatewayFile = new File(jiveHome, "jive_gateways.xml"); if (gatewayFile.exists()) { if (backupGatewayFile) { try { File gatewayFileBak = new File(jiveHome, "jive_gateways.xml.bak"); BufferedWriter writer = new BufferedWriter(new FileWriter(gatewayFileBak)); BufferedReader reader = new BufferedReader(new FileReader(gatewayFile)); String line = null; while ((line=reader.readLine()) != null) { writer.write(line); writer.write(System.getProperty("line.separator")); } reader.close(); writer.close(); gatewayFile.delete(); isGatewayFileUpdated = true; } catch (Exception e) { e.printStackTrace(); } } else { gatewayFile.delete(); isGatewayFileUpdated = true; } } } if (updateFilter) { try { DbFilterManager.addFilterClass("com.jivesoftware.forum.filter.QuoteFilter"); DbFilterManager.addFilterClass("com.jivesoftware.forum.filter.JavaCodeHighlighter"); // Remove the CodeHighlightFilter if it is installed: FilterManager filterManager = forumFactory.getFilterManager(); for (int i=0; i<filterManager.getFilterCount(); i++) { ForumMessageFilter filter = filterManager.getFilter(i); if (filter.getClass().getName().equals("com.jivesoftware.forum.filter.CodeHighlightFilter")) { filterManager.removeFilter(i); break; } } // Remove the filter in all forums: for (Iterator iter=forumFactory.getRootForumCategory().recursiveForums(); iter.hasNext(); ) { Forum forum = (Forum)iter.next(); filterManager = forum.getFilterManager(); for (int i=0; i<filterManager.getFilterCount(); i++) { ForumMessageFilter filter = filterManager.getFilter(i); if (filter.getClass().getName().equals("com.jivesoftware.forum.filter.CodeHighlightFilter")) { filterManager.removeFilter(i); break; } } } isFilterUpdated = true; } catch (Exception e) { e.printStackTrace(); } } if (updateCategories) { // Update the creation date & modified date of the root category: try { ForumCategory rootCategory = forumFactory.getRootForumCategory(); java.util.Date now = new java.util.Date(); rootCategory.setCreationDate(now); rootCategory.setModifiedDate(now); // Update category indexes: Iterator forumIDs = getForumIDList(); // Iterate through the list, call the update method: int index = 0; while (forumIDs.hasNext()) { long forumID = ((Long)forumIDs.next()).longValue(); updateForumIndex(forumID, index); index++; } } catch (Exception e) { e.printStackTrace(); } isCategoriesUpdated = true; } // We're done upgrading, so indicate so: isRunning = false; } } private Iterator getForumIDList() throws Exception { Connection con = null; PreparedStatement pstmt = null; List forumIDs = new java.util.LinkedList(); try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement("SELECT forumID FROM jiveForum WHERE " + "categoryID=1 ORDER BY creationDate ASC"); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { forumIDs.add(new Long(rs.getLong(1))); } pstmt.close(); } catch (SQLException sqle) { sqle.printStackTrace(); throw new Exception(sqle.getMessage()); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } return forumIDs.iterator(); } // Updates the forum index of the given forum private void updateForumIndex(long forumID, int index) throws Exception { Connection con = null; PreparedStatement pstmt = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement("UPDATE jiveForum SET categoryIndex=? " + "WHERE forumID=?"); pstmt.setInt(1, index); pstmt.setLong(2, forumID); pstmt.executeUpdate(); pstmt.close(); } catch (SQLException sqle) { sqle.printStackTrace(); throw new Exception(sqle.getMessage()); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } } }%>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?