001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.providers;
021:
022: import java.util.*;
023:
024: import org.apache.log4j.*;
025:
026: import com.ecyrd.jspwiki.*;
027:
028: /**
029: * A provider who counts the hits to different parts.
030: */
031: public class CounterProvider implements WikiPageProvider {
032: public int m_getPageCalls = 0;
033: public int m_pageExistsCalls = 0;
034: public int m_getPageTextCalls = 0;
035: public int m_getAllPagesCalls = 0;
036: public int m_initCalls = 0;
037:
038: static Logger log = Logger.getLogger(CounterProvider.class);
039:
040: WikiPage[] m_pages = new WikiPage[0];
041:
042: String m_defaultText = "[Foo], [Bar], [Blat], [Blah]";
043:
044: public void initialize(WikiEngine engine, Properties props) {
045: m_pages = new WikiPage[] { new WikiPage(engine, "Foo"),
046: new WikiPage(engine, "Bar"),
047: new WikiPage(engine, "Blat"),
048: new WikiPage(engine, "Blaa") };
049:
050: m_initCalls++;
051:
052: for (int i = 0; i < m_pages.length; i++) {
053: m_pages[i].setAuthor("Unknown");
054: m_pages[i].setLastModified(new Date(0L));
055: m_pages[i].setVersion(1);
056: }
057: }
058:
059: public String getProviderInfo() {
060: return "Very Simple Provider.";
061: }
062:
063: public void putPageText(WikiPage page, String text)
064: throws ProviderException {
065: }
066:
067: public boolean pageExists(String page) {
068: m_pageExistsCalls++;
069:
070: //System.out.println("PAGE="+page);
071: //TestEngine.trace();
072:
073: return findPage(page) != null;
074: }
075:
076: public Collection findPages(QueryItem[] query) {
077: return null;
078: }
079:
080: private WikiPage findPage(String page) {
081: for (int i = 0; i < m_pages.length; i++) {
082: if (m_pages[i].getName().equals(page))
083: return m_pages[i];
084: }
085:
086: return null;
087: }
088:
089: public WikiPage getPageInfo(String page, int version) {
090: m_getPageCalls++;
091:
092: //System.out.println("GETPAGEINFO="+page);
093: //TestEngine.trace();
094:
095: WikiPage p = findPage(page);
096:
097: return p;
098: }
099:
100: public Collection getAllPages() {
101: m_getAllPagesCalls++;
102:
103: Vector v = new Vector();
104:
105: for (int i = 0; i < m_pages.length; i++) {
106: v.add(m_pages[i]);
107: }
108:
109: return v;
110: }
111:
112: public Collection getAllChangedSince(Date date) {
113: return new Vector();
114: }
115:
116: public int getPageCount() {
117: return m_pages.length;
118: }
119:
120: public List getVersionHistory(String page) {
121: return new Vector();
122: }
123:
124: public String getPageText(String page, int version) {
125: m_getPageTextCalls++;
126: return m_defaultText;
127: }
128:
129: public void deleteVersion(String page, int version) {
130: }
131:
132: public void deletePage(String page) {
133: }
134:
135: /* (non-Javadoc)
136: * @see com.ecyrd.jspwiki.providers.WikiPageProvider#movePage(java.lang.String, java.lang.String)
137: */
138: public void movePage(String from, String to)
139: throws ProviderException {
140: // TODO Auto-generated method stub
141:
142: }
143:
144: }
|