1111import org .springframework .util .StreamUtils ;
1212import org .springframework .web .bind .annotation .RequestParam ;
1313
14- /**
15- * @author Guilherme Blanco
16- */
14+ /** @author Guilherme Blanco */
1715@ RequiredArgsConstructor
1816public class VoyagerIndexHtmlTemplate {
1917
2018 private static final String CDNJS_CLOUDFLARE_COM_AJAX_LIBS = "//cdnjs.cloudflare.com/ajax/libs/" ;
2119 private static final String CDN_JSDELIVR_NET_NPM = "//cdn.jsdelivr.net/npm/" ;
2220 private static final String VOYAGER = "graphql-voyager" ;
23- private static final String FAVICON_APIS_GURU = "//apis.guru/graphql-voyager/icons/favicon-16x16.png" ;
21+ private static final String FAVICON_APIS_GURU =
22+ "//apis.guru/graphql-voyager/icons/favicon-16x16.png" ;
2423
2524 private final VoyagerPropertiesConfiguration voyagerConfiguration ;
2625
2726 public String fillIndexTemplate (String contextPath , Map <String , String > params )
2827 throws IOException {
29- String template = StreamUtils
30- .copyToString (new ClassPathResource ( "voyager.html" ). getInputStream (),
31- Charset .defaultCharset ());
28+ String template =
29+ StreamUtils .copyToString (
30+ new ClassPathResource ( "voyager.html" ). getInputStream (), Charset .defaultCharset ());
3231
3332 String basePath = voyagerConfiguration .getBasePath ();
3433 String voyagerCdnVersion = voyagerConfiguration .getCdn ().getVersion ();
3534
3635 Map <String , String > replacements = new HashMap <>();
3736 replacements .put ("graphqlEndpoint" , constructGraphQlEndpoint (contextPath , params ));
3837 replacements .put ("pageTitle" , voyagerConfiguration .getPageTitle ());
39- replacements
40- .put ("pageFavicon" , getResourceUrl (basePath , "favicon.ico" , FAVICON_APIS_GURU ));
41- replacements .put ("es6PromiseJsUrl" , getResourceUrl (basePath , "es6-promise.auto.min.js" ,
42- joinCdnjsPath ("es6-promise" , "4.1.1" , "es6-promise.auto.min.js" )));
43- replacements .put ("fetchJsUrl" , getResourceUrl (basePath , "fetch.min.js" ,
44- joinCdnjsPath ("fetch" , "2.0.4" , "fetch.min.js" )));
45- replacements .put ("reactJsUrl" , getResourceUrl (basePath , "react.min.js" ,
46- joinCdnjsPath ("react" , "16.8.3" , "umd/react.production.min.js" )));
47- replacements .put ("reactDomJsUrl" , getResourceUrl (basePath , "react-dom.min.js" ,
48- joinCdnjsPath ("react-dom" , "16.8.3" , "umd/react-dom.production.min.js" )));
49- replacements .put ("voyagerCssUrl" , getResourceUrl (basePath , "voyager.css" ,
50- joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.css" )));
51- replacements .put ("voyagerJsUrl" , getResourceUrl (basePath , "voyager.min.js" ,
52- joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.min.js" )));
53- replacements .put ("voyagerWorkerJsUrl" , getResourceUrl (basePath , "voyager.worker.js" ,
54- joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.worker.min.js" )));
38+ replacements .put ("pageFavicon" , getResourceUrl (basePath , "favicon.ico" , FAVICON_APIS_GURU ));
39+ replacements .put (
40+ "es6PromiseJsUrl" ,
41+ getResourceUrl (
42+ basePath ,
43+ "es6-promise.auto.min.js" ,
44+ joinCdnjsPath ("es6-promise" , "4.1.1" , "es6-promise.auto.min.js" )));
45+ replacements .put (
46+ "fetchJsUrl" ,
47+ getResourceUrl (basePath , "fetch.min.js" , joinCdnjsPath ("fetch" , "2.0.4" , "fetch.min.js" )));
48+ replacements .put (
49+ "reactJsUrl" ,
50+ getResourceUrl (
51+ basePath ,
52+ "react.min.js" ,
53+ joinCdnjsPath ("react" , "16.8.3" , "umd/react.production.min.js" )));
54+ replacements .put (
55+ "reactDomJsUrl" ,
56+ getResourceUrl (
57+ basePath ,
58+ "react-dom.min.js" ,
59+ joinCdnjsPath ("react-dom" , "16.8.3" , "umd/react-dom.production.min.js" )));
60+ replacements .put (
61+ "voyagerCssUrl" ,
62+ getResourceUrl (
63+ basePath , "voyager.css" , joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.css" )));
64+ replacements .put (
65+ "voyagerJsUrl" ,
66+ getResourceUrl (
67+ basePath ,
68+ "voyager.min.js" ,
69+ joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.min.js" )));
70+ replacements .put (
71+ "voyagerWorkerJsUrl" ,
72+ getResourceUrl (
73+ basePath ,
74+ "voyager.worker.js" ,
75+ joinJsDelivrPath (voyagerCdnVersion , "dist/voyager.worker.min.js" )));
5576 replacements .put ("contextPath" , contextPath );
56- replacements .put ("voyagerDisplayOptionsSkipRelay" , Boolean .toString (voyagerConfiguration .getDisplayOptions ().isSkipRelay ()));
57- replacements .put ("voyagerDisplayOptionsSkipDeprecated" , Boolean .toString (voyagerConfiguration .getDisplayOptions ().isSkipDeprecated ()));
58- replacements .put ("voyagerDisplayOptionsRootType" , voyagerConfiguration .getDisplayOptions ().getRootType ());
59- replacements .put ("voyagerDisplayOptionsSortByAlphabet" , Boolean .toString (
60- voyagerConfiguration .getDisplayOptions ().isSortByAlphabet ()));
61- replacements .put ("voyagerDisplayOptionsShowLeafFields" , Boolean .toString (voyagerConfiguration .getDisplayOptions ().isShowLeafFields ()));
62- replacements .put ("voyagerDisplayOptionsHideRoot" , Boolean .toString (voyagerConfiguration .getDisplayOptions ().isHideRoot ()));
77+ replacements .put (
78+ "voyagerDisplayOptionsSkipRelay" ,
79+ Boolean .toString (voyagerConfiguration .getDisplayOptions ().isSkipRelay ()));
80+ replacements .put (
81+ "voyagerDisplayOptionsSkipDeprecated" ,
82+ Boolean .toString (voyagerConfiguration .getDisplayOptions ().isSkipDeprecated ()));
83+ replacements .put (
84+ "voyagerDisplayOptionsRootType" , voyagerConfiguration .getDisplayOptions ().getRootType ());
85+ replacements .put (
86+ "voyagerDisplayOptionsSortByAlphabet" ,
87+ Boolean .toString (voyagerConfiguration .getDisplayOptions ().isSortByAlphabet ()));
88+ replacements .put (
89+ "voyagerDisplayOptionsShowLeafFields" ,
90+ Boolean .toString (voyagerConfiguration .getDisplayOptions ().isShowLeafFields ()));
91+ replacements .put (
92+ "voyagerDisplayOptionsHideRoot" ,
93+ Boolean .toString (voyagerConfiguration .getDisplayOptions ().isHideRoot ()));
6394 replacements .put ("voyagerHideDocs" , Boolean .toString (voyagerConfiguration .isHideDocs ()));
64- replacements .put ("voyagerHideSettings" , Boolean .toString (voyagerConfiguration .isHideSettings ()));
65-
66-
95+ replacements .put (
96+ "voyagerHideSettings" , Boolean .toString (voyagerConfiguration .isHideSettings ()));
6797
6898 return StringSubstitutor .replace (template , replacements );
6999 }
70100
71- private String constructGraphQlEndpoint (String contextPath ,
72- @ RequestParam Map <String , String > params ) {
101+ private String constructGraphQlEndpoint (
102+ String contextPath , @ RequestParam Map <String , String > params ) {
73103 String endpoint = voyagerConfiguration .getEndpoint ();
74104 for (Map .Entry <String , String > param : params .entrySet ()) {
75105 endpoint = endpoint .replaceAll ("\\ {" + param .getKey () + "}" , param .getValue ());
@@ -96,6 +126,11 @@ private String joinCdnjsPath(String library, String cdnVersion, String cdnFileNa
96126 }
97127
98128 private String joinJsDelivrPath (String cdnVersion , String cdnFileName ) {
99- return CDN_JSDELIVR_NET_NPM + VoyagerIndexHtmlTemplate .VOYAGER + "@" + cdnVersion + "/" + cdnFileName ;
129+ return CDN_JSDELIVR_NET_NPM
130+ + VoyagerIndexHtmlTemplate .VOYAGER
131+ + "@"
132+ + cdnVersion
133+ + "/"
134+ + cdnFileName ;
100135 }
101136}
0 commit comments