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.items;
021:
022: import java.io.ByteArrayInputStream;
023: import java.io.InputStream;
024: import java.io.UnsupportedEncodingException;
025: import java.util.ArrayList;
026: import java.util.Collection;
027:
028: import org.apache.commons.lang.time.DateFormatUtils;
029: import org.jdom.Element;
030: import org.jdom.Namespace;
031:
032: import com.ecyrd.jspwiki.WikiPage;
033: import com.ecyrd.jspwiki.dav.DavPath;
034: import com.ecyrd.jspwiki.dav.DavProvider;
035: import com.ecyrd.jspwiki.dav.WikiDavProvider;
036:
037: /**
038: * @author jalkanen
039: *
040: * @since
041: */
042: public class PageDavItem extends DavItem {
043: protected WikiPage m_page;
044: protected Namespace m_dcns = Namespace.getNamespace("dc",
045: "http://purl.org/dc/elements/1.1/");
046: protected Namespace m_davns = Namespace.getNamespace("DAV:");
047:
048: /**
049: *
050: */
051: public PageDavItem(DavProvider provider, DavPath path, WikiPage page) {
052: super (provider, path);
053: m_page = page;
054: }
055:
056: public WikiPage getPage() {
057: return m_page;
058: }
059:
060: protected Collection getCommonProperties() {
061: ArrayList set = new ArrayList();
062:
063: set.add(new Element("resourcetype", m_davns));
064: set.add(new Element("creator", m_dcns).setText(m_page
065: .getAuthor()));
066: set.add(new Element("getlastmodified", m_davns)
067: .setText(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT
068: .format(m_page.getLastModified())));
069: set.add(new Element("displayname", m_davns).setText(m_page
070: .getName()));
071:
072: return set;
073: }
074:
075: /* (non-Javadoc)
076: * @see com.ecyrd.jspwiki.dav.DavItem#getPropertySet(int)
077: */
078: public Collection getPropertySet() {
079: Collection set = getCommonProperties();
080:
081: set.add(new Element("getcontentlength", m_davns).setText(Long
082: .toString(getLength())));
083: set.add(new Element("getcontenttype", m_davns)
084: .setText(getContentType()));
085:
086: return set;
087: }
088:
089: public String getHref() {
090: return m_provider.getURL(m_path);
091: }
092:
093: /* (non-Javadoc)
094: * @see com.ecyrd.jspwiki.dav.items.DavItem#getContentType()
095: */
096: public String getContentType() {
097: return "text/plain; charset=UTF-8";
098: }
099:
100: /* (non-Javadoc)
101: * @see com.ecyrd.jspwiki.dav.items.DavItem#getInputStream()
102: */
103: public InputStream getInputStream() {
104: String text = ((WikiDavProvider) m_provider).getEngine()
105: .getPureText(m_page);
106:
107: try {
108: ByteArrayInputStream in = new ByteArrayInputStream(text
109: .getBytes("UTF-8"));
110:
111: return in;
112: } catch (UnsupportedEncodingException e) {
113: }
114:
115: return null;
116: }
117:
118: public long getLength() {
119: // FIXME: Use getBytes()
120: String text = ((WikiDavProvider) m_provider).getEngine()
121: .getPureText(m_page);
122: return text.length();
123: }
124: }
|