protected String createDefaultExcerpt ( String text , String excerptStart , String excerptEnd , String fragmentStart , String fragmentEnd , int maxLength ) throws IOException { StringReader reader = new StringReader ( text ) ; StringBuilder excerpt = new StringBuilder ( excerptStart ) ; excerpt . append ( fragmentStart ) ; if ( ! text . isEmpty ( ) ) { int min = excerpt . length ( ) ; char [ ] buf = new char [ maxLength ] ; int len = reader . read ( buf ) ; StringBuilder tmp = new StringBuilder ( ) ; tmp . append ( buf , 0 , len ) ; if ( len == buf . length ) { for ( int i = tmp . length ( ) - 1 ; i > min ; i -- ) { if ( Character . isWhitespace ( tmp . charAt ( i ) ) ) { tmp . delete ( i , tmp . length ( ) ) ; tmp . append ( " ..." ) ; break ; } } } excerpt . append ( Text . encodeIllegalXMLCharacters ( tmp . toString ( ) ) ) ; } excerpt . append ( fragmentEnd ) . append ( excerptEnd ) ; return excerpt . toString ( ) ; }
Creates a default excerpt with the given text .