001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2002 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.dav;
021:
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.Iterator;
025:
026: import com.ecyrd.jspwiki.WikiContext;
027: import com.ecyrd.jspwiki.WikiEngine;
028: import com.ecyrd.jspwiki.WikiPage;
029: import com.ecyrd.jspwiki.dav.items.DavItem;
030: import com.ecyrd.jspwiki.dav.items.DirectoryItem;
031: import com.ecyrd.jspwiki.dav.items.HTMLPageDavItem;
032: import com.ecyrd.jspwiki.providers.ProviderException;
033:
034: public class HTMLPagesDavProvider extends RawPagesDavProvider {
035: public HTMLPagesDavProvider(WikiEngine engine) {
036: super (engine);
037: }
038:
039: private Collection listDirContents(DavPath path) {
040: String st = path.getName();
041:
042: log.info("Listing contents for dir " + st);
043: ArrayList davItems = new ArrayList();
044:
045: try {
046: Collection allPages = m_engine.getPageManager()
047: .getAllPages();
048:
049: for (Iterator i = allPages.iterator(); i.hasNext();) {
050: WikiPage p = (WikiPage) i.next();
051:
052: if (p.getName().toLowerCase().startsWith(st)) {
053: DavPath dp = new DavPath(path);
054: dp.append(p.getName() + ".html");
055:
056: DavItem di = new HTMLPageDavItem(this , dp, p);
057:
058: davItems.add(di);
059: }
060: }
061: } catch (ProviderException e) {
062: log.error("Unable to fetch a list of all pages", e);
063: // FIXME
064: }
065: return davItems;
066: }
067:
068: protected DavItem getItemNoCache(DavPath path) {
069: String pname = path.filePart();
070:
071: //
072: // Lists top-level elements
073: //
074: if (path.isRoot()) {
075: log.info("Adding DAV items from path " + path);
076: DirectoryItem di = new DirectoryItem(this , path);
077:
078: di.addDavItems(listAlphabeticals(path));
079:
080: return di;
081: }
082:
083: //
084: // Lists each item in each subdir
085: //
086: if (path.isDirectory()) {
087: log.info("Listing pages in path " + path);
088:
089: DirectoryItem di = new DirectoryItem(this , path);
090:
091: di.addDavItems(listDirContents(path));
092:
093: return di;
094: }
095:
096: if (pname.endsWith(".html") && pname.length() > 5) {
097: pname = pname.substring(0, pname.length() - 5);
098: }
099:
100: WikiPage page = m_engine.getPage(pname);
101:
102: if (page != null) {
103: return new HTMLPageDavItem(this , path, page);
104: }
105:
106: return null;
107: }
108:
109: public String getURL(DavPath path) {
110: return m_engine.getURL(WikiContext.NONE, DavUtil.combineURL(
111: "dav/html", path.getPath()), null, true);
112: }
113:
114: }
|