2007-08-28 14:15:46 +02:00
// yacysearchitem.java
// (C) 2007 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 28.08.2007 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
2009-09-27 00:07:40 +02:00
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
2007-08-28 14:15:46 +02:00
//
// LICENSE
2011-06-13 23:44:03 +02:00
//
2007-08-28 14:15:46 +02:00
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.net.MalformedURLException ;
2010-11-28 03:57:31 +01:00
import java.util.List ;
2011-03-08 23:37:17 +01:00
import java.util.Set ;
2007-08-28 14:15:46 +02:00
2011-01-03 21:52:54 +01:00
import net.yacy.cora.date.GenericFormatter ;
2011-05-27 10:24:54 +02:00
import net.yacy.cora.document.ASCII ;
2010-08-23 14:32:02 +02:00
import net.yacy.cora.protocol.HeaderFramework ;
import net.yacy.cora.protocol.RequestHeader ;
2011-10-13 00:26:48 +02:00
import net.yacy.cora.protocol.RequestHeader.FileType ;
2009-10-11 02:12:19 +02:00
import net.yacy.kelondro.data.meta.DigestURI ;
2010-09-26 00:32:26 +02:00
import net.yacy.kelondro.logging.Log ;
2009-12-08 15:25:51 +01:00
import net.yacy.kelondro.util.EventTracker ;
2009-10-10 03:14:19 +02:00
import net.yacy.kelondro.util.Formatter ;
2011-10-04 11:06:24 +02:00
import net.yacy.peers.NewsPool ;
import net.yacy.peers.Seed ;
2011-09-25 18:59:06 +02:00
import net.yacy.peers.graphics.ProfilingGraph ;
import net.yacy.search.Switchboard ;
import net.yacy.search.SwitchboardConstants ;
import net.yacy.search.query.QueryParams ;
import net.yacy.search.query.SearchEvent ;
import net.yacy.search.query.SearchEventCache ;
import net.yacy.search.snippet.ContentDomain ;
import net.yacy.search.snippet.MediaSnippet ;
import net.yacy.search.snippet.ResultEntry ;
import net.yacy.search.snippet.TextSnippet ;
2007-08-28 14:15:46 +02:00
import de.anomic.server.serverObjects ;
import de.anomic.server.serverSwitch ;
import de.anomic.tools.crypt ;
import de.anomic.tools.nxTools ;
public class yacysearchitem {
2011-06-13 23:44:03 +02:00
2011-03-08 23:37:17 +01:00
private static final String SHORTEN_SUFFIX = " ... " ;
private static final int SHORTEN_SUFFIX_LENGTH = SHORTEN_SUFFIX . length ( ) ;
private static final int MAX_NAME_LENGTH = 60 ;
private static final int MAX_URL_LENGTH = 120 ;
2007-08-28 14:15:46 +02:00
2007-09-07 13:45:38 +02:00
private static boolean col = true ;
2011-06-13 23:44:03 +02:00
2009-07-19 22:37:44 +02:00
public static serverObjects respond ( final RequestHeader header , final serverObjects post , final serverSwitch env ) {
final Switchboard sb = ( Switchboard ) env ;
2007-08-28 14:15:46 +02:00
final serverObjects prop = new serverObjects ( ) ;
2011-06-13 23:44:03 +02:00
2008-08-02 14:12:04 +02:00
final String eventID = post . get ( " eventID " , " " ) ;
final boolean authenticated = sb . adminAuthenticated ( header ) > = 2 ;
final int item = post . getInt ( " item " , - 1 ) ;
2009-07-19 22:37:44 +02:00
final boolean auth = ( header . get ( HeaderFramework . CONNECTION_PROP_CLIENTIP , " " ) ) . equals ( " localhost " ) | | sb . verifyAuthentication ( header , true ) ;
2011-10-13 00:26:48 +02:00
final RequestHeader . FileType fileType = header . fileType ( ) ;
2011-03-08 23:37:17 +01:00
2007-09-09 14:30:18 +02:00
// default settings for blank item
2007-10-24 23:38:19 +02:00
prop . put ( " content " , " 0 " ) ;
prop . put ( " rss " , " 0 " ) ;
prop . put ( " references " , " 0 " ) ;
prop . put ( " rssreferences " , " 0 " ) ;
prop . put ( " dynamic " , " 0 " ) ;
2011-06-13 23:44:03 +02:00
2007-08-28 14:15:46 +02:00
// find search event
2009-08-24 17:24:02 +02:00
final SearchEvent theSearch = SearchEventCache . getEvent ( eventID ) ;
2007-09-09 14:30:18 +02:00
if ( theSearch = = null ) {
// the event does not exist, show empty page
return prop ;
}
2009-07-09 00:14:57 +02:00
final QueryParams theQuery = theSearch . getQuery ( ) ;
2011-06-13 23:44:03 +02:00
2007-09-04 01:43:55 +02:00
// dynamically update count values
2011-05-07 01:04:27 +02:00
final int totalcount = theSearch . getRankingResult ( ) . getLocalIndexCount ( ) - theSearch . getRankingResult ( ) . getMissCount ( ) - theSearch . getRankingResult ( ) . getSortOutCount ( ) + theSearch . getRankingResult ( ) . getRemoteIndexCount ( ) ;
2008-12-02 16:24:25 +01:00
final int offset = theQuery . neededResults ( ) - theQuery . displayResults ( ) + 1 ;
prop . put ( " offset " , offset ) ;
2009-11-24 12:13:11 +01:00
prop . put ( " itemscount " , Formatter . number ( Math . min ( ( item < 0 ) ? theQuery . neededResults ( ) : item + 1 , totalcount ) ) ) ;
2011-06-13 23:44:03 +02:00
prop . put ( " itemsperpage " , Formatter . number ( theQuery . itemsPerPage ) ) ;
2009-11-24 12:13:11 +01:00
prop . put ( " totalcount " , Formatter . number ( totalcount , true ) ) ;
2010-01-13 01:04:37 +01:00
prop . put ( " localResourceSize " , Formatter . number ( theSearch . getRankingResult ( ) . getLocalIndexCount ( ) , true ) ) ;
2010-12-02 13:19:59 +01:00
prop . put ( " localMissCount " , Formatter . number ( theSearch . getRankingResult ( ) . getMissCount ( ) , true ) ) ;
2009-01-31 02:06:56 +01:00
prop . put ( " remoteResourceSize " , Formatter . number ( theSearch . getRankingResult ( ) . getRemoteResourceSize ( ) , true ) ) ;
prop . put ( " remoteIndexCount " , Formatter . number ( theSearch . getRankingResult ( ) . getRemoteIndexCount ( ) , true ) ) ;
prop . put ( " remotePeerCount " , Formatter . number ( theSearch . getRankingResult ( ) . getRemotePeerCount ( ) , true ) ) ;
2011-06-13 23:44:03 +02:00
2011-03-08 23:37:17 +01:00
final String target = sb . getConfig ( SwitchboardConstants . SEARCH_TARGET , " _self " ) ;
2009-11-19 00:56:05 +01:00
if ( theQuery . contentdom = = ContentDomain . TEXT ) {
2007-09-06 15:26:38 +02:00
// text search
2008-02-21 15:53:51 +01:00
// generate result object
2010-10-04 13:54:48 +02:00
final ResultEntry result = theSearch . oneResult ( item , theQuery . isLocal ( ) ? 1000 : 5000 ) ;
2008-02-21 15:53:51 +01:00
if ( result = = null ) return prop ; // no content
2008-12-02 16:24:25 +01:00
2011-03-08 23:37:17 +01:00
final DigestURI resultURL = result . url ( ) ;
2010-12-01 19:48:21 +01:00
final int port = resultURL . getPort ( ) ;
2009-10-11 02:12:19 +02:00
DigestURI faviconURL = null ;
2011-10-13 00:26:48 +02:00
if ( ( fileType = = FileType . HTML | | fileType = = FileType . JSON ) & & ! sb . isIntranetMode ( ) & & ! resultURL . isLocal ( ) ) try {
2010-12-01 19:48:21 +01:00
faviconURL = new DigestURI ( resultURL . getProtocol ( ) + " :// " + resultURL . getHost ( ) + ( ( port ! = - 1 ) ? ( " : " + port ) : " " ) + " /favicon.ico " ) ;
2008-08-02 14:12:04 +02:00
} catch ( final MalformedURLException e1 ) {
2010-09-26 00:32:26 +02:00
Log . logException ( e1 ) ;
2007-09-06 15:26:38 +02:00
faviconURL = null ;
}
2011-06-13 23:44:03 +02:00
2008-12-02 16:24:25 +01:00
prop . put ( " content " , 1 ) ; // switch on specific content
2011-02-02 16:54:13 +01:00
prop . put ( " content_showDate " , sb . getConfigBool ( " search.result.show.date " , true ) ? 1 : 0 ) ;
prop . put ( " content_showSize " , sb . getConfigBool ( " search.result.show.size " , true ) ? 1 : 0 ) ;
prop . put ( " content_showMetadata " , sb . getConfigBool ( " search.result.show.metadata " , true ) ? 1 : 0 ) ;
prop . put ( " content_showParser " , sb . getConfigBool ( " search.result.show.parser " , true ) ? 1 : 0 ) ;
prop . put ( " content_showPictures " , sb . getConfigBool ( " search.result.show.pictures " , true ) ? 1 : 0 ) ;
2008-12-02 16:24:25 +01:00
prop . put ( " content_authorized " , authenticated ? " 1 " : " 0 " ) ;
2011-10-04 11:06:24 +02:00
prop . put ( " content_authorized_recommend " , ( sb . peers . newsPool . getSpecific ( NewsPool . OUTGOING_DB , NewsPool . CATEGORY_SURFTIPP_ADD , " url " , result . urlstring ( ) ) = = null ) ? " 1 " : " 0 " ) ;
2011-05-27 10:24:54 +02:00
prop . putHTML ( " content_authorized_recommend_deletelink " , " /yacysearch.html?query= " + theQuery . queryString . replace ( ' ' , '+' ) + " &Enter=Search&count= " + theQuery . displayResults ( ) + " &offset= " + ( theQuery . neededResults ( ) - theQuery . displayResults ( ) ) + " &order= " + crypt . simpleEncode ( theQuery . ranking . toExternalString ( ) ) + " &resource=local&time=3&deleteref= " + ASCII . String ( result . hash ( ) ) + " &urlmaskfilter=.* " ) ;
prop . putHTML ( " content_authorized_recommend_recommendlink " , " /yacysearch.html?query= " + theQuery . queryString . replace ( ' ' , '+' ) + " &Enter=Search&count= " + theQuery . displayResults ( ) + " &offset= " + ( theQuery . neededResults ( ) - theQuery . displayResults ( ) ) + " &order= " + crypt . simpleEncode ( theQuery . ranking . toExternalString ( ) ) + " &resource=local&time=3&recommendref= " + ASCII . String ( result . hash ( ) ) + " &urlmaskfilter=.* " ) ;
prop . put ( " content_authorized_urlhash " , ASCII . String ( result . hash ( ) ) ) ;
2011-06-13 23:44:03 +02:00
final String resulthashString = ASCII . String ( result . hash ( ) ) ;
2008-12-02 16:24:25 +01:00
prop . putHTML ( " content_title " , result . title ( ) ) ;
2009-01-17 00:22:42 +01:00
prop . putXML ( " content_title-xml " , result . title ( ) ) ;
2009-04-26 21:17:36 +02:00
prop . putJSON ( " content_title-json " , result . title ( ) ) ;
2008-12-02 16:24:25 +01:00
prop . putHTML ( " content_link " , result . urlstring ( ) ) ;
2011-02-02 16:54:13 +01:00
prop . putHTML ( " content_showPictures_link " , result . urlstring ( ) ) ;
2011-02-02 01:50:06 +01:00
prop . putHTML ( " content_target " , target ) ;
2011-10-13 00:26:48 +02:00
if ( faviconURL ! = null & & fileType = = FileType . HTML ) sb . loader . loadIfNotExistBackground ( faviconURL . toNormalform ( true , false ) , 1024 * 1024 * 10 ) ;
2010-09-26 00:32:26 +02:00
prop . putHTML ( " content_faviconCode " , sb . licensedURLs . aquireLicense ( faviconURL ) ) ; // acquire license for favicon url loading
2010-04-25 23:37:36 +02:00
prop . put ( " content_urlhash " , resulthashString ) ;
2011-04-28 13:18:14 +02:00
prop . put ( " content_ranking " , result . ranking ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showMetadata_urlhash " , resulthashString ) ;
prop . put ( " content_showParser_urlhash " , resulthashString ) ;
2011-10-04 11:06:24 +02:00
prop . put ( " content_urlhexhash " , Seed . b64Hash2hexHash ( resulthashString ) ) ;
2011-03-08 23:37:17 +01:00
prop . putHTML ( " content_urlname " , nxTools . shortenURLString ( result . urlname ( ) , MAX_URL_LENGTH ) ) ;
2011-02-02 16:54:13 +01:00
prop . put ( " content_showDate_date " , GenericFormatter . RFC1123_SHORT_FORMATTER . format ( result . modified ( ) ) ) ;
2010-08-23 14:32:02 +02:00
prop . put ( " content_date822 " , HeaderFramework . formatRFC1123 ( result . modified ( ) ) ) ;
2010-05-04 22:57:09 +02:00
//prop.put("content_ybr", RankingProcess.ybr(result.hash()));
2009-02-23 12:39:20 +01:00
prop . putHTML ( " content_size " , Integer . toString ( result . filesize ( ) ) ) ; // we don't use putNUM here because that number shall be usable as sorting key. To print the size, use 'sizename'
2009-02-23 08:59:11 +01:00
prop . putHTML ( " content_sizename " , sizename ( result . filesize ( ) ) ) ;
2011-02-02 16:54:13 +01:00
prop . putHTML ( " content_showSize_sizename " , sizename ( result . filesize ( ) ) ) ;
2010-12-01 19:48:21 +01:00
prop . putHTML ( " content_host " , resultURL . getHost ( ) = = null ? " " : resultURL . getHost ( ) ) ;
prop . putHTML ( " content_file " , resultURL . getFile ( ) ) ;
prop . putHTML ( " content_path " , resultURL . getPath ( ) ) ;
2011-03-09 21:08:20 +01:00
prop . put ( " content_nl " , ( item = = theQuery . offset ) ? 0 : 1 ) ;
2010-05-11 13:14:05 +02:00
prop . putHTML ( " content_publisher " , result . publisher ( ) ) ;
prop . putHTML ( " content_creator " , result . creator ( ) ) ; // author
prop . putHTML ( " content_subject " , result . subject ( ) ) ;
2011-03-08 23:37:17 +01:00
final Set < String > [ ] query = theQuery . queryWords ( ) ;
2011-03-09 10:29:05 +01:00
final StringBuilder s = new StringBuilder ( query [ 0 ] . size ( ) * 20 ) ;
2011-03-08 23:37:17 +01:00
for ( final String t : query [ 0 ] ) {
2011-03-09 10:29:05 +01:00
s . append ( '+' ) . append ( t ) ;
2011-03-08 23:37:17 +01:00
}
final String words = ( s . length ( ) > 0 ) ? s . substring ( 1 ) : " " ;
prop . putHTML ( " content_words " , words ) ;
prop . putHTML ( " content_showParser_words " , words ) ;
2007-10-24 23:38:19 +02:00
prop . putHTML ( " content_former " , theQuery . queryString ) ;
2011-02-02 16:54:13 +01:00
prop . putHTML ( " content_showPictures_former " , theQuery . queryString ) ;
2009-08-27 16:34:41 +02:00
final TextSnippet snippet = result . textSnippet ( ) ;
2009-04-27 14:52:12 +02:00
final String desc = ( snippet = = null ) ? " " : snippet . getLineMarked ( theQuery . fullqueryHashes ) ;
prop . put ( " content_description " , desc ) ;
prop . putXML ( " content_description-xml " , desc ) ;
prop . putJSON ( " content_description-json " , desc ) ;
2011-06-13 23:44:03 +02:00
final SearchEvent . HeuristicResult heuristic = theSearch . getHeuristic ( result . hash ( ) ) ;
2010-06-27 23:38:16 +02:00
if ( heuristic = = null ) {
prop . put ( " content_heuristic " , 0 ) ;
} else {
if ( heuristic . redundant ) {
prop . put ( " content_heuristic " , 1 ) ;
} else {
prop . put ( " content_heuristic " , 2 ) ;
}
prop . put ( " content_heuristic_name " , heuristic . heuristicName ) ;
}
2011-07-14 09:07:06 +02:00
EventTracker . update ( EventTracker . EClass . SEARCH , new ProfilingGraph . EventSearch ( theQuery . id ( true ) , SearchEvent . Type . FINALIZATION , " " + item , 0 , 0 ) , false ) ;
2011-03-08 23:37:17 +01:00
final String ext = resultURL . getFileExtension ( ) . toLowerCase ( ) ;
2010-12-01 19:48:21 +01:00
if ( ext . equals ( " png " ) | | ext . equals ( " jpg " ) | | ext . equals ( " gif " ) ) {
2011-06-13 23:44:03 +02:00
final String license = sb . licensedURLs . aquireLicense ( resultURL ) ;
2010-12-01 19:48:21 +01:00
prop . put ( " content_code " , license ) ;
} else {
prop . put ( " content_code " , " " ) ;
}
2011-03-31 01:26:36 +02:00
if ( result . lat ( ) = = 0 . 0f | | result . lon ( ) = = 0 . 0f ) {
prop . put ( " content_loc " , 0 ) ;
} else {
prop . put ( " content_loc " , 1 ) ;
prop . put ( " content_loc_lat " , result . lat ( ) ) ;
prop . put ( " content_loc_lon " , result . lon ( ) ) ;
}
2011-01-11 23:58:14 +01:00
theQuery . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-06 15:26:38 +02:00
}
2011-03-08 23:37:17 +01:00
2009-11-19 00:56:05 +01:00
if ( theQuery . contentdom = = ContentDomain . IMAGE ) {
2007-09-06 15:26:38 +02:00
// image search; shows thumbnails
2008-02-21 15:53:51 +01:00
2009-11-19 00:56:05 +01:00
prop . put ( " content " , theQuery . contentdom . getCode ( ) + 1 ) ; // switch on specific content
2009-08-27 16:34:41 +02:00
final MediaSnippet ms = theSearch . result ( ) . oneImage ( item ) ;
2008-02-21 15:53:51 +01:00
if ( ms = = null ) {
2009-11-23 17:10:50 +01:00
prop . put ( " content_item " , " 0 " ) ;
2008-02-21 15:53:51 +01:00
} else {
2011-03-08 23:37:17 +01:00
final String license = sb . licensedURLs . aquireLicense ( ms . href ) ;
2010-09-06 01:02:46 +02:00
sb . loader . loadIfNotExistBackground ( ms . href . toNormalform ( true , false ) , 1024 * 1024 * 10 ) ;
2009-11-23 17:10:50 +01:00
prop . putHTML ( " content_item_hrefCache " , ( auth ) ? " /ViewImage.png?url= " + ms . href . toNormalform ( true , false ) : ms . href . toNormalform ( true , false ) ) ;
prop . putHTML ( " content_item_href " , ms . href . toNormalform ( true , false ) ) ;
2011-09-18 18:59:01 +02:00
prop . putHTML ( " content_item_target " , target ) ;
2010-12-01 19:48:21 +01:00
prop . put ( " content_item_code " , license ) ;
2011-03-08 23:37:17 +01:00
prop . putHTML ( " content_item_name " , shorten ( ms . name , MAX_NAME_LENGTH ) ) ;
2009-11-24 12:13:11 +01:00
prop . put ( " content_item_mimetype " , ms . mime ) ;
2009-11-23 17:10:50 +01:00
prop . put ( " content_item_fileSize " , ms . fileSize ) ;
prop . put ( " content_item_width " , ms . width ) ;
prop . put ( " content_item_height " , ms . height ) ;
prop . put ( " content_item_attr " , ( ms . attr . equals ( " -1 x -1 " ) ) ? " " : " ( " + ms . attr + " ) " ) ; // attributes, here: original size of image
2011-05-27 10:24:54 +02:00
prop . put ( " content_item_urlhash " , ASCII . String ( ms . source . hash ( ) ) ) ;
2009-11-23 17:10:50 +01:00
prop . put ( " content_item_source " , ms . source . toNormalform ( true , false ) ) ;
2009-12-10 00:58:56 +01:00
prop . putXML ( " content_item_source-xml " , ms . source . toNormalform ( true , false ) ) ;
2009-11-23 17:10:50 +01:00
prop . put ( " content_item_sourcedom " , ms . source . getHost ( ) ) ;
2011-03-09 21:08:20 +01:00
prop . put ( " content_item_nl " , ( item = = theQuery . offset ) ? 0 : 1 ) ;
2009-11-23 17:10:50 +01:00
prop . put ( " content_item " , 1 ) ;
2007-09-07 13:45:38 +02:00
}
2011-01-11 23:58:14 +01:00
theQuery . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-07 13:45:38 +02:00
}
2011-06-13 23:44:03 +02:00
2009-11-19 00:56:05 +01:00
if ( ( theQuery . contentdom = = ContentDomain . AUDIO ) | |
( theQuery . contentdom = = ContentDomain . VIDEO ) | |
( theQuery . contentdom = = ContentDomain . APP ) ) {
2007-09-07 13:45:38 +02:00
// any other media content
2008-02-21 15:53:51 +01:00
// generate result object
2010-10-04 13:54:48 +02:00
final ResultEntry result = theSearch . oneResult ( item , 500 ) ;
2008-02-21 15:53:51 +01:00
if ( result = = null ) return prop ; // no content
2011-06-13 23:44:03 +02:00
2009-11-19 00:56:05 +01:00
prop . put ( " content " , theQuery . contentdom . getCode ( ) + 1 ) ; // switch on specific content
2010-11-28 03:57:31 +01:00
final List < MediaSnippet > media = result . mediaSnippets ( ) ;
2007-09-07 13:45:38 +02:00
if ( item = = 0 ) col = true ;
if ( media ! = null ) {
int c = 0 ;
2010-11-28 03:57:31 +01:00
for ( final MediaSnippet ms : media ) {
2010-09-05 00:57:12 +02:00
prop . putHTML ( " content_items_ " + c + " _href " , ms . href . toNormalform ( true , false ) ) ;
2011-03-08 23:37:17 +01:00
prop . putHTML ( " content_items_ " + c + " _hrefshort " , nxTools . shortenURLString ( ms . href . toNormalform ( true , false ) , MAX_URL_LENGTH ) ) ;
2011-02-02 01:50:06 +01:00
prop . putHTML ( " content_items_ " + c + " _target " , target ) ;
2011-03-08 23:37:17 +01:00
prop . putHTML ( " content_items_ " + c + " _name " , shorten ( ms . name , MAX_NAME_LENGTH ) ) ;
2010-09-05 00:57:12 +02:00
prop . put ( " content_items_ " + c + " _col " , ( col ) ? " 0 " : " 1 " ) ;
2007-09-07 13:45:38 +02:00
c + + ;
col = ! col ;
}
prop . put ( " content_items " , c ) ;
} else {
2007-10-24 23:38:19 +02:00
prop . put ( " content_items " , " 0 " ) ;
2007-09-06 15:26:38 +02:00
}
2011-01-11 23:58:14 +01:00
theQuery . transmitcount = item + 1 ;
2007-09-09 14:30:18 +02:00
return prop ;
2007-09-06 15:26:38 +02:00
}
2011-06-13 23:44:03 +02:00
2007-08-28 14:15:46 +02:00
return prop ;
}
2011-06-13 23:44:03 +02:00
2008-08-02 14:12:04 +02:00
private static String shorten ( final String s , final int length ) {
2011-03-08 23:37:17 +01:00
final String ret ;
if ( s . length ( ) < = length ) {
ret = s ;
} else {
final int p = s . lastIndexOf ( '.' ) ;
if ( p < 0 ) {
ret = s . substring ( 0 , length - SHORTEN_SUFFIX_LENGTH ) + SHORTEN_SUFFIX ;
} else {
assert p > = 0 ;
final String ext = s . substring ( p + 1 ) ;
if ( ext . length ( ) > 4 ) {
ret = s . substring ( 0 , length / 2 - 2 ) + SHORTEN_SUFFIX + s . substring ( s . length ( ) - ( length / 2 - 2 ) ) ;
} else {
ret = s . substring ( 0 , length - ext . length ( ) - SHORTEN_SUFFIX_LENGTH ) + SHORTEN_SUFFIX + ext ;
}
}
}
return ret ;
2007-09-07 13:45:38 +02:00
}
2011-06-13 23:44:03 +02:00
2009-02-23 08:59:11 +01:00
private static String sizename ( int size ) {
if ( size < 1024 ) return size + " bytes " ;
size = size / 1024 ;
if ( size < 1024 ) return size + " kbyte " ;
size = size / 1024 ;
if ( size < 1024 ) return size + " mbyte " ;
size = size / 1024 ;
return size + " gbyte " ;
}
2007-08-28 14:15:46 +02:00
}