Package Liferay;/****/import java.text.decimalformat;import java.text.numberformat;import java.util.date;import java.util.Random; Import Java.util.regex.matcher;import Java.util.regex.Pattern;/** * @author ivan**/ Public classTextutil {Private StaticPattern N = Pattern.compile ("\ n"); Private StaticPattern R = Pattern.compile ("\ r"); Private StaticPattern RN = Pattern.compile ("\ r \ n"); Private StaticPattern NR = Pattern.compile ("\n\r"); PrivateFinalStaticString BR ="<br/>"; Private StaticNumberFormat DecimalFormat =DecimalFormat. getnumberinstance (); Public StaticString Doubletotext (DoubleNumber ) {String txt= Doubletotext (number,1); returntxt; } Public StaticString Doubletotext (DoubleNumberintDigit) {String txt=""; if(Number >0) {decimalformat.setmaximumfractiondigits (digit); TXT=Decimalformat.format (number); } returntxt; } Public StaticString DoubleToText2 (DoubleNumberintDigit) {String txt=""; if(Number >0) {DecimalFormat decimalFormat2=NewDecimalFormat (); Decimalformat2.setgroupingsize (0); Decimalformat2.setmaximumfractiondigits (digit); TXT=Decimalformat2.format (number); } returntxt; } Public StaticString Doubletotext (DoubleNumber , String format) { if(Format.equals ("") ) {format="#,# #0. XX"; } String txt=""; if(Number >0) {DecimalFormat DecimalFormat=Newdecimalformat (format); TXT=Decimalformat.format (number); } returntxt; } Public Staticstring texttohtml (String txt) {Matcher m=rn.matcher (TXT); TXT=M.replaceall (BR); M=nr.matcher (TXT); TXT=M.replaceall (BR); M=n.matcher (TXT); TXT=M.replaceall (BR); M=r.matcher (TXT); TXT=M.replaceall (BR); returntxt; } Public Static voidMain (string[] args) {//Long longduration = new Date (). GetTime ()-46450000;//longduration = new Date (). GetTime ()-longduration;//double doubleduration = longduration;//doubleduration = doubleduration/86400000;//System.out.println (doubleduration);//System.out.println (Doubletotext (doubleduration));String SQL= Getrandomstring (5); System. out. println (SQL); } Public StaticString Dosubassignlength (String str,intlength) {String commtents=NULL; if(Str.length () >length) {commtents= Str.substring (0, Length-1) +"..."; } Else{commtents=str; } returncommtents; } Public Staticstring dosubstring (String str) {string commtents=NULL; if(Str.length () > -) {commtents= Str.substring (0, -) +"..."; } Else{commtents=str; } returncommtents; } Public Staticstring GetURL (string layoutid, string url) {StringBuffer buffer=NewStringBuffer (); Buffer.append (URL); if(LayoutID! =NULL&&!"0". Equals (LayoutID)) { intStart = Url.lastindexof ("/"); intEnd = Url.indexof ("?"); Buffer.replace (Start, end, LayoutID); } returnbuffer.tostring (); } Public Staticstring toUpperCase (String tableName) {string prefix= Tablename.substring (0,1). toUpperCase (); String Results= prefix + tablename.substring (1); returnresults; } Public StaticString getrandomstring (intlength) { Char[] Chararray =New Char[length]; for(inti =0; i < length; i++) {Random R=NewRandom (); intn = r.nextint (123); while(N < -|| (N > $&& N < $) || (N > -&& N < the) || n >122) {// (!( (n>=48 && n<=57) | | (n>=65 && n<=90)//&& (n>=97 && n<=122))) {n = r.nextint (123); } Chararray[i]= (Char) n; } returnstring.valueof (Chararray); } Public StaticString Convertfilesize (Longfilesize) {String Strunit="Bytes"; String Straftercomma=""; intIntdivisor =1; if(FileSize >=1024x768*1024x768) {Strunit="MB"; Intdivisor=1024x768*1024x768; } Else if(FileSize >=1024x768) {Strunit="KB"; Intdivisor=1024x768; } if(Intdivisor = =1) returnFileSize +" "+Strunit; Straftercomma=""+ -* (filesize% intdivisor)/Intdivisor; if(Straftercomma = ="") Straftercomma=". 0"; returnFilesize/intdivisor +"."+ Straftercomma +" "+Strunit; } }
Lifyray the API Summary Textutil