1 <%-- 2 CDDL HEADER START 3 4 The contents of this file are subject to the terms of the 5 Common Development and Distribution License (the "License"). 6 You may not use this file except in compliance with the License. 7 8 See LICENSE.txt included in this distribution for the specific 9 language governing permissions and limitations under the License. 10 11 When distributing Covered Code, include this CDDL HEADER in each 12 file and include the License file at LICENSE.txt. 13 If applicable, add the following below this CDDL HEADER, with the 14 fields enclosed by brackets "[]" replaced with your own identifying 15 information: Portions Copyright [yyyy] [name of copyright owner] 16 17 CDDL HEADER END 18 19 Copyright 2005 Sun Microsystems, Inc. All rights reserved. 20 Use is subject to license terms. 21 22 ident "@(#)rss.jsp 1.2 05/12/02 SMI" 23 24 --%><%@ page import = "javax.servlet.*, 25 java.lang.*, 26 javax.servlet.http.*, 27 java.util.*, 28 java.io.*, 29 org.opensolaris.opengrok.analysis.*, 30 org.opensolaris.opengrok.web.*, 31 org.opensolaris.opengrok.history.*, 32 org.opensolaris.opengrok.index.IgnoredNames, 33 org.opensolaris.opengrok.configuration.*, 34 org.apache.lucene.analysis.*, 35 org.apache.lucene.document.*, 36 org.apache.lucene.index.*, 37 org.apache.lucene.search.*, 38 org.apache.lucene.queryParser.*, 39 java.text.*" 40 %><%@ page session="false" %><%@ page errorPage="error.jsp"%><% 41 String context = request.getContextPath(); 42 String servlet = request.getServletPath(); 43 String reqURI = request.getRequestURI(); 44 String path = request.getPathInfo(); 45 if(path == null) path = ""; 46 RuntimeEnvironment env = RuntimeEnvironment.getInstance(); 47 env.setUrlPrefix(context + "/s?"); 48 env.register(); 49 String rawSource = env.getSourceRootPath(); 50 String resourcePath = rawSource + path; 51 File resourceFile = new File(resourcePath); 52 resourcePath = resourceFile.getAbsolutePath(); 53 boolean valid; 54 String basename = resourceFile.getName(); 55 if("/".equals(path)) { 56 basename = "Cross Reference"; 57 } 58 boolean isDir = false; 59 String parent = null; 60 String parentBasename = resourceFile.getParentFile().getName(); 61 IgnoredNames ignoredNames = env.getIgnoredNames(); 62 if (resourcePath.length() < rawSource.length() 63 || !resourcePath.startsWith(rawSource) 64 || !resourceFile.canRead() 65 || ignoredNames.ignore(basename) || ignoredNames.ignore(parentBasename)) { 66 valid = false; 67 response.sendError(404); 68 return; 69 } else { 70 valid = true; 71 path = resourcePath.substring(rawSource.length()); 72 if (File.separatorChar == '\\') { 73 path = path.replace('\\','/'); 74 } 75 isDir = resourceFile.isDirectory(); 76 if (isDir && !reqURI.endsWith("/")) { 77 response.sendRedirect(context + servlet + path +"/"); 78 } else { 79 String dtag = ""; 80 81 try { 82 EftarFileReader ef = new EftarFileReader(env.getDataRootPath() + "/index/dtags.eftar"); 83 dtag = ef.get(path); 84 ef.close(); 85 } catch (Exception e) { 86 dtag = ""; 87 } 88 int lastSlash = path.lastIndexOf('/'); 89 parent = (lastSlash != -1) ? path.substring(0, lastSlash) : ""; 90 int pLastSlash = parent.lastIndexOf('/'); 91 parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent; 92 response.setContentType("text/xml"); 93 Date start = new Date(); 94 %><?xml version="1.0"?> 95 <?xml-stylesheet type="text/xsl" href="<%=context%>/rss.xsl.xml"?> 96 <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> 97 <channel> 98 <title>Changes in <%=basename%></title> 99 <link><%=request.getRequestURL()%></link> 100 <description><%=dtag%></description> 101 <language>en</language> 102 <copyright>Copyright 2005</copyright> 103 <generator>Java</generator> 104 <% 105 Format df = new SimpleDateFormat("dd-MMM-yyyy"); 106 HistoryReader hr = null; 107 if(isDir) { 108 String[] apaths = request.getParameterValues("also"); 109 String apath = path; 110 if (apaths!= null && apaths.length>0) { 111 StringBuilder paths = new StringBuilder(path); 112 for(int i=0; i< apaths.length; i++) { 113 paths.append(' '); 114 paths.append(apaths[i]); 115 } 116 apath = paths.toString(); 117 } 118 hr = new DirectoryHistoryReader(apath); 119 } else { 120 File f = new File(rawSource + parent, basename); 121 hr = HistoryGuru.getInstance().getHistoryReader(f); 122 } 123 if (hr != null) { 124 int i = 20; 125 while (hr.next() && i-- > 0) { 126 String rev = hr.getRevision(); 127 if(hr.isActive()) { 128 %> 129 <item> 130 <title><%=Util.htmlize(hr.getComment())%></title> 131 <description><% 132 if(isDir) { 133 List<String> files = hr.getFiles(); 134 if(files != null) { 135 for (String ifile : files) { 136 %><%=ifile%> 137 <% 138 } 139 } 140 } else { 141 %><%=path%> - <%=hr.getRevision()%><% 142 } 143 %></description> 144 <pubDate><%=hr.getDate()%></pubDate> 145 <dc:creator><%=hr.getAuthor()%></dc:creator> 146 </item> 147 <% 148 } 149 } 150 hr.close(); 151 } 152 %></channel></rss> 153 <% 154 } 155 } 156 %> 157