Source Code Cross Referenced for MoblogAdminPlugin.java in  » Blogger-System » blojsom-3.1 » org » blojsom » plugin » moblog » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Blogger System » blojsom 3.1 » org.blojsom.plugin.moblog.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (c) 2003-2007, David A. Czarnecki
003:         * All rights reserved.
004:         *
005:         * Redistribution and use in source and binary forms, with or without
006:         * modification, are permitted provided that the following conditions are met:
007:         *
008:         * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009:         *     following disclaimer.
010:         * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
011:         *     following disclaimer in the documentation and/or other materials provided with the distribution.
012:         * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
013:         *     endorse or promote products derived from this software without specific prior written permission.
014:         * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
015:         *     without prior written permission of David A. Czarnecki.
016:         *
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
018:         * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
019:         * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020:         * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
021:         * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
022:         * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
025:         * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026:         * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027:         * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030:         */package org.blojsom.plugin.moblog.admin;
031:
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.blojsom.blog.Blog;
035:        import org.blojsom.blog.Entry;
036:        import org.blojsom.fetcher.Fetcher;
037:        import org.blojsom.fetcher.FetcherException;
038:        import org.blojsom.plugin.PluginException;
039:        import org.blojsom.plugin.admin.WebAdminPlugin;
040:        import org.blojsom.plugin.moblog.MoblogPlugin;
041:        import org.blojsom.plugin.moblog.MoblogPluginUtils;
042:        import org.blojsom.util.BlojsomConstants;
043:        import org.blojsom.util.BlojsomUtils;
044:
045:        import javax.servlet.http.HttpServletRequest;
046:        import javax.servlet.http.HttpServletResponse;
047:        import java.util.Map;
048:
049:        /**
050:         * Moblog Admin Plugin
051:         *
052:         * @author David Czarnecki
053:         * @version $Id: MoblogAdminPlugin.java,v 1.2 2007/01/17 02:35:12 czarneckid Exp $
054:         * @since blojsom 3.0
055:         */
056:        public class MoblogAdminPlugin extends WebAdminPlugin {
057:
058:            private Log _logger = LogFactory.getLog(MoblogAdminPlugin.class);
059:
060:            private static final String EDIT_MOBLOG_SETTINGS_PAGE = "/org/blojsom/plugin/moblog/admin/templates/admin-edit-moblog-settings";
061:
062:            // Localization constants
063:            private static final String FAILED_MOBLOG_PERMISSIONS_KEY = "failed.moblog.permissions.text";
064:            private static final String UPDATED_MOBLOG_CONFIGURATION_KEY = "updated.moblog.configuration.text";
065:            private static final String FAILED_WRITE_MOBLOG_CONFIGURATION_KEY = "failed.write.moblog.configuration.text";
066:            private static final String ADDED_AUTHORIZED_EMAIL_KEY = "added.authorized.email.text";
067:            private static final String FAILED_ADD_EMAIL_KEY = "failed.add.email.text";
068:            private static final String NO_EMAIL_ADDRESS_KEY = "no.email.address.text";
069:            private static final String REMOVED_AUTHORIZED_EMAIL_KEY = "removed.authorized.email.text";
070:            private static final String FAILED_DELETE_EMAIL_KEY = "failed.delete.email.text";
071:
072:            // Form itmes
073:            private static final String MOBLOG_ENABLED = "moblog-enabled";
074:            private static final String MOBLOG_HOSTNAME = "moblog-hostname";
075:            private static final String MOBLOG_USERID = "moblog-userid";
076:            private static final String MOBLOG_PASSWORD = "moblog-password";
077:            private static final String MOBLOG_CATEGORY = "moblog-category";
078:            private static final String MOBLOG_SECRET_WORD = "moblog-secret-word";
079:            private static final String MOBLOG_IMAGE_MIME_TYPES = "moblog-image-mime-types";
080:            private static final String MOBLOG_ATTACHMENT_MIME_TYPES = "moblog-attachment-mime-types";
081:            private static final String MOBLOG_TEXT_MIME_TYPES = "moblog-text-mime-types";
082:            private static final String MOBLOG_AUTHORIZED_ADDRESS = "moblog-authorized-address";
083:            private static final String MOBLOG_IGNORE_EXPRESSION = "moblog-ignore-expression";
084:
085:            // Actions
086:            private static final String UPDATE_MOBLOG_SETTINGS_ACTIONS = "update-moblog-settings";
087:            private static final String ADD_AUTHORIZED_ADDRESS_ACTION = "add-authorized-address";
088:            private static final String DELETE_AUTHORIZED_ADDRESS_ACTION = "delete-authorized-address";
089:
090:            private static final String MOBLOG_ADMIN_PERMISSION = "moblog_admin";
091:
092:            private static final String BLOJSOM_PLUGIN_MOBLOG_MAILBOX = "BLOJSOM_PLUGIN_MOBLOG_MAILBOX";
093:
094:            private Fetcher _fetcher;
095:
096:            /**
097:             * Default constructor
098:             */
099:            public MoblogAdminPlugin() {
100:            }
101:
102:            /**
103:             * Set the {@link Fetcher}
104:             *
105:             * @param fetcher {@link Fetcher}
106:             */
107:            public void setFetcher(Fetcher fetcher) {
108:                _fetcher = fetcher;
109:            }
110:
111:            /**
112:             * Return the display name for the plugin
113:             *
114:             * @return Display name for the plugin
115:             */
116:            public String getDisplayName() {
117:                return "Moblog plugin";
118:            }
119:
120:            /**
121:             * Return the name of the initial editing page for the plugin
122:             *
123:             * @return Name of the initial editing page for the plugin
124:             */
125:            public String getInitialPage() {
126:                return EDIT_MOBLOG_SETTINGS_PAGE;
127:            }
128:
129:            /**
130:             * Process the blog entries
131:             *
132:             * @param httpServletRequest  Request
133:             * @param httpServletResponse Response
134:             * @param blog                {@link org.blojsom.blog.Blog} instance
135:             * @param context             Context
136:             * @param entries             Blog entries retrieved for the particular request
137:             * @return Modified set of blog entries
138:             * @throws PluginException If there is an error processing the blog entries
139:             */
140:            public Entry[] process(HttpServletRequest httpServletRequest,
141:                    HttpServletResponse httpServletResponse, Blog blog,
142:                    Map context, Entry[] entries) throws PluginException {
143:                entries = super .process(httpServletRequest,
144:                        httpServletResponse, blog, context, entries);
145:
146:                String page = BlojsomUtils.getRequestValue(
147:                        BlojsomConstants.PAGE_PARAM, httpServletRequest);
148:
149:                String username = getUsernameFromSession(httpServletRequest,
150:                        blog);
151:                if (!checkPermission(blog, null, username,
152:                        MOBLOG_ADMIN_PERMISSION)) {
153:                    httpServletRequest.setAttribute(
154:                            BlojsomConstants.PAGE_PARAM,
155:                            ADMIN_ADMINISTRATION_PAGE);
156:                    addOperationResultMessage(context, getAdminResource(
157:                            FAILED_MOBLOG_PERMISSIONS_KEY,
158:                            FAILED_MOBLOG_PERMISSIONS_KEY, blog
159:                                    .getBlogAdministrationLocale()));
160:
161:                    return entries;
162:                }
163:
164:                if (ADMIN_LOGIN_PAGE.equals(page)) {
165:                    return entries;
166:                } else {
167:                    String action = BlojsomUtils.getRequestValue(ACTION_PARAM,
168:                            httpServletRequest);
169:
170:                    if (UPDATE_MOBLOG_SETTINGS_ACTIONS.equals(action)) {
171:                        boolean mailboxEnabled = Boolean.valueOf(
172:                                BlojsomUtils.getRequestValue(MOBLOG_ENABLED,
173:                                        httpServletRequest)).booleanValue();
174:                        blog.setProperty(MoblogPlugin.PROPERTY_ENABLED, Boolean
175:                                .toString(mailboxEnabled));
176:
177:                        String hostname = BlojsomUtils.getRequestValue(
178:                                MOBLOG_HOSTNAME, httpServletRequest);
179:                        blog.setProperty(MoblogPlugin.PROPERTY_HOSTNAME,
180:                                hostname);
181:
182:                        String userID = BlojsomUtils.getRequestValue(
183:                                MOBLOG_USERID, httpServletRequest);
184:                        blog.setProperty(MoblogPlugin.PROPERTY_USERID, userID);
185:
186:                        String password = BlojsomUtils.getRequestValue(
187:                                MOBLOG_PASSWORD, httpServletRequest);
188:                        blog.setProperty(MoblogPlugin.PROPERTY_PASSWORD,
189:                                password);
190:
191:                        String category = BlojsomUtils.getRequestValue(
192:                                MOBLOG_CATEGORY, httpServletRequest);
193:                        blog.setProperty(MoblogPlugin.PROPERTY_CATEGORY,
194:                                category);
195:
196:                        String textMimeTypeValue = BlojsomUtils
197:                                .getRequestValue(MOBLOG_TEXT_MIME_TYPES,
198:                                        httpServletRequest);
199:                        blog.setProperty(
200:                                MoblogPlugin.PLUGIN_MOBLOG_TEXT_MIME_TYPES,
201:                                textMimeTypeValue);
202:
203:                        String attachmentMimeTypeValue = BlojsomUtils
204:                                .getRequestValue(MOBLOG_ATTACHMENT_MIME_TYPES,
205:                                        httpServletRequest);
206:                        blog
207:                                .setProperty(
208:                                        MoblogPlugin.PLUGIN_MOBLOG_ATTACHMENT_MIME_TYPES,
209:                                        attachmentMimeTypeValue);
210:
211:                        String imageMimeTypeValue = BlojsomUtils
212:                                .getRequestValue(MOBLOG_IMAGE_MIME_TYPES,
213:                                        httpServletRequest);
214:                        blog.setProperty(
215:                                MoblogPlugin.PLUGIN_MOBLOG_IMAGE_MIME_TYPES,
216:                                imageMimeTypeValue);
217:
218:                        String secretWord = BlojsomUtils.getRequestValue(
219:                                MOBLOG_SECRET_WORD, httpServletRequest);
220:                        blog.setProperty(
221:                                MoblogPlugin.PLUGIN_MOBLOG_SECRET_WORD,
222:                                secretWord);
223:
224:                        String ignoreExpression = BlojsomUtils.getRequestValue(
225:                                MOBLOG_IGNORE_EXPRESSION, httpServletRequest);
226:                        blog.setProperty(
227:                                MoblogPlugin.PLUGIN_MOBLOG_IGNORE_EXPRESSION,
228:                                ignoreExpression);
229:
230:                        try {
231:                            _fetcher.saveBlog(blog);
232:                            addOperationResultMessage(context,
233:                                    getAdminResource(
234:                                            UPDATED_MOBLOG_CONFIGURATION_KEY,
235:                                            UPDATED_MOBLOG_CONFIGURATION_KEY,
236:                                            blog.getBlogAdministrationLocale()));
237:                        } catch (FetcherException e) {
238:                            _logger.error(e);
239:                            addOperationResultMessage(
240:                                    context,
241:                                    getAdminResource(
242:                                            FAILED_WRITE_MOBLOG_CONFIGURATION_KEY,
243:                                            FAILED_WRITE_MOBLOG_CONFIGURATION_KEY,
244:                                            blog.getBlogAdministrationLocale()));
245:                        }
246:                    } else if (ADD_AUTHORIZED_ADDRESS_ACTION.equals(action)) {
247:                        String addressToAdd = BlojsomUtils.getRequestValue(
248:                                MOBLOG_AUTHORIZED_ADDRESS, httpServletRequest);
249:                        if (!BlojsomUtils.checkNullOrBlank(addressToAdd)) {
250:                            String authorizedAddresses = blog
251:                                    .getProperty(MoblogPlugin.PLUGIN_MOBLOG_AUTHORIZED_ADDRESSES);
252:                            String updatedAddresses;
253:                            Map addresses;
254:
255:                            if (!BlojsomUtils
256:                                    .checkNullOrBlank(authorizedAddresses)) {
257:                                addresses = BlojsomUtils
258:                                        .arrayOfStringsToMap(BlojsomUtils
259:                                                .parseCommaList(authorizedAddresses));
260:                                addresses.put(addressToAdd, addressToAdd);
261:                                updatedAddresses = BlojsomUtils
262:                                        .getKeysAsStringList(addresses);
263:                            } else {
264:                                updatedAddresses = addressToAdd;
265:                            }
266:
267:                            blog
268:                                    .setProperty(
269:                                            MoblogPlugin.PLUGIN_MOBLOG_AUTHORIZED_ADDRESSES,
270:                                            updatedAddresses);
271:
272:                            try {
273:                                _fetcher.saveBlog(blog);
274:                                addOperationResultMessage(
275:                                        context,
276:                                        formatAdminResource(
277:                                                ADDED_AUTHORIZED_EMAIL_KEY,
278:                                                ADDED_AUTHORIZED_EMAIL_KEY,
279:                                                blog
280:                                                        .getBlogAdministrationLocale(),
281:                                                new Object[] { addressToAdd }));
282:                            } catch (FetcherException e) {
283:                                _logger.error(e);
284:                                addOperationResultMessage(
285:                                        context,
286:                                        getAdminResource(
287:                                                FAILED_ADD_EMAIL_KEY,
288:                                                FAILED_ADD_EMAIL_KEY,
289:                                                blog
290:                                                        .getBlogAdministrationLocale()));
291:                            }
292:                        } else {
293:                            addOperationResultMessage(context,
294:                                    getAdminResource(NO_EMAIL_ADDRESS_KEY,
295:                                            NO_EMAIL_ADDRESS_KEY,
296:                                            blog.getBlogAdministrationLocale()));
297:                        }
298:                    } else if (DELETE_AUTHORIZED_ADDRESS_ACTION.equals(action)) {
299:                        String addressToDelete = BlojsomUtils.getRequestValue(
300:                                MOBLOG_AUTHORIZED_ADDRESS, httpServletRequest);
301:                        if (!BlojsomUtils.checkNullOrBlank(addressToDelete)) {
302:                            String authorizedAddresses = blog
303:                                    .getProperty(MoblogPlugin.PLUGIN_MOBLOG_AUTHORIZED_ADDRESSES);
304:                            String updatedAddresses = "";
305:                            Map addresses;
306:
307:                            if (!BlojsomUtils
308:                                    .checkNullOrBlank(authorizedAddresses)) {
309:                                addresses = BlojsomUtils
310:                                        .arrayOfStringsToMap(BlojsomUtils
311:                                                .parseCommaList(authorizedAddresses));
312:                                addresses.remove(addressToDelete);
313:                                updatedAddresses = BlojsomUtils
314:                                        .getKeysAsStringList(addresses);
315:                            }
316:
317:                            blog
318:                                    .setProperty(
319:                                            MoblogPlugin.PLUGIN_MOBLOG_AUTHORIZED_ADDRESSES,
320:                                            updatedAddresses);
321:
322:                            try {
323:                                _fetcher.saveBlog(blog);
324:                                addOperationResultMessage(
325:                                        context,
326:                                        formatAdminResource(
327:                                                REMOVED_AUTHORIZED_EMAIL_KEY,
328:                                                REMOVED_AUTHORIZED_EMAIL_KEY,
329:                                                blog
330:                                                        .getBlogAdministrationLocale(),
331:                                                new Object[] { addressToDelete }));
332:                            } catch (FetcherException e) {
333:                                _logger.error(e);
334:                                addOperationResultMessage(
335:                                        context,
336:                                        getAdminResource(
337:                                                FAILED_DELETE_EMAIL_KEY,
338:                                                FAILED_DELETE_EMAIL_KEY,
339:                                                blog
340:                                                        .getBlogAdministrationLocale()));
341:                            }
342:                        } else {
343:                            addOperationResultMessage(context,
344:                                    getAdminResource(NO_EMAIL_ADDRESS_KEY,
345:                                            NO_EMAIL_ADDRESS_KEY,
346:                                            blog.getBlogAdministrationLocale()));
347:                        }
348:                    }
349:
350:                    context.put(BLOJSOM_PLUGIN_MOBLOG_MAILBOX,
351:                            MoblogPluginUtils.readMailboxSettingsForBlog(
352:                                    _servletConfig, blog));
353:                }
354:
355:                return entries;
356:            }
357:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.