rss.jsp revision 7cbf6a20cb1925bd734d2c6664ba739e6e82c8e3
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graber<%--
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberCDDL HEADER START
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graber
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberThe contents of this file are subject to the terms of the
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberCommon Development and Distribution License (the "License").
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberYou may not use this file except in compliance with the License.
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graber
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberSee LICENSE.txt included in this distribution for the specific
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graberlanguage governing permissions and limitations under the License.
d79067a726f1b4a06828220cc11dd3cfbc244856Daniel Miranda
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberWhen distributing Covered Code, include this CDDL HEADER in each
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graberfile and include the License file at LICENSE.txt.
d4f6fa926d92803d8b8217468be483ac2f7e270eStéphane GraberIf applicable, add the following below this CDDL HEADER, with the
d4f6fa926d92803d8b8217468be483ac2f7e270eStéphane Graberfields enclosed by brackets "[]" replaced with your own identifying
d4f6fa926d92803d8b8217468be483ac2f7e270eStéphane Graberinformation: Portions Copyright [yyyy] [name of copyright owner]
d4f6fa926d92803d8b8217468be483ac2f7e270eStéphane Graber
d4f6fa926d92803d8b8217468be483ac2f7e270eStéphane GraberCDDL HEADER END
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graber
9a42db48e0bcf4f34b05a3de1cda23e06f51d131Stéphane GraberCopyright 2005 Sun Microsystems, Inc. All rights reserved.
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane GraberUse is subject to license terms.
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graber
be2e4e54da3c8054525321422f7f290d45b32a6cStéphane Graberident "@(#)rss.jsp 1.2 05/12/02 SMI"
c13c0e08da7dbfecb52e85233ac6cd17afa5d818Stéphane Graber
c13c0e08da7dbfecb52e85233ac6cd17afa5d818Stéphane Graber--%><%@ page import = "javax.servlet.*,
c13c0e08da7dbfecb52e85233ac6cd17afa5d818Stéphane Graberjava.lang.*,
f10e04e36170dbd0faae3a667d53f0af1ef6a13aStéphane Graberjavax.servlet.http.*,
f10e04e36170dbd0faae3a667d53f0af1ef6a13aStéphane Graberjava.util.*,
f10e04e36170dbd0faae3a667d53f0af1ef6a13aStéphane Graberjava.io.*,
org.opensolaris.opengrok.analysis.*,
org.opensolaris.opengrok.web.*,
org.opensolaris.opengrok.history.*,
org.opensolaris.opengrok.index.IgnoredNames,
org.opensolaris.opengrok.configuration.*,
org.apache.lucene.analysis.*,
org.apache.lucene.document.*,
org.apache.lucene.index.*,
org.apache.lucene.search.*,
org.apache.lucene.queryParser.*,
java.text.*"
%><%@ page session="false" %><%@ page errorPage="error.jsp"%><%
String context = request.getContextPath();
String servlet = request.getServletPath();
String reqURI = request.getRequestURI();
String path = request.getPathInfo();
if(path == null) path = "";
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setUrlPrefix(context + "/s?");
env.register();
String rawSource = env.getSourceRootPath();
String resourcePath = rawSource + path;
File resourceFile = new File(resourcePath);
resourcePath = resourceFile.getAbsolutePath();
boolean valid;
String basename = resourceFile.getName();
if("/".equals(path)) {
basename = "Cross Reference";
}
boolean isDir = false;
String parent = null;
String parentBasename = resourceFile.getParentFile().getName();
IgnoredNames ignoredNames = env.getIgnoredNames();
if (resourcePath.length() < rawSource.length()
|| !resourcePath.startsWith(rawSource)
|| !resourceFile.canRead()
|| ignoredNames.ignore(basename) || ignoredNames.ignore(parentBasename)) {
valid = false;
response.sendError(404);
return;
} else {
valid = true;
path = resourcePath.substring(rawSource.length());
if (File.separatorChar == '\\') {
path = path.replace('\\','/');
}
isDir = resourceFile.isDirectory();
if (isDir && !reqURI.endsWith("/")) {
response.sendRedirect(context + servlet + path +"/");
} else {
String dtag = "";
try {
EftarFileReader ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar");
dtag = ef.get(path);
ef.close();
} catch (Exception e) {
dtag = "";
}
int lastSlash = path.lastIndexOf('/');
parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
int pLastSlash = parent.lastIndexOf('/');
parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
response.setContentType("text/xml");
Date start = new Date();
%><?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="<%=context%>/rss.xsl.xml"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Changes in <%=basename%></title>
<link><%=request.getRequestURL()%></link>
<description><%=dtag%></description>
<language>en</language>
<copyright>Copyright 2005</copyright>
<generator>Java</generator>
<%
Format df = new SimpleDateFormat("dd-MMM-yyyy");
HistoryReader hr = null;
if(isDir) {
String[] apaths = request.getParameterValues("also");
String apath = path;
if (apaths!= null && apaths.length>0) {
StringBuilder paths = new StringBuilder(path);
for(int i=0; i< apaths.length; i++) {
paths.append(' ');
paths.append(apaths[i]);
}
apath = paths.toString();
}
hr = new DirectoryHistoryReader(apath);
} else {
File f = new File(rawSource + parent, basename);
hr = HistoryGuru.getInstance().getHistoryReader(f);
}
if (hr != null) {
int i = 20;
while (hr.next() && i-- > 0) {
String rev = hr.getRevision();
if(hr.isActive()) {
%>
<item>
<title><%=Util.Htmlize(hr.getComment())%></title>
<description><%
if(isDir) {
List<String> files = hr.getFiles();
if(files != null) {
for (String ifile : files) {
%><%=ifile%>
<%
}
}
} else {
%><%=path%> - <%=hr.getRevision()%><%
}
%></description>
<pubDate><%=hr.getDate()%></pubDate>
<dc:creator><%=hr.getAuthor()%></dc:creator>
</item>
<%
}
}
hr.close();
}
%></channel></rss>
<%
}
}
%>