Source Code Cross Referenced for EditBlogTemplatesPlugin.java in  » Blogger-System » blojsom-3.1 » org » blojsom » plugin » 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.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.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.plugin.PluginException;
037:        import org.blojsom.util.BlojsomConstants;
038:        import org.blojsom.util.BlojsomUtils;
039:
040:        import javax.servlet.http.HttpServletRequest;
041:        import javax.servlet.http.HttpServletResponse;
042:        import java.io.*;
043:        import java.util.*;
044:
045:        /**
046:         * EditBlogTemplatesPlugin
047:         *
048:         * @author David Czarnecki
049:         * @version $Id: EditBlogTemplatesPlugin.java,v 1.6 2007/01/17 02:35:05 czarneckid Exp $
050:         * @since blojsom 3.0
051:         */
052:        public class EditBlogTemplatesPlugin extends BaseAdminPlugin {
053:
054:            private Log _logger = LogFactory
055:                    .getLog(EditBlogTemplatesPlugin.class);
056:
057:            private static final String DEFAULT_ACCEPTED_TEMPLATE_EXTENSIONS = "vm";
058:            private static final String ACCEPTED_TEMPLATE_EXTENSIONS_INIT_PARAM = "accepted-template-extensions";
059:
060:            // Pages
061:            private static final String EDIT_BLOG_TEMPLATES_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-templates";
062:            private static final String EDIT_BLOG_TEMPLATE_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-template";
063:
064:            // Constants
065:            private static final String BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILES = "BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILES";
066:            private static final String BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILE = "BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILE";
067:            private static final String BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE = "BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE";
068:            private static final String BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_DIRECTORIES = "BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_DIRECTORIES";
069:
070:            // Localization constants
071:            private static final String FAILED_EDIT_TEMPLATES_PERMISSION_KEY = "failed.edit.templates.permission.text";
072:            private static final String INVALID_TEMPLATE_PATH_KEY = "invalid.template.path.text";
073:            private static final String UNABLE_TO_LOAD_TEMPLATE_KEY = "unable.to.load.template.text";
074:            private static final String UNABLE_TO_DELETE_TEMPLATE_KEY = "unable.to.delete.template.text";
075:            private static final String UPDATED_TEMPLATE_KEY = "updated.template.text";
076:            private static final String NO_TEMPLATE_NAME_KEY = "no.template.name.text";
077:            private static final String INVALID_TEMPLATE_EXTENSION_KEY = "invalid.template.extension.text";
078:            private static final String TEMPLATE_DIRECTORY_NONEXISTENT_KEY = "template.directory.nonexistent.text";
079:            private static final String TEMPLATE_DIRECTORY_NOTSPECIFIED_KEY = "template.directory.notspecified.text";
080:            private static final String UNABLE_TO_ADD_TEMPLATE_DIRECTORY_KEY = "unable.to.add.template.directory.text";
081:            private static final String ADDED_TEMPLATE_DIRECTORY_KEY = "added.template.directory.text";
082:            private static final String CANNOT_REMOVE_TOP_TEMPLATE_DIRECTORY_KEY = "cannot.remove.top.template.directory.text";
083:            private static final String UNABLE_TO_DELETE_TEMPLATE_DIRECTORY_KEY = "unable.to.delete.template.directory.text";
084:            private static final String REMOVED_TEMPLATE_DIRECTORY_KEY = "removed.template.directory.text";
085:            private static final String DELETED_TEMPLATE_KEY = "deleted.template.text";
086:
087:            // Actions
088:            private static final String ADD_BLOG_TEMPLATE_ACTION = "add-blog-template";
089:            private static final String DELETE_BLOG_TEMPLATE_ACTION = "delete-blog-template";
090:            private static final String EDIT_BLOG_TEMPLATES_ACTION = "edit-blog-template";
091:            private static final String UPDATE_BLOG_TEMPLATE_ACTION = "update-blog-template";
092:            private static final String ADD_TEMPLATE_DIRECTORY_ACTION = "add-template-directory";
093:            private static final String DELETE_TEMPLATE_DIRECTORY_ACTION = "delete-template-directory";
094:
095:            // Form elements
096:            private static final String BLOG_TEMPLATE = "blog-template";
097:            private static final String BLOG_TEMPLATE_DATA = "blog-template-data";
098:            private static final String BLOG_TEMPLATE_DIRECTORY = "blog-template-directory";
099:            private static final String TEMPLATE_DIRECTORY_TO_ADD = "template-directory-to-add";
100:
101:            // Permissions
102:            private static final String EDIT_BLOG_TEMPLATES_PERMISSION = "edit_blog_templates_permission";
103:
104:            private Map _acceptedTemplateExtensions;
105:            private Properties _templateEditProperties;
106:            private Properties _blojsomProperties;
107:            private String _templatesDirectory;
108:            private String _blogsDirectory;
109:
110:            /**
111:             * Default constructor.
112:             */
113:            public EditBlogTemplatesPlugin() {
114:            }
115:
116:            /**
117:             * Set the template editing properties
118:             *
119:             * @param templateEditProperties Template editing properties
120:             */
121:            public void setTemplateEditProperties(
122:                    Properties templateEditProperties) {
123:                _templateEditProperties = templateEditProperties;
124:            }
125:
126:            /**
127:             * Set the default blojsom properties
128:             *
129:             * @param blojsomProperties Default blojsom properties
130:             */
131:            public void setBlojsomProperties(Properties blojsomProperties) {
132:                _blojsomProperties = blojsomProperties;
133:            }
134:
135:            /**
136:             * Initialize this plugin. This method only called when the plugin is instantiated.
137:             *
138:             * @throws org.blojsom.plugin.PluginException
139:             *          If there is an error initializing the plugin
140:             */
141:            public void init() throws PluginException {
142:                super .init();
143:
144:                String acceptedTemplateExtensions = _templateEditProperties
145:                        .getProperty(ACCEPTED_TEMPLATE_EXTENSIONS_INIT_PARAM);
146:                if (BlojsomUtils.checkNullOrBlank(acceptedTemplateExtensions)) {
147:                    acceptedTemplateExtensions = DEFAULT_ACCEPTED_TEMPLATE_EXTENSIONS;
148:                }
149:
150:                _acceptedTemplateExtensions = new HashMap();
151:                String[] templateExtensions = BlojsomUtils
152:                        .parseCommaList(acceptedTemplateExtensions);
153:                for (int i = 0; i < templateExtensions.length; i++) {
154:                    String templateExtension = templateExtensions[i];
155:                    _acceptedTemplateExtensions.put(templateExtension,
156:                            templateExtension);
157:                }
158:
159:                _templatesDirectory = _blojsomProperties.getProperty(
160:                        BlojsomConstants.TEMPLATES_DIRECTORY_IP,
161:                        BlojsomConstants.DEFAULT_TEMPLATES_DIRECTORY);
162:                _blogsDirectory = _blojsomProperties.getProperty(
163:                        BlojsomConstants.BLOGS_DIRECTORY_IP,
164:                        BlojsomConstants.DEFAULT_BLOGS_DIRECTORY);
165:            }
166:
167:            /**
168:             * Sanitize a filename
169:             *
170:             * @param blogTemplate Blog template filename
171:             * @return Sanitized filename or <code>null</code> if error in sanitizing
172:             */
173:            protected String sanitizeFilename(String blogTemplate) {
174:                String templateFilename = new File(blogTemplate).getName();
175:                int lastSeparator;
176:                blogTemplate = BlojsomUtils.normalize(blogTemplate);
177:                lastSeparator = blogTemplate.lastIndexOf(File.separator);
178:                if (lastSeparator == -1) {
179:                    if (templateFilename != null) {
180:                        return templateFilename;
181:                    } else {
182:                        return null;
183:                    }
184:                } else {
185:                    blogTemplate = blogTemplate.substring(0, lastSeparator + 1)
186:                            + templateFilename;
187:                }
188:
189:                return blogTemplate;
190:            }
191:
192:            /**
193:             * Put the list of template files in the context
194:             *
195:             * @param templatesDirectory Templates directory
196:             * @param context            Context
197:             */
198:            protected void putTemplatesInContext(File templatesDirectory,
199:                    Map context) {
200:                List templateFiles = new ArrayList();
201:                BlojsomUtils.listFilesInSubdirectories(templatesDirectory,
202:                        templatesDirectory.getAbsolutePath(), templateFiles);
203:                File[] templates = (File[]) templateFiles
204:                        .toArray(new File[templateFiles.size()]);
205:                Arrays.sort(templates);
206:
207:                context.put(BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILES,
208:                        templates);
209:            }
210:
211:            /**
212:             * Put the list of template directories in the context
213:             *
214:             * @param templatesDirectory Templates directory
215:             * @param context            Context
216:             */
217:            protected void putTemplateDirectoriesInContext(
218:                    File templatesDirectory, Map context) {
219:                List templateDirectories = new ArrayList();
220:                BlojsomUtils.listDirectoriesInSubdirectories(
221:                        templatesDirectory, templatesDirectory
222:                                .getAbsolutePath(), templateDirectories);
223:                File[] directories = (File[]) templateDirectories
224:                        .toArray(new File[templateDirectories.size()]);
225:                Arrays.sort(directories);
226:
227:                context.put(BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_DIRECTORIES,
228:                        directories);
229:            }
230:
231:            /**
232:             * Process the blog entries
233:             *
234:             * @param httpServletRequest  Request
235:             * @param httpServletResponse Response
236:             * @param blog                {@link Blog} instance
237:             * @param context             Context
238:             * @param entries             Blog entries retrieved for the particular request
239:             * @return Modified set of blog entries
240:             * @throws PluginException If there is an error processing the blog entries
241:             */
242:            public Entry[] process(HttpServletRequest httpServletRequest,
243:                    HttpServletResponse httpServletResponse, Blog blog,
244:                    Map context, Entry[] entries) throws PluginException {
245:                if (!authenticateUser(httpServletRequest, httpServletResponse,
246:                        context, blog)) {
247:                    httpServletRequest.setAttribute(
248:                            BlojsomConstants.PAGE_PARAM, ADMIN_LOGIN_PAGE);
249:
250:                    return entries;
251:                }
252:
253:                String username = getUsernameFromSession(httpServletRequest,
254:                        blog);
255:                if (!checkPermission(blog, null, username,
256:                        EDIT_BLOG_TEMPLATES_PERMISSION)) {
257:                    httpServletRequest.setAttribute(
258:                            BlojsomConstants.PAGE_PARAM,
259:                            ADMIN_ADMINISTRATION_PAGE);
260:                    addOperationResultMessage(context, getAdminResource(
261:                            FAILED_EDIT_TEMPLATES_PERMISSION_KEY,
262:                            FAILED_EDIT_TEMPLATES_PERMISSION_KEY, blog
263:                                    .getBlogAdministrationLocale()));
264:
265:                    return entries;
266:                }
267:
268:                // Add list of templates to context
269:                File templatesDirectory = new File(_servletConfig
270:                        .getServletContext().getRealPath("/")
271:                        + BlojsomConstants.DEFAULT_CONFIGURATION_BASE_DIRECTORY
272:                        + _blogsDirectory
273:                        + blog.getBlogId()
274:                        + _templatesDirectory);
275:                _logger.debug("Looking for templates in directory: "
276:                        + templatesDirectory.toString());
277:
278:                putTemplatesInContext(templatesDirectory, context);
279:                putTemplateDirectoriesInContext(templatesDirectory, context);
280:
281:                String action = BlojsomUtils.getRequestValue(ACTION_PARAM,
282:                        httpServletRequest);
283:                if (BlojsomUtils.checkNullOrBlank(action)) {
284:                    _logger.debug("User did not request edit action");
285:                    httpServletRequest.setAttribute(
286:                            BlojsomConstants.PAGE_PARAM,
287:                            ADMIN_ADMINISTRATION_PAGE);
288:                } else if (PAGE_ACTION.equals(action)) {
289:                    _logger.debug("User requested edit blog templates page");
290:
291:                    httpServletRequest.setAttribute(
292:                            BlojsomConstants.PAGE_PARAM,
293:                            EDIT_BLOG_TEMPLATES_PAGE);
294:                } else if (EDIT_BLOG_TEMPLATES_ACTION.equals(action)) {
295:                    _logger.debug("User requested edit blog templates action");
296:
297:                    String blogTemplate = BlojsomUtils.getRequestValue(
298:                            BLOG_TEMPLATE, httpServletRequest);
299:                    if (BlojsomUtils.checkNullOrBlank(blogTemplate)) {
300:                        httpServletRequest.setAttribute(
301:                                BlojsomConstants.PAGE_PARAM,
302:                                EDIT_BLOG_TEMPLATES_PAGE);
303:
304:                        return entries;
305:                    }
306:
307:                    blogTemplate = sanitizeFilename(blogTemplate);
308:                    if (blogTemplate == null) {
309:                        addOperationResultMessage(context, getAdminResource(
310:                                INVALID_TEMPLATE_PATH_KEY,
311:                                INVALID_TEMPLATE_PATH_KEY, blog
312:                                        .getBlogAdministrationLocale()));
313:                        httpServletRequest.setAttribute(
314:                                BlojsomConstants.PAGE_PARAM,
315:                                EDIT_BLOG_TEMPLATES_PAGE);
316:
317:                        return entries;
318:                    }
319:
320:                    File blogTemplateFile = new File(
321:                            _servletConfig.getServletContext().getRealPath("/")
322:                                    + BlojsomConstants.DEFAULT_CONFIGURATION_BASE_DIRECTORY
323:                                    + _blogsDirectory + blog.getBlogId()
324:                                    + _templatesDirectory + blogTemplate);
325:                    _logger.debug("Reading template file: "
326:                            + blogTemplateFile.toString());
327:
328:                    try {
329:                        BufferedReader br = new BufferedReader(
330:                                new InputStreamReader(new FileInputStream(
331:                                        blogTemplateFile),
332:                                        BlojsomConstants.UTF8));
333:                        String input;
334:                        StringBuffer template = new StringBuffer();
335:
336:                        while ((input = br.readLine()) != null) {
337:                            template.append(input);
338:                            template.append(BlojsomConstants.LINE_SEPARATOR);
339:                        }
340:
341:                        br.close();
342:
343:                        context
344:                                .put(
345:                                        BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILE,
346:                                        blogTemplate);
347:                        context.put(
348:                                BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE,
349:                                BlojsomUtils.escapeString(template.toString()));
350:                        httpServletRequest.setAttribute(
351:                                BlojsomConstants.PAGE_PARAM,
352:                                EDIT_BLOG_TEMPLATE_PAGE);
353:                    } catch (UnsupportedEncodingException e) {
354:                        _logger.error(e);
355:                        addOperationResultMessage(context, formatAdminResource(
356:                                UNABLE_TO_LOAD_TEMPLATE_KEY,
357:                                UNABLE_TO_LOAD_TEMPLATE_KEY, blog
358:                                        .getBlogAdministrationLocale(),
359:                                new Object[] { blogTemplate }));
360:                        httpServletRequest.setAttribute(
361:                                BlojsomConstants.PAGE_PARAM,
362:                                EDIT_BLOG_TEMPLATES_PAGE);
363:                    } catch (IOException e) {
364:                        _logger.error(e);
365:                        addOperationResultMessage(context, formatAdminResource(
366:                                UNABLE_TO_LOAD_TEMPLATE_KEY,
367:                                UNABLE_TO_LOAD_TEMPLATE_KEY, blog
368:                                        .getBlogAdministrationLocale(),
369:                                new Object[] { blogTemplate }));
370:                        httpServletRequest.setAttribute(
371:                                BlojsomConstants.PAGE_PARAM,
372:                                EDIT_BLOG_TEMPLATES_PAGE);
373:                    }
374:                } else if (UPDATE_BLOG_TEMPLATE_ACTION.equals(action)) {
375:                    _logger.debug("User requested update blog template action");
376:
377:                    String blogTemplate = BlojsomUtils.getRequestValue(
378:                            BLOG_TEMPLATE, httpServletRequest);
379:                    if (BlojsomUtils.checkNullOrBlank(blogTemplate)) {
380:                        httpServletRequest.setAttribute(
381:                                BlojsomConstants.PAGE_PARAM,
382:                                EDIT_BLOG_TEMPLATES_PAGE);
383:
384:                        return entries;
385:                    }
386:
387:                    blogTemplate = sanitizeFilename(blogTemplate);
388:                    if (blogTemplate == null) {
389:                        addOperationResultMessage(context, getAdminResource(
390:                                INVALID_TEMPLATE_PATH_KEY,
391:                                INVALID_TEMPLATE_PATH_KEY, blog
392:                                        .getBlogAdministrationLocale()));
393:                        httpServletRequest.setAttribute(
394:                                BlojsomConstants.PAGE_PARAM,
395:                                EDIT_BLOG_TEMPLATES_PAGE);
396:
397:                        return entries;
398:                    }
399:
400:                    String blogTemplateData = BlojsomUtils.getRequestValue(
401:                            BLOG_TEMPLATE_DATA, httpServletRequest);
402:                    File blogTemplateFile = new File(
403:                            _servletConfig.getServletContext().getRealPath("/")
404:                                    + BlojsomConstants.DEFAULT_CONFIGURATION_BASE_DIRECTORY
405:                                    + _blogsDirectory + blog.getBlogId()
406:                                    + _templatesDirectory + blogTemplate);
407:
408:                    _logger.debug("Writing template file: "
409:                            + blogTemplateFile.toString());
410:
411:                    try {
412:                        BufferedWriter bw = new BufferedWriter(
413:                                new OutputStreamWriter(new FileOutputStream(
414:                                        blogTemplateFile),
415:                                        BlojsomConstants.UTF8));
416:                        bw.write(blogTemplateData);
417:                        bw.close();
418:                    } catch (UnsupportedEncodingException e) {
419:                        _logger.error(e);
420:                        addOperationResultMessage(context, formatAdminResource(
421:                                UNABLE_TO_DELETE_TEMPLATE_KEY,
422:                                UNABLE_TO_DELETE_TEMPLATE_KEY, blog
423:                                        .getBlogAdministrationLocale(),
424:                                new Object[] { blogTemplate }));
425:                    } catch (IOException e) {
426:                        _logger.error(e);
427:                        addOperationResultMessage(context, formatAdminResource(
428:                                UNABLE_TO_DELETE_TEMPLATE_KEY,
429:                                UNABLE_TO_DELETE_TEMPLATE_KEY, blog
430:                                        .getBlogAdministrationLocale(),
431:                                new Object[] { blogTemplate }));
432:                    }
433:
434:                    addOperationResultMessage(context, formatAdminResource(
435:                            UPDATED_TEMPLATE_KEY, UPDATED_TEMPLATE_KEY, blog
436:                                    .getBlogAdministrationLocale(),
437:                            new Object[] { blogTemplate }));
438:
439:                    context.put(
440:                            BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILE,
441:                            blogTemplate);
442:                    context.put(BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE,
443:                            BlojsomUtils.escapeString(blogTemplateData));
444:                    httpServletRequest.setAttribute(
445:                            BlojsomConstants.PAGE_PARAM,
446:                            EDIT_BLOG_TEMPLATE_PAGE);
447:                } else if (ADD_BLOG_TEMPLATE_ACTION.equals(action)) {
448:                    _logger.debug("User requested add blog template action");
449:
450:                    String blogTemplate = BlojsomUtils.getRequestValue(
451:                            BLOG_TEMPLATE, httpServletRequest);
452:                    String blogTemplateDirectory = BlojsomUtils
453:                            .getRequestValue(BLOG_TEMPLATE_DIRECTORY,
454:                                    httpServletRequest);
455:
456:                    if (BlojsomUtils.checkNullOrBlank(blogTemplate)) {
457:                        addOperationResultMessage(context, getAdminResource(
458:                                NO_TEMPLATE_NAME_KEY, NO_TEMPLATE_NAME_KEY,
459:                                blog.getBlogAdministrationLocale()));
460:                        httpServletRequest.setAttribute(
461:                                BlojsomConstants.PAGE_PARAM,
462:                                EDIT_BLOG_TEMPLATES_PAGE);
463:
464:                        return entries;
465:                    }
466:
467:                    String templateName = BlojsomUtils
468:                            .getFilenameFromPath(blogTemplate);
469:                    String templateExtension = BlojsomUtils
470:                            .getFileExtension(templateName);
471:
472:                    if (!_acceptedTemplateExtensions
473:                            .containsKey(templateExtension)) {
474:                        addOperationResultMessage(context, formatAdminResource(
475:                                INVALID_TEMPLATE_EXTENSION_KEY,
476:                                INVALID_TEMPLATE_EXTENSION_KEY, blog
477:                                        .getBlogAdministrationLocale(),
478:                                new Object[] { templateExtension }));
479:                        httpServletRequest.setAttribute(
480:                                BlojsomConstants.PAGE_PARAM,
481:                                EDIT_BLOG_TEMPLATES_PAGE);
482:
483:                        return entries;
484:                    } else {
485:                        blogTemplateDirectory = BlojsomUtils
486:                                .normalize(blogTemplateDirectory);
487:                        File addedTemplateDirectory = new File(
488:                                templatesDirectory, blogTemplateDirectory);
489:                        if (addedTemplateDirectory.exists()) {
490:                            context
491:                                    .put(
492:                                            BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE_FILE,
493:                                            blogTemplateDirectory
494:                                                    + File.separator
495:                                                    + templateName);
496:                            context
497:                                    .put(
498:                                            BLOJSOM_PLUGIN_EDIT_BLOG_TEMPLATES_TEMPLATE,
499:                                            "");
500:
501:                            httpServletRequest.setAttribute(
502:                                    BlojsomConstants.PAGE_PARAM,
503:                                    EDIT_BLOG_TEMPLATE_PAGE);
504:                        } else {
505:                            addOperationResultMessage(context,
506:                                    getAdminResource(
507:                                            TEMPLATE_DIRECTORY_NONEXISTENT_KEY,
508:                                            TEMPLATE_DIRECTORY_NONEXISTENT_KEY,
509:                                            blog.getBlogAdministrationLocale()));
510:                        }
511:                    }
512:                } else if (ADD_TEMPLATE_DIRECTORY_ACTION.equals(action)) {
513:                    _logger
514:                            .debug("User requested add blog template directory action");
515:
516:                    String templateDirectoryToAdd = BlojsomUtils
517:                            .getRequestValue(TEMPLATE_DIRECTORY_TO_ADD,
518:                                    httpServletRequest);
519:                    String blogTemplateDirectory = BlojsomUtils
520:                            .getRequestValue(BLOG_TEMPLATE_DIRECTORY,
521:                                    httpServletRequest);
522:                    if (BlojsomUtils.checkNullOrBlank(templateDirectoryToAdd)) {
523:                        addOperationResultMessage(context, getAdminResource(
524:                                TEMPLATE_DIRECTORY_NOTSPECIFIED_KEY,
525:                                TEMPLATE_DIRECTORY_NOTSPECIFIED_KEY, blog
526:                                        .getBlogAdministrationLocale()));
527:                    } else {
528:                        blogTemplateDirectory = BlojsomUtils
529:                                .normalize(blogTemplateDirectory);
530:                        templateDirectoryToAdd = BlojsomUtils
531:                                .normalize(templateDirectoryToAdd);
532:
533:                        File newTemplateDirectory = new File(
534:                                templatesDirectory, blogTemplateDirectory
535:                                        + File.separator
536:                                        + templateDirectoryToAdd);
537:                        _logger.debug("Adding blog template directory: "
538:                                + newTemplateDirectory.toString());
539:
540:                        if (!newTemplateDirectory.mkdir()) {
541:                            addOperationResultMessage(
542:                                    context,
543:                                    formatAdminResource(
544:                                            UNABLE_TO_ADD_TEMPLATE_DIRECTORY_KEY,
545:                                            UNABLE_TO_ADD_TEMPLATE_DIRECTORY_KEY,
546:                                            blog.getBlogAdministrationLocale(),
547:                                            new Object[] { templateDirectoryToAdd }));
548:                        } else {
549:                            addOperationResultMessage(
550:                                    context,
551:                                    formatAdminResource(
552:                                            ADDED_TEMPLATE_DIRECTORY_KEY,
553:                                            ADDED_TEMPLATE_DIRECTORY_KEY,
554:                                            blog.getBlogAdministrationLocale(),
555:                                            new Object[] { templateDirectoryToAdd }));
556:
557:                            putTemplateDirectoriesInContext(templatesDirectory,
558:                                    context);
559:                        }
560:                    }
561:
562:                    httpServletRequest.setAttribute(
563:                            BlojsomConstants.PAGE_PARAM,
564:                            EDIT_BLOG_TEMPLATES_PAGE);
565:                } else if (DELETE_TEMPLATE_DIRECTORY_ACTION.equals(action)) {
566:                    _logger
567:                            .debug("User requested delete blog template directory action");
568:
569:                    String blogTemplateDirectory = BlojsomUtils
570:                            .getRequestValue(BLOG_TEMPLATE_DIRECTORY,
571:                                    httpServletRequest);
572:                    if (BlojsomUtils.checkNullOrBlank(blogTemplateDirectory)) {
573:                        addOperationResultMessage(context, getAdminResource(
574:                                CANNOT_REMOVE_TOP_TEMPLATE_DIRECTORY_KEY,
575:                                CANNOT_REMOVE_TOP_TEMPLATE_DIRECTORY_KEY, blog
576:                                        .getBlogAdministrationLocale()));
577:                    } else {
578:                        blogTemplateDirectory = BlojsomUtils
579:                                .normalize(blogTemplateDirectory);
580:                        _logger.debug("Sanitized template directory: "
581:                                + blogTemplateDirectory);
582:                        File templateDirectoryToDelete = new File(
583:                                templatesDirectory, blogTemplateDirectory);
584:                        _logger.debug("Removing blog template directory: "
585:                                + templateDirectoryToDelete);
586:
587:                        if (!BlojsomUtils.deleteDirectory(
588:                                templateDirectoryToDelete, true)) {
589:                            addOperationResultMessage(
590:                                    context,
591:                                    formatAdminResource(
592:                                            UNABLE_TO_DELETE_TEMPLATE_DIRECTORY_KEY,
593:                                            UNABLE_TO_DELETE_TEMPLATE_DIRECTORY_KEY,
594:                                            blog.getBlogAdministrationLocale(),
595:                                            new Object[] { blogTemplateDirectory }));
596:                        } else {
597:                            addOperationResultMessage(
598:                                    context,
599:                                    formatAdminResource(
600:                                            REMOVED_TEMPLATE_DIRECTORY_KEY,
601:                                            REMOVED_TEMPLATE_DIRECTORY_KEY,
602:                                            blog.getBlogAdministrationLocale(),
603:                                            new Object[] { blogTemplateDirectory }));
604:
605:                            putTemplateDirectoriesInContext(templatesDirectory,
606:                                    context);
607:                        }
608:                    }
609:
610:                    httpServletRequest.setAttribute(
611:                            BlojsomConstants.PAGE_PARAM,
612:                            EDIT_BLOG_TEMPLATES_PAGE);
613:                } else if (DELETE_BLOG_TEMPLATE_ACTION.equals(action)) {
614:                    _logger
615:                            .debug("User requested delete blog template directory action");
616:
617:                    String blogTemplate = BlojsomUtils.getRequestValue(
618:                            BLOG_TEMPLATE, httpServletRequest);
619:                    if (BlojsomUtils.checkNullOrBlank(blogTemplate)) {
620:                        addOperationResultMessage(context, getAdminResource(
621:                                NO_TEMPLATE_NAME_KEY, NO_TEMPLATE_NAME_KEY,
622:                                blog.getBlogAdministrationLocale()));
623:                    }
624:
625:                    blogTemplate = sanitizeFilename(blogTemplate);
626:                    File templateToDelete = new File(templatesDirectory,
627:                            blogTemplate);
628:                    _logger.debug("Deleting blog template: "
629:                            + templateToDelete.toString());
630:
631:                    if (!templateToDelete.delete()) {
632:                        addOperationResultMessage(context, formatAdminResource(
633:                                UNABLE_TO_DELETE_TEMPLATE_KEY,
634:                                UNABLE_TO_DELETE_TEMPLATE_KEY, blog
635:                                        .getBlogAdministrationLocale(),
636:                                new Object[] { blogTemplate }));
637:                    } else {
638:                        addOperationResultMessage(context, formatAdminResource(
639:                                DELETED_TEMPLATE_KEY, DELETED_TEMPLATE_KEY,
640:                                blog.getBlogAdministrationLocale(),
641:                                new Object[] { blogTemplate }));
642:
643:                        putTemplatesInContext(templatesDirectory, context);
644:                    }
645:
646:                    httpServletRequest.setAttribute(
647:                            BlojsomConstants.PAGE_PARAM,
648:                            EDIT_BLOG_TEMPLATES_PAGE);
649:                }
650:
651:                return entries;
652:            }
653:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.