Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
**2026-11-21 Arturo Bernal (abernal AT apache DOT org)**

* _3.0.2-git-2_

* [JSPWIKI-1226](https://issues.apache.org/jira/browse/JSPWIKI-1226): every item of the RSS 2.0 feed has a `guid`, and the channel has an `atom:link` with `rel="self"` that tells a feed reader where the feed is, as feed validators ask. The link to the feed itself in the Atom feed is absolute too.

**2026-11-19 Arturo Bernal (abernal AT apache DOT org)**
* _3.0.2-git-1_

Expand Down
2 changes: 1 addition & 1 deletion jspwiki-api/src/main/java/org/apache/wiki/api/Release.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class Release {
* <p>
* If the build identifier is empty, it is not added.
*/
public static final String BUILD = "1";
public static final String BUILD = "2";

/**
* This is the generic version string you should use when printing out the version. It is of
Expand Down
6 changes: 1 addition & 5 deletions jspwiki-main/src/main/java/org/apache/wiki/rss/AtomFeed.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ public String getString() {
root.addContent( getElement( "link" ).setAttribute( "href", engine.getBaseURL() ) );
root.addContent( getElement( "generator" ).setText( "JSPWiki " + Release.VERSTR ) );

final String rssFeedURL = engine.getURL( ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp",
"page=" + engine.encodeName( m_wikiContext.getPage().getName() ) +
"&mode=" + m_mode +
"&type=atom" );
final Element self = getElement( "link" ).setAttribute( "rel","self" );
self.setAttribute( "href", rssFeedURL );
self.setAttribute( "href", getSelfURL( RSSGenerator.ATOM ) );
root.addContent( self );

// Items
Expand Down
20 changes: 20 additions & 0 deletions jspwiki-main/src/main/java/org/apache/wiki/rss/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Licensed to the Apache Software Foundation (ASF) under one

import org.apache.commons.text.StringEscapeUtils;
import org.apache.wiki.api.core.Context;
import org.apache.wiki.api.core.ContextEnum;
import org.apache.wiki.api.core.Engine;
import org.apache.wiki.api.exceptions.NoSuchVariableException;
import org.apache.wiki.util.HttpUtil;
import org.apache.wiki.variables.VariableManager;

import jakarta.servlet.ServletContext;
Expand Down Expand Up @@ -172,6 +174,24 @@ public void setFeedURL( final String feedurl) {
m_feedURL = feedurl;
}

/**
* Returns the address of this feed, for the link that tells a feed reader where the feed is. The address is absolute when the
* request is known, because a feed reader has no page to resolve a relative one against.
*
* @param type the type of the feed, one of the types of {@link RSSGenerator}.
* @return the URL of this feed.
* @since 3.0.2
*/
protected String getSelfURL( final String type ) {
final Engine engine = m_wikiContext.getEngine();
final String url = engine.getURL( ContextEnum.PAGE_NONE.getRequestContext(), "rss.jsp",
"page=" + engine.encodeName( m_wikiContext.getPage().getName() ) + "&mode=" + m_mode + "&type=" + type );
if( m_wikiContext.getHttpRequest() == null || !url.startsWith( "/" ) ) {
return url;
}
return HttpUtil.getAbsoluteUrl( m_wikiContext.getHttpRequest(), url );
}

/**
* A helper method for figuring out the MIME type for an enclosure.
*
Expand Down
9 changes: 9 additions & 0 deletions jspwiki-main/src/main/java/org/apache/wiki/rss/RSS20Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.wiki.attachment.AttachmentManager;
import org.apache.wiki.variables.VariableManager;
import org.jdom2.Element;
import org.jdom2.Namespace;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

Expand All @@ -52,6 +53,8 @@ public class RSS20Feed extends Feed
{
private static final Logger LOG = LogManager.getLogger( RSS20Feed.class );

private static final Namespace NS_ATOM = Namespace.getNamespace( "atom", "http://www.w3.org/2005/Atom" );

/**
* Creates an RSS 2.0 feed for the specified Context.
*
Expand All @@ -78,6 +81,8 @@ private List<Element> getItems()
final String url = e.getURL();
final Element item = new Element( "item" );
item.addContent( new Element( "link" ).setText( url ) );
// the address of an entry includes its version, so it never identifies another entry
item.addContent( new Element( "guid" ).setAttribute( "isPermaLink", "true" ).setText( url ) );
item.addContent( new Element( "title" ).setText( e.getTitle() ) );
item.addContent( new Element( "description" ).setText( e.getContent() ) );

Expand Down Expand Up @@ -126,6 +131,7 @@ public String getString()
final Engine engine = m_wikiContext.getEngine();
final Element root = new Element("rss");
root.setAttribute("version","2.0");
root.addNamespaceDeclaration( NS_ATOM );

final Element channel = new Element("channel");
root.addContent( channel );
Expand All @@ -142,6 +148,9 @@ public String getString()
channel.addContent( new Element("link").setText("https://0.0.0.0/"));
}
channel.addContent( new Element("description").setText( getChannelDescription() ));
channel.addContent( new Element( "link", NS_ATOM ).setAttribute( "href", getSelfURL( RSSGenerator.RSS20 ) )
.setAttribute( "rel", "self" )
.setAttribute( "type", "application/rss+xml" ) );

//
// Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,30 @@ public void testEntryLinksAreAbsolute() throws Exception {
}

/** The feed is cached and shared, so an entry that the anonymous user may not view must not be listed in it. */
/** JSPWIKI-1226: a feed validator wants a guid in every item and a link to the feed itself. */
@Test
public void testRss20HasGuidAndLinkToItself() throws Exception {
final TestEngine engine = buildRssEngine();
engine.saveText( "RssGuid", "Foo" );

final HttpServletRequest request = HttpMockFactory.createHttpRequest();
Mockito.doReturn( "http" ).when( request ).getScheme();
Mockito.doReturn( "localhost" ).when( request ).getServerName();
Mockito.doReturn( 8080 ).when( request ).getServerPort();
final Page page = engine.getManager( PageManager.class ).getPage( "RssGuid" );
final Context context = Wiki.context().create( engine, request, page );
final RSSGenerator gen = engine.getManager( RSSGenerator.class );

final String rss20 = gen.generateWikiPageRSS( context, new ArrayList<>( List.of( page ) ), new RSS20Feed( context ) );
final String atom = gen.generateWikiPageRSS( context, new ArrayList<>( List.of( page ) ), new AtomFeed( context ) );

Assertions.assertTrue( rss20.contains( "xmlns:atom=\"http://www.w3.org/2005/Atom\"" ), rss20 );
Assertions.assertTrue( rss20.contains( "<atom:link href=\"http://localhost:8080/test/rss.jsp?page=RssGuid&amp;mode=wiki&amp;type=rss20\" rel=\"self\" type=\"application/rss+xml\" />" ), rss20 );
Assertions.assertTrue( rss20.contains( "<guid isPermaLink=\"true\">http://localhost:8080/test/Wiki.jsp?page=RssGuid" ), rss20 );
Assertions.assertTrue( atom.contains( "rel=\"self\" href=\"http://localhost:8080/test/rss.jsp?page=RssGuid&amp;mode=wiki&amp;type=atom\"" ), atom );
engine.shutdown();
}

@Test
public void testBlogRSSSkipsEntriesTheAnonymousUserMayNotView() throws Exception {
final Properties props = TestEngine.getTestProperties();
Expand Down
Loading