File Source: EntryBase.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.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.roller.weblogger.WebloggerException;
28 import org.apache.roller.weblogger.business.plugins.PluginManager;
29 import org.apache.roller.weblogger.business.WebloggerFactory;
30 import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
31 import org.apache.roller.weblogger.business.search.IndexManager;
32 import org.apache.roller.weblogger.pojos.WeblogPermission;
33 import org.apache.roller.weblogger.pojos.WeblogEntry;
34 import org.apache.roller.weblogger.ui.core.RollerContext;
35 import org.apache.roller.weblogger.ui.core.plugins.UIPluginManager;
36 import org.apache.roller.weblogger.ui.core.plugins.WeblogEntryEditor;
37 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
38
39
40 /**
41 * A collection of base functionality used by entry actions.
42 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.editor.EntryBase()
*/
43 public abstract class EntryBase extends UIAction {
44
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.editor.EntryBase__static_init
*
* Postconditions:
* init'ed(log)
*/
45 private static Log log = LogFactory.getLog(EntryBase.class);
46
47
48 /**
49 * Trigger reindexing of modified entry.
50 */
51 protected void reindexEntry(WeblogEntry entry) {
/*
P/P * Method: void reindexEntry(WeblogEntry)
*
* Preconditions:
* entry != null
* (soft) log != null
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getIndexManager(...)@52 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@52 != null
*
* Test Vectors:
* org.apache.roller.weblogger.pojos.WeblogEntry:isPublished(...)@55: {0}, {1}
*/
52 IndexManager manager = WebloggerFactory.getWeblogger().getIndexManager();
53
54 // if published, index the entry
55 if (entry.isPublished()) {
56 try {
57 manager.addEntryReIndexOperation(entry);
58 } catch (WebloggerException ex) {
59 log.warn("Trouble triggering entry indexing", ex);
60 }
61 }
62 }
63
64
65 /**
66 * Get recent weblog entries using request parameters to determine
67 * username, date, and category name parameters.
68 * @return List of WeblogEntryData objects.
69 * @throws WebloggerException
70 */
71 public List<WeblogEntry> getRecentPublishedEntries() {
/*
P/P * Method: List getRecentPublishedEntries()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@74 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@74 != null
*
* Postconditions:
* init'ed(return_value)
*/
72 List<WeblogEntry> entries = Collections.EMPTY_LIST;
73 try {
74 entries = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogEntries(
75
76 getActionWeblog(), // userName
77 null,
78 null, // startDate
79 null, // endDate
80 null, // catName
81 null,WeblogEntry.PUBLISHED, // status
82 null, // text
83 null, // sortby (null for pubTime)
84 null,
85 null,
86 0, 20);
87 } catch (WebloggerException ex) {
88 log.error("Error getting entries list", ex);
89 }
90 return entries;
91 }
92
93
94 /**
95 * Get recent weblog entries using request parameters to determine
96 * username, date, and category name parameters.
97 * @return List of WeblogEntryData objects.
98 * @throws WebloggerException
99 */
100 public List<WeblogEntry> getRecentScheduledEntries() {
/*
P/P * Method: List getRecentScheduledEntries()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@103 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@103 != null
*
* Postconditions:
* init'ed(return_value)
*/
101 List<WeblogEntry> entries = Collections.EMPTY_LIST;
102 try {
103 entries = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogEntries(
104
105 getActionWeblog(), // userName
106 null,
107 null, // startDate
108 null, // endDate
109 null, // catName
110 null,WeblogEntry.SCHEDULED, // status
111 null, // text
112 null, // sortby (null for pubTime)
113 null,
114 null,
115 0, 20);
116 } catch (WebloggerException ex) {
117 log.error("Error getting entries list", ex);
118 }
119 return entries;
120 }
121
122 /**
123 * Get recent weblog entries using request parameters to determine
124 * username, date, and category name parameters.
125 * @return List of WeblogEntryData objects.
126 * @throws WebloggerException
127 */
128 public List<WeblogEntry> getRecentDraftEntries() {
/*
P/P * Method: List getRecentDraftEntries()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@131 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@131 != null
*
* Postconditions:
* init'ed(return_value)
*/
129 List<WeblogEntry> entries = Collections.EMPTY_LIST;
130 try {
131 entries = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogEntries(
132
133 getActionWeblog(),
134 null,
135 null, // startDate
136 null, // endDate
137 null, // catName
138 null,WeblogEntry.DRAFT, // status
139 null, // text
140 "updateTime", // sortby
141 null,
142 null,
143 0, 20); // maxEntries
144 } catch (WebloggerException ex) {
145 log.error("Error getting entries list", ex);
146 }
147 return entries;
148 }
149
150 /**
151 * Get recent weblog entries using request parameters to determine
152 * username, date, and category name parameters.
153 * @return List of WeblogEntryData objects.
154 * @throws WebloggerException
155 */
156 public List<WeblogEntry> getRecentPendingEntries() {
/*
P/P * Method: List getRecentPendingEntries()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@159 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@159 != null
*
* Postconditions:
* init'ed(return_value)
*/
157 List<WeblogEntry> entries = Collections.EMPTY_LIST;
158 try {
159 entries = WebloggerFactory.getWeblogger().getWeblogManager().getWeblogEntries(
160
161 getActionWeblog(),
162 null,
163 null, // startDate
164 null, // endDate
165 null, // catName
166 null,WeblogEntry.PENDING, // status
167 null, // text
168 "updateTime", // sortby
169 null,
170 null,
171 0, 20);
172 } catch (WebloggerException ex) {
173 log.error("Error getting entries list", ex);
174 }
175 return entries;
176 }
177
178
179 public List<WeblogEntryPlugin> getEntryPlugins() {
/*
P/P * Method: List getEntryPlugins()
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* init'ed(java.util.Collections.EMPTY_LIST)
* java.util.Map:values(...)@187 != null
* org.apache.roller.weblogger.business.Weblogger:getPluginManager(...)@182 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@182 != null
* org.apache.roller.weblogger.business.plugins.PluginManager:getWeblogEntryPlugins(...)@183 != null
*
* Postconditions:
* return_value == One-of{java.util.Collections.EMPTY_LIST, &new ArrayList(getEntryPlugins#1)}
* (soft) init'ed(return_value)
* new ArrayList(getEntryPlugins#1) num objects <= 1
*/
180 List<WeblogEntryPlugin> availablePlugins = Collections.EMPTY_LIST;
181 try {
182 PluginManager ppmgr = WebloggerFactory.getWeblogger().getPluginManager();
183 Map<String, WeblogEntryPlugin> plugins = ppmgr.getWeblogEntryPlugins(getActionWeblog());
184
185 if(plugins.size() > 0) {
186 availablePlugins = new ArrayList();
187 for(WeblogEntryPlugin plugin : plugins.values()) {
188 availablePlugins.add(plugin);
189 }
190 }
191 } catch (Exception ex) {
192 log.error("Error getting plugins list", ex);
193 }
194 return availablePlugins;
195 }
196
197
198 public WeblogEntryEditor getEditor() {
/*
P/P * Method: WeblogEntryEditor getEditor()
*
* Presumptions:
* org.apache.roller.weblogger.ui.core.RollerContext:getUIPluginManager(...)@199 != null
* org.apache.roller.weblogger.ui.struts2.editor.EntryBase:getActionWeblog(...)@200 != null
*
* Postconditions:
* init'ed(return_value)
*/
199 UIPluginManager pmgr = RollerContext.getUIPluginManager();
200 return pmgr.getWeblogEntryEditor(getActionWeblog().getEditorPage());
201 }
202
203
204 public boolean isUserAnAuthor() {
/*
P/P * Method: bool isUserAnAuthor()
*
* Presumptions:
* init'ed(org.apache.roller.weblogger.pojos.WeblogPermission.AUTHOR)
* org.apache.roller.weblogger.ui.struts2.editor.EntryBase:getActionWeblog(...)@205 != null
*
* Postconditions:
* init'ed(return_value)
*/
205 return getActionWeblog().hasUserPermissions(getAuthenticatedUser(),WeblogPermission.AUTHOR);
206 }
207
208
209 public String getJsonAutocompleteUrl() {
/*
P/P * Method: String getJsonAutocompleteUrl()
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getUrlStrategy(...)@210 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@210 != null
*
* Postconditions:
* init'ed(return_value)
*/
210 return WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogTagsJsonURL(getActionWeblog(), false);
211 }
212
213 }
SofCheck Inspector Build Version : 2.18479
| EntryBase.java |
2009-Jan-02 14:24:46 |
| EntryBase.class |
2009-Sep-04 03:12:45 |