1818 */
1919
2020/*
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.
2222 * Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
2323 */
2424package org .opengrok .indexer .web ;
3131import java .util .TreeMap ;
3232import java .util .TreeSet ;
3333
34+ import org .webjars .WebJarAssetLocator ;
35+
3436/**
3537 * A list-like container for javascripts in the page.
3638 *
3941public class Scripts implements Iterable <Scripts .Script > {
4042
4143 private static final String DEBUG_SUFFIX = "-debug" ;
44+ private static final String WEBJAR_PATH_PREFIX = "META-INF/resources/" ;
4245
4346 enum Type {
4447 MINIFIED , DEBUG
@@ -86,27 +89,27 @@ public FileScript(String script, int priority) {
8689
8790 @ Override
8891 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 " ;
9697 }
9798
9899 }
99100
100101 protected static final Map <String , Script > SCRIPTS = new TreeMap <>();
101102
103+ private static final WebJarAssetLocator assetLocator = new WebJarAssetLocator ();
104+
102105 /**
103106 * Aliases for the page scripts. The path in the FileScript is relatively to
104107 * the request's context path.
105108 *
106109 * @see HttpServletRequest#getContextPath()
107110 */
108111 static {
109- putjs ("jquery" , "js/ jquery-3.4.1 " , 10 );
112+ putFromWebJar ("jquery" , "jquery.min.js " , 10 );
110113 putjs ("jquery-ui" , "js/jquery-ui-1.12.1-custom" , 11 );
111114 putjs ("jquery-tablesorter" , "js/jquery-tablesorter-2.31.3" , 12 );
112115 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
128131 }
129132 }
130133
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+
131142 private static final Comparator <Script > SCRIPTS_COMPARATOR = Comparator
132143 .comparingInt (Script ::getPriority )
133144 .thenComparing (Script ::getScriptData );
0 commit comments