18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2005, 2014 , Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2005, 2017 , Oracle and/or its affiliates. All rights reserved.
22
22
*/
23
23
24
24
package org .opensolaris .opengrok .search .context ;
43
43
import org .opensolaris .opengrok .search .Hit ;
44
44
import org .opensolaris .opengrok .search .QueryBuilder ;
45
45
import org .opensolaris .opengrok .web .Prefix ;
46
+ import org .opensolaris .opengrok .web .Util ;
46
47
47
48
/**
48
49
* it is supposed to get the matching lines from history log files.
49
- * since lucene does not easily give the match context.
50
+ * since Lucene does not easily give the match context.
50
51
*/
51
52
public class HistoryContext {
52
53
@@ -199,21 +200,28 @@ private boolean getHistoryContext(
199
200
* @param end position of the first char after the match
200
201
* @param flatten should multi-line log entries be flattened to a single
201
202
* @param path path to the file
202
- * @param wcontext web context (begin of url )
203
+ * @param wcontext web context (begin of URL )
203
204
* @param nrev old revision
204
205
* @param rev current revision
205
206
* line? If {@code true}, replace newline with space.
206
207
*/
207
- private void writeMatch (Appendable out , String line ,
208
- int start , int end , boolean flatten , String path , String wcontext , String nrev , String rev )
208
+ protected static void writeMatch (Appendable out , String line ,
209
+ int start , int end , boolean flatten , String path ,
210
+ String wcontext , String nrev , String rev )
209
211
throws IOException {
212
+
210
213
String prefix = line .substring (0 , start );
211
214
String match = line .substring (start , end );
212
215
String suffix = line .substring (end );
213
216
214
- if (wcontext !=null && nrev !=null && !wcontext .isEmpty () ) {
215
- //does below need to be encoded? see bug 16985
216
- out .append ("<a href=" +wcontext +Prefix .DIFF_P +path +"?r2=" +path +"@" +rev +"&r1=" +path +"@" +nrev +" title=\" diff to previous version\" >diff</a> " );
217
+ if (wcontext != null && nrev != null && !wcontext .isEmpty ()) {
218
+ out .append ("<a href=\" " );
219
+ printHTML (out , wcontext + Prefix .DIFF_P +
220
+ Util .URIEncodePath (path ) +
221
+ "?r2=" + Util .URIEncodePath (path ) + "@" + rev +
222
+ "&r1=" + Util .URIEncodePath (path ) + "@" + nrev +
223
+ "\" title=\" diff to previous version\" " , flatten );
224
+ out .append (">diff</a> " );
217
225
}
218
226
219
227
printHTML (out , prefix , flatten );
@@ -231,7 +239,7 @@ private void writeMatch(Appendable out, String line,
231
239
* @param flatten should multi-line strings be flattened to a single
232
240
* line? If {@code true}, replace newline with space.
233
241
*/
234
- private void printHTML (Appendable out , String str , boolean flatten )
242
+ private static void printHTML (Appendable out , String str , boolean flatten )
235
243
throws IOException {
236
244
for (int i = 0 ; i < str .length (); i ++) {
237
245
char ch = str .charAt (i );
0 commit comments