xref: /OpenGrok/opengrok-web/src/main/webapp/rss.jsp (revision 0516dd21dfeb393bf975b3930bbbf13ecc1deed8)
1<%--
2$Id$
3
4CDDL HEADER START
5
6The contents of this file are subject to the terms of the
7Common Development and Distribution License (the "License").
8You may not use this file except in compliance with the License.
9
10See LICENSE.txt included in this distribution for the specific
11language governing permissions and limitations under the License.
12
13When distributing Covered Code, include this CDDL HEADER in each
14file and include the License file at LICENSE.txt.
15If applicable, add the following below this CDDL HEADER, with the
16fields enclosed by brackets "[]" replaced with your own identifying
17information: Portions Copyright [yyyy] [name of copyright owner]
18
19CDDL HEADER END
20
21Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
22Portions Copyright 2011 Jens Elkner.
23
24--%><%@page import="
25java.text.SimpleDateFormat,
26java.util.Set,
27
28org.opengrok.indexer.history.DirectoryHistoryReader,
29org.opengrok.indexer.history.History,
30org.opengrok.indexer.history.HistoryEntry,
31org.opengrok.indexer.history.HistoryGuru,
32org.opengrok.indexer.web.Util,
33org.opengrok.indexer.web.Prefix,
34org.opengrok.web.PageConfig"
35%>
36<%@ page import="jakarta.servlet.http.HttpServletResponse" %>
37<%@ page session="false" errorPage="error.jsp"%><%
38/* ---------------------- rss.jsp start --------------------- */
39{
40    PageConfig cfg = PageConfig.get(request);
41    cfg.checkSourceRootExistence();
42
43    String redir = cfg.canProcess();
44    if (redir == null || redir.length() > 0) {
45        if (redir != null) {
46            response.sendRedirect(redir);
47        } else {
48            response.sendError(HttpServletResponse.SC_NOT_FOUND);
49        }
50        return;
51    }
52    String path = cfg.getPath();
53    String dtag = cfg.getDefineTagsIndex();
54    response.setContentType("text/xml");
55%><?xml version="1.0"?>
56<?xml-stylesheet type="text/xsl" href="<%= request.getContextPath()
57    %>/rss.xsl.xml"?>
58<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
59<channel>
60    <title>Changes in <%= path.length() == 0
61        ? "Cross Reference"
62        : Util.htmlize(cfg.getResourceFile().getName()) %></title>
63    <description><%= Util.htmlize(dtag) %></description>
64    <language>en</language>
65    <copyright>Copyright 2015</copyright>
66    <generator>Java</generator><%
67    History hist = null;
68    String newline = System.getProperty("line.separator");
69    if(cfg.isDir()) {
70        hist = new DirectoryHistoryReader(cfg.getHistoryDirs()).getHistory();
71    } else {
72        hist = HistoryGuru.getInstance().getHistory(cfg.getResourceFile());
73    }
74    if (hist != null) {
75        int i = 20;
76        for (HistoryEntry entry : hist.getHistoryEntries()) {
77            if (i-- <= 0) {
78                break;
79            }
80            if (entry.isActive()) {
81    %>
82    <item>
83        <title><%
84            /*
85             * Newlines would result in HTML tags inside the 'title' which
86             * causes the title to be displayed as 'null'. Print first line
87             * of the message. The whole message will be printed in description.
88             */
89            String replaced = entry.getMessage().split("\n")[0];
90        %><%= Util.htmlize(entry.getRevision()) %> - <%= Util.htmlize(replaced) %></title>
91        <link><%
92            String requestURL = request.getScheme() + "://";
93            String serverName = cfg.getServerName();
94            requestURL += serverName;
95            String port = Integer.toString(request.getLocalPort());
96            if (!port.isEmpty()) {
97                requestURL += ":" + port;
98            }
99
100            requestURL += request.getContextPath();
101            requestURL += Prefix.HIST_L + cfg.getPath() + "#" + entry.getRevision();
102        %><%= Util.htmlize(requestURL) %></link>
103        <description><%
104            for (String e : entry.getMessage().split("\n")) {
105            %>
106            <%= Util.htmlize(e) %><%
107            }
108            %>
109
110            List of files:
111            <%
112            if (cfg.isDir()) {
113                Set<String> files = entry.getFiles();
114                if (files != null) {
115                    for (String ifile : files) {
116            %>
117            <%= Util.htmlize(ifile) %><%
118                    }
119                }
120            } else {
121            %><%= Util.htmlize(path) %><%
122            }
123        %>
124        </description>
125        <pubDate><%
126            SimpleDateFormat df =
127                new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
128        %><%= Util.htmlize(df.format(entry.getDate())) %></pubDate>
129        <dc:creator><%= Util.htmlize(entry.getAuthor()) %></dc:creator>
130    </item>
131<%
132            }
133        }
134    }
135%>
136</channel>
137</rss>
138<%
139}
140/* ---------------------- rss.jsp end --------------------- */
141%>
142