File Source: Maintenance.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.struts2.editor;
20
21 import java.util.Date;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.roller.weblogger.business.search.IndexManager;
25 import org.apache.roller.weblogger.business.WebloggerFactory;
26 import org.apache.roller.weblogger.business.UserManager;
27 import org.apache.roller.weblogger.pojos.WeblogPermission;
28 import org.apache.roller.weblogger.pojos.Weblog;
29 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
30 import org.apache.roller.weblogger.util.cache.CacheManager;
31
32
33 /**
34 * Allows user to perform maintenence operations such as flushing
35 * the page cache or re-indexing the search index.
36 */
37 public class Maintenance extends UIAction {
38
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.editor.Maintenance__static_init
*
* Postconditions:
* init'ed(log)
*/
39 private static Log log = LogFactory.getLog(Maintenance.class);
40
41
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.editor.Maintenance()
*
* Postconditions:
* this.actionName == &"maintenance"
* this.desiredMenu == &"editor"
* this.pageTitle == &"maintenance.title"
*/
42 public Maintenance() {
43 this.actionName = "maintenance";
44 this.desiredMenu = "editor";
45 this.pageTitle = "maintenance.title";
46 }
47
48
49 // admin perms required
50 public short requiredWeblogPermissions() {
/*
P/P * Method: short requiredWeblogPermissions()
*
* Presumptions:
* init'ed(org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN)
*
* Postconditions:
* return_value == org.apache.roller.weblogger.pojos.WeblogPermission.ADMIN
* (soft) init'ed(return_value)
*/
51 return WeblogPermission.ADMIN;
52 }
53
54
55 public String execute() {
/*
P/P * Method: String execute()
*
* Postconditions:
* return_value == &"success"
*/
56 return SUCCESS;
57 }
58
59
60 /**
61 * Rebuild search index for weblog.
62 */
63 public String index() {
64
65 try {
/*
P/P * Method: String index()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getIndexManager(...)@66 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@66 != null
*
* Postconditions:
* return_value == &"success"
*/
66 IndexManager manager = WebloggerFactory.getWeblogger().getIndexManager();
67 manager.rebuildWebsiteIndex(getActionWeblog());
68
69 addMessage("maintenance.message.indexed");
70 } catch (Exception ex) {
71 log.error("Error doing index rebuild", ex);
72 // TODO: i18n
73 addError("Error rebuilding search index");
74 }
75
76 return SUCCESS;
77 }
78
79
80 /**
81 * Flush page cache for weblog.
82 */
83 public String flushCache() {
84
85 try {
/*
P/P * Method: String flushCache()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getUserManager(...)@91 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@91 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@93 != null
* org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog(...)@101 != null
* org.apache.roller.weblogger.ui.struts2.editor.Maintenance:getActionWeblog(...)@86 != null
*
* Postconditions:
* return_value == &"success"
*/
86 Weblog weblog = getActionWeblog();
87
88 // some caches are based on weblog last-modified, so update it
89 weblog.setLastModified(new Date());
90
91 UserManager umgr = WebloggerFactory.getWeblogger().getUserManager();
92 umgr.saveWebsite(weblog);
93 WebloggerFactory.getWeblogger().flush();
94
95 // also notify cache manager
96 CacheManager.invalidate(weblog);
97
98 addMessage("maintenance.message.flushed");
99
100 } catch (Exception ex) {
101 log.error("Error saving weblog - "+getActionWeblog().getHandle(), ex);
102 // TODO: i18n
103 addError("Error flushing page cache");
104 }
105
106 return SUCCESS;
107 }
108
109 }
SofCheck Inspector Build Version : 2.18479
| Maintenance.java |
2009-Jan-02 14:25:04 |
| Maintenance.class |
2009-Sep-04 03:12:45 |