xref: /OpenGrok/opengrok-web/src/main/webapp/opensearch.jsp (revision 0d40e9d0d07acb46ebe450cbc6042a9705a36e41)
1*0d40e9d0SAdam Hornáček<%--
2*0d40e9d0SAdam Hornáček$Id$
3*0d40e9d0SAdam Hornáček
4*0d40e9d0SAdam HornáčekCDDL HEADER START
5*0d40e9d0SAdam Hornáček
6*0d40e9d0SAdam HornáčekThe contents of this file are subject to the terms of the
7*0d40e9d0SAdam HornáčekCommon Development and Distribution License (the "License").
8*0d40e9d0SAdam HornáčekYou may not use this file except in compliance with the License.
9*0d40e9d0SAdam Hornáček
10*0d40e9d0SAdam HornáčekSee LICENSE.txt included in this distribution for the specific
11*0d40e9d0SAdam Hornáčeklanguage governing permissions and limitations under the License.
12*0d40e9d0SAdam Hornáček
13*0d40e9d0SAdam HornáčekWhen distributing Covered Code, include this CDDL HEADER in each
14*0d40e9d0SAdam Hornáčekfile and include the License file at LICENSE.txt.
15*0d40e9d0SAdam HornáčekIf applicable, add the following below this CDDL HEADER, with the
16*0d40e9d0SAdam Hornáčekfields enclosed by brackets "[]" replaced with your own identifying
17*0d40e9d0SAdam Hornáčekinformation: Portions Copyright [yyyy] [name of copyright owner]
18*0d40e9d0SAdam Hornáček
19*0d40e9d0SAdam HornáčekCDDL HEADER END
20*0d40e9d0SAdam Hornáček
21*0d40e9d0SAdam HornáčekCopyright (c) 2009, 2017, Oracle and/or its affiliates. All rights reserved.
22*0d40e9d0SAdam Hornáček
23*0d40e9d0SAdam HornáčekPortions Copyright 2011 Jens Elkner.
24*0d40e9d0SAdam Hornáček
25*0d40e9d0SAdam Hornáček--%><%@page  session="false" errorPage="error.jsp" import="
26*0d40e9d0SAdam Hornáčekjava.util.Set,
27*0d40e9d0SAdam Hornáček
28*0d40e9d0SAdam Hornáčekorg.opensolaris.opengrok.web.Util"
29*0d40e9d0SAdam Hornáček%>
30*0d40e9d0SAdam Hornáček<%
31*0d40e9d0SAdam Hornáček{
32*0d40e9d0SAdam Hornáček    PageConfig cfg = PageConfig.get(request);
33*0d40e9d0SAdam Hornáček    cfg.checkSourceRootExistence();
34*0d40e9d0SAdam Hornáček}
35*0d40e9d0SAdam Hornáček%><%@
36*0d40e9d0SAdam Hornáček
37*0d40e9d0SAdam Hornáčekinclude file="projects.jspf"
38*0d40e9d0SAdam Hornáček
39*0d40e9d0SAdam Hornáček%><%
40*0d40e9d0SAdam Hornáček    /* ---------------------- opensearch.jsp start --------------------- */
41*0d40e9d0SAdam Hornáček{
42*0d40e9d0SAdam Hornáček    PageConfig cfg = PageConfig.get(request);
43*0d40e9d0SAdam Hornáček
44*0d40e9d0SAdam Hornáček    // Optimize for URLs up to 128 characters.
45*0d40e9d0SAdam Hornáček    StringBuilder url = new StringBuilder(128);
46*0d40e9d0SAdam Hornáček    String ForwardedHost = request.getHeader("X-Forwarded-Host");
47*0d40e9d0SAdam Hornáček    String scheme = request.getScheme();
48*0d40e9d0SAdam Hornáček    int port = request.getServerPort();
49*0d40e9d0SAdam Hornáček
50*0d40e9d0SAdam Hornáček    url.append(scheme).append("://");
51*0d40e9d0SAdam Hornáček
52*0d40e9d0SAdam Hornáček    // Play nice in proxy environment by using hostname from the original
53*0d40e9d0SAdam Hornáček    // request to construct the URLs.
54*0d40e9d0SAdam Hornáček    // Will not work well if the scheme or port is different for proxied server
55*0d40e9d0SAdam Hornáček    // and original server. Unfortunately the X-Forwarded-Host does not seem to
56*0d40e9d0SAdam Hornáček    // contain the port number so there is no way around it.
57*0d40e9d0SAdam Hornáček    if (ForwardedHost != null) {
58*0d40e9d0SAdam Hornáček        url.append(ForwardedHost);
59*0d40e9d0SAdam Hornáček    } else {
60*0d40e9d0SAdam Hornáček        url.append(request.getServerName());
61*0d40e9d0SAdam Hornáček
62*0d40e9d0SAdam Hornáček        // Append port if needed.
63*0d40e9d0SAdam Hornáček        if ((port != 80 && scheme.equals("http")) ||
64*0d40e9d0SAdam Hornáček                   (port != 443 && scheme.equals("https"))) {
65*0d40e9d0SAdam Hornáček            url.append(':').append(port);
66*0d40e9d0SAdam Hornáček        }
67*0d40e9d0SAdam Hornáček    }
68*0d40e9d0SAdam Hornáček
69*0d40e9d0SAdam Hornáček    String imgurl = url +  cfg.getCssDir() + "/img/icon.png";
70*0d40e9d0SAdam Hornáček
71*0d40e9d0SAdam Hornáček    /* TODO  Bug 11749 ??? */
72*0d40e9d0SAdam Hornáček    StringBuilder text = new StringBuilder();
73*0d40e9d0SAdam Hornáček    url.append(request.getContextPath()).append(Prefix.SEARCH_P).append('?');
74*0d40e9d0SAdam Hornáček    Set<String> projects = cfg.getRequestedProjects();
75*0d40e9d0SAdam Hornáček    for (String name : projects) {
76*0d40e9d0SAdam Hornáček        text.append(name).append(',');
77*0d40e9d0SAdam Hornáček        Util.appendQuery(url, "project", name);
78*0d40e9d0SAdam Hornáček    }
79*0d40e9d0SAdam Hornáček    if (text.length() != 0) {
80*0d40e9d0SAdam Hornáček        text.setLength(text.length()-1);
81*0d40e9d0SAdam Hornáček    }
82*0d40e9d0SAdam Hornáček%><?xml version="1.0" encoding="UTF-8"?>
83*0d40e9d0SAdam Hornáček<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
84*0d40e9d0SAdam Hornáček    <ShortName>OpenGrok <%= text.toString() %></ShortName>
85*0d40e9d0SAdam Hornáček    <Description>Search in OpenGrok <%= text.toString() %></Description>
86*0d40e9d0SAdam Hornáček    <InputEncoding>UTF-8</InputEncoding>
87*0d40e9d0SAdam Hornáček    <Image height="16" width="16" type="image/png"><%= imgurl %></Image>
88*0d40e9d0SAdam Hornáček<%-- <Url type="application/x-suggestions+json" template="suggestionURL"/>--%>
89*0d40e9d0SAdam Hornáček    <Url template="<%= url.toString() %>&amp;q={searchTerms}" type="text/html"/>
90*0d40e9d0SAdam Hornáček</OpenSearchDescription>
91*0d40e9d0SAdam Hornáček<%
92*0d40e9d0SAdam Hornáček}
93*0d40e9d0SAdam Hornáček/* ---------------------- opensearch.jsp end --------------------- */
94*0d40e9d0SAdam Hornáček%>
95