Source Code Cross Referenced for MapPageProvider.java in  » Project-Management » EmForce » ru » emdev » EmForge » wiki » providers » mapprovider » 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 » Project Management » EmForce » ru.emdev.EmForge.wiki.providers.mapprovider 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package ru.emdev.EmForge.wiki.providers.mapprovider;
002:
003:        import java.io.IOException;
004:        import java.util.ArrayList;
005:        import java.util.Collection;
006:        import java.util.Date;
007:        import java.util.HashMap;
008:        import java.util.Iterator;
009:        import java.util.List;
010:        import java.util.Map;
011:        import java.util.Properties;
012:        import java.util.Set;
013:
014:        import org.apache.commons.logging.Log;
015:        import org.apache.commons.logging.LogFactory;
016:
017:        import com.ecyrd.jspwiki.NoRequiredPropertyException;
018:        import com.ecyrd.jspwiki.QueryItem;
019:        import com.ecyrd.jspwiki.WikiEngine;
020:        import com.ecyrd.jspwiki.WikiPage;
021:        import com.ecyrd.jspwiki.providers.ProviderException;
022:        import com.ecyrd.jspwiki.providers.WikiPageProvider;
023:
024:        /** Map Page Provider used for storing wiki-pages in memory
025:         * 
026:         * May be used for test purposes
027:         */
028:        public class MapPageProvider implements  WikiPageProvider {
029:            protected final Log logger = LogFactory.getLog(getClass());
030:
031:            public class WikiStorage {
032:                WikiPage page;
033:                String content;
034:
035:                public WikiStorage(WikiPage page, String content) {
036:                    this .page = page;
037:                    this .content = content;
038:                }
039:
040:                public WikiPage getPage() {
041:                    return page;
042:                }
043:
044:                public String getContent() {
045:                    return content;
046:                }
047:
048:                public void setPage(WikiPage page) {
049:                    this .page = page;
050:                }
051:            }
052:
053:            // Map for storing wiki pages with contents
054:            private Map<String, Collection> m_pagesMap = null;
055:            private Map<String, Integer> m_latestVersion = null;
056:
057:            public MapPageProvider() {
058:                m_pagesMap = new HashMap<String, Collection>();
059:                m_latestVersion = new HashMap<String, Integer>();
060:            }
061:
062:            @SuppressWarnings("unchecked")
063:            public void putPageText(WikiPage i_page, String i_text)
064:                    throws ProviderException {
065:                String pageName = i_page.getName();
066:                WikiPage page = null;
067:                Collection<WikiStorage> versList = new ArrayList<WikiStorage>();
068:                if (m_pagesMap.containsKey(pageName)) {
069:                    page = (WikiPage) i_page.clone();
070:                    int latestVersion = m_latestVersion.get(pageName);
071:                    page.setVersion(latestVersion + 1);
072:                    m_latestVersion.put(pageName, latestVersion + 1);
073:                    versList = m_pagesMap.get(pageName);
074:                } else {
075:                    page = i_page;
076:                    page.setVersion(1);
077:                    m_latestVersion.put(pageName, 1);
078:                }
079:                page.setLastModified(new Date());
080:                if (i_text != null) {
081:                    page.setSize(i_text.getBytes().length);
082:                } else {
083:                    page.setSize(0);
084:                }
085:                versList.add(new WikiStorage(page, i_text));
086:                m_pagesMap.put(pageName, versList);
087:            }
088:
089:            public boolean pageExists(String i_name) {
090:                return m_pagesMap.containsKey(i_name);
091:            }
092:
093:            public Collection findPages(QueryItem[] arg0) {
094:                // TODO Auto-generated method stub
095:                return null;
096:            }
097:
098:            public WikiPage getPageInfo(String i_name, int i_version)
099:                    throws ProviderException {
100:                logger.debug("Get information about page " + i_name
101:                        + " version " + i_version);
102:                WikiPage result = null;
103:                WikiStorage wikiStorage = getWiki(i_name, m_pagesMap
104:                        .get(i_name), i_version);
105:                if (wikiStorage != null) {
106:                    result = wikiStorage.getPage();
107:                }
108:                return result;
109:            }
110:
111:            /* WikiPageProvider method implementation */
112:            public Collection getAllPages() throws ProviderException {
113:                Collection<WikiPage> result = new ArrayList<WikiPage>();
114:                Set<String> keyset = m_pagesMap.keySet();
115:                if (!keyset.isEmpty()) {
116:                    Iterator iterator = keyset.iterator();
117:                    while (iterator.hasNext()) {
118:                        String pageName = (String) iterator.next();
119:                        result.add(getWiki(pageName, m_pagesMap.get(pageName),
120:                                WikiPageProvider.LATEST_VERSION).getPage());
121:                    }
122:                }
123:
124:                return result;
125:            }
126:
127:            /** returns page with needed version; i_version = -1 - return the last version 
128:             * @author spopov
129:             */
130:            private WikiStorage getWiki(String i_name, Collection i_wiki,
131:                    long i_version) {
132:
133:                if (i_wiki == null) {
134:                    return null;
135:                }
136:
137:                WikiStorage result = null;
138:                long version;
139:                if (i_version == WikiPageProvider.LATEST_VERSION) {
140:                    version = m_latestVersion.get(i_name);
141:                } else {
142:                    version = i_version;
143:                }
144:
145:                Iterator iterator = i_wiki.iterator();
146:                while (iterator.hasNext()) {
147:                    WikiStorage wikiStorage = (WikiStorage) iterator.next();
148:                    if (wikiStorage.getPage().getVersion() == version) {
149:                        result = wikiStorage;
150:                        break;
151:                    }
152:                }
153:
154:                return result;
155:            }
156:
157:            // [AKO] PageDAO method implementation 
158:            /* public Collection getPages() {
159:            	return getHibernateTemplate().loadAll(WikiPageImpl.class);		
160:            } */
161:
162:            public Collection getAllChangedSince(Date i_date) {
163:                // TODO Auto-generated method stub
164:                return null;
165:            }
166:
167:            public int getPageCount() throws ProviderException {
168:                return m_pagesMap.size();
169:            }
170:
171:            @SuppressWarnings("unchecked")
172:            public List getVersionHistory(String i_name)
173:                    throws ProviderException {
174:                ArrayList<Object> result = new ArrayList<Object>();
175:                Collection<WikiStorage> wikis = m_pagesMap.get(i_name);
176:                for (WikiStorage wikiStorage : wikis) {
177:                    result.add(wikiStorage.getPage());
178:                }
179:                return result;
180:            }
181:
182:            public String getPageText(String i_name, int i_version)
183:                    throws ProviderException {
184:                WikiStorage wikiStorage = getWiki(i_name, m_pagesMap
185:                        .get(i_name), i_version);
186:                if (wikiStorage == null) {
187:                    return null;
188:                }
189:                return wikiStorage.getContent();
190:            }
191:
192:            public void deleteVersion(String i_name, int i_version)
193:                    throws ProviderException {
194:                /// versionning is not supported
195:            }
196:
197:            public void deletePage(String i_name) throws ProviderException {
198:                m_pagesMap.remove(i_name);
199:            }
200:
201:            /* [AKO]: PageDAO method implementation
202:            /* public void deletePage(Page page) {
203:            	
204:            } */
205:            WikiEngine m_wikiEngine;
206:
207:            public void initialize(WikiEngine engine, Properties arg1)
208:                    throws NoRequiredPropertyException, IOException {
209:                m_wikiEngine = engine;
210:            }
211:
212:            public String getProviderInfo() {
213:                return "Map Page Provider";
214:            }
215:
216:            @SuppressWarnings("unchecked")
217:            public void movePage(String from, String to)
218:                    throws ProviderException {
219:                logger.debug("move page");
220:                Collection<WikiStorage> oldVers = m_pagesMap.get(from);
221:                Collection<WikiStorage> newVers = new ArrayList<WikiStorage>();
222:                for (WikiStorage wikiStorage : oldVers) {
223:                    // copy page data to new page
224:                    WikiPage page = new WikiPage(m_wikiEngine, to);
225:                    page.setAcl(wikiStorage.getPage().getAcl());
226:                    page.setAuthor(wikiStorage.getPage().getAuthor());
227:                    page.setLastModified(wikiStorage.getPage()
228:                            .getLastModified());
229:                    page.setSize(wikiStorage.getPage().getSize());
230:                    page.setVersion(wikiStorage.getPage().getVersion());
231:                    newVers
232:                            .add(new WikiStorage(page, wikiStorage.getContent()));
233:                }
234:                // delete renamed page
235:                m_pagesMap.remove(from);
236:                // put new page with new name
237:                m_pagesMap.put(to, newVers);
238:                // refresh key in Latest Version Map
239:                int lastVers = m_latestVersion.get(from);
240:                m_latestVersion.remove(from);
241:                m_latestVersion.put(to, lastVers);
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.