private static synchronized void init ( ) { LOGGER . trace ( "Reads static resources definition from [static-resources.xml]" ) ; final File staticResources = Latkes . getWebFile ( "/WEB-INF/static-resources.xml" ) ; if ( null == staticResources || ! staticResources . exists ( ) ) { throw new IllegalStateException ( "Not found static resources definition from [static-resources.xml]" ) ; } final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory . newInstance ( ) ; try { final DocumentBuilder documentBuilder = documentBuilderFactory . newDocumentBuilder ( ) ; final Document document = documentBuilder . parse ( staticResources ) ; final Element root = document . getDocumentElement ( ) ; root . normalize ( ) ; final StringBuilder logBuilder = new StringBuilder ( "Reading static files: [" ) . append ( Strings . LINE_SEPARATOR ) ; final NodeList includes = root . getElementsByTagName ( "include" ) ; for ( int i = 0 ; i < includes . getLength ( ) ; i ++ ) { final Element include = ( Element ) includes . item ( i ) ; String path = include . getAttribute ( "path" ) ; final URI uri = new URI ( "http" , "b3log.org" , path , null ) ; final String s = uri . toASCIIString ( ) ; path = StringUtils . substringAfter ( s , "b3log.org" ) ; STATIC_RESOURCE_PATHS . add ( path ) ; logBuilder . append ( " " ) . append ( "path pattern [" ) . append ( path ) . append ( "]" ) ; if ( i < includes . getLength ( ) - 1 ) { logBuilder . append ( "," ) ; } logBuilder . append ( Strings . LINE_SEPARATOR ) ; } logBuilder . append ( "]" ) ; if ( LOGGER . isTraceEnabled ( ) ) { LOGGER . debug ( logBuilder . toString ( ) ) ; } } catch ( final Exception e ) { LOGGER . log ( Level . ERROR , "Reads [" + staticResources . getName ( ) + "] failed" , e ) ; throw new RuntimeException ( e ) ; } final StringBuilder logBuilder = new StringBuilder ( "Static files: [" ) . append ( Strings . LINE_SEPARATOR ) ; final Iterator < String > iterator = STATIC_RESOURCE_PATHS . iterator ( ) ; while ( iterator . hasNext ( ) ) { final String pattern = iterator . next ( ) ; logBuilder . append ( " " ) . append ( pattern ) ; if ( iterator . hasNext ( ) ) { logBuilder . append ( ' ' ) ; } logBuilder . append ( Strings . LINE_SEPARATOR ) ; } logBuilder . append ( "], " ) . append ( ' ' ) . append ( STATIC_RESOURCE_PATHS . size ( ) ) . append ( "] path patterns" ) ; if ( LOGGER . isTraceEnabled ( ) ) { LOGGER . trace ( logBuilder . toString ( ) ) ; } inited = true ; }
Initializes the static resource path patterns .