private void initIdAndToken ( ) { boolean setCookie = true ; // From URL Object oCfid = urlScope ( ) . get ( KeyConstants . _cfid , null ) ; Object oCftoken = urlScope ( ) . get ( KeyConstants . _cftoken , null ) ; // if CFID comes from URL, we only accept if already exists if ( oCfid != null ) { if ( Decision . isGUIdSimple ( oCfid ) ) { if ( ! scopeContext . hasExistingCFID ( this , Caster . toString ( oCfid , null ) ) ) { oCfid = null ; oCftoken = null ; } } else { oCfid = null ; oCftoken = null ; } } // Cookie if ( oCfid == null ) { setCookie = false ; oCfid = cookieScope ( ) . get ( KeyConstants . _cfid , null ) ; oCftoken = cookieScope ( ) . get ( KeyConstants . _cftoken , null ) ; } // check cookie value if ( oCfid != null ) { // cookie value is invalid, maybe from ACF if ( ! Decision . isGUIdSimple ( oCfid ) ) { oCfid = null ; oCftoken = null ; Charset charset = getWebCharset ( ) ; // check if we have multiple cookies with the name "cfid" and a other one is valid javax . servlet . http . Cookie [ ] cookies = getHttpServletRequest ( ) . getCookies ( ) ; String name , value ; if ( cookies != null ) { for ( int i = 0 ; i < cookies . length ; i ++ ) { name = ReqRspUtil . decode ( cookies [ i ] . getName ( ) , charset . name ( ) , false ) ; // CFID if ( "cfid" . equalsIgnoreCase ( name ) ) { value = ReqRspUtil . decode ( cookies [ i ] . getValue ( ) , charset . name ( ) , false ) ; if ( Decision . isGUIdSimple ( value ) ) oCfid = value ; ReqRspUtil . removeCookie ( getHttpServletResponse ( ) , name ) ; } // CFToken else if ( "cftoken" . equalsIgnoreCase ( name ) ) { value = ReqRspUtil . decode ( cookies [ i ] . getValue ( ) , charset . name ( ) , false ) ; if ( isValidCfToken ( value ) ) oCftoken = value ; ReqRspUtil . removeCookie ( getHttpServletResponse ( ) , name ) ; } } } if ( oCfid != null ) { setCookie = true ; if ( oCftoken == null ) oCftoken = "0" ; } } } // New One if ( oCfid == null || oCftoken == null ) { setCookie = true ; cfid = ScopeContext . getNewCFId ( ) ; cftoken = ScopeContext . getNewCFToken ( ) ; } else { cfid = Caster . toString ( oCfid , null ) ; cftoken = Caster . toString ( oCftoken , "0" ) ; } if ( setCookie && applicationContext . isSetClientCookies ( ) ) setClientCookies ( ) ; }
initialize the cfid and the cftoken