Source Code Cross Referenced for AdministrationServlet.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 Lesser General Public Licence (LGPL)
004:         */
005:        package vqwiki.servlets;
006:
007:        import org.apache.log4j.Logger;
008:
009:        import vqwiki.ChangeLog;
010:        import vqwiki.Environment;
011:        import vqwiki.Topic;
012:        import vqwiki.WikiBase;
013:        import vqwiki.WikiMembers;
014:        import vqwiki.db.DBDate;
015:        import vqwiki.utils.JSPUtils;
016:        import vqwiki.utils.Utilities;
017:
018:        import javax.servlet.ServletException;
019:        import javax.servlet.http.HttpServletRequest;
020:        import javax.servlet.http.HttpServletResponse;
021:        import java.io.IOException;
022:        import java.text.DateFormat;
023:        import java.util.Collection;
024:        import java.util.Iterator;
025:        import java.util.ResourceBundle;
026:
027:        public class AdministrationServlet extends VQWikiServlet {
028:
029:            private static final Logger logger = Logger
030:                    .getLogger(AdministrationServlet.class);
031:            private Environment environment = Environment.getInstance();
032:
033:            /**
034:             *
035:             */
036:            protected void doGet(HttpServletRequest request,
037:                    HttpServletResponse httpServletResponse)
038:                    throws ServletException, IOException {
039:                if (!Utilities.isAdmin(request)) {
040:                    request.setAttribute("title", Utilities.resource(
041:                            "login.title", request.getLocale()));
042:                    logger.debug("Current URL: " + request.getRequestURL());
043:                    String rootPath = JSPUtils.createLocalRootPath(request,
044:                            (String) request.getAttribute("virtualWiki"));
045:                    StringBuffer buffer = new StringBuffer();
046:                    buffer.append(rootPath);
047:                    buffer.append("Wiki?action=" + WikiServlet.ACTION_ADMIN
048:                            + "&username=admin");
049:                    request.setAttribute("redirect", buffer.toString());
050:                    dispatch("/jsp/login.jsp", request, httpServletResponse);
051:                    return;
052:                }
053:                if (request.getParameter("function") != null) {
054:                    if (request.getParameter("function").equals("logout")) {
055:                        request.getSession().removeAttribute("admin");
056:                        redirect(JSPUtils.createRedirectURL(request,
057:                                "Wiki?StartingPoints"), httpServletResponse);
058:                        return;
059:                    }
060:                }
061:                dispatch("/jsp/admin.jsp", request, httpServletResponse);
062:            }
063:
064:            /**
065:             *
066:             */
067:            protected void doPost(HttpServletRequest request,
068:                    HttpServletResponse response) throws ServletException,
069:                    IOException {
070:                logger.debug("Admin request");
071:                String message = "";
072:                try {
073:                    ResourceBundle messages = ResourceBundle.getBundle(
074:                            "ApplicationResources", request.getLocale());
075:                    String virtualWiki = (String) request
076:                            .getAttribute("virtual-wiki");
077:                    String functionType = request.getParameter("function");
078:                    if (request.getParameter("function") == null) {
079:                        // nothing
080:                    } else if (functionType.equals("refreshIndex")) {
081:                        WikiBase.getInstance().getSearchEngineInstance()
082:                                .refreshIndex();
083:                        message = messages
084:                                .getString("admin.message.indexrefreshed");
085:                    } else if (request.getParameter("function")
086:                            .equals("logout")) {
087:                        request.getSession().removeAttribute("admin");
088:                        redirect("Wiki?StartingPoints", response);
089:                        return;
090:                    } else if (functionType.equals("purge")) {
091:                        Collection purged = WikiBase.getInstance()
092:                                .purgeDeletes(
093:                                        request.getParameter("virtual-wiki"));
094:                        StringBuffer buffer = new StringBuffer();
095:                        ChangeLog cl = WikiBase.getInstance()
096:                                .getChangeLogInstance();
097:                        cl.removeChanges(virtualWiki, purged);
098:                        buffer.append("Purged: ");
099:                        for (Iterator iterator = purged.iterator(); iterator
100:                                .hasNext();) {
101:                            String topicName = (String) iterator.next();
102:                            buffer.append(topicName);
103:                            buffer.append("; ");
104:                        }
105:                        message = buffer.toString();
106:                    } else if (functionType.equals("purge-versions")) {
107:                        DateFormat dateFormat = DateFormat.getInstance();
108:                        DBDate date = new DBDate(dateFormat.parse(request
109:                                .getParameter("purgedate")));
110:                        WikiBase.getInstance().purgeVersionsOlderThan(
111:                                virtualWiki, date);
112:                    } else if (functionType.equals("properties")) {
113:                        Environment en = environment;
114:                        en
115:                                .setEncodePasswords(request
116:                                        .getParameter(Environment.PROPERTY_ENCODE_PASSWORDS) != null);
117:                        en.setEditTimeOut(Integer.parseInt(request
118:                                .getParameter("editTimeout")));
119:                        en.setSetting(Environment.PROPERTY_RECENT_CHANGES_DAYS,
120:                                request.getParameter("recentChangesDays"));
121:                        en.setSetting(Environment.PROPERTY_MAXIMUM_BACKLINKS,
122:                                request.getParameter("maximumBacklinks"));
123:                        en.setIndexRefreshInterval(Integer.parseInt(request
124:                                .getParameter("indexInterval")));
125:                        en
126:                                .setRecentChangesRefreshInterval(Integer
127:                                        .parseInt(request
128:                                                .getParameter("recentChangesInterval")));
129:                        en.setSetting(Environment.PROPERTY_SMTP_HOST, request
130:                                .getParameter("smtp"));
131:                        en.setSetting(Environment.PROPERTY_SMTP_USERNAME,
132:                                request.getParameter("smtpUsername"));
133:                        en
134:                                .setSmtpPassword(request
135:                                        .getParameter("smtpPassword"));
136:                        en.setSetting(Environment.PROPERTY_REPLY_ADDRESS,
137:                                request.getParameter("replyAddress"));
138:                        en.setSetting(Environment.PROPERTY_NEW_LINE_BREAKS,
139:                                request.getParameter("newLineBreaks"));
140:                        en
141:                                .setVersioningOn(request
142:                                        .getParameter("versioning") != null);
143:                        en
144:                                .setAllowHTML(request.getParameter("allowHtml") != null);
145:                        en.setForceUsername(request
146:                                .getParameter("forceUserName") != null);
147:                        en.setAllowBackTick(request
148:                                .getParameter("allowBackTick") != null);
149:                        en
150:                                .setSetting(
151:                                        Environment.PROPERTY_ALLOW_VWIKI_LIST,
152:                                        request
153:                                                .getParameter("allowVirtualWikiList") != null);
154:                        en
155:                                .setSetting(
156:                                        Environment.PROPERTY_ATTACHMENT_INDEXING_ENABLED,
157:                                        request
158:                                                .getParameter("indexAttachments") != null);
159:                        en.setSetting(
160:                                Environment.PROPERTY_EXTLINKS_INDEXING_ENABLED,
161:                                request.getParameter("indexExtLinks") != null);
162:                        en
163:                                .setSetting(
164:                                        Environment.PROPERTY_ATTACHMENT_TIMESTAMP,
165:                                        request
166:                                                .getParameter("attachmentTimestamp") != null);
167:                        en
168:                                .setSetting(
169:                                        Environment.PROPERTY_FRANZ_NEWTOPIC_STYLE,
170:                                        request
171:                                                .getParameter("franzNewTopicStyle") != null);
172:                        en.setUploadDir(request.getParameter("uploadDir"));
173:                        en.setHomeDir(request.getParameter("homeDir"));
174:                        en.setPersistenceType(Integer.parseInt(request
175:                                .getParameter("persistenceType")));
176:                        if (request.getParameter("driver") != null) {
177:                            en.setDriver(request.getParameter("driver"));
178:                            en.setUrl(request.getParameter("url"));
179:                            en.setUserName(request.getParameter("dbUsername"));
180:                            en.setPassword(request.getParameter("dbPassword"));
181:                            en.setSetting(Environment.PROPERTY_DBCP_MAX_ACTIVE,
182:                                    Integer.parseInt(request
183:                                            .getParameter("dbcp_max_active")));
184:                            en.setSetting(Environment.PROPERTY_DBCP_MAX_IDLE,
185:                                    Integer.parseInt(request
186:                                            .getParameter("dbcp_max_idle")));
187:                            en
188:                                    .setSetting(
189:                                            Environment.PROPERTY_DBCP_TEST_ON_BORROW,
190:                                            request
191:                                                    .getParameter("dbcp_test_on_borrow") != null);
192:                            en
193:                                    .setSetting(
194:                                            Environment.PROPERTY_DBCP_TEST_ON_RETURN,
195:                                            request
196:                                                    .getParameter("dbcp_test_on_return") != null);
197:                            en
198:                                    .setSetting(
199:                                            Environment.PROPERTY_DBCP_TEST_WHILE_IDLE,
200:                                            request
201:                                                    .getParameter("dbcp_test_while_idle") != null);
202:                            en
203:                                    .setSetting(
204:                                            Environment.PROPERTY_DBCP_MIN_EVICTABLE_IDLE_TIME,
205:                                            Integer
206:                                                    .parseInt(request
207:                                                            .getParameter("dbcp_min_evictable_idle_time")));
208:                            en
209:                                    .setSetting(
210:                                            Environment.PROPERTY_DBCP_TIME_BETWEEN_EVICTION_RUNS,
211:                                            Integer
212:                                                    .parseInt(request
213:                                                            .getParameter("dbcp_time_between_eviction_runs")));
214:                            en
215:                                    .setSetting(
216:                                            Environment.PROPERTY_DBCP_NUM_TESTS_PER_EVICTION_RUN,
217:                                            Integer
218:                                                    .parseInt(request
219:                                                            .getParameter("dbcp_num_tests_per_eviction_run")));
220:                            en
221:                                    .setSetting(
222:                                            Environment.PROPERTY_DBCP_WHEN_EXHAUSTED_ACTION,
223:                                            Integer
224:                                                    .parseInt(request
225:                                                            .getParameter("dbcp_when_exhausted_action")));
226:                            en
227:                                    .setSetting(
228:                                            Environment.PROPERTY_DBCP_VALIDATION_QUERY,
229:                                            request
230:                                                    .getParameter("dbcp_validation_query"));
231:                            en
232:                                    .setSetting(
233:                                            Environment.PROPERTY_DBCP_REMOVE_ABANDONED,
234:                                            request
235:                                                    .getParameter("dbcp_remove_abandoned") != null);
236:                            en
237:                                    .setSetting(
238:                                            Environment.PROPERTY_DBCP_REMOVE_ABANDONED_TIMEOUT,
239:                                            Integer
240:                                                    .parseInt(request
241:                                                            .getParameter("dbcp_remove_abandoned_timeout")));
242:                            en
243:                                    .setSetting(
244:                                            Environment.PROPERTY_DBCP_LOG_ABANDONED,
245:                                            request
246:                                                    .getParameter("dbcp_log_abandoned") != null);
247:                        }
248:                        en.setSetting(Environment.PROPERTY_ALLOW_TEMPLATES,
249:                                request.getParameter("allowTemplates") != null);
250:                        en.setSetting(Environment.PROPERTY_USE_PREVIEW, request
251:                                .getParameter("usePreview") != null);
252:                        en.setSetting(Environment.PROPERTY_DEFAULT_TOPIC,
253:                                request.getParameter("defaultTopic"));
254:                        en.setSetting(Environment.PROPERTY_PARSER, request
255:                                .getParameter(Environment.PROPERTY_PARSER));
256:                        en.setSetting(Environment.PROPERTY_FORMAT_LEXER,
257:                                request.getParameter("formatLexer"));
258:                        en.setSetting(Environment.PROPERTY_LINK_LEXER, request
259:                                .getParameter("linkLexer"));
260:                        en.setSetting(Environment.PROPERTY_LAYOUT_LEXER,
261:                                request.getParameter("layoutLexer"));
262:                        int maxFileSizeInKB = Integer.parseInt(request
263:                                .getParameter("maximumFileSize"));
264:                        en.setSetting(Environment.PROPERTY_MAX_FILE_SIZE,
265:                                maxFileSizeInKB * 1000);
266:                        en.setSetting(Environment.PROPERTY_ATTACHMENT_TYPE,
267:                                request.getParameter("attachmentType"));
268:                        en.setSetting(Environment.PROPERTY_CONVERT_TABS,
269:                                (request.getParameter("convertTabs") != null));
270:                        en
271:                                .setSetting(
272:                                        Environment.PROPERTY_CONVERT_ENTITIES,
273:                                        (request
274:                                                .getParameter("convertEntities") != null));
275:                        if (request.getParameter("databaseType") != null) {
276:                            en.setSetting(Environment.PROPERTY_DATABASE_TYPE,
277:                                    request.getParameter("databaseType"));
278:                        }
279:                        if (request.getParameter("wikiServerHostname") != null
280:                                && !request.getParameter("wikiServerHostname")
281:                                        .equals("")) {
282:                            en.setSetting(
283:                                    Environment.PROPERTY_WIKI_SERVER_HOSTNAME,
284:                                    request.getParameter("wikiServerHostname"));
285:                        } else {
286:                            en.setSetting(
287:                                    Environment.PROPERTY_WIKI_SERVER_HOSTNAME,
288:                                    "");
289:                        }
290:                        en.setSetting(Environment.PROPERTY_FILE_ENCODING,
291:                                request.getParameter("fileEncoding"));
292:                        en
293:                                .setSetting(
294:                                        Environment.PROPERTY_SEPARATE_WIKI_TITLE_WORDS,
295:                                        request
296:                                                .getParameter("separateWikiTitleWords") != null);
297:                        en
298:                                .setSetting(
299:                                        Environment.PROPERTY_SUPPRESS_NOTIFY_WITHIN_SAME_DAY,
300:                                        request
301:                                                .getParameter("suppressNotifyWithinSameDay") != null);
302:                        en.setUsergroupType(Integer.parseInt(request
303:                                .getParameter("usergroupType")));
304:                        String[] autoFill = {
305:                                Environment.PROPERTY_USERGROUP_FACTORY,
306:                                Environment.PROPERTY_USERGROUP_URL,
307:                                Environment.PROPERTY_USERGROUP_USERNAME,
308:                                Environment.PROPERTY_USERGROUP_PASSWORD,
309:                                Environment.PROPERTY_USERGROUP_BASIC_SEARCH,
310:                                Environment.PROPERTY_USERGROUP_SEARCH_RESTRICTIONS,
311:                                Environment.PROPERTY_USERGROUP_USERID_FIELD,
312:                                Environment.PROPERTY_USERGROUP_FULLNAME_FIELD,
313:                                Environment.PROPERTY_USERGROUP_MAIL_FIELD,
314:                                Environment.PROPERTY_USERGROUP_DETAILVIEW };
315:                        for (int i = 0; i < autoFill.length; i++) {
316:                            if (request.getParameter(autoFill[i]) != null) {
317:                                if (autoFill[i]
318:                                        .equals(Environment.PROPERTY_USERGROUP_PASSWORD)) {
319:                                    en.setUserGroupPassword(request
320:                                            .getParameter(autoFill[i]));
321:                                } else {
322:                                    en.setSetting(autoFill[i], request
323:                                            .getParameter(autoFill[i]));
324:                                }
325:                            }
326:                        }
327:                        // FIXME (PARSER_TEMP) - temporary property until conversion is complete
328:                        en
329:                                .setUseNewParser(request
330:                                        .getParameter(Environment.PROPERTY_USE_NEW_PARSER) != null);
331:                        en.saveProperties();
332:                        en.refresh();
333:                        WikiBase.initialise();
334:                        message = messages
335:                                .getString("admin.message.changessaved");
336:                    } else if (functionType.equals("clearEditLock")) {
337:                        WikiBase base = WikiBase.getInstance();
338:                        base.unlockTopic(request.getParameter("virtual-wiki"),
339:                                request.getParameter("topic"));
340:                        message = Utilities.resource(
341:                                "admin.message.lockcleared", request
342:                                        .getLocale());
343:                    } else if (functionType.equals("removeUser")) {
344:                        String user = request.getParameter("userName");
345:                        WikiMembers members = WikiBase.getInstance()
346:                                .getWikiMembersInstance(virtualWiki);
347:                        if (members.removeMember(user)) {
348:                            message = user
349:                                    + messages
350:                                            .getString("admin.message.userremoved.success");
351:                        } else {
352:                            message = user
353:                                    + messages
354:                                            .getString("admin.message.userremoved.failure");
355:                        }
356:                    } else if (functionType.equals("addVirtualWiki")) {
357:                        String newWiki = request.getParameter("newVirtualWiki");
358:                        logger.debug("Adding new Wiki: " + newWiki);
359:                        WikiBase.getInstance().addVirtualWiki(newWiki);
360:                        message = messages
361:                                .getString("admin.message.virtualwikiadded");
362:                        WikiBase.initialise();
363:                    } else if (functionType.equals("changePassword")) {
364:                        String oldPassword = request
365:                                .getParameter("oldPassword");
366:                        String newPassword = request
367:                                .getParameter("newPassword");
368:                        String confirmPassword = request
369:                                .getParameter("confirmPassword");
370:                        if (!environment.getAdminPassword().equals(oldPassword)) {
371:                            message = messages
372:                                    .getString("admin.message.oldpasswordincorrect");
373:                        } else if (!newPassword.equals(confirmPassword)) {
374:                            message = messages
375:                                    .getString("admin.message.passwordsnomatch");
376:                        } else {
377:                            environment.setAdminPassword(newPassword);
378:                            environment.saveProperties();
379:                            message = messages
380:                                    .getString("admin.message.passwordchanged");
381:                        }
382:                    } else if ("panic".equals(functionType)) {
383:                        WikiBase.getInstance().panic();
384:                    }
385:                } catch (Exception err) {
386:                    if (err instanceof  java.sql.SQLException) {
387:                        logger.warn(
388:                                "SQL-Exception in the admin console catched",
389:                                err);
390:                        message = err.getMessage();
391:                    } else {
392:                        error(request, response, err);
393:                        return;
394:                    }
395:                }
396:                try {
397:                    String virtualWiki = (String) request
398:                            .getAttribute("virtualWiki");
399:                    if (request.getParameter("addReadOnly") != null) {
400:                        Topic t = new Topic(request
401:                                .getParameter("readOnlyTopic"));
402:                        t.makeTopicReadOnly(virtualWiki);
403:                    }
404:                    if (request.getParameter("removeReadOnly") != null) {
405:                        String[] topics = request
406:                                .getParameterValues("markRemove");
407:                        for (int i = 0; i < topics.length; i++) {
408:                            Topic t = new Topic(topics[i]);
409:                            t.makeTopicWritable(virtualWiki);
410:                        }
411:                    }
412:                } catch (Exception e) {
413:                    logger.error("", e);
414:                }
415:                String next = JSPUtils.createRedirectURL(request,
416:                        "Wiki?action=" + WikiServlet.ACTION_ADMIN + "&message="
417:                                + message);
418:                response.sendRedirect(response.encodeRedirectURL(next));
419:            }
420:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.