public final LangPreferences revealLangPreferences(
    final IRequestData pRequestData, final List<Languages> pLangs,
      final List<DecimalSeparator> pDecSeps,
        final List<DecimalGroupSeparator> pDecGrSeps,
          final List<LangPreferences> pLangPrefs,
            final boolean pIsFirstReq) throws Exception {
    boolean isDbgSh = this.logger.getDbgSh(this.getClass())
      && this.logger.getDbgFl() < 5001 && this.logger.getDbgCl() > 5003;
    LangPreferences lpf = null;
    boolean needSetCookie = false;
    //check request changing preferences:
    String lang = pRequestData.getParameter("lang");
    String decSep = pRequestData.getParameter("decSep");
    String decGrSep = pRequestData.getParameter("decGrSep");
    String digInGr = pRequestData.getParameter("digInGr");
    if (pIsFirstReq || isDbgSh) {
      this.logger.debug(null, HndlI18nRequest.class,
        "Request's lang/decSep/decGrSep/digInGr: " + lang + "/"
          + decSep + "/" + decGrSep + "/" + digInGr);
    }
    if (lang == null || lang.length() == 0
      || decSep == null || decSep.length() == 0
        || decGrSep == null || decGrSep.length() == 0
          || digInGr == null || digInGr.length() == 0) {
      lang = null;
      decSep = null;
      decGrSep = null;
      digInGr = null;
    } else {
      needSetCookie = true;
    }
    if (decGrSep == null && decSep == null && lang == null) {
      lang = pRequestData.getCookieValue("lang");
      decSep = pRequestData.getCookieValue("decSep");
      decGrSep = pRequestData.getCookieValue("decGrSep");
      digInGr = pRequestData.getCookieValue("digInGr");
      if (pIsFirstReq || isDbgSh) {
        this.logger.debug(null, HndlI18nRequest.class,
          "Client's cookie lang/decSep/decGrSep/digInGr: " + lang
            + "/" + decSep + "/" + decGrSep + "/" + digInGr);
      }
    }
    if (decGrSep != null && decSep != null && lang != null
      && digInGr != null) {
      if (decGrSep.equals(decSep)) {
        if (pIsFirstReq || isDbgSh) {
          this.logger.debug(null, HndlI18nRequest.class,
            "Separators are same!! decSep/decGrSep: " + decSep);
        }
      } else {
        //try to match from cookies or changed by user:
        lpf = new LangPreferences();
        lpf.setDigitsInGroup(Integer.parseInt(digInGr));
        for (Languages ln : pLangs) {
          if (ln.getItsId().equals(lang)) {
            lpf.setLang(ln);
            break;
          }
        }
        if (lpf.getLang() == null) {
          lpf = null;
        } else {
          for (DecimalSeparator ds : pDecSeps) {
            if (ds.getItsId().equals(decSep)) {
              lpf.setDecimalSep(ds);
              break;
            }
          }
          if (lpf.getDecimalSep() == null) {
            lpf = null;
          } else {
            for (DecimalGroupSeparator dgs : pDecGrSeps) {
              if (dgs.getItsId().equals(decGrSep)) {
                lpf.setDecimalGroupSep(dgs);
                break;
              }
            }
            if (lpf.getDecimalGroupSep() == null) {
              lpf = null;
            }
          }
        }
      }
    }
    if (lpf == null) {
      // try match client's locale, if not - default or the first:
      String ccountry = null;
      String clang = null;
      if (pRequestData.getLocale() != null) {
        ccountry = pRequestData.getLocale().getCountry();
        clang = pRequestData.getLocale().getLanguage();
        if (pIsFirstReq || isDbgSh) {
          this.logger.debug(null, HndlI18nRequest.class,
            "Client prefers lang/country: " + clang + "/" + ccountry);
        }
      }
      LangPreferences lpfMf = null;
      LangPreferences lpfMl = null;
      LangPreferences lpfDef = null;
      for (LangPreferences lpft : pLangPrefs) {
        if (lpft.getCountry().getItsId().equals(ccountry)
          && lpft.getLang().getItsId().equals(clang)) {
          lpfMf = lpft;
          break;
        }
        if (lpft.getLang().getItsId().equals(clang)) {
          lpfMl = lpft;
        }
        if (lpft.getIsDefault()) {
          lpfDef = lpft;
        } else if (lpfDef == null) {
          lpfDef = lpft;
        }
      }
      if (lpfMf != null) {
        lpf = lpfMf;
        if (pIsFirstReq || isDbgSh) {
          this.logger.debug(null, HndlI18nRequest.class,
        "Full match lang/decSep/decGrSep/digInGr: " + lpf.getLang()
      .getItsId() + "/" + lpf.getDecimalSep().getItsId() + "/"
    + lpf.getDecimalGroupSep().getItsId() + "/" + lpf.getDigitsInGroup());
        }
      } else if (lpfMl != null) {
        lpf = lpfMl;
        if (pIsFirstReq || isDbgSh) {
          this.logger.debug(null, HndlI18nRequest.class,
        "Lang match lang/decSep/decGrSep/digInGr: " + lpf.getLang()
      .getItsId() + "/" + lpf.getDecimalSep().getItsId() + "/"
    + lpf.getDecimalGroupSep().getItsId() + "/" + lpf.getDigitsInGroup());
        }
      } else {
        lpf = lpfDef;
        if (pIsFirstReq || isDbgSh) {
          this.logger.debug(null, HndlI18nRequest.class,
        "No match, default lang/decSep/decGrSep/digInGr: "
      + lpf.getLang().getItsId() + "/" + lpf.getDecimalSep().getItsId() + "/"
    + lpf.getDecimalGroupSep().getItsId() + "/" + lpf.getDigitsInGroup());
        }
      }
      needSetCookie = true;
    }
    if (needSetCookie) {
      pRequestData.setCookieValue("digInGr",
        lpf.getDigitsInGroup().toString());
      pRequestData.setCookieValue("lang", lpf.getLang().getItsId());
      pRequestData.setCookieValue("decSep",
        lpf.getDecimalSep().getItsId());
      pRequestData.setCookieValue("decGrSep",
        lpf.getDecimalGroupSep().getItsId());
      if (pIsFirstReq || isDbgSh) {
        this.logger.debug(null, HndlI18nRequest.class,
          "Cookie is set lang/decSep/decGrSep: " + lpf.getLang()
            .getItsId() + "/" + lpf.getDecimalSep().getItsId() + "/"
              + lpf.getDecimalGroupSep().getItsId());
      }
    }
    return lpf;
  }
