xref: /OpenGrok/opengrok-web/src/main/webapp/opensearch.jsp (revision 0516dd21dfeb393bf975b3930bbbf13ecc1deed8)
1<%--
2$Id$
3
4CDDL HEADER START
5
6The contents of this file are subject to the terms of the
7Common Development and Distribution License (the "License").
8You may not use this file except in compliance with the License.
9
10See LICENSE.txt included in this distribution for the specific
11language governing permissions and limitations under the License.
12
13When distributing Covered Code, include this CDDL HEADER in each
14file and include the License file at LICENSE.txt.
15If applicable, add the following below this CDDL HEADER, with the
16fields enclosed by brackets "[]" replaced with your own identifying
17information: Portions Copyright [yyyy] [name of copyright owner]
18
19CDDL HEADER END
20
21Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
22Portions Copyright 2011 Jens Elkner.
23Portions Copyright (c) 2018, 2020, Chris Fraire <cfraire@me.com>.
24
25--%><%@page  session="false" errorPage="error.jsp" import="
26java.util.Set,
27
28org.opengrok.indexer.web.Prefix,
29org.opengrok.indexer.web.QueryParameters,
30org.opengrok.indexer.web.Util"
31%>
32<%
33{
34    PageConfig cfg = PageConfig.get(request);
35    cfg.checkSourceRootExistence();
36}
37%><%@
38
39include file="projects.jspf"
40
41%><%
42    /* ---------------------- opensearch.jsp start --------------------- */
43{
44    PageConfig cfg = PageConfig.get(request);
45
46    // Optimize for URLs up to 128 characters.
47    StringBuilder url = new StringBuilder(128);
48    String scheme = request.getScheme();
49    int port = request.getServerPort();
50
51    url.append(scheme).append("://");
52
53    String serverName = cfg.getServerName();
54    url.append(serverName);
55
56    // Append port if needed.
57    if ((port != 80 && scheme.equals("http")) || (port != 443 && scheme.equals("https"))) {
58        url.append(':').append(port);
59    }
60
61    String imgUrl = url + cfg.getCssDir() + "/img/icon.png";
62
63    /* TODO  Bug 11749 ??? */
64    StringBuilder text = new StringBuilder();
65    url.append(request.getContextPath()).append(Prefix.SEARCH_P).append('?');
66    Set<String> projects = cfg.getRequestedProjects();
67    for (String name : projects) {
68        text.append(name).append(',');
69        Util.appendQuery(url, QueryParameters.PROJECT_SEARCH_PARAM, name);
70    }
71    if (text.length() != 0) {
72        text.setLength(text.length()-1);
73    }
74%><?xml version="1.0" encoding="UTF-8"?>
75<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
76    <ShortName>OpenGrok <%= text.toString() %></ShortName>
77    <Description>Search in OpenGrok <%= text.toString() %></Description>
78    <InputEncoding>UTF-8</InputEncoding>
79    <Image height="16" width="16" type="image/png"><%= imgUrl %></Image>
80<%-- <Url type="application/x-suggestions+json" template="suggestionURL"/>--%>
81    <Url template="<%= url.toString() %>&amp;<%= QueryParameters.FULL_SEARCH_PARAM_EQ %>{searchTerms}"
82        type="text/html"/>
83</OpenSearchDescription>
84<%
85}
86/* ---------------------- opensearch.jsp end --------------------- */
87%>
88