atom.css" type="text/css"?> <%@ page import="java.util.*"%> <%@ page import="com.ecyrd.jspwiki.*" %> <%@ page import="org.apache.log4j.*" %> <%@ page import="java.text.*" %> <%@ page import="com.ecyrd.jspwiki.rss.*" %> <%@ page import="com.ecyrd.jspwiki.util.*" %> <%! public void jspInit() { wiki = WikiEngine.getInstance( getServletConfig() ); } Category log = Category.getInstance("JSPWiki"); WikiEngine wiki; private String getFormattedDate( Date d ) { Calendar cal = Calendar.getInstance(); SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); cal.setTime( d ); cal.add( Calendar.MILLISECOND, - (cal.get( Calendar.ZONE_OFFSET ) + (cal.getTimeZone().inDaylightTime( d ) ? cal.get( Calendar.DST_OFFSET ) : 0 )) ); return iso8601fmt.format( cal.getTime() ); } %> <% WikiContext wikiContext = wiki.createContext( request, "rss" ); WikiPage wikipage = wikiContext.getPage(); if( wiki.getBaseURL().length() == 0 ) { response.sendError( 500, "The jspwiki.baseURL property has not been defined for this wiki - cannot generate Atom feed" ); return; } NDC.push( wiki.getApplicationName()+":"+wikipage.getName() ); // // Force the TranslatorReader to output absolute URLs // regardless of the current settings. // wikiContext.setVariable( WikiEngine.PROP_REFSTYLE, "absolute" ); response.setContentType("text/xml; charset=UTF-8" ); StringBuffer result = new StringBuffer(); SimpleDateFormat iso8601fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); Properties properties = wiki.getWikiProperties(); String channelDescription, channelLanguage; try { channelDescription = WikiEngine.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_DESCRIPTION ); channelLanguage = WikiEngine.getRequiredProperty( properties, RSSGenerator.PROP_CHANNEL_LANGUAGE ); } catch( NoRequiredPropertyException e ) { throw new JspException("Did not find a required property!"); } // // Now, list items. // com.ecyrd.jspwiki.plugin.WeblogPlugin plug = new com.ecyrd.jspwiki.plugin.WeblogPlugin(); List changed = plug.findBlogEntries(wiki.getPageManager(), wikipage.getName(), new Date(0L), new Date()); Collections.sort( changed, new PageTimeComparator() ); // // Check if nothing has changed, so we can just return a 304 // boolean hasChanged = false; Date latest = new Date(0); for( Iterator i = changed.iterator(); i.hasNext(); ) { WikiPage p = (WikiPage) i.next(); if( !HttpUtil.checkFor304( request, p ) ) hasChanged = true; if( p.getLastModified().after( latest ) ) latest = p.getLastModified(); } if( !hasChanged ) { response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); return; } response.addDateHeader("Last-Modified",latest.getTime()); %> <%=wiki.getApplicationName()%> <%--FIXME: We support no subtitles here --%> <% Date blogmodified = new Date(); String blogauthor = ""; if( changed.size() > 0 ) { blogmodified = ((WikiPage)changed.get(0)).getLastModified(); blogauthor = ((WikiPage)changed.get(0)).getAuthor(); } %> <%=iso8601fmt.format(blogmodified)%> <%=blogauthor%>
This is an Atom formatted XML site feed. It is intended to be viewed in a Newsreader or syndicated to another site.
<% int items = 0; for( Iterator i = changed.iterator(); i.hasNext() && items < 15; items++ ) { WikiPage p = (WikiPage) i.next(); String encodedName = wiki.encodeName(p.getName()); String url = wikiContext.getViewURL(p.getName()); out.println(" "); // // Title // out.println(" "); String pageText = wiki.getText(p.getName()); String title = ""; int firstLine = pageText.indexOf('\n'); if( firstLine > 0 ) { title = pageText.substring( 0, firstLine ); } if( title.trim().length() == 0 ) title = p.getName(); // Remove wiki formatting while( title.startsWith("!") ) title = title.substring(1); out.println( RSSGenerator.format(title) ); out.println(""); // // Link element // out.println(""); // // Description // out.println(""); out.print(" 0 ) { int maxlen = pageText.length(); // if( maxlen > 1000 ) maxlen = 1000; // Assume 112 bytes of growth. if( maxlen > 0 ) { pageText = wiki.textToHTML( wikiContext, pageText.substring( firstLine+1, maxlen ).trim() ); out.print( pageText ); // if( maxlen == 1000 ) out.print( "..." ); } else { out.print( RSSGenerator.format(title) ); } } else { out.print( RSSGenerator.format(title) ); } out.print("]]>"); out.println(""); // // Creation date. // out.print(""); WikiPage firstversion = wiki.getPage(p.getName(),1); out.print( getFormattedDate( firstversion.getLastModified() ) ); out.print("\n"); // // Issued date. JSPWiki does not support drafts, so we essentially output // the same date. // out.print(""+getFormattedDate(firstversion.getLastModified())+"\n"); // // Modification date. // out.print(""); out.print( getFormattedDate(p.getLastModified()) ); out.print("\n"); // // Author. // String author = p.getAuthor(); if( author == null ) author = "unknown"; out.println(" "); out.println(" "+author+""); /* // This may be useful later on, once I figure out which -tag to use. if( wiki.pageExists(author) ) { out.println(""+wikiContext.getViewURL(author)+""); } */ out.println(" \n"); // // Unique id. FIXME: is not really a GUID. // out.println(""+url+""); out.println(" \n"); } %>
<% NDC.pop(); NDC.remove(); %>