Home | History | Annotate | Download | only in web
      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 <%@ page import = "javax.servlet.*,
     23              java.lang.*,
     24              javax.servlet.http.*,
     25              java.util.*,
     26              java.io.*,
     27              org.opensolaris.opengrok.index.*,
     28              org.opensolaris.opengrok.configuration.*
     29              "
     30              %>
     31 <%@ page session="false" %><%@ page errorPage="error.jsp"%><%
     32 String context = request.getContextPath();
     33 String servlet = request.getServletPath();
     34 String reqURI = request.getRequestURI();
     35 String path = request.getPathInfo();
     36 if (path == null) path = "";
     37 RuntimeEnvironment environment = RuntimeEnvironment.getInstance();
     38 environment.setUrlPrefix(context + "/s?");
     39 environment.register();
     40 String rawSource = environment.getSourceRootPath();
     41 String resourcePath = rawSource + path;
     42 File resourceFile = new File(resourcePath);
     43 resourcePath = resourceFile.getAbsolutePath();
     44 boolean valid = true;
     45 boolean noHistory = true;
     46 boolean noAnnotation = true;
     47 boolean annotate = false;
     48 String basename = resourceFile.getName();
     49 boolean isDir = false;
     50 EftarFileReader ef = null;
     51 String parent = null;
     52 String parentBasename = resourceFile.getParentFile().getName();
     53 IgnoredNames ignoredNames = environment.getIgnoredNames();
     54 String uriEncodedName = Util.URIEncodePath(path);
     55 
     56 if(resourcePath.length() < rawSource.length()
     57 || ignoredNames.ignore(path)
     58 || ignoredNames.ignore(parentBasename)
     59 || !resourcePath.startsWith(rawSource)) {
     60     valid = false;
     61     response.sendError(404);
     62     return;
     63 } else if (!resourceFile.canRead() && resourcePath.startsWith(rawSource)) {
     64     String newPath = rawSource + "/on/" + path;
     65     File newFile = new File(newPath);
     66     if(newFile.canRead()) {
     67         if(newFile.isDirectory() && servlet.startsWith("/xref") && !path.endsWith("/")) {
     68             response.sendRedirect(context + servlet + "/on" + path + "/");
     69         } else {
     70             response.sendRedirect(context + servlet + "/on" + path);
     71         }
     72     }
     73     valid = false;
     74     response.sendError(404);
     75     return;
     76 } else {
     77     valid = true;
     78     path = resourcePath.substring(rawSource.length());
     79     if ("".equals(path)) {
     80         path = "/";
     81     }
     82     if (File.separatorChar == '\\') {
     83         path = path.replace('\\','/');
     84     }
     85     isDir = resourceFile.isDirectory();
     86     if (isDir && !servlet.startsWith("/xref") && !servlet.startsWith("/hist")) {	//if it is an existing directory perhaps people wanted directory xref
     87         if(!reqURI.endsWith("/")) {
     88             response.sendRedirect(context + "/xref" + path + "/");
     89         } else {
     90             response.sendRedirect(context + "/xref" + path);
     91         }
     92     } if (isDir && !reqURI.endsWith("/")) {
     93         response.sendRedirect(context + servlet + path +"/");
     94     } else {
     95         
     96         long flast = resourceFile.lastModified();
     97         String dtag = "";
     98         
     99         if (request.getDateHeader("If-Modified-Since") >= flast ) {
    100             response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
    101             valid = false;
    102         } else {
    103             
    104             response.setDateHeader("Last-Modified", flast);
    105             int lastSlash = path.lastIndexOf('/');
    106             parent = (lastSlash != -1) ? path.substring(0, lastSlash) : "";
    107             int pLastSlash = parent.lastIndexOf('/');
    108             parentBasename = pLastSlash != -1 ? parent.substring(pLastSlash+1) : parent;
    109             noHistory = !HistoryGuru.getInstance().hasHistory(resourceFile);
    110             noAnnotation = isDir ||
    111                     !HistoryGuru.getInstance().hasAnnotation(resourceFile);
    112             annotate = !noAnnotation &&
    113                     Boolean.parseBoolean(request.getParameter("a"));
    114             try{
    115                 ef = new EftarFileReader(environment.getDataRootPath() + "/index/dtags.eftar");
    116                 dtag = ef.get(path);
    117                 if(servlet.startsWith("/xr")) {
    118                 } else {
    119                     if(ef != null) {
    120                         try {
    121                             ef.close();
    122                         } catch (IOException e) {
    123                         } finally {
    124                             ef = null;
    125                         }
    126                     }
    127                 }
    128             } catch (Exception e) {
    129                 dtag = "";
    130             }
    131     String pageTitle="Cross Reference: " + path;
    132 
    133 %><%@ include file="httpheader.jspf" %>
    134 <body><div id="page">
    135 <form action="<%=context%>/search">
    136     <div id="header"><%@ include file="pageheader.jspf" %>
    137         <div id="pagetitle"><b id="filename">Cross Reference: <%=basename%></b><br/><%=dtag%></div>
    138     </div>
    139     <div id="Masthead"><tt><a href="<%=context%>/xref/">xref</a>: <%=org.opensolaris.opengrok.web.Util.breadcrumbPath(context + "/xref", path)%></tt></div>    
    140     <div id="bar"><a href="<%=context%>" id="home">Home</a> | 
    141         <%
    142         
    143         if (noHistory || servlet.startsWith("/hi")) {
    144         %> <span class="c" id="history">History</span><%
    145         } else {
    146         %><a id="history" href="<%=context%>/history<%=path%>">History</a><%
    147         }
    148         if (noAnnotation) {
    149         %> | <span class="c" id="annotate">Annotate</span><%
    150         } else {
    151            String rev = request.getParameter("r");
    152             if (rev == null) {
    153                 rev = "";
    154             } else if (rev.length() > 0) {
    155                 rev = "&r=" + rev;
    156             }
    157         
    158             if (Boolean.parseBoolean(request.getParameter("a"))) {
    159         %> | <span id="toggle-annotate-by-javascript" style="display: none">
    160             <a href="#" onClick="javascript:toggle_annotations(); return false;">Annotate</a>
    161         </span>
    162         <span id="toggle-annotate">
    163             <a href="<%=context%>/xref<%=path%><% 
    164                if (rev.length() > 0) { 
    165                %>?<%=rev%><% 
    166            } %>">Annotate</a></span>
    167         <script type="text/javascript">
    168             <!--
    169             var toggle_js = document.getElementById('toggle-annotate-by-javascript'); 
    170             var toggle_ss = document.getElementById('toggle-annotate');
    171 
    172             toggle_js.style.display = 'inline';
    173             toggle_ss.style.display = 'none';
    174             // -->
    175         </script> <%
    176         } else {
    177         %> | <a href="<%=context%>/xref<%=path%>?a=true<%=rev%>">Annotate</a><%
    178         }        
    179     }
    180             if (!isDir) {
    181                String rev = request.getParameter("r");
    182                if (rev == null || rev.equals("")) {
    183         %> | <a id="download" href="<%=context%>/raw<%=path%>">Download</a><%
    184         } else {
    185         %> | <a id="download" href="<%=context%>/raw<%=path%>?r=<%=rev%>">Download</a><%
    186         }
    187      }
    188 
    189      Project proj = Project.getProject(resourceFile);
    190      if  (proj != null || !environment.hasProjects()) {
    191         %> | <input id="search" name="q" class="q"/>
    192         <input type="submit" value="Search" class="submit"/>
    193         <%
    194         if (proj != null) {
    195         %><input type="hidden" name="project" value="<%=proj.getId()%>"/><%
    196         }
    197         if(isDir) {
    198                 if(path.length() > 0) {
    199         %><input type="checkbox" name="path" value="<%=path%>"/> only in <b><%=path%></b><%
    200           }
    201         } else {
    202           %><input type="checkbox" name="path" value="<%=parent%>"/> only in <b><%=parentBasename%></b><%
    203         }
    204         }
    205         %>
    206 </div></form>
    207 <%        
    208 } // date check
    209     } // not a directory redirect
    210 }
    211 %>
    212