private String getTitle ( Resource resource ) { String title = null ; try ( InputStream is = resource . getInputStream ( ) ) { Iterator < String > iter = IOUtils . lineIterator ( is , "UTF-8" ) ; while ( iter . hasNext ( ) ) { String line = iter . next ( ) . trim ( ) ; String lower = line . toLowerCase ( ) ; int i = lower . indexOf ( "<title>" ) ; if ( i > - 1 ) { i += 7 ; int j = lower . indexOf ( "</title>" , i ) ; title = line . substring ( i , j == - 1 ? line . length ( ) : j ) . trim ( ) ; title = title . replace ( "_no" , "" ) . replace ( ' ' , ' ' ) ; break ; } } } catch ( Exception e ) { throw MiscUtil . toUnchecked ( e ) ; } return title ; }
Extract the title of the document if any .