Skip to content

Commit 3c9e4bb

Browse files
pjeanjeanmichitux
authored andcommitted
XWIKI-21472: Directly write RSS feed content in Main.DatabaseSearch
* Add a page test (cherry picked from commit 95bdd6c)
1 parent 73aef96 commit 3c9e4bb

File tree

3 files changed

+124
-1
lines changed

3 files changed

+124
-1
lines changed

xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-ui/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,12 @@
7979
<type>test-jar</type>
8080
<scope>test</scope>
8181
</dependency>
82+
83+
<dependency>
84+
<groupId>org.xwiki.platform</groupId>
85+
<artifactId>xwiki-platform-feed-api</artifactId>
86+
<version>${project.version}</version>
87+
<scope>test</scope>
88+
</dependency>
8289
</dependencies>
8390
</project>

xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-ui/src/main/resources/Main/DatabaseSearch.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,21 @@
120120
#set ($discard = $feed.setDescription($services.localization.render('search.rss', [$text])))
121121
#set ($discard = $feed.setLanguage("$xcontext.locale"))
122122
#set ($discard = $feed.setCopyright($xwiki.getXWikiPreference('copyright')))
123+
#set ($feedOutput = $xwiki.feed.getFeedOutput($feed, $xwiki.getXWikiPreference('feed_type', 'rss_2.0')))
124+
123125
#set ($discard = $response.setContentType('application/rss+xml'))
124-
{{{$xwiki.feed.getFeedOutput($feed, $xwiki.getXWikiPreference('feed_type', 'rss_2.0'))}}}
126+
#set ($characterEncoding = 'utf-8')
127+
## Make sure the Character Encoding response header matches the character encoding used to write the response and
128+
## compute its length.
129+
#set ($discard = $response.setCharacterEncoding($characterEncoding))
130+
## We write the output directly to the response to avoid the execution of the Rendering Transformations.
131+
#set ($discard = $response.writer.print($feedOutput))
132+
## The content length is measured in bytes and one character can use more than one byte.
133+
#set ($discard = $response.setContentLength($feedOutput.getBytes($characterEncoding).size()))
134+
## Make sure the entire content is send back to the client.
135+
#set ($discard = $response.flushBuffer())
136+
## Make sure XWiki doesn't write any more content to the response.
137+
#set ($discard = $xcontext.setFinished(true))
125138
#else
126139
{{include reference="XWiki.Results"/}}
127140

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* See the NOTICE file distributed with this work for additional
3+
* information regarding copyright ownership.
4+
*
5+
* This is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU Lesser General Public License as
7+
* published by the Free Software Foundation; either version 2.1 of
8+
* the License, or (at your option) any later version.
9+
*
10+
* This software is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this software; if not, write to the Free
17+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19+
*/
20+
package org.xwiki.search.ui;
21+
22+
import java.io.PrintWriter;
23+
import java.io.StringWriter;
24+
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.xwiki.model.reference.DocumentReference;
28+
import org.xwiki.rendering.RenderingScriptServiceComponentList;
29+
import org.xwiki.rendering.internal.configuration.DefaultRenderingConfigurationComponentList;
30+
import org.xwiki.rendering.syntax.Syntax;
31+
import org.xwiki.test.annotation.ComponentList;
32+
import org.xwiki.test.page.HTML50ComponentList;
33+
import org.xwiki.test.page.PageTest;
34+
import org.xwiki.test.page.TestNoScriptMacro;
35+
import org.xwiki.test.page.XWikiSyntax21ComponentList;
36+
37+
import com.xpn.xwiki.doc.XWikiDocument;
38+
import com.xpn.xwiki.plugin.feed.FeedPlugin;
39+
import com.xpn.xwiki.web.XWikiServletResponseStub;
40+
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
42+
43+
/**
44+
* Page test for {@code Main.DatabaseSearch}.
45+
*
46+
* @version $Id$
47+
*/
48+
@ComponentList({
49+
TestNoScriptMacro.class
50+
})
51+
@RenderingScriptServiceComponentList
52+
@DefaultRenderingConfigurationComponentList
53+
@HTML50ComponentList
54+
@XWikiSyntax21ComponentList
55+
class DatabaseSearchPageTest extends PageTest
56+
{
57+
private static final String WIKI_NAME = "xwiki";
58+
59+
private static final String MAIN_SPACE = "Main";
60+
61+
private static final DocumentReference DATABASE_SEARCH_REFERENCE =
62+
new DocumentReference(WIKI_NAME, MAIN_SPACE, "DatabaseSearch");
63+
64+
@BeforeEach
65+
void setUp()
66+
{
67+
this.xwiki.initializeMandatoryDocuments(this.context);
68+
69+
this.xwiki.getPluginManager().addPlugin("feed", FeedPlugin.class.getName(), this.context);
70+
}
71+
72+
@Test
73+
void checkRSSFeedContent() throws Exception
74+
{
75+
String unescapedText = "<b>}}}{{noscript}}</b>";
76+
String escapedText = "&lt;b&gt;}}}{{noscript}}&lt;/b&gt;";
77+
78+
this.request.put("text", unescapedText);
79+
this.context.setAction("get");
80+
81+
XWikiDocument databaseSearchDocument = loadPage(DATABASE_SEARCH_REFERENCE);
82+
this.context.setDoc(databaseSearchDocument);
83+
84+
// Get directly the writer to check the RSS feed.
85+
StringWriter out = new StringWriter();
86+
PrintWriter writer = new PrintWriter(out);
87+
this.response = new XWikiServletResponseStub() {
88+
@Override
89+
public PrintWriter getWriter()
90+
{
91+
return writer;
92+
}
93+
};
94+
this.context.setResponse(this.response);
95+
96+
String rssFeed = databaseSearchDocument.displayDocument(Syntax.PLAIN_1_0, this.context);
97+
assertTrue(rssFeed.isEmpty());
98+
99+
rssFeed = out.toString();
100+
assertTrue(rssFeed.contains("<title>search.rss [" + escapedText + "]</title>"));
101+
assertTrue(rssFeed.contains("<description>search.rss [" + escapedText + "]</description>"));
102+
}
103+
}

0 commit comments

Comments
 (0)