    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 org.apache.wiki.api.core.ContextEnum;
    022import org.apache.wiki.api.core.Engine;
    023import org.apache.wiki.api.core.Page;
    024import org.apache.wiki.plugin.WeblogPlugin;
    025import org.apache.wiki.rss.Feed;
    026import org.apache.wiki.util.TextUtil;
    027
    028import java.io.IOException;
    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 extends WikiTagBase {
    036
    037    private static final long serialVersionUID = 0L;
    038
    039    @Override
    040    public final int doWikiStartTag() throws IOException {
    041        final Engine engine = m_wikiContext.getEngine();
    042        final Page page = m_wikiContext.getPage();
    043
    044        final String encodedName = engine.encodeName( page.getName() );
    045        final String rssURL      = engine.getGlobalRSSURL();
    046        final String rssFeedURL  = engine.getURL( ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp","page="+encodedName+"&amp;mode=wiki" );
    047
    048        if( rssURL != null ) {
    049            String siteName = Feed.getSiteName(m_wikiContext);
    050            siteName = TextUtil.replaceEntities( siteName );
    051
    052            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for the entire site.\" href=\""+rssURL+"\" />\n");
    053            pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS wiki feed for page "+siteName+".\" href=\""+rssFeedURL+"\" />\n");
    054
    055            // TODO: Enable this
    056            /*
    057            pageContext.getOut().print("<link rel=\"service.post\" type=\"application/atom+xml\" title=\""+
    058                                       siteName+"\" href=\""+atomPostURL+"\" />\n");
    059            */
    060            // FIXME: This does not work always, as plugins are not initialized until the first fetch
    061            if( "true".equals( page.getAttribute( WeblogPlugin.ATTR_ISWEBLOG ) ) ) {
    062                final String blogFeedURL = engine.getURL( ContextEnum.PAGE_NONE.getRequestContext(),"rss.jsp","page="+encodedName );
    063                final String atomFeedURL = engine.getURL( ContextEnum.PAGE_NONE.getRequestContext(),"rss.jsp","page="+encodedName+"&amp;type=atom" );
    064
    065                pageContext.getOut().print("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS feed for weblog "+
    066                                           siteName+".\" href=\""+blogFeedURL+"\" />\n");
    067
    068                pageContext.getOut().print("<link rel=\"service.feed\" type=\"application/atom+xml\" title=\"Atom 1.0 weblog feed for "+
    069                                           siteName+"\" href=\""+atomFeedURL+"\" />\n");
    070            }
    071        }
    072
    073        return SKIP_BODY;
    074    }
    075
    076}