Source Code Cross Referenced for ManageServlet.java in  » Wiki-Engine » JAMWiki » org » jamwiki » servlets » 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 » Wiki Engine » JAMWiki » org.jamwiki.servlets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003:         *
004:         * This program is free software; you can redistribute it and/or modify
005:         * it under the terms of the latest version of the GNU Lesser General
006:         * Public License as published by the Free Software Foundation;
007:         *
008:         * This program is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011:         * GNU Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public License
014:         * along with this program (LICENSE.txt); if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
016:         */package org.jamwiki.servlets;
017:
018:        import javax.servlet.http.HttpServletRequest;
019:        import javax.servlet.http.HttpServletResponse;
020:        import org.apache.commons.lang.StringUtils;
021:        import org.jamwiki.WikiBase;
022:        import org.jamwiki.WikiException;
023:        import org.jamwiki.WikiMessage;
024:        import org.jamwiki.model.Topic;
025:        import org.jamwiki.model.TopicVersion;
026:        import org.jamwiki.model.WikiUser;
027:        import org.jamwiki.utils.Utilities;
028:        import org.jamwiki.utils.WikiLogger;
029:        import org.jamwiki.utils.WikiUtil;
030:        import org.springframework.web.servlet.ModelAndView;
031:
032:        /**
033:         * Used to provide capability for deleting, undeleting, and protecting topics.
034:         */
035:        public class ManageServlet extends JAMWikiServlet {
036:
037:            private static final WikiLogger logger = WikiLogger
038:                    .getLogger(ManageServlet.class.getName());
039:            protected static final String JSP_ADMIN_MANAGE = "admin-manage.jsp";
040:
041:            /**
042:             *
043:             */
044:            protected ModelAndView handleJAMWikiRequest(
045:                    HttpServletRequest request, HttpServletResponse response,
046:                    ModelAndView next, WikiPageInfo pageInfo) throws Exception {
047:                if (!StringUtils.isBlank(request.getParameter("delete"))) {
048:                    delete(request, next, pageInfo);
049:                } else if (!StringUtils.isBlank(request
050:                        .getParameter("undelete"))) {
051:                    undelete(request, next, pageInfo);
052:                } else if (!StringUtils.isBlank(request
053:                        .getParameter("permissions"))) {
054:                    permissions(request, next, pageInfo);
055:                } else {
056:                    view(request, next, pageInfo);
057:                }
058:                return next;
059:            }
060:
061:            /**
062:             *
063:             */
064:            private void delete(HttpServletRequest request, ModelAndView next,
065:                    WikiPageInfo pageInfo) throws Exception {
066:                String topicName = WikiUtil.getTopicFromRequest(request);
067:                if (topicName == null) {
068:                    throw new WikiException(new WikiMessage(
069:                            "common.exception.notopic"));
070:                }
071:                deletePage(request, next, pageInfo, topicName);
072:                if (!StringUtils.isBlank(request
073:                        .getParameter("manageCommentsPage"))) {
074:                    String manageCommentsPage = Utilities.decodeFromRequest(
075:                            request.getParameter("manageCommentsPage"), true);
076:                    if (WikiUtil.isCommentsPage(manageCommentsPage)
077:                            && !manageCommentsPage.equals(topicName)) {
078:                        deletePage(request, next, pageInfo, manageCommentsPage);
079:                    }
080:                }
081:                next.addObject("message", new WikiMessage(
082:                        "manage.message.updated", topicName));
083:                view(request, next, pageInfo);
084:            }
085:
086:            /**
087:             *
088:             */
089:            private void deletePage(HttpServletRequest request,
090:                    ModelAndView next, WikiPageInfo pageInfo, String topicName)
091:                    throws Exception {
092:                String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
093:                Topic topic = WikiBase.getDataHandler().lookupTopic(
094:                        virtualWiki, topicName, true, null);
095:                if (topic.getDeleted()) {
096:                    logger
097:                            .warning("Attempt to delete a topic that is already deleted: "
098:                                    + virtualWiki + " / " + topicName);
099:                    return;
100:                }
101:                String contents = "";
102:                topic.setTopicContent(contents);
103:                WikiUser user = ServletUtil.currentUser();
104:                TopicVersion topicVersion = new TopicVersion(user, ServletUtil
105:                        .getIpAddress(request), request
106:                        .getParameter("deleteComment"), contents);
107:                topicVersion.setEditType(TopicVersion.EDIT_DELETE);
108:                WikiBase.getDataHandler().deleteTopic(topic, topicVersion,
109:                        true, null);
110:            }
111:
112:            /**
113:             *
114:             */
115:            private void permissions(HttpServletRequest request,
116:                    ModelAndView next, WikiPageInfo pageInfo) throws Exception {
117:                String topicName = WikiUtil.getTopicFromRequest(request);
118:                String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
119:                if (topicName == null) {
120:                    throw new WikiException(new WikiMessage(
121:                            "common.exception.notopic"));
122:                }
123:                Topic topic = WikiBase.getDataHandler().lookupTopic(
124:                        virtualWiki, topicName, false, null);
125:                if (topic == null) {
126:                    throw new WikiException(new WikiMessage(
127:                            "common.exception.notopic"));
128:                }
129:                topic.setReadOnly(request.getParameter("readOnly") != null);
130:                topic.setAdminOnly(request.getParameter("adminOnly") != null);
131:                WikiUser user = ServletUtil.currentUser();
132:                TopicVersion topicVersion = new TopicVersion(user, ServletUtil
133:                        .getIpAddress(request), Utilities.formatMessage(
134:                        "manage.message.permissions", request.getLocale()),
135:                        topic.getTopicContent());
136:                topicVersion.setEditType(TopicVersion.EDIT_PERMISSION);
137:                WikiBase.getDataHandler().writeTopic(topic, topicVersion, null,
138:                        null, true, null);
139:                next.addObject("message", new WikiMessage(
140:                        "manage.message.updated", topicName));
141:                view(request, next, pageInfo);
142:            }
143:
144:            /**
145:             *
146:             */
147:            private void undelete(HttpServletRequest request,
148:                    ModelAndView next, WikiPageInfo pageInfo) throws Exception {
149:                String topicName = WikiUtil.getTopicFromRequest(request);
150:                if (topicName == null) {
151:                    throw new WikiException(new WikiMessage(
152:                            "common.exception.notopic"));
153:                }
154:                undeletePage(request, next, pageInfo, topicName);
155:                if (!StringUtils.isBlank(request
156:                        .getParameter("manageCommentsPage"))) {
157:                    String manageCommentsPage = Utilities.decodeFromRequest(
158:                            request.getParameter("manageCommentsPage"), true);
159:                    if (WikiUtil.isCommentsPage(manageCommentsPage)
160:                            && !manageCommentsPage.equals(topicName)) {
161:                        undeletePage(request, next, pageInfo,
162:                                manageCommentsPage);
163:                    }
164:                }
165:                next.addObject("message", new WikiMessage(
166:                        "manage.message.updated", topicName));
167:                view(request, next, pageInfo);
168:            }
169:
170:            /**
171:             *
172:             */
173:            private void undeletePage(HttpServletRequest request,
174:                    ModelAndView next, WikiPageInfo pageInfo, String topicName)
175:                    throws Exception {
176:                String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
177:                Topic topic = WikiBase.getDataHandler().lookupTopic(
178:                        virtualWiki, topicName, true, null);
179:                if (!topic.getDeleted()) {
180:                    logger
181:                            .warning("Attempt to undelete a topic that is not deleted: "
182:                                    + virtualWiki + " / " + topicName);
183:                    return;
184:                }
185:                TopicVersion previousVersion = WikiBase.getDataHandler()
186:                        .lookupTopicVersion(
187:                                topic.getCurrentVersionId().intValue(), null);
188:                while (previousVersion != null
189:                        && previousVersion.getPreviousTopicVersionId() != null
190:                        && previousVersion.getEditType() == TopicVersion.EDIT_DELETE) {
191:                    // loop back to find the last non-delete edit
192:                    previousVersion = WikiBase.getDataHandler()
193:                            .lookupTopicVersion(
194:                                    previousVersion.getPreviousTopicVersionId()
195:                                            .intValue(), null);
196:                }
197:                String contents = previousVersion.getVersionContent();
198:                topic.setTopicContent(contents);
199:                WikiUser user = ServletUtil.currentUser();
200:                TopicVersion topicVersion = new TopicVersion(user, ServletUtil
201:                        .getIpAddress(request), request
202:                        .getParameter("undeleteComment"), contents);
203:                topicVersion.setEditType(TopicVersion.EDIT_UNDELETE);
204:                WikiBase.getDataHandler().undeleteTopic(topic, topicVersion,
205:                        true, null);
206:            }
207:
208:            /**
209:             *
210:             */
211:            private void view(HttpServletRequest request, ModelAndView next,
212:                    WikiPageInfo pageInfo) throws Exception {
213:                String topicName = WikiUtil.getTopicFromRequest(request);
214:                String virtualWiki = WikiUtil.getVirtualWikiFromURI(request);
215:                Topic topic = WikiBase.getDataHandler().lookupTopic(
216:                        virtualWiki, topicName, true, null);
217:                if (topic == null) {
218:                    throw new WikiException(new WikiMessage(
219:                            "common.exception.notopic"));
220:                }
221:                String commentsPage = WikiUtil.extractCommentsLink(topicName);
222:                if (!topicName.equals(commentsPage)) {
223:                    Topic commentsTopic = WikiBase.getDataHandler()
224:                            .lookupTopic(virtualWiki, commentsPage, true, null);
225:                    if (commentsTopic != null
226:                            && commentsTopic.getDeleted() == topic.getDeleted()) {
227:                        // add option to also move comments page
228:                        next.addObject("manageCommentsPage", commentsPage);
229:                    }
230:                }
231:                next.addObject("readOnly", new Boolean(topic.getReadOnly()));
232:                next.addObject("adminOnly", new Boolean(topic.getAdminOnly()));
233:                next.addObject("deleted", new Boolean(
234:                        topic.getDeleteDate() != null));
235:                pageInfo.setTopicName(topicName);
236:                pageInfo.setContentJsp(JSP_ADMIN_MANAGE);
237:                pageInfo
238:                        .setPageTitle(new WikiMessage("manage.title", topicName));
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.