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


001:        /*
002:        Very Quick Wiki - WikiWikiWeb clone
003:        Copyright (C) 2001-2002 Gareth Cronin
004:
005:        This program is free software; you can redistribute it and/or modify
006:        it under the terms of the latest version of the GNU Lesser General
007:        Public License as published by the Free Software Foundation;
008:
009:        This program is distributed in the hope that it will be useful,
010:        but WITHOUT ANY WARRANTY; without even the implied warranty of
011:        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:        GNU Lesser General Public License for more details.
013:
014:        You should have received a copy of the GNU Lesser General Public License
015:        along with this program (gpl.txt); if not, write to the Free Software
016:        Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:         */
018:        package vqwiki;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:        import java.util.Comparator;
024:        import java.util.Date;
025:        import java.util.Iterator;
026:        import java.util.List;
027:
028:        import org.apache.log4j.Logger;
029:
030:        /**
031:         * Class, which represents one topic
032:         *
033:         * @author $author$
034:         * @version $Revision: 644 $
035:         */
036:        public class Topic {
037:
038:            /** Reference to the wiki base class */
039:            protected WikiBase wb;
040:            /** Name of this topic */
041:            protected String topicName;
042:            /** Contents of this topic */
043:            protected String contents;
044:            /** Author of this topic */
045:            protected String author;
046:            /** Last modification date of this topic */
047:            protected Date lastRevisionDate;
048:            /** revision number of this topic */
049:            protected int revision;
050:            private static Logger logger = Logger.getLogger(Topic.class);
051:
052:            /**
053:             * Creates a new Topic object.
054:             *
055:             * @param topicName The name of this topic
056:             *
057:             * @throws Exception If the topic cannot be retrieved
058:             */
059:            public Topic(String topicName) throws Exception {
060:                this .topicName = topicName;
061:                wb = WikiBase.getInstance();
062:                this .contents = null;
063:                this .author = null;
064:                this .lastRevisionDate = null;
065:                this .revision = -1;
066:            }
067:
068:            /**
069:             * Find the most recent revision before the current
070:             *
071:             * @param virtualWiki The virtualWiki, which contains the topic
072:             *
073:             * @return the last revision date, or null if versioning is off
074:             */
075:            public Date getMostRecentRevisionDate(String virtualWiki)
076:                    throws Exception {
077:                if (Environment.getInstance().isVersioningOn()) {
078:                    this .lastRevisionDate = wb.getVersionManagerInstance()
079:                            .lastRevisionDate(virtualWiki, this .topicName);
080:                    return this .lastRevisionDate;
081:                } else {
082:                    return null;
083:                }
084:            }
085:
086:            /**
087:             * Return a diff for the current vs the most recent revision before it.
088:             *
089:             * @param virtualWiki The virtualWiki, which contains the topic
090:             * @param useHtml Set to true if the diff should be returned as HTML.
091:             *  Returns the diff as text otherwise.
092:             *
093:             * @return a diff to the last revision
094:             */
095:            public String mostRecentDiff(String virtualWiki, boolean useHtml)
096:                    throws Exception {
097:                return wb.getVersionManagerInstance().diff(virtualWiki,
098:                        topicName, 0, 1, useHtml);
099:            }
100:
101:            /**
102:             * Get a diff for two arbitrary versions of a topic
103:             * @param virtualWiki the virtual wiki
104:             * @param firstVersion the first version number
105:             * @param secondVersion the second version number
106:             * @param useHtml Set to true if the diff should be returned as HTML.
107:             *  Returns the diff as text otherwise.
108:             * @return
109:             */
110:            public String getDiff(String virtualWiki, int firstVersion,
111:                    int secondVersion, boolean useHtml) throws Exception {
112:                return wb.getVersionManagerInstance().diff(virtualWiki,
113:                        topicName, firstVersion, secondVersion, useHtml);
114:            }
115:
116:            /**
117:             * Find the most recent author.
118:             *
119:             * @param virtualWiki The virtualWiki, which contains the topic
120:             *
121:             * @return the author, who editied the last revision, or null if versioning is off
122:             */
123:            public String getMostRecentAuthor(String virtualWiki)
124:                    throws Exception {
125:                this .author = null;
126:                if (Environment.getInstance().isVersioningOn()) {
127:                    // get list of versions:
128:                    List allVersions = wb.getVersionManagerInstance()
129:                            .getAllVersions(virtualWiki, this .topicName);
130:                    // sort the list so that the most recent version is on top:
131:                    Collections.sort(allVersions, new Comparator() {
132:                        public int compare(Object o1, Object o2) {
133:                            TopicVersion bean1 = (TopicVersion) o1;
134:                            TopicVersion bean2 = (TopicVersion) o2;
135:                            return bean2.getRevisionDate().compareTo(
136:                                    (Date) bean1.getRevisionDate());
137:                        }
138:                    });
139:                    logger.debug("Having " + allVersions.size() + " versions: "
140:                            + allVersions);
141:                    String foundAuthor = null;
142:                    // go through all the versions
143:                    for (Iterator iter = allVersions.iterator(); iter.hasNext()
144:                            && foundAuthor == null;) {
145:                        TopicVersion version = (TopicVersion) iter.next();
146:                        if (version.getRevisionDate() != null) {
147:                            logger.debug("Checking version date "
148:                                    + version.getRevisionDate());
149:                            // get list of changes for that date
150:                            Collection c = WikiBase.getInstance()
151:                                    .getChangeLogInstance().getChanges(
152:                                            virtualWiki,
153:                                            version.getRevisionDate());
154:                            if (c != null) {
155:                                // remove all changes, which do not apply for this topic
156:                                logger.debug("Got " + c.size()
157:                                        + " changes for that date");
158:                                Collection cGood = new ArrayList();
159:                                for (Iterator iterChange = c.iterator(); iterChange
160:                                        .hasNext();) {
161:                                    Change this change = (Change) iterChange
162:                                            .next();
163:                                    if (this change.getTopic().equals(
164:                                            this .topicName)) {
165:                                        cGood.add(this change);
166:                                    }
167:                                }
168:                                logger.debug("Got " + cGood.size()
169:                                        + " changes left after filtering");
170:                                if (!cGood.isEmpty()) {
171:                                    // find author on that day; check, if there are multiple
172:                                    // modifications on the same day
173:                                    Iterator it = cGood.iterator();
174:                                    Date authorDate = null;
175:                                    while (it.hasNext()) {
176:                                        Change this change = (Change) it.next();
177:                                        if (authorDate == null) {
178:                                            foundAuthor = this change.getUser();
179:                                            authorDate = this change.getTime();
180:                                        } else {
181:                                            if (authorDate.before(this change
182:                                                    .getTime())) {
183:                                                foundAuthor = this change
184:                                                        .getUser();
185:                                                authorDate = this change
186:                                                        .getTime();
187:                                            }
188:                                        }
189:                                    }
190:                                }
191:                            }
192:                        }
193:                    }
194:                    this .author = foundAuthor;
195:                } else {
196:                    this .author = null;
197:                }
198:                return this .author;
199:            }
200:
201:            /**
202:             * Find the revision number.
203:             *
204:             * @param virtualWiki The virtualWiki, which contains the topic
205:             *
206:             * @return the revision number
207:             */
208:            public int getRevision(String virtualWiki) throws Exception {
209:                this .revision = wb.getVersionManagerInstance()
210:                        .getNumberOfVersions(virtualWiki, this .topicName);
211:                return this .revision;
212:            }
213:
214:            /**
215:             * Make a topic read-only
216:             *
217:             * @param virtualWiki The virtualWiki, which contains the topic
218:             */
219:            public synchronized void makeTopicReadOnly(String virtualWiki)
220:                    throws Exception {
221:                wb.addReadOnlyTopic(virtualWiki, topicName);
222:            }
223:
224:            /**
225:             * Return whether a topic is read-only
226:             *
227:             * @param virtualWiki The virtualWiki, which contains the topic
228:             */
229:            public boolean isReadOnlyTopic(String virtualWiki) throws Exception {
230:                return wb.isTopicReadOnly(virtualWiki, topicName);
231:            }
232:
233:            /**
234:             * Make a previously read-only topic writable
235:             *
236:             * @param virtualWiki The virtualWiki, which contains the topic
237:             */
238:            public synchronized void makeTopicWritable(String virtualWiki)
239:                    throws Exception {
240:                wb.removeReadOnlyTopic(virtualWiki, topicName);
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.