001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.tags; 020 021import java.io.IOException; 022 023import org.apache.wiki.WikiContext; 024import org.apache.wiki.WikiEngine; 025import org.apache.wiki.WikiPage; 026import org.apache.wiki.plugin.WeblogPlugin; 027import org.apache.wiki.rss.Feed; 028import org.apache.wiki.util.TextUtil; 029 030/** 031 * Outputs links to all the site feeds and APIs this Wiki/blog supports. 032 * 033 * @since 2.2 034 */ 035public class FeedDiscoveryTag 036 extends WikiTagBase 037{ 038 private static final long serialVersionUID = 0L; 039 040 public final int doWikiStartTag() 041 throws IOException 042 { 043 WikiEngine engine = m_wikiContext.getEngine(); 044 WikiPage page = m_wikiContext.getPage(); 045 046 String encodedName = engine.encodeName( page.getName() ); 047 048 String rssURL = engine.getGlobalRSSURL(); 049 String rssFeedURL = engine.getURL(WikiContext.NONE, "rss.jsp", 050 "page="+encodedName+"&mode=wiki", 051 true ); 052 053 if( rssURL != null ) 054 { 055 String siteName = Feed.getSiteName(m_wikiContext); 056 siteName = TextUtil.replaceEntities( siteName ); 057 058 pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for the entire site.\" href=\""+rssURL+"\" />\n"); 059 pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for page "+siteName+".\" href=\""+rssFeedURL+"\" />\n"); 060 061 // TODO: Enable this 062 /* 063 pageContext.getOut().print("<link rel=\"service.post\" type=\"application/atom+xml\" title=\""+ 064 siteName+"\" href=\""+atomPostURL+"\" />\n"); 065 */ 066 // FIXME: This does not work always, as plugins are not initialized until the first fetch 067 if( "true".equals(page.getAttribute(WeblogPlugin.ATTR_ISWEBLOG)) ) 068 { 069 String blogFeedURL = engine.getURL(WikiContext.NONE,"rss.jsp","page="+encodedName,true); 070 String atomFeedURL = engine.getURL(WikiContext.NONE,"rss.jsp","page="+encodedName+"&type=atom",true); 071 072 pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS feed for weblog "+ 073 siteName+".\" href=\""+blogFeedURL+"\" />\n"); 074 075 pageContext.getOut().print("<link rel=\"service.feed\" type=\"application/atom+xml\" title=\"Atom 1.0 weblog feed for "+ 076 siteName+"\" href=\""+atomFeedURL+"\" />\n"); 077 } 078 } 079 080 return SKIP_BODY; 081 } 082}