protected String determineThemeNameToChoose ( final HttpServletRequest request , final Service service , final RegisteredService rService ) { HttpResponse response = null ; try { LOGGER . debug ( "Service [{}] is configured to use a custom theme [{}]" , rService , rService . getTheme ( ) ) ; val resource = ResourceUtils . getRawResourceFrom ( rService . getTheme ( ) ) ; if ( resource instanceof FileSystemResource && resource . exists ( ) ) { LOGGER . debug ( "Executing groovy script to determine theme for [{}]" , service . getId ( ) ) ; val result = ScriptingUtils . executeGroovyScript ( resource , new Object [ ] { service , rService , request . getQueryString ( ) , HttpRequestUtils . getRequestHeaders ( request ) , LOGGER } , String . class , true ) ; return StringUtils . defaultIfBlank ( result , getDefaultThemeName ( ) ) ; } if ( resource instanceof UrlResource ) { val url = resource . getURL ( ) . toExternalForm ( ) ; LOGGER . debug ( "Executing URL [{}] to determine theme for [{}]" , url , service . getId ( ) ) ; response = HttpUtils . executeGet ( url , CollectionUtils . wrap ( "service" , service . getId ( ) ) ) ; if ( response != null && response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_OK ) { val result = IOUtils . toString ( response . getEntity ( ) . getContent ( ) , StandardCharsets . UTF_8 ) ; return StringUtils . defaultIfBlank ( result , getDefaultThemeName ( ) ) ; } } val messageSource = new CasThemeResourceBundleMessageSource ( ) ; messageSource . setBasename ( rService . getTheme ( ) ) ; if ( messageSource . doGetBundle ( rService . getTheme ( ) , request . getLocale ( ) ) != null ) { LOGGER . trace ( "Found custom theme [{}] for service [{}]" , rService . getTheme ( ) , rService ) ; return rService . getTheme ( ) ; } LOGGER . warn ( "Custom theme [{}] for service [{}] cannot be located. Falling back to default theme..." , rService . getTheme ( ) , rService ) ; } catch ( final Exception e ) { LOGGER . error ( e . getMessage ( ) , e ) ; } finally { HttpUtils . close ( response ) ; } return getDefaultThemeName ( ) ; }
Determine theme name to choose .