xref: /OpenGrok/opengrok-web/src/main/webapp/opensearch.jsp (revision 29fe9da193f1c5033b11722d60cb853bdca759ae)
10d40e9d0SAdam Hornáček<%--
20d40e9d0SAdam Hornáček$Id$
30d40e9d0SAdam Hornáček
40d40e9d0SAdam HornáčekCDDL HEADER START
50d40e9d0SAdam Hornáček
60d40e9d0SAdam HornáčekThe contents of this file are subject to the terms of the
70d40e9d0SAdam HornáčekCommon Development and Distribution License (the "License").
80d40e9d0SAdam HornáčekYou may not use this file except in compliance with the License.
90d40e9d0SAdam Hornáček
100d40e9d0SAdam HornáčekSee LICENSE.txt included in this distribution for the specific
110d40e9d0SAdam Hornáčeklanguage governing permissions and limitations under the License.
120d40e9d0SAdam Hornáček
130d40e9d0SAdam HornáčekWhen distributing Covered Code, include this CDDL HEADER in each
140d40e9d0SAdam Hornáčekfile and include the License file at LICENSE.txt.
150d40e9d0SAdam HornáčekIf applicable, add the following below this CDDL HEADER, with the
160d40e9d0SAdam Hornáčekfields enclosed by brackets "[]" replaced with your own identifying
170d40e9d0SAdam Hornáčekinformation: Portions Copyright [yyyy] [name of copyright owner]
180d40e9d0SAdam Hornáček
190d40e9d0SAdam HornáčekCDDL HEADER END
200d40e9d0SAdam Hornáček
2156f072caSAdam HornáčekCopyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
220d40e9d0SAdam HornáčekPortions Copyright 2011 Jens Elkner.
23*29fe9da1SChris FrairePortions Copyright (c) 2018, Chris Fraire <cfraire@me.com>.
240d40e9d0SAdam Hornáček
250d40e9d0SAdam Hornáček--%><%@page  session="false" errorPage="error.jsp" import="
260d40e9d0SAdam Hornáčekjava.util.Set,
270d40e9d0SAdam Hornáček
28*29fe9da1SChris Fraireorg.opengrok.indexer.web.Prefix,
29686556f2SAdam Hornáčekorg.opengrok.indexer.web.Util"
300d40e9d0SAdam Hornáček%>
310d40e9d0SAdam Hornáček<%
320d40e9d0SAdam Hornáček{
330d40e9d0SAdam Hornáček    PageConfig cfg = PageConfig.get(request);
340d40e9d0SAdam Hornáček    cfg.checkSourceRootExistence();
350d40e9d0SAdam Hornáček}
360d40e9d0SAdam Hornáček%><%@
370d40e9d0SAdam Hornáček
380d40e9d0SAdam Hornáčekinclude file="projects.jspf"
390d40e9d0SAdam Hornáček
400d40e9d0SAdam Hornáček%><%
410d40e9d0SAdam Hornáček    /* ---------------------- opensearch.jsp start --------------------- */
420d40e9d0SAdam Hornáček{
430d40e9d0SAdam Hornáček    PageConfig cfg = PageConfig.get(request);
440d40e9d0SAdam Hornáček
450d40e9d0SAdam Hornáček    // Optimize for URLs up to 128 characters.
460d40e9d0SAdam Hornáček    StringBuilder url = new StringBuilder(128);
470d40e9d0SAdam Hornáček    String ForwardedHost = request.getHeader("X-Forwarded-Host");
480d40e9d0SAdam Hornáček    String scheme = request.getScheme();
490d40e9d0SAdam Hornáček    int port = request.getServerPort();
500d40e9d0SAdam Hornáček
510d40e9d0SAdam Hornáček    url.append(scheme).append("://");
520d40e9d0SAdam Hornáček
530d40e9d0SAdam Hornáček    // Play nice in proxy environment by using hostname from the original
540d40e9d0SAdam Hornáček    // request to construct the URLs.
550d40e9d0SAdam Hornáček    // Will not work well if the scheme or port is different for proxied server
560d40e9d0SAdam Hornáček    // and original server. Unfortunately the X-Forwarded-Host does not seem to
570d40e9d0SAdam Hornáček    // contain the port number so there is no way around it.
580d40e9d0SAdam Hornáček    if (ForwardedHost != null) {
590d40e9d0SAdam Hornáček        url.append(ForwardedHost);
600d40e9d0SAdam Hornáček    } else {
610d40e9d0SAdam Hornáček        url.append(request.getServerName());
620d40e9d0SAdam Hornáček
630d40e9d0SAdam Hornáček        // Append port if needed.
640d40e9d0SAdam Hornáček        if ((port != 80 && scheme.equals("http")) ||
650d40e9d0SAdam Hornáček                   (port != 443 && scheme.equals("https"))) {
660d40e9d0SAdam Hornáček            url.append(':').append(port);
670d40e9d0SAdam Hornáček        }
680d40e9d0SAdam Hornáček    }
690d40e9d0SAdam Hornáček
700d40e9d0SAdam Hornáček    String imgurl = url +  cfg.getCssDir() + "/img/icon.png";
710d40e9d0SAdam Hornáček
720d40e9d0SAdam Hornáček    /* TODO  Bug 11749 ??? */
730d40e9d0SAdam Hornáček    StringBuilder text = new StringBuilder();
740d40e9d0SAdam Hornáček    url.append(request.getContextPath()).append(Prefix.SEARCH_P).append('?');
750d40e9d0SAdam Hornáček    Set<String> projects = cfg.getRequestedProjects();
760d40e9d0SAdam Hornáček    for (String name : projects) {
770d40e9d0SAdam Hornáček        text.append(name).append(',');
780d40e9d0SAdam Hornáček        Util.appendQuery(url, "project", name);
790d40e9d0SAdam Hornáček    }
800d40e9d0SAdam Hornáček    if (text.length() != 0) {
810d40e9d0SAdam Hornáček        text.setLength(text.length()-1);
820d40e9d0SAdam Hornáček    }
830d40e9d0SAdam Hornáček%><?xml version="1.0" encoding="UTF-8"?>
840d40e9d0SAdam Hornáček<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
850d40e9d0SAdam Hornáček    <ShortName>OpenGrok <%= text.toString() %></ShortName>
860d40e9d0SAdam Hornáček    <Description>Search in OpenGrok <%= text.toString() %></Description>
870d40e9d0SAdam Hornáček    <InputEncoding>UTF-8</InputEncoding>
880d40e9d0SAdam Hornáček    <Image height="16" width="16" type="image/png"><%= imgurl %></Image>
890d40e9d0SAdam Hornáček<%-- <Url type="application/x-suggestions+json" template="suggestionURL"/>--%>
900d40e9d0SAdam Hornáček    <Url template="<%= url.toString() %>&amp;q={searchTerms}" type="text/html"/>
910d40e9d0SAdam Hornáček</OpenSearchDescription>
920d40e9d0SAdam Hornáček<%
930d40e9d0SAdam Hornáček}
940d40e9d0SAdam Hornáček/* ---------------------- opensearch.jsp end --------------------- */
950d40e9d0SAdam Hornáček%>
96