17
17
* CDDL HEADER END
18
18
*/
19
19
20
- /*
20
+ /*
21
21
* Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
22
22
*/
23
23
package org .opensolaris .opengrok .web ;
39
39
public class JSONSearchServlet extends HttpServlet {
40
40
41
41
private static final long serialVersionUID = -1675062445999680962L ;
42
- private static final Base64Converter conv = new Base64Converter ();
42
+ private static final Base64Converter BASE64CONV = new Base64Converter ();
43
43
private static final int MAX_RESULTS = 1000 ; // hard coded limit
44
44
private static final String PARAM_FREETEXT = "freetext" ;
45
45
private static final String PARAM_DEF = "def" ;
@@ -49,6 +49,7 @@ public class JSONSearchServlet extends HttpServlet {
49
49
private static final String PARAM_START = "start" ;
50
50
private static final String PARAM_MAXRESULTS = "maxresults" ;
51
51
private static final String PARAM_PROJECT = "project" ;
52
+ private static final String PARAM_TYPE = "type" ;
52
53
private static final String ATTRIBUTE_DIRECTORY = "directory" ;
53
54
private static final String ATTRIBUTE_FILENAME = "filename" ;
54
55
private static final String ATTRIBUTE_LINENO = "lineno" ;
@@ -73,6 +74,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
73
74
String path = req .getParameter (PARAM_PATH );
74
75
String hist = req .getParameter (PARAM_HIST );
75
76
String projects [] = req .getParameterValues (PARAM_PROJECT );
77
+ String type = req .getParameter (PARAM_TYPE );
76
78
77
79
if (freetext != null ) {
78
80
freetext = URLDecoder .decode (freetext );
@@ -109,6 +111,13 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
109
111
result .put (PARAM_HIST , hist );
110
112
}
111
113
114
+ if (type != null ) {
115
+ type = URLDecoder .decode (type );
116
+ engine .setType (type );
117
+ valid = true ;
118
+ result .put (PARAM_TYPE , type );
119
+ }
120
+
112
121
if (!valid ) {
113
122
return ;
114
123
}
@@ -141,7 +150,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
141
150
hitJson .put (ATTRIBUTE_FILENAME ,
142
151
JSONObject .escape (hit .getFilename ()));
143
152
hitJson .put (ATTRIBUTE_LINENO , hit .getLineno ());
144
- hitJson .put (ATTRIBUTE_LINE , conv .encode (hit .getLine ()));
153
+ hitJson .put (ATTRIBUTE_LINE , BASE64CONV .encode (hit .getLine ()));
145
154
hitJson .put (ATTRIBUTE_PATH , hit .getPath ());
146
155
resultsArray .add (hitJson );
147
156
}
@@ -172,7 +181,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
172
181
* @return The integer value of the request param if present or the
173
182
* defaultValue if none is present.
174
183
*/
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
+
176
187
final String paramValue = request .getParameter (paramName );
177
188
if (paramValue == null ) {
178
189
return defaultValue ;
0 commit comments