<%-- CDDL HEADER START The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. See LICENSE.txt included in this distribution for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at LICENSE.txt. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] CDDL HEADER END Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. Portions Copyright 2011 Jens Elkner. Portions Copyright (c) 2017-2020, Chris Fraire . --%> <%@page errorPage="error.jsp" import=" java.io.BufferedInputStream, java.io.File, java.io.FileInputStream, java.io.InputStream, java.io.InputStreamReader, java.io.IOException, java.nio.charset.StandardCharsets, java.util.logging.Level, org.opengrok.indexer.analysis.AnalyzerGuru, org.opengrok.indexer.analysis.Ctags, org.opengrok.indexer.analysis.Definitions, org.opengrok.indexer.analysis.AbstractAnalyzer, org.opengrok.indexer.analysis.AbstractAnalyzer.Genre, org.opengrok.indexer.analysis.AnalyzerFactory, org.opengrok.indexer.history.Annotation, org.opengrok.indexer.history.HistoryGuru, org.opengrok.indexer.util.ObjectPool, org.opengrok.indexer.util.IOUtils, org.opengrok.indexer.web.QueryParameters" %> <%@ page import="org.opengrok.indexer.web.Util" %> <%@ page import="static org.opengrok.web.PageConfig.DUMMY_REVISION" %> <% /* ---------------------- xref.jspf start --------------------- */ { // requesting a previous revision or needed to generate xref on the fly // (either economy mode is enabled or the cfg.findDataFile() call failed). AnalyzerFactory a = AnalyzerGuru.find(basename); Genre g = AnalyzerGuru.getGenre(a); String error = null; if (g == Genre.PLAIN || g == Genre.HTML || g == null) { InputStream in = null; File tempf = null; try { if (rev.isBlank() || rev.equals(DUMMY_REVISION)) { in = new BufferedInputStream(new FileInputStream(resourceFile)); } else { tempf = File.createTempFile("ogtags", basename); if (HistoryGuru.getInstance().getRevision(tempf, resourceFile.getParent(), basename, rev)) { in = new BufferedInputStream(new FileInputStream(tempf)); } else { tempf.delete(); tempf = null; } } } catch (Exception e) { // fall through to error message error = e.getMessage(); if (tempf != null) { tempf.delete(); tempf = null; } } if (in != null) { try { if (g == null) { a = AnalyzerGuru.find(in, basename); g = AnalyzerGuru.getGenre(a); } if (g == AbstractAnalyzer.Genre.DATA || g == AbstractAnalyzer.Genre.XREFABLE || g == null) { %>
Download binary file, <%= basename %>
<% } else { %>
<%
                    if (g == AbstractAnalyzer.Genre.PLAIN) {
                        Definitions defs = null;
                        ObjectPool ctagsPool = cfg.getEnv().getIndexerParallelizer().getCtagsPool();
                        int tries = 2;
                        while (cfg.getEnv().isWebappCtags()) {
                            Ctags ctags = ctagsPool.get();
                            try {
                                ctags.setTabSize(project != null ?
                                project.getTabSize() : 0);
                                defs = ctags.doCtags(tempf.getPath());
                                break;
                            } catch (InterruptedException ex) {
                                if (--tries > 0) {
                                    LOGGER.log(Level.WARNING, "doCtags() interrupted--{0}",
                                    ex.getMessage());
                                    continue;
                                }
                                LOGGER.log(Level.WARNING, "doCtags()", ex);
                                break;
                            } catch (Exception ex) {
                                LOGGER.log(Level.WARNING, "doCtags()", ex);
                                break;
                            } finally {
                                ctags.reset();
                                ctagsPool.release(ctags);
                            }
                        }
                        Annotation annotation = cfg.getAnnotation();
                        //not needed yet
                        //annotation.writeTooltipMap(out);
                        // The data under source root is read with UTF-8 as a default.
                        r = IOUtils.createBOMStrippedReader(in, StandardCharsets.UTF_8.name());
                        AnalyzerGuru.writeDumpedXref(request.getContextPath(),
                            a, r, out,
                            defs, annotation, project);
                    } else if (g == AbstractAnalyzer.Genre.IMAGE) {
        %>
<%
                    } else if (g == AbstractAnalyzer.Genre.HTML) {
                        /*
                         * For backward compatibility, read the
                         * OpenGrok-produced document using the system
                         * default charset.
                         */
                        r = new InputStreamReader(in);
                        /*
                         * dumpXref() is also useful here for
                         * translating links.
                         */
                        Util.dumpXref(out, r, request.getContextPath());
                    } else {
    %>Download binary file, <%= basename %><%
                    }
                }
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed xref on-the-fly", e);
            } finally {
                if (r != null) {
                    IOUtils.close(r);
                    in = null;
                }
                if (in != null) {
                    IOUtils.close(in);
                    in = null;
                }
                if (tempf != null) {
                    tempf.delete();
                }
            }
    %>
<% } else { %>

Error reading file

<% if (error != null) { %>

<%= error %>

<% } } } else if (g == AbstractAnalyzer.Genre.IMAGE) { %>
Image from Source Repository
<% } else { %>
Download binary file, <%= basename %>
<% } } /* ---------------------- xref.jspf end --------------------- */ %>