17b79f34fSVladimir Kotal<%-- 27c7653c2SVladimir KotalCDDL HEADER START 37c7653c2SVladimir Kotal 47c7653c2SVladimir KotalThe contents of this file are subject to the terms of the 57c7653c2SVladimir KotalCommon Development and Distribution License (the "License"). 67c7653c2SVladimir KotalYou may not use this file except in compliance with the License. 77c7653c2SVladimir Kotal 87c7653c2SVladimir KotalSee LICENSE.txt included in this distribution for the specific 97c7653c2SVladimir Kotallanguage governing permissions and limitations under the License. 107c7653c2SVladimir Kotal 117c7653c2SVladimir KotalWhen distributing Covered Code, include this CDDL HEADER in each 127c7653c2SVladimir Kotalfile and include the License file at LICENSE.txt. 137c7653c2SVladimir KotalIf applicable, add the following below this CDDL HEADER, with the 147c7653c2SVladimir Kotalfields enclosed by brackets "[]" replaced with your own identifying 157c7653c2SVladimir Kotalinformation: Portions Copyright [yyyy] [name of copyright owner] 167c7653c2SVladimir Kotal 177c7653c2SVladimir KotalCDDL HEADER END 187c7653c2SVladimir Kotal 197c7653c2SVladimir KotalCopyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. 207c7653c2SVladimir KotalPortions Copyright 2011 Jens Elkner. 217c7653c2SVladimir KotalPortions Copyright (c) 2017-2020, Chris Fraire <cfraire@me.com>. 227b79f34fSVladimir Kotal--%> 237c7653c2SVladimir Kotal<%@page errorPage="error.jsp" import=" 247c7653c2SVladimir Kotaljava.io.BufferedInputStream, 257c7653c2SVladimir Kotaljava.io.File, 267c7653c2SVladimir Kotaljava.io.FileInputStream, 277c7653c2SVladimir Kotaljava.io.InputStream, 287c7653c2SVladimir Kotaljava.io.InputStreamReader, 297c7653c2SVladimir Kotaljava.io.IOException, 307c7653c2SVladimir Kotaljava.nio.charset.StandardCharsets, 317c7653c2SVladimir Kotaljava.util.logging.Level, 327c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.AnalyzerGuru, 337c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.Ctags, 347c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.Definitions, 357c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.AbstractAnalyzer, 367c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.AbstractAnalyzer.Genre, 377c7653c2SVladimir Kotalorg.opengrok.indexer.analysis.AnalyzerFactory, 387c7653c2SVladimir Kotalorg.opengrok.indexer.history.Annotation, 397c7653c2SVladimir Kotalorg.opengrok.indexer.history.HistoryGuru, 407c7653c2SVladimir Kotalorg.opengrok.indexer.util.ObjectPool, 417c7653c2SVladimir Kotalorg.opengrok.indexer.util.IOUtils, 427c7653c2SVladimir Kotalorg.opengrok.indexer.web.QueryParameters" 437c7653c2SVladimir Kotal%> 447c7653c2SVladimir Kotal<%@ page import="org.opengrok.indexer.web.Util" %> 457c7653c2SVladimir Kotal<%@ page import="static org.opengrok.web.PageConfig.DUMMY_REVISION" %> 467c7653c2SVladimir Kotal<% 477c7653c2SVladimir Kotal /* ---------------------- xref.jspf start --------------------- */ 487c7653c2SVladimir Kotal{ 497c7653c2SVladimir Kotal // requesting a previous revision or needed to generate xref on the fly 507c7653c2SVladimir Kotal // (either economy mode is enabled or the cfg.findDataFile() call failed). 517c7653c2SVladimir Kotal AnalyzerFactory a = AnalyzerGuru.find(basename); 527c7653c2SVladimir Kotal Genre g = AnalyzerGuru.getGenre(a); 537c7653c2SVladimir Kotal String error = null; 547c7653c2SVladimir Kotal 557c7653c2SVladimir Kotal if (g == Genre.PLAIN || g == Genre.HTML || g == null) { 567c7653c2SVladimir Kotal InputStream in = null; 577c7653c2SVladimir Kotal File tempf = null; 587c7653c2SVladimir Kotal try { 597c7653c2SVladimir Kotal if (rev.equals(DUMMY_REVISION)) { 607c7653c2SVladimir Kotal in = new BufferedInputStream(new FileInputStream(resourceFile)); 617c7653c2SVladimir Kotal } else { 627c7653c2SVladimir Kotal tempf = File.createTempFile("ogtags", basename); 637c7653c2SVladimir Kotal if (HistoryGuru.getInstance().getRevision(tempf, resourceFile.getParent(), basename, rev)) { 647c7653c2SVladimir Kotal in = new BufferedInputStream(new FileInputStream(tempf)); 657c7653c2SVladimir Kotal } else { 667c7653c2SVladimir Kotal tempf.delete(); 677c7653c2SVladimir Kotal tempf = null; 687c7653c2SVladimir Kotal } 697c7653c2SVladimir Kotal } 707c7653c2SVladimir Kotal } catch (Exception e) { 717c7653c2SVladimir Kotal // fall through to error message 727c7653c2SVladimir Kotal error = e.getMessage(); 737c7653c2SVladimir Kotal if (tempf != null) { 747c7653c2SVladimir Kotal tempf.delete(); 757c7653c2SVladimir Kotal tempf = null; 767c7653c2SVladimir Kotal } 777c7653c2SVladimir Kotal } 787c7653c2SVladimir Kotal 797c7653c2SVladimir Kotal if (in != null) { 807c7653c2SVladimir Kotal try { 817c7653c2SVladimir Kotal if (g == null) { 827c7653c2SVladimir Kotal a = AnalyzerGuru.find(in, basename); 837c7653c2SVladimir Kotal g = AnalyzerGuru.getGenre(a); 847c7653c2SVladimir Kotal } 857c7653c2SVladimir Kotal if (g == AbstractAnalyzer.Genre.DATA || g == AbstractAnalyzer.Genre.XREFABLE || g == null) { 867c7653c2SVladimir Kotal%> 877c7653c2SVladimir Kotal<div id="src"> 887c7653c2SVladimir Kotal Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %> 897c7653c2SVladimir Kotal<%= Util.URIEncode(rev) %>"><%= basename %></a> 907c7653c2SVladimir Kotal</div><% 917c7653c2SVladimir Kotal } else { 927c7653c2SVladimir Kotal%> 937c7653c2SVladimir Kotal<div id="src"> 947c7653c2SVladimir Kotal <pre><% 957c7653c2SVladimir Kotal if (g == AbstractAnalyzer.Genre.PLAIN) { 967c7653c2SVladimir Kotal Definitions defs = null; 977c7653c2SVladimir Kotal ObjectPool<Ctags> ctagsPool = cfg.getEnv().getIndexerParallelizer().getCtagsPool(); 987c7653c2SVladimir Kotal int tries = 2; 997c7653c2SVladimir Kotal while (cfg.getEnv().isWebappCtags()) { 1007c7653c2SVladimir Kotal Ctags ctags = ctagsPool.get(); 1017c7653c2SVladimir Kotal try { 1027c7653c2SVladimir Kotal ctags.setTabSize(project != null ? 1037c7653c2SVladimir Kotal project.getTabSize() : 0); 1047c7653c2SVladimir Kotal defs = ctags.doCtags(tempf.getPath()); 1057c7653c2SVladimir Kotal break; 1067c7653c2SVladimir Kotal } catch (InterruptedException ex) { 1077c7653c2SVladimir Kotal if (--tries > 0) { 1087c7653c2SVladimir Kotal LOGGER.log(Level.WARNING, "doCtags() interrupted--{0}", 1097c7653c2SVladimir Kotal ex.getMessage()); 1107c7653c2SVladimir Kotal continue; 1117c7653c2SVladimir Kotal } 1127c7653c2SVladimir Kotal LOGGER.log(Level.WARNING, "doCtags()", ex); 1137c7653c2SVladimir Kotal break; 1147c7653c2SVladimir Kotal } catch (Exception ex) { 1157c7653c2SVladimir Kotal LOGGER.log(Level.WARNING, "doCtags()", ex); 1167c7653c2SVladimir Kotal break; 1177c7653c2SVladimir Kotal } finally { 1187c7653c2SVladimir Kotal ctags.reset(); 1197c7653c2SVladimir Kotal ctagsPool.release(ctags); 1207c7653c2SVladimir Kotal } 1217c7653c2SVladimir Kotal } 1227c7653c2SVladimir Kotal Annotation annotation = cfg.getAnnotation(); 1237c7653c2SVladimir Kotal //not needed yet 1247c7653c2SVladimir Kotal //annotation.writeTooltipMap(out); 1257c7653c2SVladimir Kotal // The data under source root is read with UTF-8 as a default. 1267c7653c2SVladimir Kotal r = IOUtils.createBOMStrippedReader(in, StandardCharsets.UTF_8.name()); 1277c7653c2SVladimir Kotal AnalyzerGuru.writeDumpedXref(request.getContextPath(), 1287c7653c2SVladimir Kotal a, r, out, 1297c7653c2SVladimir Kotal defs, annotation, project); 1307c7653c2SVladimir Kotal } else if (g == AbstractAnalyzer.Genre.IMAGE) { 1317c7653c2SVladimir Kotal %></pre> 1327c7653c2SVladimir Kotal <img src="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %><%= Util.URIEncode(rev) %>"/> 1337c7653c2SVladimir Kotal <pre><% 1347c7653c2SVladimir Kotal } else if (g == AbstractAnalyzer.Genre.HTML) { 1357c7653c2SVladimir Kotal /* 1367c7653c2SVladimir Kotal * For backward compatibility, read the 1377c7653c2SVladimir Kotal * OpenGrok-produced document using the system 1387c7653c2SVladimir Kotal * default charset. 1397c7653c2SVladimir Kotal */ 1407c7653c2SVladimir Kotal r = new InputStreamReader(in); 1417c7653c2SVladimir Kotal /* 1427c7653c2SVladimir Kotal * dumpXref() is also useful here for 1437c7653c2SVladimir Kotal * translating links. 1447c7653c2SVladimir Kotal */ 1457c7653c2SVladimir Kotal Util.dumpXref(out, r, request.getContextPath()); 1467c7653c2SVladimir Kotal } else { 1477c7653c2SVladimir Kotal %>Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %> 1487c7653c2SVladimir Kotal<%= Util.URIEncode(rev) %>"><%= basename %></a><% 1497c7653c2SVladimir Kotal } 1507c7653c2SVladimir Kotal } 1517c7653c2SVladimir Kotal } catch (IOException e) { 1527c7653c2SVladimir Kotal LOGGER.log(Level.SEVERE, "Failed xref on-the-fly", e); 1537c7653c2SVladimir Kotal } finally { 1547c7653c2SVladimir Kotal if (r != null) { 1557c7653c2SVladimir Kotal IOUtils.close(r); 1567c7653c2SVladimir Kotal in = null; 1577c7653c2SVladimir Kotal } 1587c7653c2SVladimir Kotal if (in != null) { 1597c7653c2SVladimir Kotal IOUtils.close(in); 1607c7653c2SVladimir Kotal in = null; 1617c7653c2SVladimir Kotal } 1627c7653c2SVladimir Kotal if (tempf != null) { 1637c7653c2SVladimir Kotal tempf.delete(); 1647c7653c2SVladimir Kotal } 1657c7653c2SVladimir Kotal } 1667c7653c2SVladimir Kotal %></pre> 1677c7653c2SVladimir Kotal</div><% 1687c7653c2SVladimir Kotal } else { 1697c7653c2SVladimir Kotal%> 1707c7653c2SVladimir Kotal<h3 class="error">Error reading file</h3><% 1717c7653c2SVladimir Kotal if (error != null) { 1727c7653c2SVladimir Kotal%> 1737c7653c2SVladimir Kotal<p class="error"><%= error %></p><% 1747c7653c2SVladimir Kotal } 1757c7653c2SVladimir Kotal } 1767c7653c2SVladimir Kotal } else if (g == AbstractAnalyzer.Genre.IMAGE) { 1777c7653c2SVladimir Kotal%> 1787c7653c2SVladimir Kotal<div id="src"> 1797c7653c2SVladimir Kotal <img src="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %><%= Util.URIEncode(rev) %>" 1807c7653c2SVladimir Kotal alt="Image from Source Repository"/> 1817c7653c2SVladimir Kotal</div><% 1827c7653c2SVladimir Kotal } else { 1837c7653c2SVladimir Kotal%> 1847c7653c2SVladimir Kotal<div id="src"> 1857c7653c2SVladimir Kotal Download binary file, <a href="<%= rawPath %>?<%= QueryParameters.REVISION_PARAM_EQ %> 1867c7653c2SVladimir Kotal<%= Util.URIEncode(rev) %>"><%= basename %></a> 1877c7653c2SVladimir Kotal</div><% 1887c7653c2SVladimir Kotal } 1897c7653c2SVladimir Kotal} 1907c7653c2SVladimir Kotal/* ---------------------- xref.jspf end --------------------- */ 191*1f5d4ee8SVladimir Kotal%> 192