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.i18n.InternationalizationManager; 024import org.apache.wiki.preferences.Preferences; 025import org.apache.wiki.rss.RSSGenerator; 026 027import javax.servlet.jsp.JspWriter; 028import java.io.IOException; 029import java.text.MessageFormat; 030import java.util.ResourceBundle; 031 032/** 033 * Writes an image link to a JSPWiki RSS file. If RSS generation has 034 * been turned off in jspwiki.properties, returns an empty string. 035 * 036 * @since 2.0 037 */ 038public class RSSImageLinkTag 039 extends WikiTagBase 040{ 041 private static final long serialVersionUID = 0L; 042 043 protected String m_title; 044 private String m_mode; 045 private String m_pageName; 046 047 /** 048 * {@inheritDoc} 049 */ 050 @Override 051 public void initTag() 052 { 053 super.initTag(); 054 m_title = null; 055 m_mode = RSSGenerator.MODE_FULL; 056 m_pageName = null; 057 } 058 059 /** 060 * Sets the title for the link. If not defined, no title is shown. 061 * 062 * @param title A string for the title. 063 */ 064 public void setTitle( final String title ) 065 { 066 m_title = title; 067 } 068 069 public void setMode( final String mode ) 070 { 071 m_mode = mode; 072 } 073 074 075 /** 076 * Returns the title. 077 * 078 * @return The title. 079 */ 080 public String getTitle() 081 { 082 return m_title; 083 } 084 085 /** 086 * {@inheritDoc} 087 */ 088 @Override 089 public final int doWikiStartTag() throws IOException { 090 final Engine engine = m_wikiContext.getEngine(); 091 final JspWriter out = pageContext.getOut(); 092 final ResourceBundle rb = Preferences.getBundle( m_wikiContext, InternationalizationManager.CORE_BUNDLE ); 093 if( engine.getManager( RSSGenerator.class ) != null && engine.getManager( RSSGenerator.class ).isEnabled() ) { 094 if( RSSGenerator.MODE_FULL.equals(m_mode) ) { 095 final String rssURL = engine.getGlobalRSSURL(); 096 if( rssURL != null ) { 097 out.print("<a class=\"feed\" href=\""+rssURL); 098 out.print( " title='"+rb.getString( "rss.title.full" )+"'>" ); 099 out.print( " </a> "); 100 } 101 } else { 102 final String page = m_pageName != null ? m_pageName : m_wikiContext.getPage().getName(); 103 final String params = "page="+page+"&mode="+m_mode; 104 out.print( "<a href='"+m_wikiContext.getURL( ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp", params )); 105 out.print( "' class='feed'" ); 106 out.print( " title='"+MessageFormat.format( rb.getString( "rss.title" ), page )+"'>" ); 107 out.print( " </a> "); 108 } 109 } 110 111 return SKIP_BODY; 112 } 113 114}