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.rss;
021:
022: import java.text.SimpleDateFormat;
023: import java.util.Calendar;
024: import java.util.Iterator;
025:
026: import org.apache.ecs.xml.XML;
027:
028: import com.ecyrd.jspwiki.WikiContext;
029: import com.ecyrd.jspwiki.WikiEngine;
030: import com.ecyrd.jspwiki.WikiPage;
031:
032: /**
033: * @author jalkanen
034: *
035: * @since
036: */
037: public class RSS10Feed extends Feed {
038: public RSS10Feed(WikiContext context) {
039: super (context);
040: }
041:
042: private XML getRDFItems() {
043: XML items = new XML("items");
044:
045: XML rdfseq = new XML("rdf:Seq");
046:
047: for (Iterator i = m_entries.iterator(); i.hasNext();) {
048: Entry e = (Entry) i.next();
049:
050: String url = e.getURL();
051:
052: rdfseq.addElement(new XML("rdf:li").addAttribute(
053: "rdf:resource", url));
054: }
055:
056: items.addElement(rdfseq);
057:
058: return items;
059: }
060:
061: private void addItemList(XML root) {
062: SimpleDateFormat iso8601fmt = new SimpleDateFormat(
063: "yyyy-MM-dd'T'HH:mm:ss'Z'");
064:
065: WikiEngine engine = m_wikiContext.getEngine();
066:
067: for (Iterator i = m_entries.iterator(); i.hasNext();) {
068: Entry e = (Entry) i.next();
069:
070: String url = e.getURL();
071:
072: XML item = new XML("item");
073: item.addAttribute("rdf:about", url);
074:
075: item.addElement(new XML("title").addElement(format(e
076: .getTitle())));
077:
078: item.addElement(new XML("link").addElement(url));
079:
080: XML content = new XML("description");
081:
082: // TODO: Add a size limiter here
083: content.addElement(format(e.getContent()));
084:
085: item.addElement(content);
086:
087: WikiPage p = e.getPage();
088:
089: if (p.getVersion() != -1) {
090: item.addElement(new XML("wiki:version")
091: .addElement(Integer.toString(p.getVersion())));
092: }
093:
094: if (p.getVersion() > 1) {
095: item.addElement(new XML("wiki:diff").addElement(engine
096: .getURL(WikiContext.DIFF, p.getName(), "r1=-1",
097: true)));
098: }
099:
100: //
101: // Modification date.
102: //
103: Calendar cal = Calendar.getInstance();
104: cal.setTime(p.getLastModified());
105: cal.add(Calendar.MILLISECOND, -(cal
106: .get(Calendar.ZONE_OFFSET) + (cal.getTimeZone()
107: .inDaylightTime(p.getLastModified()) ? cal
108: .get(Calendar.DST_OFFSET) : 0)));
109:
110: item.addElement(new XML("dc:date").addElement(iso8601fmt
111: .format(cal.getTime())));
112:
113: //
114: // Author
115: String author = e.getAuthor();
116: if (author == null)
117: author = "unknown";
118:
119: XML contributor = new XML("dc:creator");
120:
121: item.addElement(contributor);
122:
123: /*
124: XML description = new XML("rdf:Description");
125: if( m_wikiContext.getEngine().pageExists(author) )
126: {
127: description.addAttribute( "link", engine.getURL( WikiContext.VIEW,
128: author,
129: null,
130: true ) );
131: }
132:
133: description.addElement( new XML("value").addElement( format(author) ) );
134: contributor.addElement( description );
135: */
136:
137: // Not too many aggregators seem to like this. Therefore we're
138: // just adding the name here.
139: contributor.addElement(format(author));
140:
141: // PageHistory
142:
143: item
144: .addElement(new XML("wiki:history")
145: .addElement(engine.getURL(WikiContext.INFO,
146: p.getName(), null, true)));
147:
148: //
149: // Add to root
150: //
151:
152: root.addElement(item);
153: }
154: }
155:
156: private XML getChannelElement() {
157: XML channel = new XML("channel");
158:
159: channel.addAttribute("rdf:about", m_feedURL);
160:
161: channel.addElement(new XML("link").addElement(m_feedURL));
162:
163: if (m_channelTitle != null)
164: channel.addElement(new XML("title")
165: .addElement(format(m_channelTitle)));
166:
167: if (m_channelDescription != null)
168: channel.addElement(new XML("description")
169: .addElement(format(m_channelDescription)));
170:
171: if (m_channelLanguage != null)
172: channel.addElement(new XML("dc:language")
173: .addElement(m_channelLanguage));
174:
175: channel.setPrettyPrint(true);
176:
177: channel.addElement(getRDFItems());
178:
179: return channel;
180: }
181:
182: /* (non-Javadoc)
183: * @see com.ecyrd.jspwiki.rss.Feed#getString()
184: */
185: public String getString() {
186: XML root = new XML("rdf:RDF");
187:
188: root.addAttribute("xmlns:rdf",
189: "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
190: root.addAttribute("xmlns", "http://purl.org/rss/1.0/");
191: root.addAttribute("xmlns:dc",
192: "http://purl.org/dc/elements/1.1/");
193: root.addAttribute("xmlns:wiki",
194: "http://purl.org/rss/1.0/modules/wiki/");
195:
196: root.addElement(getChannelElement());
197:
198: addItemList(root);
199:
200: root.setPrettyPrint(true);
201:
202: return root.toString();
203: }
204:
205: }
|