public final LangPreferences revealLangPreferences ( final IRequestData pRequestData , final List < Languages > pLangs , final List < DecimalSeparator > pDecSeps , final List < DecimalGroupSeparator > pDecGrSeps , final List < LangPreferences > pLangPrefs , final boolean pIsFirstReq ) throws Exception { boolean isDbgSh = this . logger . getDbgSh ( this . getClass ( ) ) && this . logger . getDbgFl ( ) < 5001 && this . logger . getDbgCl ( ) > 5003 ; LangPreferences lpf = null ; boolean needSetCookie = false ; String lang = pRequestData . getParameter ( "lang" ) ; String decSep = pRequestData . getParameter ( "decSep" ) ; String decGrSep = pRequestData . getParameter ( "decGrSep" ) ; String digInGr = pRequestData . getParameter ( "digInGr" ) ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Request's lang/decSep/decGrSep/digInGr: " + lang + "/" + decSep + "/" + decGrSep + "/" + digInGr ) ; } if ( lang == null || lang . length ( ) == 0 || decSep == null || decSep . length ( ) == 0 || decGrSep == null || decGrSep . length ( ) == 0 || digInGr == null || digInGr . length ( ) == 0 ) { lang = null ; decSep = null ; decGrSep = null ; digInGr = null ; } else { needSetCookie = true ; } if ( decGrSep == null && decSep == null && lang == null ) { lang = pRequestData . getCookieValue ( "lang" ) ; decSep = pRequestData . getCookieValue ( "decSep" ) ; decGrSep = pRequestData . getCookieValue ( "decGrSep" ) ; digInGr = pRequestData . getCookieValue ( "digInGr" ) ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Client's cookie lang/decSep/decGrSep/digInGr: " + lang + "/" + decSep + "/" + decGrSep + "/" + digInGr ) ; } } if ( decGrSep != null && decSep != null && lang != null && digInGr != null ) { if ( decGrSep . equals ( decSep ) ) { if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Separators are same!! decSep/decGrSep: " + decSep ) ; } } else { lpf = new LangPreferences ( ) ; lpf . setDigitsInGroup ( Integer . parseInt ( digInGr ) ) ; for ( Languages ln : pLangs ) { if ( ln . getItsId ( ) . equals ( lang ) ) { lpf . setLang ( ln ) ; break ; } } if ( lpf . getLang ( ) == null ) { lpf = null ; } else { for ( DecimalSeparator ds : pDecSeps ) { if ( ds . getItsId ( ) . equals ( decSep ) ) { lpf . setDecimalSep ( ds ) ; break ; } } if ( lpf . getDecimalSep ( ) == null ) { lpf = null ; } else { for ( DecimalGroupSeparator dgs : pDecGrSeps ) { if ( dgs . getItsId ( ) . equals ( decGrSep ) ) { lpf . setDecimalGroupSep ( dgs ) ; break ; } } if ( lpf . getDecimalGroupSep ( ) == null ) { lpf = null ; } } } } } if ( lpf == null ) { String ccountry = null ; String clang = null ; if ( pRequestData . getLocale ( ) != null ) { ccountry = pRequestData . getLocale ( ) . getCountry ( ) ; clang = pRequestData . getLocale ( ) . getLanguage ( ) ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Client prefers lang/country: " + clang + "/" + ccountry ) ; } } LangPreferences lpfMf = null ; LangPreferences lpfMl = null ; LangPreferences lpfDef = null ; for ( LangPreferences lpft : pLangPrefs ) { if ( lpft . getCountry ( ) . getItsId ( ) . equals ( ccountry ) && lpft . getLang ( ) . getItsId ( ) . equals ( clang ) ) { lpfMf = lpft ; break ; } if ( lpft . getLang ( ) . getItsId ( ) . equals ( clang ) ) { lpfMl = lpft ; } if ( lpft . getIsDefault ( ) ) { lpfDef = lpft ; } else if ( lpfDef == null ) { lpfDef = lpft ; } } if ( lpfMf != null ) { lpf = lpfMf ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Full match lang/decSep/decGrSep/digInGr: " + lpf . getLang ( ) . getItsId ( ) + "/" + lpf . getDecimalSep ( ) . getItsId ( ) + "/" + lpf . getDecimalGroupSep ( ) . getItsId ( ) + "/" + lpf . getDigitsInGroup ( ) ) ; } } else if ( lpfMl != null ) { lpf = lpfMl ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Lang match lang/decSep/decGrSep/digInGr: " + lpf . getLang ( ) . getItsId ( ) + "/" + lpf . getDecimalSep ( ) . getItsId ( ) + "/" + lpf . getDecimalGroupSep ( ) . getItsId ( ) + "/" + lpf . getDigitsInGroup ( ) ) ; } } else { lpf = lpfDef ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "No match, default lang/decSep/decGrSep/digInGr: " + lpf . getLang ( ) . getItsId ( ) + "/" + lpf . getDecimalSep ( ) . getItsId ( ) + "/" + lpf . getDecimalGroupSep ( ) . getItsId ( ) + "/" + lpf . getDigitsInGroup ( ) ) ; } } needSetCookie = true ; } if ( needSetCookie ) { pRequestData . setCookieValue ( "digInGr" , lpf . getDigitsInGroup ( ) . toString ( ) ) ; pRequestData . setCookieValue ( "lang" , lpf . getLang ( ) . getItsId ( ) ) ; pRequestData . setCookieValue ( "decSep" , lpf . getDecimalSep ( ) . getItsId ( ) ) ; pRequestData . setCookieValue ( "decGrSep" , lpf . getDecimalGroupSep ( ) . getItsId ( ) ) ; if ( pIsFirstReq || isDbgSh ) { this . logger . debug ( null , HndlI18nRequest . class , "Cookie is set lang/decSep/decGrSep: " + lpf . getLang ( ) . getItsId ( ) + "/" + lpf . getDecimalSep ( ) . getItsId ( ) + "/" + lpf . getDecimalGroupSep ( ) . getItsId ( ) ) ; } } return lpf ; }
<p>Reveals language preference and adds preferences
into cookie if need.</p>
@param pRequestData Request Data
@param pLangs lang. list
@param pDecSeps dec.sep. list
@param pDecGrSeps dec.gr.sep. list
@param pLangPrefs lang.pref. list
@param pIsFirstReq if first request
@return lang. preferences
@throws Exception - an exception