Source Code Cross Referenced for FileNotify.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 org.apache.log4j.Logger;
004:        import vqwiki.AbstractNotify;
005:        import vqwiki.Environment;
006:        import vqwiki.WikiException;
007:
008:        import java.io.*;
009:        import java.util.*;
010:
011:        /**
012:         * Implementation of Notify which stores notification records in text files.
013:         * Notification files use the same filename as the associated topic and use
014:         * the extension ".ntf".
015:         *
016:         * @author Robert E Brewer
017:         * @version 0.1
018:         */
019:        public class FileNotify extends AbstractNotify {
020:
021:            private static final Logger logger = Logger
022:                    .getLogger(FileNotify.class);
023:            protected Set membersToNotify = new HashSet();
024:            protected File notifyFile;
025:
026:            /**
027:             * No-arg constructor for compatibility only, always use FileNotify(newTopicName) instead.
028:             */
029:            public FileNotify() {
030:            }
031:
032:            /**
033:             * Instantiates and reads in a Notify object.
034:             *
035:             * @param newTopicName  the topic name with which this notification is associated
036:             * @exception vqwiki.WikiException if the file could not be opened or read
037:             */
038:            public FileNotify(String virtualWiki, String newTopicName)
039:                    throws WikiException {
040:                this .topicName = newTopicName;
041:                this .virtualWiki = virtualWiki;
042:                this .notifyFile = makeNotifyFile();
043:                if (this .notifyFile.exists())
044:                    readNotifyFile();
045:            }
046:
047:            /**
048:             *
049:             */
050:            private File makeNotifyFile() {
051:                return FileHandler.getPathFor(virtualWiki, topicName + ".ntf");
052:            }
053:
054:            /**
055:             *
056:             */
057:            private synchronized boolean createNotifyFile()
058:                    throws WikiException {
059:                try {
060:                    notifyFile.createNewFile();
061:                    if (notifyFile.exists())
062:                        return true;
063:                } catch (IOException e) {
064:                }
065:                throw new WikiException("Notify File could not be created.");
066:            }
067:
068:            /**
069:             *
070:             */
071:            private synchronized boolean readNotifyFile() throws WikiException {
072:                try {
073:                    String aMember;
074:                    BufferedReader reader = new BufferedReader(
075:                            new InputStreamReader(new FileInputStream(
076:                                    notifyFile)));
077:                    do {
078:                        aMember = reader.readLine();
079:                        if (aMember != null)
080:                            membersToNotify.add(aMember);
081:                    } while (aMember != null);
082:                    reader.close();
083:                } catch (IOException e) {
084:                    throw new WikiException("Notify File could not be read.");
085:                }
086:                return true;
087:            }
088:
089:            /**
090:             *
091:             */
092:            public Collection getMembers() throws Exception {
093:                return this .membersToNotify;
094:            }
095:
096:            /**
097:             *
098:             */
099:            private synchronized boolean writeNotifyFile() throws WikiException {
100:                try {
101:                    if (!notifyFile.exists())
102:                        createNotifyFile();
103:                    BufferedWriter writer = new BufferedWriter(
104:                            new OutputStreamWriter(new FileOutputStream(
105:                                    notifyFile), Environment.getInstance()
106:                                    .getFileEncoding()));
107:                    Iterator anIterator = membersToNotify.iterator();
108:                    while (anIterator.hasNext()) {
109:                        String aMember = (String) anIterator.next();
110:                        writer.write(aMember);
111:                        writer.newLine();
112:                    }
113:                    writer.close();
114:                } catch (IOException e) {
115:                    throw new WikiException("Notify File could not be written");
116:                }
117:                return true;
118:            }
119:
120:            /**
121:             * Adds a user to the list of members to be notified when the associated topic changes.
122:             *
123:             * @param userName  the name of the user to add
124:             * @exception vqwiki.WikiException if the file could not be written
125:             */
126:            public void addMember(String userName) throws WikiException {
127:                membersToNotify.add(userName);
128:                writeNotifyFile();
129:            }
130:
131:            /**
132:             * Removes a user from the list of members to be notified when the associated topic changes.
133:             *
134:             * @param userName  the name of the user to remove
135:             * @exception vqwiki.WikiException if the file could not be written
136:             */
137:            public synchronized void removeMember(String userName)
138:                    throws WikiException {
139:                membersToNotify.remove(userName);
140:                if (membersToNotify.isEmpty()) {
141:                    notifyFile.delete();
142:                } else {
143:                    writeNotifyFile();
144:                }
145:            }
146:
147:            /**
148:             * Checks whether the user is in the list of members to be notified when the associated topic changes.
149:             *
150:             * @param userName  the name of the user to check
151:             * @return boolean  True if the user is in the list.
152:             */
153:            public boolean isMember(String userName) {
154:                return membersToNotify.contains(userName);
155:            }
156:
157:            /**
158:             * Retrieves the home directory of the VQWiki installation.
159:             *
160:             * @return String the home directory
161:             */
162:            protected String fileBase() {
163:                return Environment.getInstance().getHomeDir();
164:            }
165:
166:            /**
167:             *
168:             */
169:            public static Collection getAll(String virtualWiki)
170:                    throws Exception {
171:                Collection all = new ArrayList();
172:                File path = FileHandler.getPathFor(virtualWiki, "");
173:                File[] list = path.listFiles(new FileExtensionFilter("ntf"));
174:                for (int i = 0; i < list.length; i++) {
175:                    File file = list[i];
176:                    String fileName = file.getName();
177:                    all.add(new FileNotify(virtualWiki, fileName.substring(0,
178:                            fileName.length() - 4)));
179:                }
180:                return all;
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.