18
18
*/
19
19
20
20
/*
21
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
21
+ * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected] >.
23
23
*/
24
24
package org .opengrok .indexer .web ;
31
31
import java .util .TreeMap ;
32
32
import java .util .TreeSet ;
33
33
34
+ import org .webjars .WebJarAssetLocator ;
35
+
34
36
/**
35
37
* A list-like container for javascripts in the page.
36
38
*
39
41
public class Scripts implements Iterable <Scripts .Script > {
40
42
41
43
private static final String DEBUG_SUFFIX = "-debug" ;
44
+ private static final String WEBJAR_PATH_PREFIX = "META-INF/resources/" ;
42
45
43
46
enum Type {
44
47
MINIFIED , DEBUG
@@ -86,27 +89,27 @@ public FileScript(String script, int priority) {
86
89
87
90
@ Override
88
91
public String toHtml () {
89
- StringBuilder builder = new StringBuilder ();
90
- builder .append ("\t <script type=\" text/javascript\" src=\" " );
91
- builder .append (this .getScriptData ());
92
- builder .append ("\" data-priority=\" " );
93
- builder .append (this .getPriority ());
94
- builder .append ("\" ></script>\n " );
95
- return builder .toString ();
92
+ return "\t <script type=\" text/javascript\" src=\" " +
93
+ this .getScriptData () +
94
+ "\" data-priority=\" " +
95
+ this .getPriority () +
96
+ "\" ></script>\n " ;
96
97
}
97
98
98
99
}
99
100
100
101
protected static final Map <String , Script > SCRIPTS = new TreeMap <>();
101
102
103
+ private static final WebJarAssetLocator assetLocator = new WebJarAssetLocator ();
104
+
102
105
/**
103
106
* Aliases for the page scripts. The path in the FileScript is relatively to
104
107
* the request's context path.
105
108
*
106
109
* @see HttpServletRequest#getContextPath()
107
110
*/
108
111
static {
109
- putjs ("jquery" , "js/ jquery-3.4.1 " , 10 );
112
+ putFromWebJar ("jquery" , "jquery.min.js " , 10 );
110
113
putjs ("jquery-ui" , "js/jquery-ui-1.12.1-custom" , 11 );
111
114
putjs ("jquery-tablesorter" , "js/jquery-tablesorter-2.31.3" , 12 );
112
115
putjs ("tablesorter-parsers" , "js/tablesorter-parsers-0.0.2" , 13 , true );
@@ -128,6 +131,14 @@ private static void putjs(String key, String pathPrefix, int priority, boolean d
128
131
}
129
132
}
130
133
134
+ private static void putFromWebJar (String key , String fileName , int priority ) {
135
+ String path = assetLocator .getFullPath (fileName );
136
+ if (path .startsWith (WEBJAR_PATH_PREFIX )) {
137
+ path = path .substring (WEBJAR_PATH_PREFIX .length ());
138
+ }
139
+ SCRIPTS .put (key , new FileScript (path , priority ));
140
+ }
141
+
131
142
private static final Comparator <Script > SCRIPTS_COMPARATOR = Comparator
132
143
.comparingInt (Script ::getPriority )
133
144
.thenComparing (Script ::getScriptData );
0 commit comments