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 --%><%@ page import = "javax.servlet.*, 22 java.lang.*, 23 javax.servlet.http.*, 24 java.util.*, 25 java.io.*, 26 java.util.zip.GZIPInputStream, 27 java.util.logging.Level, 28 org.opensolaris.opengrok.OpenGrokLogger, 29 org.opensolaris.opengrok.analysis.*, 30 org.opensolaris.opengrok.configuration.Project, 31 org.opensolaris.opengrok.index.*, 32 org.opensolaris.opengrok.analysis.FileAnalyzer.Genre, 33 org.opensolaris.opengrok.web.*, 34 org.opensolaris.opengrok.history.* 35 " 36 %><%@include file="mast.jsp"%><% 37 String rev = null; 38 if(!isDir && ef != null) { 39 try { 40 ef.close(); 41 } catch (IOException e) { 42 } 43 ef = null; 44 } 45 46 if (valid) { 47 if (isDir) { 48 49 // verify that the current path is part of the selected project 50 Project activeProject = Project.getProject(resourceFile); 51 52 if (activeProject != null) { 53 String project = null; 54 55 Cookie[] cookies = request.getCookies(); 56 if (cookies != null) { 57 for (Cookie cookie : cookies) { 58 if (cookie.getName().equals("OpenGrok/project")) { 59 project = cookie.getValue(); 60 break; 61 } 62 } 63 } 64 65 boolean set = false; 66 if (project != null) { 67 boolean found = false; 68 for (String aproj : project.split(" ")) { 69 if (activeProject.getPath().equalsIgnoreCase(aproj)) { 70 found = true; 71 break; 72 } 73 } 74 if (!found) { 75 set = true; 76 } 77 } else { 78 set = true; 79 } 80 81 if (set) { 82 Cookie cookie = new Cookie("OpenGrok/project", activeProject.getPath()); 83 cookie.setPath(context + "/"); 84 response.addCookie(cookie); 85 } 86 } 87 88 // If requesting a Directory listing ------------- 89 DirectoryListing dl = new DirectoryListing(ef); 90 String[] files = resourceFile.list(); 91 if (files != null) { 92 Arrays.sort(files, String.CASE_INSENSITIVE_ORDER); 93 List<String> readMes = dl.listTo(resourceFile, out, path, files); 94 if(readMes != null && readMes.size() > 0) { 95 File xdir = new File(environment.getDataRootPath() + "/xref" + path); 96 if (xdir.exists() && xdir.isDirectory()) { 97 char[] buf = new char[8192]; 98 for (String readme : readMes) { 99 File readmeFile = new File(xdir, readme + ".gz"); 100 Reader br = null; 101 try { 102 if (environment.isCompressXref() && readmeFile.exists()) { 103 br = new InputStreamReader(new GZIPInputStream(new FileInputStream(readmeFile))); 104 } else { 105 readmeFile = new File(xdir, readme); 106 if (readmeFile.exists()) { 107 br = new FileReader(readmeFile); 108 } 109 } 110 111 if (br != null) { 112 int len = 0; 113 %><h3><%=readme%></h3><div id="src"><pre><% 114 while((len = br.read(buf)) > 0) { 115 out.write(buf, 0, len); 116 } 117 %></pre></div><% 118 } 119 } catch(IOException e) { 120 OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while reading/writing readme:", e); 121 } finally { 122 if (br != null) { 123 try { 124 br.close(); 125 } catch (IOException e) { 126 OpenGrokLogger.getLogger().log(Level.WARNING, "An error occured while closing file:", e); 127 } 128 } 129 } 130 } 131 } 132 } 133 } 134 } else if ((rev = request.getParameter("r")) != null && !rev.equals("")) { 135 // Else if requesting a previous revision ------------- 136 if (noHistory) { 137 response.sendError(404, "Revision not found"); 138 } else { 139 FileAnalyzerFactory a = AnalyzerGuru.find(basename); 140 Genre g = AnalyzerGuru.getGenre(a); 141 if (g == Genre.PLAIN|| g == Genre.HTML || g == null) { 142 InputStream in = null; 143 try { 144 in = HistoryGuru.getInstance().getRevision(resourceFile.getParent(), basename, rev); 145 } catch (Exception e) { 146 response.sendError(404, "Revision not found"); 147 return; 148 } 149 if (in != null) { 150 try { 151 if (g == null) { 152 a = AnalyzerGuru.find(in); 153 g = AnalyzerGuru.getGenre(a); 154 } 155 if (g == Genre.DATA || g == Genre.XREFABLE || g == null) { 156 %><div id="src">Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><% 157 } else { 158 %><div id="src"><span class="pagetitle"><%=basename%> revision <%=rev%> </span><pre><% 159 if (g == Genre.PLAIN) { 160 Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null; 161 AnalyzerGuru.writeXref(a, in, out, annotation, Project.getProject(resourceFile)); 162 } else if (g == Genre.IMAGE) { 163 %><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/><% 164 } else if (g == Genre.HTML) { 165 char[] buf = new char[8192]; 166 Reader br = new InputStreamReader(in); 167 int len = 0; 168 while((len = br.read(buf)) > 0) { 169 out.write(buf, 0, len); 170 } 171 } else { 172 %> Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">download <%=basename%></a><% 173 } 174 } 175 } catch (IOException e) { 176 %> <h3 class="error">IO Error</h3> <p> <%=e.getMessage() %> </p> <% 177 } 178 %></pre></div><% 179 in.close(); 180 } else { 181 %> <h3 class="error">Error reading file</h3> <% 182 } 183 } else if(g == Genre.IMAGE) { 184 %><div id="src"><img src="<%=context%>/raw<%=path%>?r=<%=rev%>"/></div><% 185 } else { 186 %><div id="src"> Binary file [Click <a href="<%=context%>/raw<%=path%>?r=<%=rev%>">here</a> to download] </div><% 187 } 188 } 189 } else { 190 // requesting cross referenced file ------------- 191 File xrefSource = new File(environment.getDataRootFile(), "/xref"); 192 File xrefFile = new File(xrefSource, path + ".gz"); 193 Reader fileReader = null; 194 195 if (environment.isCompressXref() && xrefFile.exists()) { 196 fileReader = new InputStreamReader(new GZIPInputStream(new FileInputStream(xrefFile))); 197 } else { 198 xrefFile = new File(xrefSource, path); 199 if (xrefFile.exists()) { 200 fileReader = new FileReader(xrefFile); 201 } 202 } 203 204 if (fileReader != null && !annotate) { 205 char[] buf = new char[8192]; 206 BufferedReader br = new BufferedReader(fileReader); 207 int len = 0; 208 %><div id="src"><pre><% 209 while((len = br.read(buf)) > 0) { 210 out.write(buf, 0, len); 211 } 212 %></pre></div><% 213 br.close(); 214 } else { 215 BufferedInputStream bin = new BufferedInputStream(new FileInputStream(resourceFile)); 216 FileAnalyzerFactory a = AnalyzerGuru.find(basename); 217 Genre g = AnalyzerGuru.getGenre(a); 218 if(g == null) { 219 a = AnalyzerGuru.find(bin); 220 g = AnalyzerGuru.getGenre(a); 221 } 222 if (g == Genre.IMAGE) { 223 %><div id="src"><img src="<%=context%>/raw<%=path%>"/></div><% 224 } else if( g == Genre.HTML) { 225 char[] buf = new char[8192]; 226 Reader br = new InputStreamReader(bin); 227 int len = 0; 228 while((len = br.read(buf)) > 0) { 229 out.write(buf, 0, len); 230 } 231 } else if(g == Genre.PLAIN) { 232 %><div id="src"><pre><% 233 Annotation annotation = annotate ? HistoryGuru.getInstance().annotate(resourceFile, rev) : null; 234 AnalyzerGuru.writeXref(a, bin, out, annotation, Project.getProject(resourceFile)); 235 %></pre></div><% 236 } else { 237 %> Click <a href="<%=context%>/raw<%=path%>">download <%=basename%></a><% 238 } 239 } 240 } 241 %><%@include file="foot.jspf"%><% 242 } 243 if (ef != null) { 244 try { 245 ef.close(); 246 } catch (IOException e) { 247 } 248 } 249 %> 250