idx
int64
0
41.2k
question
stringlengths
74
4.21k
target
stringlengths
5
888
23,300
private void storeArgs ( Constructor constructor , Array conArgs ) { Class [ ] pmt = constructor . getParameterTypes ( ) ; Object o = conArgs . get ( pmt . length + 1 , null ) ; Constructor [ ] args ; if ( o == null ) { args = new Constructor [ 1 ] ; conArgs . setEL ( pmt . length + 1 , args ) ; } else { Constructor [ ] cs = ( Constructor [ ] ) o ; args = new Constructor [ cs . length + 1 ] ; for ( int i = 0 ; i < cs . length ; i ++ ) { args [ i ] = cs [ i ] ; } conArgs . setEL ( pmt . length + 1 , args ) ; } args [ args . length - 1 ] = constructor ; }
seperate and store the different arguments of one constructor
23,301
public void release ( ) { super . release ( ) ; type = SearchCollection . SEARCH_TYPE_SIMPLE ; maxrows = - 1 ; criteria = "" ; startrow = 1 ; collections = null ; category = EMPTY ; categoryTree = "" ; status = null ; suggestions = SUGGESTIONS_NEVER ; contextPassages = 0 ; contextBytes = 300 ; contextHighlightBegin = "<b>" ; contextHighlightEnd = "</b>" ; previousCriteria = null ; }
private String result = null ;
23,302
public void setType ( String type ) throws ApplicationException { if ( type == null ) return ; type = type . toLowerCase ( ) . trim ( ) ; if ( type . equals ( "simple" ) ) this . type = SearchCollection . SEARCH_TYPE_SIMPLE ; else if ( type . equals ( "explicit" ) ) this . type = SearchCollection . SEARCH_TYPE_EXPLICIT ; else throw new ApplicationException ( "attribute type of tag search has an invalid value, valid values are [simple,explicit] now is [" + type + "]" ) ; }
set the value type Specifies the criteria type for the search .
23,303
public void setCollection ( String collection ) throws PageException { String [ ] collNames = ListUtil . toStringArrayTrim ( ListUtil . listToArrayRemoveEmpty ( collection , ',' ) ) ; collections = new SearchCollection [ collNames . length ] ; SearchEngine se = pageContext . getConfig ( ) . getSearchEngine ( pageContext ) ; try { for ( int i = 0 ; i < collections . length ; i ++ ) { collections [ i ] = se . getCollectionByName ( collNames [ i ] ) ; } } catch ( SearchException e ) { collections = null ; throw Caster . toPageException ( e ) ; } }
set the value collection The logical collection name that is the target of the search operation or an external collection with fully qualified path .
23,304
protected static Object reDefineType ( QueryColumnImpl column , Object value ) { column . typeChecked = false ; if ( value == null || column . type == Types . OTHER ) return value ; if ( value instanceof String && ( ( String ) value ) . isEmpty ( ) ) return value ; switch ( column . type ) { case Types . DOUBLE : return reDefineDouble ( column , value ) ; case Types . BIGINT : return reDefineDecimal ( column , value ) ; case Types . NUMERIC : return reDefineDouble ( column , value ) ; case Types . INTEGER : return reDefineInteger ( column , value ) ; case Types . TINYINT : return reDefineTinyInt ( column , value ) ; case Types . FLOAT : return reDefineFloat ( column , value ) ; case Types . DECIMAL : return reDefineDecimal ( column , value ) ; case Types . REAL : return reDefineFloat ( column , value ) ; case Types . SMALLINT : return reDefineShort ( column , value ) ; case Types . TIMESTAMP : return reDefineDateTime ( column , value ) ; case Types . DATE : return reDefineDateTime ( column , value ) ; case Types . TIME : return reDefineDateTime ( column , value ) ; case Types . CHAR : return reDefineString ( column , value ) ; case Types . VARCHAR : return reDefineString ( column , value ) ; case Types . LONGVARCHAR : return reDefineString ( column , value ) ; case Types . CLOB : return reDefineClob ( column , value ) ; case Types . BOOLEAN : return reDefineBoolean ( column , value ) ; case Types . BIT : return reDefineBoolean ( column , value ) ; case Types . BINARY : return reDefineBinary ( column , value ) ; case Types . VARBINARY : return reDefineBinary ( column , value ) ; case Types . LONGVARBINARY : return reDefineBinary ( column , value ) ; case Types . BLOB : return reDefineBlob ( column , value ) ; case Types . ARRAY : return reDefineOther ( column , value ) ; case Types . DATALINK : return reDefineOther ( column , value ) ; case Types . DISTINCT : return reDefineOther ( column , value ) ; case Types . JAVA_OBJECT : return reDefineOther ( column , value ) ; case Types . NULL : return reDefineOther ( column , value ) ; case Types . STRUCT : return reDefineOther ( column , value ) ; case Types . REF : return reDefineOther ( column , value ) ; default : return value ; } }
redefine type of value
23,305
protected static void reOrganizeType ( QueryColumnImpl column ) { if ( ( column . type == Types . OTHER ) && ! column . typeChecked ) { column . typeChecked = true ; if ( column . size ( ) > 0 ) { checkOther ( column , column . data [ 0 ] ) ; for ( int i = 1 ; i < column . size ( ) ; i ++ ) { switch ( column . type ) { case Types . NULL : checkOther ( column , column . data [ i ] ) ; break ; case Types . TIMESTAMP : checkDate ( column , column . data [ i ] ) ; break ; case Types . BOOLEAN : checkBoolean ( column , column . data [ i ] ) ; break ; case Types . DOUBLE : checkDouble ( column , column . data [ i ] ) ; break ; case Types . VARCHAR : checkBasic ( column , column . data [ i ] ) ; break ; default : break ; } } } } }
reorganize type of a column
23,306
public static String wrap ( String str , int wrapTextLength ) { if ( wrapTextLength <= 0 ) return str ; StringBuilder rtn = new StringBuilder ( ) ; String ls = SystemUtil . getOSSpecificLineSeparator ( ) ; Array arr = ListUtil . listToArray ( str , ls ) ; int len = arr . size ( ) ; for ( int i = 1 ; i <= len ; i ++ ) { rtn . append ( wrapLine ( Caster . toString ( arr . get ( i , "" ) , "" ) , wrapTextLength ) ) ; if ( i + 1 < len ) rtn . append ( ls ) ; } return rtn . toString ( ) ; }
wraps a String to specified length
23,307
public TagLib execute ( Config config , Tag tag , TagLibTag libTag , FunctionLib [ ] flibs , Data data ) throws TemplateException { return null ; }
Die Methode execute wird aufgerufen wenn der Context eines Tags geprueft werden soll . Diese Methode ueberschreibt jene des Interface Evaluator . Falls diese Methode durch eine Implementation nicht ueberschrieben wird ruft sie wiederere allenfalls implementierte evaluate Methoden auf . Mit Hilfe dieses Konstrukt ist es moeglich drei evaluate methoden anzubieten .
23,308
public void evaluate ( Tag tag , TagLibTag libTag , FunctionLib [ ] flibs ) throws EvaluatorException { evaluate ( tag ) ; evaluate ( tag , libTag ) ; }
Die Methode evaluate wird aufgerufen wenn der Context eines Tags geprueft werden soll . Diese Methode ueberschreibt jene des Interface Evaluator . Falls diese Methode durch eine Implementation nicht ueberschrieben wird ruft sie wiederere allenfalls implementierte evaluate Methoden auf . Mit Hilfe dieses Konstrukt ist es moeglich drei evaluate methoden anzubieten .
23,309
public Element getElement ( NodeList list , String key , String value ) { int len = list . getLength ( ) ; for ( int i = 0 ; i < len ; i ++ ) { Node n = list . item ( i ) ; if ( n instanceof Element ) { Element el = ( Element ) n ; if ( el . getAttribute ( key ) . equalsIgnoreCase ( value ) ) return el ; } } return null ; }
return XML Element matching name
23,310
public DateTime toDateTime ( Config config , Element el , String attributeName ) { String str = el . getAttribute ( attributeName ) ; if ( str == null ) return null ; return DateCaster . toDateAdvanced ( str , ThreadLocalPageContext . getTimeZone ( config ) , null ) ; }
reads a XML Element Attribute ans cast it to a DateTime Object
23,311
public DateTime toDateTime ( Element el , String attributeName , DateTime defaultValue ) { String value = el . getAttribute ( attributeName ) ; if ( value == null ) return defaultValue ; DateTime dtValue = Caster . toDate ( value , false , null , null ) ; if ( dtValue == null ) return defaultValue ; return dtValue ; }
reads a XML Element Attribute ans cast it to a DateTime
23,312
public Date toDate ( Config config , Element el , String attributeName ) { DateTime dt = toDateTime ( config , el , attributeName ) ; if ( dt == null ) return null ; return new DateImpl ( dt ) ; }
reads a XML Element Attribute ans cast it to a Date Object
23,313
public Time toTime ( Config config , Element el , String attributeName ) { DateTime dt = toDateTime ( config , el , attributeName ) ; if ( dt == null ) return null ; return new TimeImpl ( dt ) ; }
reads a XML Element Attribute ans cast it to a Time Object
23,314
public Credentials toCredentials ( Element el , String attributeUser , String attributePassword , Credentials defaultCredentials ) { String user = el . getAttribute ( attributeUser ) ; String pass = el . getAttribute ( attributePassword ) ; if ( user == null ) return defaultCredentials ; if ( pass == null ) pass = "" ; return CredentialsImpl . toCredentials ( user , pass ) ; }
reads 2 XML Element Attribute ans cast it to a Credential
23,315
public void setString ( Element el , String key , String value ) { if ( value != null ) el . setAttribute ( key , value ) ; }
sets a string value to a XML Element
23,316
public void setBoolean ( Element el , String key , boolean value ) { el . setAttribute ( key , String . valueOf ( value ) ) ; }
sets a boolean value to a XML Element
23,317
public void setInt ( Element el , String key , int value ) { el . setAttribute ( key , String . valueOf ( value ) ) ; }
sets a int value to a XML Element
23,318
public void setDateTime ( Element el , String key , DateTime value ) { if ( value != null ) { String str = value . castToString ( null ) ; if ( str != null ) el . setAttribute ( key , str ) ; } }
sets a datetime value to a XML Element
23,319
public void setCredentials ( Element el , String username , String password , Credentials c ) { if ( c == null ) return ; if ( c . getUsername ( ) != null ) el . setAttribute ( username , c . getUsername ( ) ) ; if ( c . getPassword ( ) != null ) el . setAttribute ( password , c . getPassword ( ) ) ; }
sets a Credentials to a XML Element
23,320
public boolean removeSpace ( ) { int start = pos ; while ( pos < text . length && lcText [ pos ] == ' ' ) { pos ++ ; } return ( start < pos ) ; }
Stellt den Zeiger nach vorne wenn er sich innerhalb von Leerzeichen befindet bis die Leerzeichen fertig sind .
23,321
public ParserString subCFMLString ( int start , int count ) { return new ParserString ( String . valueOf ( text , start , count ) ) ; }
Gibt eine Untermenge des CFMLString als CFMLString zurueck ausgehend von start mit einer maximalen Laenge count .
23,322
public static synchronized CFMLEngine getInstance ( CFMLEngineFactory factory , BundleCollection bc ) { if ( engine == null ) { if ( SystemUtil . getLoaderVersion ( ) < 6.0D ) { if ( SystemUtil . isWindows ( ) ) throw new RuntimeException ( "You need to update a newer lucee.jar to run this version, you can download the latest jar from http://download.lucee.org." ) ; else if ( SystemUtil . getLoaderVersion ( ) < 5.8D ) throw new RuntimeException ( "You need to update your lucee.jar to run this version, you can download the latest jar from http://download.lucee.org." ) ; else if ( SystemUtil . getLoaderVersion ( ) < 5.9D ) SystemOut . printDate ( "To use all features Lucee provides, you need to update your lucee.jar, you can download the latest jar from http://download.lucee.org." ) ; } engine = new CFMLEngineImpl ( factory , bc ) ; } return engine ; }
get singelton instance of the CFML Engine
23,323
public void setScope ( String strScope ) throws ApplicationException { strScope = strScope . trim ( ) . toLowerCase ( ) ; if ( strScope . equals ( "onelevel" ) ) scope = SearchControls . ONELEVEL_SCOPE ; else if ( strScope . equals ( "base" ) ) scope = SearchControls . OBJECT_SCOPE ; else if ( strScope . equals ( "subtree" ) ) scope = SearchControls . SUBTREE_SCOPE ; else throw new ApplicationException ( "invalid value for attribute scope [" + strScope + "], valid values are [oneLevel,base,subtree]" ) ; }
Specifies the scope of the search from the entry specified in the Start attribute for action = Query .
23,324
public void setModifytype ( String modifyType ) throws ApplicationException { modifyType = modifyType . trim ( ) . toLowerCase ( ) ; if ( modifyType . equals ( "add" ) ) this . modifyType = DirContext . ADD_ATTRIBUTE ; else if ( modifyType . equals ( "delete" ) ) this . modifyType = DirContext . REMOVE_ATTRIBUTE ; else if ( modifyType . equals ( "replace" ) ) this . modifyType = DirContext . REPLACE_ATTRIBUTE ; else throw new ApplicationException ( "invalid value for attribute modifyType [" + modifyType + "], valid values are [add,replace,delete]" ) ; }
Indicates whether to add delete or replace an attribute in a multi - value list of attributes .
23,325
public void setSortcontrol ( String sortControl ) throws PageException { String [ ] sortControlArr = ArrayUtil . trim ( ListUtil . toStringArray ( ListUtil . listToArrayRemoveEmpty ( sortControl , ',' ) ) ) ; for ( int i = 0 ; i < sortControlArr . length ; i ++ ) { String scs = sortControlArr [ i ] . trim ( ) . toLowerCase ( ) ; if ( scs . equals ( "asc" ) ) sortDirection = LDAPClient . SORT_DIRECTION_ASC ; else if ( scs . equals ( "desc" ) ) sortDirection = LDAPClient . SORT_DIRECTION_DESC ; else if ( scs . equals ( "case" ) ) sortType = LDAPClient . SORT_TYPE_CASE ; else if ( scs . equals ( "nocase" ) ) sortType = LDAPClient . SORT_TYPE_NOCASE ; else throw new ApplicationException ( "invalid value for attribute sortControl [" + sortControl + "], " + "valid values are [asc,desc,case,nocase]" ) ; } }
Specifies how to sort query results .
23,326
public String [ ] getChildNames ( ) { if ( children == null || children . size ( ) == 0 ) return EMPTY_NAMES ; String [ ] arr = new String [ children . size ( ) ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { arr [ i ] = ( ( RamResourceCore ) children . get ( i ) ) . getName ( ) ; } return arr ; }
Gibt den Feldnamen children zurueck .
23,327
public RamResourceCore getChild ( String name , boolean caseSensitive ) { if ( children == null ) return null ; RamResourceCore child ; for ( int i = children . size ( ) - 1 ; i >= 0 ; i -- ) { child = ( RamResourceCore ) children . get ( i ) ; if ( child != null && ( caseSensitive ? child . getName ( ) . equals ( name ) : child . getName ( ) . equalsIgnoreCase ( name ) ) ) return child ; } return null ; }
returns a child that match given name
23,328
public void removeChild ( RamResourceCore core ) { if ( children == null ) return ; RamResourceCore child ; for ( int i = children . size ( ) - 1 ; i >= 0 ; i -- ) { child = ( RamResourceCore ) children . get ( i ) ; if ( child == core ) { children . remove ( i ) ; break ; } } }
remove given child from this core
23,329
public static Object getVariable ( PageContext pc , Collection collection , String var ) throws PageException { StringList list = parse ( pc , new ParserString ( var ) , false ) ; if ( list == null ) throw new InterpreterException ( "invalid variable declaration [" + var + "]" ) ; while ( list . hasNextNext ( ) ) { collection = Caster . toCollection ( collection . get ( KeyImpl . init ( list . next ( ) ) ) ) ; } return collection . get ( KeyImpl . init ( list . next ( ) ) ) ; }
reads a subelement from a struct
23,330
public static Object getVariableEL ( PageContext pc , String var , Object defaultValue ) { StringList list = parse ( pc , new ParserString ( var ) , false ) ; if ( list == null ) return defaultValue ; int scope = scopeString2Int ( pc . ignoreScopes ( ) , list . next ( ) ) ; Object coll = null ; if ( scope == Scope . SCOPE_UNDEFINED ) { coll = pc . undefinedScope ( ) . get ( KeyImpl . init ( list . current ( ) ) , NullSupportHelper . NULL ( ) ) ; if ( coll == NullSupportHelper . NULL ( ) ) return defaultValue ; } else { try { coll = VariableInterpreter . scope ( pc , scope , list . hasNext ( ) ) ; } catch ( PageException e ) { return defaultValue ; } } while ( list . hasNext ( ) ) { coll = pc . getVariableUtil ( ) . get ( pc , coll , KeyImpl . init ( list . next ( ) ) , NullSupportHelper . NULL ( ) ) ; if ( coll == NullSupportHelper . NULL ( ) ) return defaultValue ; } return coll ; }
get a variable from page context
23,331
public static Object setVariable ( PageContext pc , String var , Object value ) throws PageException { StringList list = parse ( pc , new ParserString ( var ) , false ) ; if ( list == null ) throw new InterpreterException ( "invalid variable name declaration [" + var + "]" ) ; if ( list . size ( ) == 1 ) { return pc . undefinedScope ( ) . set ( list . next ( ) , value ) ; } int scope = scopeString2Int ( pc . ignoreScopes ( ) , list . next ( ) ) ; Object coll ; if ( scope == Scope . SCOPE_UNDEFINED ) { coll = pc . touch ( pc . undefinedScope ( ) , KeyImpl . init ( list . current ( ) ) ) ; } else { coll = VariableInterpreter . scope ( pc , scope , true ) ; } while ( list . hasNextNext ( ) ) { coll = pc . touch ( coll , KeyImpl . init ( list . next ( ) ) ) ; } return pc . set ( coll , KeyImpl . init ( list . next ( ) ) , value ) ; }
sets a variable to page Context
23,332
public static Object removeVariable ( PageContext pc , String var ) throws PageException { StringList list = parse ( pc , new ParserString ( var ) , false ) ; if ( list == null ) throw new InterpreterException ( "invalid variable declaration [" + var + "]" ) ; if ( list . size ( ) == 1 ) { return pc . undefinedScope ( ) . remove ( KeyImpl . init ( list . next ( ) ) ) ; } int scope = scopeString2Int ( pc . ignoreScopes ( ) , list . next ( ) ) ; Object coll ; if ( scope == Scope . SCOPE_UNDEFINED ) { coll = pc . undefinedScope ( ) . get ( list . current ( ) ) ; } else { coll = VariableInterpreter . scope ( pc , scope , true ) ; } while ( list . hasNextNext ( ) ) { coll = pc . get ( coll , list . next ( ) ) ; } return Caster . toCollection ( coll ) . remove ( KeyImpl . init ( list . next ( ) ) ) ; }
removes a variable eith matching name from page context
23,333
private static StringList parse ( PageContext pc , ParserString ps , boolean doLowerCase ) { String id = readIdentifier ( ps , doLowerCase ) ; if ( id == null ) return null ; StringList list = new StringList ( id ) ; CFMLExpressionInterpreter interpreter = null ; while ( true ) { if ( ps . forwardIfCurrent ( '.' ) ) { id = readIdentifier ( ps , doLowerCase ) ; if ( id == null ) return null ; list . add ( id ) ; } else if ( ps . forwardIfCurrent ( '[' ) ) { if ( interpreter == null ) interpreter = new CFMLExpressionInterpreter ( false ) ; try { list . add ( Caster . toString ( interpreter . interpretPart ( pc , ps ) ) ) ; } catch ( PageException e ) { return null ; } if ( ! ps . forwardIfCurrent ( ']' ) ) return null ; ps . removeSpace ( ) ; } else break ; } if ( ps . isValidIndex ( ) ) return null ; list . reset ( ) ; return list ; }
parse a Literal variable String and return result as String List
23,334
public static int scopeString2Int ( boolean ignoreScope , String type ) { type = StringUtil . toLowerCase ( type ) ; char c = type . charAt ( 0 ) ; if ( ignoreScope ) { if ( 'a' == c ) { if ( "arguments" . equals ( type ) ) return Scope . SCOPE_ARGUMENTS ; } else if ( 'l' == c ) { if ( "local" . equals ( type ) ) return Scope . SCOPE_LOCAL ; } else if ( 'r' == c ) { if ( "request" . equals ( type ) ) return Scope . SCOPE_REQUEST ; } else if ( 'v' == c ) { if ( "variables" . equals ( type ) ) return Scope . SCOPE_VARIABLES ; } else if ( 's' == c ) { if ( "server" . equals ( type ) ) return Scope . SCOPE_SERVER ; } return Scope . SCOPE_UNDEFINED ; } if ( 'a' == c ) { if ( "application" . equals ( type ) ) return Scope . SCOPE_APPLICATION ; else if ( "arguments" . equals ( type ) ) return Scope . SCOPE_ARGUMENTS ; } else if ( 'c' == c ) { if ( "cgi" . equals ( type ) ) return Scope . SCOPE_CGI ; if ( "cookie" . equals ( type ) ) return Scope . SCOPE_COOKIE ; if ( "client" . equals ( type ) ) return Scope . SCOPE_CLIENT ; if ( "cluster" . equals ( type ) ) return Scope . SCOPE_CLUSTER ; } else if ( 'f' == c ) { if ( "form" . equals ( type ) ) return Scope . SCOPE_FORM ; } else if ( 'l' == c ) { if ( "local" . equals ( type ) ) return Scope . SCOPE_LOCAL ; } else if ( 'r' == c ) { if ( "request" . equals ( type ) ) return Scope . SCOPE_REQUEST ; } else if ( 's' == c ) { if ( "session" . equals ( type ) ) return Scope . SCOPE_SESSION ; if ( "server" . equals ( type ) ) return Scope . SCOPE_SERVER ; } else if ( 'u' == c ) { if ( "url" . equals ( type ) ) return Scope . SCOPE_URL ; } else if ( 'v' == c ) { if ( "variables" . equals ( type ) ) return Scope . SCOPE_VARIABLES ; } return Scope . SCOPE_UNDEFINED ; }
translate a string type definition to its int representation
23,335
public PageSource getPageSource ( String key , boolean updateAccesTime ) { PageSource ps = pageSources . get ( key . toLowerCase ( ) ) ; if ( ps == null ) return null ; if ( updateAccesTime ) ps . setLastAccessTime ( ) ; return ps ; }
return pages matching to key
23,336
public void setPage ( String key , PageSource ps ) { ps . setLastAccessTime ( ) ; pageSources . put ( key . toLowerCase ( ) , ps ) ; }
sts a page object to the page pool
23,337
public boolean remove ( String key ) { if ( pageSources . remove ( key . toLowerCase ( ) ) != null ) return true ; Set < String > set = pageSources . keySet ( ) ; String [ ] keys = set . toArray ( new String [ set . size ( ) ] ) ; PageSource ps ; for ( String k : keys ) { ps = pageSources . get ( k ) ; if ( key . equalsIgnoreCase ( ps . getClassName ( ) ) ) { pageSources . remove ( k ) ; return true ; } } return false ; }
removes a page from the page pool
23,338
public void clearUnused ( ConfigImpl config ) { SystemOut . printDate ( config . getOutWriter ( ) , "PagePool: " + size ( ) + ">(" + maxSize + ")" ) ; if ( size ( ) > maxSize ) { String [ ] keys = keys ( ) ; LongKeyList list = new LongKeyList ( ) ; for ( int i = 0 ; i < keys . length ; i ++ ) { PageSource ps = getPageSource ( keys [ i ] , false ) ; long updateTime = ps . getLastAccessTime ( ) ; if ( updateTime + timeout < System . currentTimeMillis ( ) ) { long add = ( ( ps . getAccessCount ( ) - 1 ) * 10000 ) ; if ( add > timeout ) add = timeout ; list . add ( updateTime + add , keys [ i ] ) ; } } while ( size ( ) > maxSize ) { Object key = list . shift ( ) ; if ( key == null ) break ; remove ( key . toString ( ) ) ; } } }
clear unused pages from page pool
23,339
public void clearPages ( ClassLoader cl ) { Iterator < PageSource > it = this . pageSources . values ( ) . iterator ( ) ; PageSourceImpl entry ; while ( it . hasNext ( ) ) { entry = ( PageSourceImpl ) it . next ( ) ; if ( cl != null ) entry . clear ( cl ) ; else entry . clear ( ) ; } }
remove all Page from Pool using this classloader
23,340
public static void writeOut ( BufferedImage image , OutputStream os , String format ) throws IOException { ImageIO . write ( image , format , os ) ; }
write out image object to a output stream
23,341
public static String randomString ( int length ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < length ; i ++ ) { sb . append ( chars [ AbstractCaptcha . rnd ( 0 , chars . length - 1 ) ] ) ; } return sb . toString ( ) ; }
creates a random String in given length
23,342
private Pair [ ] translateQS ( String qs ) { if ( qs == null ) return new Pair [ 0 ] ; Array arr = lucee . runtime . type . util . ListUtil . listToArrayRemoveEmpty ( qs , "&" ) ; Pair [ ] parameters = new Pair [ arr . size ( ) ] ; int index ; String name ; for ( int i = 1 ; i <= parameters . length ; i ++ ) { name = Caster . toString ( arr . get ( i , "" ) , "" ) ; index = name . indexOf ( '=' ) ; if ( index != - 1 ) parameters [ i - 1 ] = new Pair ( name . substring ( 0 , index ) , name . substring ( index + 1 ) ) ; else parameters [ i - 1 ] = new Pair ( name , "" ) ; } return parameters ; }
constructor of the class
23,343
public void setHeader ( String name , String value ) { headers = ReqRspUtil . set ( headers , name , value ) ; }
sets a new header value
23,344
public void addHeader ( String name , String value ) { headers = ReqRspUtil . add ( headers , name , value ) ; }
add a new header value
23,345
public static Object call ( PageContext pc , Object udf , double timeout ) throws PageException { return Future . _then ( pc , Caster . toFunction ( udf ) , ( long ) timeout ) ; }
Verify if in thread or not
23,346
private static void loadAgent ( Config config , Log log , String agentJar , Class < ? > vmClass ) { try { RuntimeMXBean runtime = ManagementFactory . getRuntimeMXBean ( ) ; String pid = runtime . getName ( ) ; if ( pid . indexOf ( "@" ) != - 1 ) pid = pid . substring ( 0 , pid . indexOf ( "@" ) ) ; log . info ( "Instrumentation" , "pid:" + pid ) ; Object vm = vmClass . getMethod ( "attach" , new Class < ? > [ ] { String . class } ) . invoke ( null , new Object [ ] { pid } ) ; vmClass . getMethod ( "loadAgent" , new Class [ ] { String . class } ) . invoke ( vm , new Object [ ] { agentJar } ) ; vmClass . getMethod ( "detach" , new Class [ ] { } ) . invoke ( vm , new Object [ ] { } ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; log . log ( Log . LEVEL_INFO , "Instrumentation" , t ) ; } }
Attach and load an agent class .
23,347
public static lucee . runtime . config . DebugEntry getDebugEntry ( PageContext pc ) { String addr = pc . getHttpServletRequest ( ) . getRemoteAddr ( ) ; lucee . runtime . config . DebugEntry debugEntry = ( ( ConfigImpl ) pc . getConfig ( ) ) . getDebugEntry ( addr , null ) ; return debugEntry ; }
returns the DebugEntry for the current request s IP address or null if no template matches the address
23,348
private static void buildRanges ( ) { ranges = new LCR [ ] { new LCR ( 4000000000000L , 4999999999999L , 13 , VISA , true ) , new LCR ( 30000000000000L , 30599999999999L , 14 , DINERS , true ) , new LCR ( 36000000000000L , 36999999999999L , 14 , DINERS , true ) , new LCR ( 38000000000000L , 38999999999999L , 14 , DINERS , true ) , new LCR ( 180000000000000L , 180099999999999L , 15 , JCB , true ) , new LCR ( 201400000000000L , 201499999999999L , 15 , ENROUTE , false ) , new LCR ( 213100000000000L , 213199999999999L , 15 , JCB , true ) , new LCR ( 214900000000000L , 214999999999999L , 15 , ENROUTE , false ) , new LCR ( 340000000000000L , 349999999999999L , 15 , AMEX , true ) , new LCR ( 370000000000000L , 379999999999999L , 15 , AMEX , true ) , new LCR ( 3000000000000000L , 3999999999999999L , 16 , JCB , true ) , new LCR ( 4000000000000000L , 4999999999999999L , 16 , VISA , true ) , new LCR ( 5100000000000000L , 5599999999999999L , 16 , MASTERCARD , true ) , new LCR ( 6011000000000000L , 6011999999999999L , 16 , DISCOVER , true ) } ; }
build table of which ranges of credit card number belong to which vendor
23,349
protected static int findMatchingRange ( long creditCardNumber ) { if ( creditCardNumber < 1000000000000L ) { return NOT_ENOUGH_DIGITS ; } if ( creditCardNumber > 9999999999999999L ) { return TOO_MANY_DIGITS ; } if ( ranges [ cachedLastFind ] . low <= creditCardNumber && creditCardNumber <= ranges [ cachedLastFind ] . high ) { return cachedLastFind ; } for ( int i = 0 ; i < ranges . length ; i ++ ) { if ( ranges [ i ] . low <= creditCardNumber && creditCardNumber <= ranges [ i ] . high ) { cachedLastFind = i ; return i ; } } return UNKNOWN_VENDOR ; }
Finds a matching range in the ranges array for a given creditCardNumber .
23,350
public static boolean isValid ( long creditCardNumber ) { int i = findMatchingRange ( creditCardNumber ) ; if ( i < 0 ) { return false ; } if ( ranges [ i ] . hasCheckDigit ) { long number = creditCardNumber ; int checksum = 0 ; for ( int place = 0 ; place < 16 ; place ++ ) { int digit = ( int ) ( number % 10 ) ; number /= 10 ; if ( ( place & 1 ) == 0 ) { checksum += digit ; } else { checksum += z ( digit ) ; } if ( number == 0 ) { break ; } } return ( checksum % 10 ) == 0 ; } return true ; }
Determine if the credit card number is valid i . e . has good prefix and checkdigit . Does _not_ ask the credit card company if this card has been issued or is in good standing .
23,351
public static int recognizeVendor ( long creditCardNumber ) { int i = findMatchingRange ( creditCardNumber ) ; if ( i < 0 ) { return i ; } return ranges [ i ] . vendor ; }
Determine the credit card company . Does NOT validate checkdigit .
23,352
public static String toCreditcard ( String strCreditCardNumber ) throws ExpressionException { long number = toLong ( strCreditCardNumber , - 1 ) ; if ( number == - 1 ) throw new ExpressionException ( "invalid creditcard number [" + strCreditCardNumber + "]" ) ; return toPrettyString ( number ) ; }
1800 15 mod 10
23,353
private static String toPrettyString ( long creditCardNumber ) { String plain = Long . toString ( creditCardNumber ) ; int length = plain . length ( ) ; switch ( length ) { case 12 : return plain . substring ( 0 , 3 ) + ' ' + plain . substring ( 3 , 6 ) + ' ' + plain . substring ( 6 , 9 ) + ' ' + plain . substring ( 9 , 12 ) ; case 13 : return plain . substring ( 0 , 4 ) + ' ' + plain . substring ( 4 , 7 ) + ' ' + plain . substring ( 7 , 10 ) + ' ' + plain . substring ( 10 , 13 ) ; case 14 : return plain . substring ( 0 , 2 ) + ' ' + plain . substring ( 2 , 6 ) + ' ' + plain . substring ( 6 , 10 ) + ' ' + plain . substring ( 10 , 14 ) ; case 15 : return plain . substring ( 0 , 3 ) + ' ' + plain . substring ( 3 , 7 ) + ' ' + plain . substring ( 7 , 11 ) + ' ' + plain . substring ( 11 , 15 ) ; case 16 : return plain . substring ( 0 , 4 ) + ' ' + plain . substring ( 4 , 8 ) + ' ' + plain . substring ( 8 , 12 ) + ' ' + plain . substring ( 12 , 16 ) ; case 17 : return plain . substring ( 0 , 1 ) + ' ' + plain . substring ( 1 , 5 ) + ' ' + plain . substring ( 5 , 9 ) + ' ' + plain . substring ( 9 , 13 ) + ' ' + plain . substring ( 13 , 17 ) ; default : return plain ; } }
Convert a creditCardNumber as long to a formatted String . Currently it breaks 16 - digit numbers into groups of 4 .
23,354
public static void swap ( Array array , int left , int right ) throws ExpressionException { int len = array . size ( ) ; if ( len == 0 ) throw new ExpressionException ( "array is empty" ) ; if ( left < 1 || left > len ) throw new ExpressionException ( "invalid index [" + left + "]" , "valid indexes are from 1 to " + len ) ; if ( right < 1 || right > len ) throw new ExpressionException ( "invalid index [" + right + "]" , "valid indexes are from 1 to " + len ) ; try { Object leftValue = array . get ( left , null ) ; Object rightValue = array . get ( right , null ) ; array . setE ( left , rightValue ) ; array . setE ( right , leftValue ) ; } catch ( PageException e ) { throw new ExpressionException ( "can't swap values of array" , e . getMessage ( ) ) ; } }
swap to values of the array
23,355
public static int find ( Array array , Object object ) { int len = array . size ( ) ; for ( int i = 1 ; i <= len ; i ++ ) { Object tmp = array . get ( i , null ) ; try { if ( tmp != null && Operator . compare ( object , tmp ) == 0 ) return i ; } catch ( PageException e ) { } } return 0 ; }
find a object in array
23,356
public static double avg ( Array array ) throws ExpressionException { if ( array . size ( ) == 0 ) return 0 ; return sum ( array ) / array . size ( ) ; }
average of all values of the array only work when all values are numeric
23,357
public static double sum ( Array array ) throws ExpressionException { if ( array . getDimension ( ) > 1 ) throw new ExpressionException ( "can only get sum/avg from 1 dimensional arrays" ) ; double rtn = 0 ; int len = array . size ( ) ; for ( int i = 1 ; i <= len ; i ++ ) { rtn += _toDoubleValue ( array , i ) ; } return rtn ; }
sum of all values of a array only work when all values are numeric
23,358
public static double median ( Array array ) throws ExpressionException { int len = array . size ( ) ; if ( len == 0 ) return 0 ; if ( array . getDimension ( ) > 1 ) throw new ExpressionException ( "Median() can only be calculated for one dimensional arrays" ) ; double [ ] arr = new double [ len ] ; for ( int i = 0 ; i < len ; i ++ ) arr [ i ] = _toDoubleValue ( array , i + 1 ) ; Arrays . sort ( arr ) ; double result = arr [ len / 2 ] ; if ( len % 2 == 0 ) { return ( result + arr [ ( len - 2 ) / 2 ] ) / 2 ; } return result ; }
median value of all items in the arrays only works when all values are numeric
23,359
public static double min ( Array array ) throws PageException { if ( array . getDimension ( ) > 1 ) throw new ExpressionException ( "can only get max value from 1 dimensional arrays" ) ; if ( array . size ( ) == 0 ) return 0 ; double rtn = _toDoubleValue ( array , 1 ) ; int len = array . size ( ) ; try { for ( int i = 2 ; i <= len ; i ++ ) { double v = _toDoubleValue ( array , i ) ; if ( rtn > v ) rtn = v ; } } catch ( PageException e ) { throw new ExpressionException ( "exception while execute array operation: " + e . getMessage ( ) ) ; } return rtn ; }
the smallest value of all values inside the array only work when all values are numeric
23,360
public static Object setEL ( Object o , int index , Object value ) { try { return set ( o , index , value ) ; } catch ( ArrayUtilException e ) { return null ; } }
sets a value to a array at defined index
23,361
public static Object [ ] toArray ( List < ? > list ) { Iterator < ? > it = list . iterator ( ) ; Class clazz = null ; while ( it . hasNext ( ) ) { Object v = it . next ( ) ; if ( v == null ) continue ; if ( clazz == null ) clazz = v . getClass ( ) ; else if ( clazz != v . getClass ( ) ) return list . toArray ( ) ; } if ( clazz == Object . class || clazz == null ) return list . toArray ( ) ; Object arr = java . lang . reflect . Array . newInstance ( clazz , list . size ( ) ) ; return list . toArray ( ( Object [ ] ) arr ) ; }
creates a native array out of the input list if all values are from the same type this type is used for the array otherwise object
23,362
public static Object [ ] resizeIfNeeded ( Object [ ] arr , int minSize , boolean doPowerOf2 ) { if ( arr . length >= minSize ) return arr ; if ( doPowerOf2 ) minSize = MathUtil . nextPowerOf2 ( minSize ) ; Object [ ] result = new Object [ minSize ] ; System . arraycopy ( arr , 0 , result , 0 , arr . length ) ; return result ; }
this method returns the original array if its length is equal or greater than the minSize or create a new array and copies the data from the original array into the new one .
23,363
public void setLog ( String log ) throws ApplicationException { if ( StringUtil . isEmpty ( log , true ) ) return ; this . log = log . trim ( ) ; }
set the value log If you omit the file attribute specifies the standard log file in which to write the message . Ignored if you specify a file attribute
23,364
public void setType ( String type ) throws ApplicationException { type = type . toLowerCase ( ) . trim ( ) ; if ( type . equals ( "information" ) ) this . type = lucee . commons . io . log . Log . LEVEL_INFO ; else if ( type . equals ( "info" ) ) this . type = lucee . commons . io . log . Log . LEVEL_INFO ; else if ( type . equals ( "warning" ) ) this . type = lucee . commons . io . log . Log . LEVEL_WARN ; else if ( type . equals ( "warn" ) ) this . type = lucee . commons . io . log . Log . LEVEL_WARN ; else if ( type . equals ( "error" ) ) this . type = lucee . commons . io . log . Log . LEVEL_ERROR ; else if ( type . startsWith ( "fatal" ) ) this . type = lucee . commons . io . log . Log . LEVEL_FATAL ; else if ( type . startsWith ( "debug" ) ) this . type = lucee . commons . io . log . Log . LEVEL_DEBUG ; else if ( type . startsWith ( "trace" ) ) this . type = lucee . commons . io . log . Log . LEVEL_TRACE ; else throw new ApplicationException ( "invalid value for attribute type [" + type + "]" , "valid values are [information,warning,error,fatal,debug]" ) ; }
set the value type The type or severity of the message .
23,365
public void setFile ( String file ) throws ApplicationException { if ( StringUtil . isEmpty ( file ) ) return ; if ( file . indexOf ( '/' ) != - 1 || file . indexOf ( '\\' ) != - 1 ) throw new ApplicationException ( "value [" + file + "] from attribute [file] at tag [log] can only contain a filename, file separators like [\\/] are not allowed" ) ; if ( ! file . endsWith ( ".log" ) ) file += ".log" ; this . file = file ; }
set the value file
23,366
private static List copyValues ( FDStackFrameImpl frame , List to , Struct from ) { Iterator it = from . entrySet ( ) . iterator ( ) ; Entry entry ; while ( it . hasNext ( ) ) { entry = ( Entry ) it . next ( ) ; to . add ( new FDVariable ( frame , ( String ) entry . getKey ( ) , FDCaster . toFDValue ( frame , entry . getValue ( ) ) ) ) ; } return to ; }
copy all data from given struct to given list and translate it to a FDValue
23,367
public static boolean isNewerThan ( final Version left , final Version right ) { if ( left . getMajor ( ) > right . getMajor ( ) ) return true ; if ( left . getMajor ( ) < right . getMajor ( ) ) return false ; if ( left . getMinor ( ) > right . getMinor ( ) ) return true ; if ( left . getMinor ( ) < right . getMinor ( ) ) return false ; if ( left . getMicro ( ) > right . getMicro ( ) ) return true ; if ( left . getMicro ( ) < right . getMicro ( ) ) return false ; String q = left . getQualifier ( ) ; int index = q . indexOf ( '-' ) ; String qla = index == - 1 ? "" : q . substring ( index + 1 ) . trim ( ) ; String qln = index == - 1 ? q : q . substring ( 0 , index ) ; int ql = isEmpty ( qln ) ? Integer . MIN_VALUE : Integer . parseInt ( qln ) ; q = right . getQualifier ( ) ; index = q . indexOf ( '-' ) ; String qra = index == - 1 ? "" : q . substring ( index + 1 ) . trim ( ) ; String qrn = index == - 1 ? q : q . substring ( 0 , index ) ; int qr = isEmpty ( qln ) ? Integer . MIN_VALUE : Integer . parseInt ( qrn ) ; if ( ql > qr ) return true ; if ( ql < qr ) return false ; int qlan = qualifierAppendix2Number ( qla ) ; int qran = qualifierAppendix2Number ( qra ) ; if ( qlan > qran ) return true ; if ( qlan < qran ) return false ; if ( qlan == QUALIFIER_APPENDIX_OTHER && qran == QUALIFIER_APPENDIX_OTHER ) return left . compareTo ( right ) > 0 ; return false ; }
check left value against right value
23,368
public static byte [ ] encrypt ( byte [ ] input , String key , String algorithm , byte [ ] ivOrSalt , int iterations ) throws PageException { return crypt ( input , key , algorithm , ivOrSalt , iterations , false ) ; }
an encrypt method that takes a byte - array for input and returns an encrypted byte - array
23,369
public static String encrypt ( String input , String key , String algorithm , byte [ ] ivOrSalt , int iterations , String encoding , String charset ) throws PageException { try { if ( charset == null ) charset = DEFAULT_CHARSET ; if ( encoding == null ) encoding = DEFAULT_ENCODING ; byte [ ] baInput = input . getBytes ( charset ) ; byte [ ] encrypted = encrypt ( baInput , key , algorithm , ivOrSalt , iterations ) ; return Coder . encode ( encoding , encrypted ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; throw Caster . toPageException ( t ) ; } }
an encrypt method that takes a clear - text String for input and returns an encrypted encoded String
23,370
public static byte [ ] decrypt ( byte [ ] input , String key , String algorithm , byte [ ] ivOrSalt , int iterations ) throws PageException { return crypt ( input , key , algorithm , ivOrSalt , iterations , true ) ; }
a decrypt method that takes an encrypted byte - array for input and returns an unencrypted byte - array
23,371
public static String decrypt ( String input , String key , String algorithm , byte [ ] ivOrSalt , int iterations , String encoding , String charset ) throws PageException { try { if ( charset == null ) charset = DEFAULT_CHARSET ; if ( encoding == null ) encoding = DEFAULT_ENCODING ; byte [ ] baInput = Coder . decode ( encoding , input ) ; byte [ ] decrypted = decrypt ( baInput , key , algorithm , ivOrSalt , iterations ) ; return new String ( decrypted , charset ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; throw Caster . toPageException ( t ) ; } }
a decrypt method that takes an encrypted encoded String for input and returns a clear - text String
23,372
void release ( DatasourceConnection dc ) { if ( dc != null ) { try { dc . getConnection ( ) . commit ( ) ; dc . getConnection ( ) . setAutoCommit ( true ) ; dc . getConnection ( ) . setTransactionIsolation ( Connection . TRANSACTION_NONE ) ; } catch ( SQLException e ) { } getManager ( ) . releaseConnection ( ThreadLocalPageContext . get ( ) , dc ) ; } }
release datasource connection
23,373
public static int matchPath ( Struct variables , Path [ ] restPath , String [ ] callerPath ) { if ( restPath . length > callerPath . length ) return - 1 ; int index = 0 ; for ( ; index < restPath . length ; index ++ ) { if ( ! restPath [ index ] . match ( variables , callerPath [ index ] ) ) return - 1 ; } return index - 1 ; }
check if caller path match the cfc path
23,374
public String sendMessage ( String gatewayId , Struct data ) throws PageException , IOException { Gateway g = getGateway ( gatewayId ) ; if ( g . getState ( ) != Gateway . RUNNING ) throw new GatewayException ( "Gateway [" + gatewayId + "] is not running" ) ; return g . sendMessage ( data ) ; }
send the message to the gateway
23,375
public void stopAll ( ) { Iterator < GatewayEntry > it = getEntries ( ) . values ( ) . iterator ( ) ; Gateway g ; while ( it . hasNext ( ) ) { g = it . next ( ) . getGateway ( ) ; if ( g != null ) stop ( g ) ; } }
stop all entries
23,376
private static void compressGZip ( Resource source , Resource target ) throws IOException { if ( source . isDirectory ( ) ) { throw new IOException ( "you can only create a GZIP File from a single source file, use TGZ (TAR-GZIP) to first TAR multiple files" ) ; } InputStream is = null ; OutputStream os = null ; try { is = source . getInputStream ( ) ; os = target . getOutputStream ( ) ; } catch ( IOException ioe ) { IOUtil . closeEL ( is , os ) ; throw ioe ; } compressGZip ( is , os ) ; }
compress a source file to a gzip file
23,377
private static void _compressBZip2 ( InputStream source , OutputStream target ) throws IOException { InputStream is = IOUtil . toBufferedInputStream ( source ) ; OutputStream os = new BZip2CompressorOutputStream ( IOUtil . toBufferedOutputStream ( target ) ) ; IOUtil . copy ( is , os , true , true ) ; }
compress a source file to a bzip2 file
23,378
public Field [ ] getFields ( Class clazz , String fieldname ) { Struct fieldMap ; Object o ; synchronized ( map ) { o = map . get ( clazz ) ; if ( o == null ) { fieldMap = store ( clazz ) ; } else fieldMap = ( Struct ) o ; } o = fieldMap . get ( fieldname , null ) ; if ( o == null ) return null ; return ( Field [ ] ) o ; }
returns all fields matching given criteria or null if field does exist
23,379
public MappingImpl cloneReadOnly ( ConfigImpl config ) { return new MappingImpl ( config , virtual , strPhysical , strArchive , inspect , physicalFirst , hidden , true , topLevel , appMapping , ignoreVirtual , appListener , listenerMode , listenerType ) ; }
clones a mapping and make it readOnly
23,380
public static String serialize ( Object object ) { if ( object == null ) return "[null]" ; try { return new ScriptConverter ( ) . serialize ( object ) ; } catch ( Throwable t ) { ExceptionUtil . rethrowIfNecessary ( t ) ; return object . toString ( ) ; } }
translate a object to its string representation
23,381
public static Object callWithNamedValues ( PageContext pc , Object coll , Collection . Key methodName , Struct args , short type , String strType ) throws PageException { Map < Key , FunctionLibFunction > members = getMembers ( pc , type ) ; FunctionLibFunction member = members . get ( methodName ) ; if ( member != null ) { List < FunctionLibFunctionArg > _args = member . getArg ( ) ; FunctionLibFunctionArg arg ; if ( args . size ( ) < _args . size ( ) ) { Object val ; ArrayList < Ref > refs = new ArrayList < Ref > ( ) ; arg = _args . get ( 0 ) ; refs . add ( new Casting ( arg . getTypeAsString ( ) , arg . getType ( ) , new LFunctionValue ( new LString ( arg . getName ( ) ) , coll ) ) ) ; for ( int y = 1 ; y < _args . size ( ) ; y ++ ) { arg = _args . get ( y ) ; val = args . get ( arg . getName ( ) , null ) ; if ( val == null ) { String alias = arg . getAlias ( ) ; if ( ! StringUtil . isEmpty ( alias , true ) ) { String [ ] aliases = lucee . runtime . type . util . ListUtil . trimItems ( lucee . runtime . type . util . ListUtil . listToStringArray ( alias , ',' ) ) ; for ( int x = 0 ; x < aliases . length ; x ++ ) { val = args . get ( aliases [ x ] , null ) ; if ( val != null ) break ; } } } if ( val == null ) { if ( arg . getRequired ( ) ) { String [ ] names = member . getMemberNames ( ) ; String n = ArrayUtil . isEmpty ( names ) ? "" : names [ 0 ] ; throw new ExpressionException ( "missing required argument [" + arg . getName ( ) + "] for member function call [" + n + "]" ) ; } } else { refs . add ( new Casting ( arg . getTypeAsString ( ) , arg . getType ( ) , new LFunctionValue ( new LString ( arg . getName ( ) ) , val ) ) ) ; } } return new BIFCall ( coll , member , refs . toArray ( new Ref [ refs . size ( ) ] ) ) . getValue ( pc ) ; } } throw new ExpressionException ( "No matching function member [" + methodName + "] for call with named arguments found, available function members are [" + lucee . runtime . type . util . ListUtil . sort ( CollectionUtil . getKeyList ( members . keySet ( ) . iterator ( ) , "," ) , "textnocase" , "asc" , "," ) + "]" ) ; }
used in extension image
23,382
public static TimeZone toTimeZone ( String strTimezone , TimeZone defaultValue ) { if ( strTimezone == null ) return defaultValue ; String strTimezoneTrimmed = StringUtil . replace ( strTimezone . trim ( ) . toLowerCase ( ) , " " , "" , false ) ; TimeZone tz = getTimeZoneFromIDS ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; float gmtOffset = Float . NaN ; if ( strTimezoneTrimmed . startsWith ( "gmt" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 3 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "etc/gmt" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 7 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "utc" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 3 ) . trim ( ) , Float . NaN ) ; else if ( strTimezoneTrimmed . startsWith ( "etc/utc" ) ) gmtOffset = getGMTOffset ( strTimezoneTrimmed . substring ( 7 ) . trim ( ) , Float . NaN ) ; if ( ! Float . isNaN ( gmtOffset ) ) { strTimezoneTrimmed = "etc/gmt" + ( gmtOffset >= 0 ? "+" : "" ) + Caster . toString ( gmtOffset ) ; tz = getTimeZoneFromIDS ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; } if ( ! StringUtil . isEmpty ( strTimezoneTrimmed ) ) { tz = dn . get ( strTimezoneTrimmed ) ; if ( tz != null ) return tz ; Iterator < Object > it = IDS . values ( ) . iterator ( ) ; Object o ; while ( it . hasNext ( ) ) { o = it . next ( ) ; if ( o instanceof TimeZone ) { tz = ( TimeZone ) o ; if ( strTimezone . equalsIgnoreCase ( tz . getDisplayName ( true , TimeZone . SHORT , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( false , TimeZone . SHORT , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( true , TimeZone . LONG , Locale . US ) ) || strTimezone . equalsIgnoreCase ( tz . getDisplayName ( false , TimeZone . LONG , Locale . US ) ) ) { dn . put ( strTimezoneTrimmed , tz ) ; return tz ; } } } } return defaultValue ; }
translate timezone string format to a timezone
23,383
public String getValueAsString ( Expression expr ) throws PageException { expr . writeOut ( this , Expression . MODE_REF ) ; return Caster . toString ( stack . pop ( ) ) ; }
removes the element from top of the stack
23,384
public static String repeatString ( String str , int count ) { if ( count <= 0 ) return "" ; char [ ] chars = str . toCharArray ( ) ; char [ ] rtn = new char [ chars . length * count ] ; int pos = 0 ; for ( int i = 0 ; i < count ; i ++ ) { for ( int y = 0 ; y < chars . length ; y ++ ) rtn [ pos ++ ] = chars [ y ] ; } return new String ( rtn ) ; }
reapeats a string
23,385
public static String reqExpEscape ( String str ) { char [ ] arr = str . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( str . length ( ) * 2 ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { sb . append ( '\\' ) ; sb . append ( arr [ i ] ) ; } return sb . toString ( ) ; }
escape all special characters of the regular expresson language
23,386
public static String toIdentityVariableName ( String varName ) { char [ ] chars = varName . toCharArray ( ) ; long changes = 0 ; StringBuilder rtn = new StringBuilder ( chars . length + 2 ) ; rtn . append ( "CF" ) ; for ( int i = 0 ; i < chars . length ; i ++ ) { char c = chars [ i ] ; if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) ) rtn . append ( c ) ; else { rtn . append ( '_' ) ; changes += ( c * ( i + 1 ) ) ; } } return rtn . append ( changes ) . toString ( ) ; }
translate a string to a valid identity variable name
23,387
public static String toClassName ( String str ) { StringBuilder rtn = new StringBuilder ( ) ; String [ ] arr = str . split ( "[\\\\|//]" ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] . length ( ) == 0 ) continue ; if ( rtn . length ( ) != 0 ) rtn . append ( '.' ) ; char [ ] chars = arr [ i ] . toCharArray ( ) ; long changes = 0 ; for ( int y = 0 ; y < chars . length ; y ++ ) { char c = chars [ y ] ; if ( y == 0 && ( c >= '0' && c <= '9' ) ) rtn . append ( "_" + c ) ; else if ( ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || ( c >= '0' && c <= '9' ) ) rtn . append ( c ) ; else { rtn . append ( '_' ) ; changes += ( c * ( i + 1 ) ) ; } } if ( changes > 0 ) rtn . append ( changes ) ; } return rtn . toString ( ) ; }
translate a string to a valid classname string
23,388
public static String ltrim ( String str , String defaultValue ) { if ( str == null ) return defaultValue ; int len = str . length ( ) ; int st = 0 ; while ( ( st < len ) && ( str . charAt ( st ) <= ' ' ) ) { st ++ ; } return ( ( st > 0 ) ) ? str . substring ( st ) : str ; }
This function returns a string with whitespace stripped from the beginning of str
23,389
public static String rtrim ( String str , String defaultValue ) { if ( str == null ) return defaultValue ; int len = str . length ( ) ; while ( ( 0 < len ) && ( str . charAt ( len - 1 ) <= ' ' ) ) { len -- ; } return ( len < str . length ( ) ) ? str . substring ( 0 , len ) : str ; }
This function returns a string with whitespace stripped from the end of str
23,390
public static String trim ( String str , String defaultValue ) { if ( str == null ) return defaultValue ; return str . trim ( ) ; }
trim given value return defaultvalue when input is null
23,391
public static String trim ( String str , boolean removeBOM , boolean removeSpecialWhiteSpace , String defaultValue ) { if ( str == null ) return defaultValue ; if ( str . isEmpty ( ) ) return str ; if ( removeBOM ) { if ( str . charAt ( 0 ) == '\uFEFF' ) str = str . substring ( 1 ) ; else if ( str . charAt ( 0 ) == '\uFFFD' ) str = str . substring ( 1 ) ; else if ( str . charAt ( 0 ) == '\uFFFE' ) str = str . substring ( 1 ) ; else if ( str . length ( ) >= 2 ) { if ( str . charAt ( 0 ) == '\uBBEF' && str . charAt ( 1 ) == '\uFFFD' ) str = str . substring ( 2 ) ; } } if ( removeSpecialWhiteSpace ) { int len = str . length ( ) ; int startIndex = 0 , endIndex = len - 1 ; while ( ( startIndex < len ) && isWhiteSpace ( str . charAt ( startIndex ) , true ) ) { startIndex ++ ; } while ( ( startIndex < endIndex ) && isWhiteSpace ( str . charAt ( endIndex ) , true ) ) { endIndex -- ; } return ( ( startIndex > 0 ) || ( endIndex + 1 < len ) ) ? str . substring ( startIndex , endIndex + 1 ) : str ; } return str . trim ( ) ; }
trim given value return defaultvalue when input is null this function no only removes the classic whitespaces it also removes Byte order masks forgotten to remove when reading a UTF file .
23,392
public static boolean hasLineFeed ( String str ) { int len = str . length ( ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = str . charAt ( i ) ; if ( c == '\n' || c == '\r' ) return true ; } return false ; }
return if in a string are line feeds or not
23,393
public static String suppressWhiteSpace ( String str ) { int len = str . length ( ) ; StringBuilder sb = new StringBuilder ( len ) ; char c ; char buffer = 0 ; for ( int i = 0 ; i < len ; i ++ ) { c = str . charAt ( i ) ; if ( c == '\n' || c == '\r' ) buffer = '\n' ; else if ( isWhiteSpace ( c ) ) { if ( buffer == 0 ) buffer = c ; } else { if ( buffer != 0 ) { sb . append ( buffer ) ; buffer = 0 ; } sb . append ( c ) ; } } if ( buffer != 0 ) sb . append ( buffer ) ; return sb . toString ( ) ; }
remove all white spaces followed by whitespaces
23,394
public static String replace ( String input , String find , String repl , boolean firstOnly , boolean ignoreCase ) { int findLen = find . length ( ) ; if ( findLen == 0 ) return input ; if ( ! ignoreCase && findLen == repl . length ( ) ) { if ( find . equals ( repl ) ) return input ; if ( ! firstOnly && findLen == 1 ) return input . replace ( find . charAt ( 0 ) , repl . charAt ( 0 ) ) ; } int pos = ignoreCase ? indexOfIgnoreCase ( input , find ) : input . indexOf ( find ) ; if ( pos == - 1 ) return input ; int start = 0 ; StringBuilder sb = new StringBuilder ( repl . length ( ) > find . length ( ) ? ( int ) Math . ceil ( input . length ( ) * 1.2 ) : input . length ( ) ) ; while ( pos != - 1 ) { sb . append ( input . substring ( start , pos ) ) ; sb . append ( repl ) ; start = pos + findLen ; if ( firstOnly ) break ; pos = ignoreCase ? indexOfIgnoreCase ( input , find , start ) : input . indexOf ( find , start ) ; } if ( input . length ( ) > start ) sb . append ( input . substring ( start ) ) ; return sb . toString ( ) ; }
performs a replace operation on a string
23,395
public static boolean startsWith ( String str , char prefix ) { return str != null && str . length ( ) > 0 && str . charAt ( 0 ) == prefix ; }
Tests if this string starts with the specified prefix .
23,396
public static boolean endsWith ( String str , char suffix ) { return str != null && str . length ( ) > 0 && str . charAt ( str . length ( ) - 1 ) == suffix ; }
Tests if this string ends with the specified suffix .
23,397
public static boolean startsWithIgnoreCase ( final String base , final String start ) { if ( base . length ( ) < start . length ( ) ) { return false ; } return base . regionMatches ( true , 0 , start , 0 , start . length ( ) ) ; }
Helper functions to query a strings start portion . The comparison is case insensitive .
23,398
public static boolean endsWithIgnoreCase ( final String base , final String end ) { if ( base . length ( ) < end . length ( ) ) { return false ; } return base . regionMatches ( true , base . length ( ) - end . length ( ) , end , 0 , end . length ( ) ) ; }
Helper functions to query a strings end portion . The comparison is case insensitive .
23,399
public static String toLowerCase ( String str ) { int len = str . length ( ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = str . charAt ( i ) ; if ( ! ( ( c >= 'a' && c <= 'z' ) || ( c >= '0' && c <= '9' ) ) ) { return str . toLowerCase ( ) ; } } return str ; }
cast a string a lower case String is faster than the String . toLowerCase if all Character are already Low Case