Skip to content

Commit 22080cc

Browse files
author
Vladimir Kotal
committed
add type parameter to JSON servlet
fixes #1892
1 parent 8ae5dce commit 22080cc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/org/opensolaris/opengrok/web/JSONSearchServlet.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* CDDL HEADER END
1818
*/
1919

20-
/*
20+
/*
2121
* Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.web;
@@ -39,7 +39,7 @@
3939
public class JSONSearchServlet extends HttpServlet {
4040

4141
private static final long serialVersionUID = -1675062445999680962L;
42-
private static final Base64Converter conv = new Base64Converter();
42+
private static final Base64Converter BASE64CONV = new Base64Converter();
4343
private static final int MAX_RESULTS = 1000; // hard coded limit
4444
private static final String PARAM_FREETEXT = "freetext";
4545
private static final String PARAM_DEF = "def";
@@ -49,6 +49,7 @@ public class JSONSearchServlet extends HttpServlet {
4949
private static final String PARAM_START = "start";
5050
private static final String PARAM_MAXRESULTS = "maxresults";
5151
private static final String PARAM_PROJECT = "project";
52+
private static final String PARAM_TYPE = "type";
5253
private static final String ATTRIBUTE_DIRECTORY = "directory";
5354
private static final String ATTRIBUTE_FILENAME = "filename";
5455
private static final String ATTRIBUTE_LINENO = "lineno";
@@ -73,6 +74,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
7374
String path = req.getParameter(PARAM_PATH);
7475
String hist = req.getParameter(PARAM_HIST);
7576
String projects[] = req.getParameterValues(PARAM_PROJECT);
77+
String type = req.getParameter(PARAM_TYPE);
7678

7779
if (freetext != null) {
7880
freetext = URLDecoder.decode(freetext);
@@ -109,6 +111,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
109111
result.put(PARAM_HIST, hist);
110112
}
111113

114+
if (type != null) {
115+
type = URLDecoder.decode(type);
116+
engine.setType(type);
117+
valid = true;
118+
result.put(PARAM_TYPE, type);
119+
}
120+
112121
if (!valid) {
113122
return;
114123
}
@@ -141,7 +150,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
141150
hitJson.put(ATTRIBUTE_FILENAME,
142151
JSONObject.escape(hit.getFilename()));
143152
hitJson.put(ATTRIBUTE_LINENO, hit.getLineno());
144-
hitJson.put(ATTRIBUTE_LINE, conv.encode(hit.getLine()));
153+
hitJson.put(ATTRIBUTE_LINE, BASE64CONV.encode(hit.getLine()));
145154
hitJson.put(ATTRIBUTE_PATH, hit.getPath());
146155
resultsArray.add(hitJson);
147156
}
@@ -172,7 +181,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
172181
* @return The integer value of the request param if present or the
173182
* defaultValue if none is present.
174183
*/
175-
private static Integer getIntParameter(final HttpServletRequest request, final String paramName, final Integer defaultValue) {
184+
private static Integer getIntParameter(final HttpServletRequest request,
185+
final String paramName, final Integer defaultValue) {
186+
176187
final String paramValue = request.getParameter(paramName);
177188
if (paramValue == null) {
178189
return defaultValue;

0 commit comments

Comments
 (0)