Source Code Cross Referenced for SaveTopicServlet.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » 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 » VeryQuickWiki » vqwiki.servlets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002 Gareth Cronin
003:         * This software is subject to the GNU Public Licence
004:         */
005:        package vqwiki.servlets;
006:
007:        import java.io.IOException;
008:        import java.util.Collection;
009:        import java.util.ResourceBundle;
010:
011:        import javax.servlet.RequestDispatcher;
012:        import javax.servlet.ServletException;
013:        import javax.servlet.http.HttpServletRequest;
014:        import javax.servlet.http.HttpServletResponse;
015:
016:        import vqwiki.Change;
017:        import vqwiki.ChangeLog;
018:        import vqwiki.SearchEngine;
019:        import vqwiki.Topic;
020:        import vqwiki.WikiBase;
021:        import vqwiki.file.FileChangeLog;
022:        import vqwiki.utils.JSPUtils;
023:        import vqwiki.utils.Utilities;
024:        import org.apache.log4j.Logger;
025:
026:        public class SaveTopicServlet extends VQWikiServlet {
027:
028:            private static final Logger logger = Logger
029:                    .getLogger(SaveTopicServlet.class);
030:
031:            /**
032:             *
033:             */
034:            protected void doPost(HttpServletRequest request,
035:                    HttpServletResponse response) throws ServletException,
036:                    IOException {
037:                logger.debug("Request for save");
038:                String virtualWiki = null;
039:                String user = request.getRemoteAddr();
040:                logger.debug("user: " + user);
041:                if (Utilities.getUserFromRequest(request) != null) {
042:                    user = Utilities.getUserFromRequest(request);
043:                }
044:                String topic = request.getParameter("topic");
045:                logger.debug("Saving topic: " + topic);
046:                if (topic == null) {
047:                    WikiServletException err = new WikiServletException(
048:                            "Topic must be specified");
049:                    error(request, response, err);
050:                    return;
051:                }
052:                WikiBase base = null;
053:                try {
054:                    base = WikiBase.getInstance();
055:                    virtualWiki = (String) request.getAttribute("virtual-wiki");
056:                    logger.debug("vwiki is " + virtualWiki);
057:                } catch (Exception err) {
058:                    error(request, response, new WikiServletException(err
059:                            .getMessage()));
060:                    return;
061:                }
062:                ResourceBundle messages = ResourceBundle.getBundle(
063:                        "ApplicationResources", request.getLocale());
064:                String append = messages.getString("edit.action.append");
065:                if (append == null)
066:                    append = "append";
067:                // First try the above templatelist.
068:                String templatevalue = request.getParameter("templateabove");
069:                String notemplate = Utilities.resource("edit.notemplate",
070:                        request.getLocale());
071:                if (templatevalue != null) {
072:                    // if it is not set try the below templatelist.
073:                    if (templatevalue.equals(notemplate)) {
074:                        templatevalue = request.getParameter("templatebelow");
075:                    }
076:                }
077:                if ((templatevalue != null)
078:                        && append.equals(request.getParameter("action"))) {
079:                    logger.debug("appending template contents from template: "
080:                            + templatevalue);
081:                    if (!templatevalue.equals(notemplate)) {
082:                        String templateContents = null;
083:                        Collection templateNames = null;
084:                        try {
085:                            templateContents = base.getTemplate(virtualWiki,
086:                                    templatevalue);
087:                            templateNames = base.getTemplates(virtualWiki);
088:                        } catch (Exception e) {
089:                            error(request, response, e);
090:                            return;
091:                        }
092:                        StringBuffer buffer = new StringBuffer();
093:                        buffer.append(request.getParameter("contents"));
094:                        buffer.append(templateContents);
095:                        request.setAttribute("contents", buffer.toString());
096:                        String title = Utilities.resource("edit", request
097:                                .getLocale())
098:                                + " " + topic;
099:                        request.setAttribute("title", title);
100:                        request.setAttribute("templateNames", templateNames);
101:                        request.setAttribute("topic", topic);
102:                        dispatch("/jsp/edit.jsp", request, response);
103:                        return;
104:                    } else {
105:                        Collection templateNames = null;
106:                        try {
107:                            templateNames = base.getTemplates(virtualWiki);
108:                        } catch (Exception e) {
109:                            error(request, response, e);
110:                            return;
111:                        }
112:                        StringBuffer buffer = new StringBuffer();
113:                        buffer.append(request.getParameter("contents"));
114:                        request.setAttribute("contents", buffer.toString());
115:                        String title = Utilities.resource("edit", request
116:                                .getLocale())
117:                                + " " + topic;
118:                        request.setAttribute("title", title);
119:                        request.setAttribute("templateNames", templateNames);
120:                        request.setAttribute("topic", topic);
121:                        dispatch("/jsp/edit.jsp", request, response);
122:                        return;
123:                    }
124:                }
125:                try {
126:                    Topic t = new Topic(topic);
127:                    if (t.isReadOnlyTopic(virtualWiki)) {
128:                        throw new WikiServletException(
129:                                WikiServletException.READ_ONLY);
130:                    }
131:                    String key = request.getSession().getId();
132:                    if (!base.holdsLock(virtualWiki, topic, key)) {
133:                        logger.debug("No lock for " + virtualWiki + "/" + topic
134:                                + "/" + key);
135:                        error(request, response, new WikiServletException(
136:                                WikiServletException.LOCK_TIMEOUT));
137:                        return;
138:                    }
139:                    String contents = request.getParameter("contents");
140:                    if (contents == null) {
141:                        error(request, response, new WikiServletException(
142:                                "Contents must be supplied"));
143:                        return;
144:                    }
145:                    base.write(virtualWiki, contents, request
146:                            .getParameter("convertTabs") != null, topic, user);
147:                    if (request.getParameter("minorEdit") == null) {
148:                        Change change = new Change();
149:                        change.setTopic(topic);
150:                        change.setUser(user);
151:                        change.setTime(new java.util.Date());
152:                        change.setVirtualWiki(virtualWiki);
153:                        ChangeLog cl = WikiBase.getInstance()
154:                                .getChangeLogInstance();
155:                        cl.logChange(change, request);
156:                    }
157:                    SearchEngine sedb = WikiBase.getInstance()
158:                            .getSearchEngineInstance();
159:                    sedb.indexText(virtualWiki, topic, request
160:                            .getParameter("contents"));
161:                } catch (Exception err) {
162:                    logger.debug("Exception saving: " + err.toString());
163:                    if (err instanceof  java.io.InvalidClassException) {
164:                        try {
165:                            ((FileChangeLog) WikiBase.getInstance()
166:                                    .getChangeLogInstance())
167:                                    .deleteChangeTableFile(virtualWiki);
168:                        } catch (Exception ignore) {
169:                        }
170:                        request
171:                                .setAttribute(
172:                                        "exception",
173:                                        new WikiServletException(
174:                                                "Due to a change to the RecentChanges mechanism, "
175:                                                        + "this upgrade is incompatible with previous recent changes, the offending file (wikihome/recent.hashtable) should now have been deleted, "
176:                                                        + "please restart the app server"));
177:                    } else {
178:                        request.setAttribute("exception",
179:                                new WikiServletException(err.toString()));
180:                    }
181:                    err.printStackTrace();
182:                    RequestDispatcher dispatch = request
183:                            .getRequestDispatcher("/jsp/servlet-error.jsp");
184:                    dispatch.forward(request, response);
185:                    return;
186:                }
187:                try {
188:                    base.unlockTopic(virtualWiki, topic);
189:                } catch (Exception err) {
190:                    request.setAttribute("exception", new WikiServletException(
191:                            err.toString()));
192:                    err.printStackTrace();
193:                    RequestDispatcher dispatch = request
194:                            .getRequestDispatcher("/jsp/servlet-error.jsp");
195:                    dispatch.forward(request, response);
196:                    return;
197:                }
198:                String next = null;
199:                response.setLocale(request.getLocale());
200:                next = JSPUtils.createRedirectURL(request, "Wiki?"
201:                        + JSPUtils.encodeURL(topic));
202:                logger.debug("Creating redirect: " + next);
203:                logger.debug("Redirect URL: "
204:                        + response.encodeRedirectURL(next));
205:                response.sendRedirect(response.encodeRedirectURL(next));
206:            }
207:
208:            /**
209:             *
210:             */
211:            protected void doGet(HttpServletRequest request,
212:                    HttpServletResponse response) throws ServletException,
213:                    IOException {
214:                response.sendError(HttpServletResponse.SC_BAD_REQUEST,
215:                        "GET requests are not serviced in saves");
216:            }
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.