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


001:        package vqwiki.file;
002:
003:        import JSX.ObjIn;
004:        import JSX.ObjOut;
005:        import org.apache.log4j.Logger;
006:        import vqwiki.AbstractWikiMembers;
007:        import vqwiki.Environment;
008:        import vqwiki.WikiException;
009:        import vqwiki.WikiMember;
010:
011:        import javax.servlet.http.HttpServletRequest;
012:        import java.io.File;
013:        import java.io.FileReader;
014:        import java.io.FileWriter;
015:        import java.io.IOException;
016:        import java.util.*;
017:
018:        /**
019:         * Stores a list of usernames and their registered email addresses so
020:         * that users may set notifications and reminders per topic page. Users
021:         * must set a canonical username and provide a valid email address.
022:         * An email will then be sent to the supplied address with a hyperlink
023:         * containing a validation key. The key is then checked against the
024:         * list of registered names and confirmed, at which point the user
025:         * is allowed to set notifications and reminders. This is a file-based
026:         * implementation of the WikiMembers interface.
027:         *
028:         * @author Robert E Brewer
029:         * @version 0.1
030:         */
031:        public class FileWikiMembers extends AbstractWikiMembers {
032:
033:            private static final Logger logger = Logger
034:                    .getLogger(FileWikiMembers.class);
035:            private File memberFile;
036:            private Hashtable memberTable;
037:
038:            /**
039:             * Constructor for the members list.
040:             *
041:             * @exception java.lang.ClassNotFoundException if hashtable file is the wrong class
042:             * @exception java.io.IOException if the members file could not be read
043:             */
044:            public FileWikiMembers(String virtualWiki)
045:                    throws ClassNotFoundException, IOException {
046:                this .virtualWiki = virtualWiki;
047:                this .memberFile = FileHandler.getPathFor(virtualWiki,
048:                        "member.xml");
049:                if (!memberFile.exists()) {
050:                    File dirFile = new File(Environment.dir());
051:                    if (!dirFile.exists())
052:                        dirFile.mkdir();
053:                    memberTable = new Hashtable();
054:                } else {
055:                    ObjIn in = new ObjIn(new FileReader(memberFile));
056:                    memberTable = (Hashtable) in.readObject();
057:                    in.close();
058:                }
059:            }
060:
061:            /**
062:             *
063:             */
064:            public boolean confirmMembership(String username, String key)
065:                    throws Exception {
066:                boolean result = super .confirmMembership(username, key);
067:                if (result == true)
068:                    return true;
069:                WikiMember member = findMemberByName(username);
070:                // Look up the username and check the keys
071:                if (!member.checkKey(key))
072:                    return false;
073:                member.confirm();
074:                writeMemberTable();
075:                return writeMemberTable();
076:            }
077:
078:            /**
079:             * Finds a WikiMember object in the Member collection using the username.
080:             *
081:             * @param username  the name of the user to find
082:             * @return WikiMember  the Member object for the specified user
083:             */
084:            public WikiMember findMemberByName(String username) {
085:                WikiMember aMember;
086:                if (memberTable.containsKey(username)) {
087:                    aMember = (WikiMember) memberTable.get(username);
088:                } else {
089:                    aMember = new WikiMember(username);
090:                }
091:                return aMember;
092:            }
093:
094:            /**
095:             *
096:             */
097:            public Collection getAllMembers() throws Exception {
098:                return memberTable.values();
099:            }
100:
101:            /**
102:             *
103:             */
104:            public void addMember(String username, String email, String key)
105:                    throws Exception {
106:                WikiMember aMember = new WikiMember(username, email);
107:                aMember.setKey(key);
108:                memberTable.put(username, aMember);
109:                writeMemberTable();
110:            }
111:
112:            /**
113:             * Add a user account to the Members collection. A key will be generated and sent via
114:             * email to the specified address in a hyperlink, which the user can then visit
115:             * to confirm the membership request.
116:             *
117:             * @param username  the name of the user for whom membership is requested
118:             * @param email  the email address of the user for whom membership is requested
119:             * in the confirmation email. For example, http://www.mybogusdomain.com/vqwiki/jsp/confirm.jsp
120:             * @return boolean  true if the user account has been added, false if an account already exists for this username or the member file could not be written
121:             * @exception vqwiki.WikiException if the mailer could not be instantiated
122:             */
123:            public synchronized boolean requestMembership(String username,
124:                    String email, HttpServletRequest request)
125:                    throws WikiException {
126:                WikiMember aMember = createMember(username, email);
127:                mailMember(username, request, aMember, email);
128:                // Add the request to the members table
129:                memberTable.put(username, aMember);
130:                return writeMemberTable();
131:            }
132:
133:            /**
134:             * Add a user account to the Members collection. It is assumed that the
135:             * confirmation was done somewhere else e.g. in the LDAP directory.
136:             *
137:             * @param username  the name of the user for whom membership is requested
138:             * @param email  the email address of the user for whom membership is requested
139:             * in the confirmation email. For example, http://www.mybogusdomain.com/vqwiki/jsp/confirm.jsp
140:             * @exception vqwiki.WikiException if the mailer could not be instantiated
141:             */
142:            public synchronized boolean createMembershipWithoutRequest(
143:                    String username, String email) throws WikiException {
144:                WikiMember aMember = createMember(username, email);
145:                aMember.confirm();
146:                // Add the request to the members table
147:                memberTable.put(username, aMember);
148:                return writeMemberTable();
149:            }
150:
151:            /**
152:             * Removes a WikiMember from the members list.
153:             *
154:             * @param username  the name of the user to remove
155:             * @return boolean  true if the operation completed successfully, false if the member file could not be written
156:             */
157:            public synchronized boolean removeMember(String username) {
158:                if (!memberTable.containsKey(username))
159:                    return false;
160:                memberTable.remove(username);
161:                return writeMemberTable();
162:            }
163:
164:            /**
165:             *
166:             */
167:            private boolean writeMemberTable() {
168:                try {
169:                    ObjOut out = new ObjOut(new FileWriter(memberFile));
170:                    out.writeObject(memberTable);
171:                    return true;
172:                } catch (IOException e) {
173:                    logger.error(e);
174:                    return false;
175:                }
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.