Source Code Cross Referenced for FileReminders.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 vqwiki.*;
004:
005:        import java.io.*;
006:        import java.util.Date;
007:        import java.util.Hashtable;
008:        import java.util.Iterator;
009:
010:        /**
011:         * Implementation of Reminders which stores reminder records in text files.
012:         * Reminder files use the same filename as the associated topic and use
013:         * the extension ".rmd". Only one reminder is allowed per user per topic;
014:         * the user must either create a new page to set an additional reminder,
015:         * or plan to alter the existing reminder on a recurring basis to simulate
016:         * recurring reminders. Each Reminders object represents a single topic,
017:         * which must be specified at instantiation, either by name or by File.
018:         *
019:         * @author Robert E Brewer
020:         * @version 0.1
021:         */
022:        public class FileReminders implements  Reminders {
023:
024:            private Hashtable curReminders = new Hashtable();
025:            private String topicName;
026:            private File remindFile;
027:
028:            /**
029:             * No-arg constructor for compatibility only; always use FileReminders(newTopicName)
030:             * or FileReminders(newRemindFile) instead.
031:             */
032:            public FileReminders() {
033:            }
034:
035:            /**
036:             * Opens and reads a Reminders object using the topic name.
037:             *
038:             * @param newTopicName the name of the topic
039:             * @exception vqwiki.WikiException if the reminder file could not be opened or read
040:             */
041:            public FileReminders(String newTopicName) throws WikiException {
042:                topicName = newTopicName;
043:                remindFile = makeRemindFile();
044:                if (remindFile.exists())
045:                    readRemindFile();
046:            }
047:
048:            /**
049:             * Reads a Reminders object from a File which has already been opened.
050:             *
051:             * @param newRemindFile the open File from which to read Reminders data.
052:             * @exception vqwiki.WikiException if the reminder file could not be read
053:             */
054:            public FileReminders(File newRemindFile) throws WikiException {
055:                remindFile = newRemindFile;
056:                topicName = remindFile.getName();
057:                topicName = topicName.substring(0, topicName.length() - 4);
058:                if (remindFile.exists())
059:                    readRemindFile();
060:            }
061:
062:            /**
063:             *
064:             */
065:            private File makeRemindFile() {
066:                return new File(fileBase()
067:                        + System.getProperty("file.separator") + topicName
068:                        + ".rmd");
069:            }
070:
071:            /**
072:             *
073:             */
074:            private synchronized boolean createRemindFile()
075:                    throws WikiException {
076:                try {
077:                    remindFile.createNewFile();
078:                    if (remindFile.exists())
079:                        return true;
080:                } catch (IOException e) {
081:                }
082:                throw new WikiException("Remind File could not be created.");
083:            }
084:
085:            /**
086:             *
087:             */
088:            private synchronized boolean readRemindFile() throws WikiException {
089:                try {
090:                    ObjectInputStream in = null;
091:                    in = new ObjectInputStream(new FileInputStream(remindFile));
092:                    curReminders = (Hashtable) in.readObject();
093:                    in.close();
094:                } catch (Exception e) {
095:                    throw new WikiException("Remind File could not be read.");
096:                }
097:                return true;
098:            }
099:
100:            /**
101:             *
102:             */
103:            private synchronized boolean writeRemindFile() throws WikiException {
104:                try {
105:                    if (!remindFile.exists())
106:                        createRemindFile();
107:                    ObjectOutputStream out = new ObjectOutputStream(
108:                            new FileOutputStream(remindFile));
109:                    out.writeObject(curReminders);
110:                    out.close();
111:                } catch (IOException e) {
112:                    throw new WikiException("Remind File could not be written");
113:                }
114:                return true;
115:            }
116:
117:            /**
118:             * Adds a reminder to this topic. If a reminder already exists for this user, it will be
119:             * replaced with the new reminder date.
120:             *
121:             * @param userName  the name of the user to add
122:             * @param dateToRemind  the date on which to send a reminder to the specified user
123:             * @exception vqwiki.WikiException if the file could not be written
124:             */
125:            public void addReminder(String userName, Date dateToRemind)
126:                    throws WikiException {
127:                WikiReminder tReminder = new WikiReminder(userName,
128:                        dateToRemind);
129:                curReminders.put(userName, tReminder);
130:                writeRemindFile();
131:            }
132:
133:            /**
134:             * Removes reminder for the specified user for this topic. If the removal
135:             * empties the reminder list for this topic, the reminder file is deleted.
136:             *
137:             * @param userName  the name of the user for whom to remove reminders
138:             * @exception vqwiki.WikiException if the file could not be written
139:             */
140:            public synchronized void removeReminder(String userName)
141:                    throws WikiException {
142:                curReminders.remove(userName);
143:                if (curReminders.isEmpty()) {
144:                    remindFile.delete();
145:                } else {
146:                    writeRemindFile();
147:                }
148:            }
149:
150:            /**
151:             * Checks whether the specified user has a reminder set for this topic.
152:             *
153:             * @param userName  the name of the user to check
154:             * @return boolean  True if the specified user has a reminder set for this topic.
155:             */
156:            public boolean hasReminder(String userName) {
157:                return curReminders.containsKey(userName);
158:            }
159:
160:            /**
161:             * Returns the date specified for a reminder for this user for this topic.
162:             *
163:             * @param userName  the name of the user to check
164:             * @return Date  the date of the reminder, or null if no reminder is set
165:             */
166:            public Date dateToRemind(String userName) {
167:                if (!hasReminder(userName))
168:                    return null;
169:                WikiReminder aReminder = (WikiReminder) curReminders
170:                        .get(userName);
171:                return aReminder.getRemindDate();
172:            }
173:
174:            /**
175:             * Retrieves the home directory of the VQWiki installation.
176:             *
177:             * @return String the home directory
178:             */
179:            protected String fileBase() {
180:                return Environment.getInstance().getHomeDir();
181:            }
182:
183:            /**
184:             * Sends reminders via email to all users who have requested a reminder
185:             * on the specified date for this topic.
186:             *
187:             * @param remindDate  the date of reminders to send
188:             * @return boolean  true if the operation completes successfully
189:             * @exception java.lang.ClassNotFoundException, IOException if the mailer could not be instantiated
190:             */
191:            public boolean sendReminders(Date remindDate) throws Exception {
192:                WikiMembers members = WikiBase.getInstance()
193:                        .getWikiMembersInstance(null);
194:                WikiMail mailer = WikiMail.getInstance();
195:                Iterator anIterator = curReminders.values().iterator();
196:                while (anIterator.hasNext()) {
197:                    WikiReminder aReminder = (WikiReminder) anIterator.next();
198:                    if (aReminder.remindDateEquals(remindDate)) {
199:                        WikiMember aMember = members.findMemberByName(aReminder
200:                                .getUserName());
201:                        String replyAddress = Environment.getInstance()
202:                                .getStringSetting(
203:                                        Environment.PROPERTY_REPLY_ADDRESS);
204:                        mailer.sendMail(replyAddress, aMember.getEmail(),
205:                                "Wiki Reminder", "Please visit the topic, '"
206:                                        + topicName + "'.");
207:                    }
208:                }
209:                return true;
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.