public void addTokenWithEqualsSign(CookieRecipe recipe, String token, int equalsIndex) { final String name = token.substring(0, equalsIndex).trim(); final String value = token.substring(equalsIndex + 1).trim(); StringBuffer _value = getFieldValue("_value", StringBuffer.class); _value.insert(0, value); HashMap _attributes = getFieldValue("_attributes", HashMap.class); if (recipe.isCookieAttribute(name.toLowerCase())) { _attributes.put(name.toLowerCase(), _value.toString()); } else { try { getAccessibleMethod(CookiePress.class, "addCookieIfValid", new Class[] { Cookie.class }).invoke(this, new Cookie(name, _value.toString(), _attributes)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } _attributes.clear(); } _value.setLength(0); }
/** * Extracts cookies from a cookie header. Works in conjunction with a cookie press class, which actually creates * the cookies and adds them to the jar as appropriate. * * 1. Parse the header into tokens, separated by ',' and ';' (respecting single and double quotes) * 2. Process tokens from the end: * a. if the token contains an '=' we have a name/value pair. Add them to the cookie press, which * will decide if it is a cookie name or an attribute name. * b. if the token is a reserved word, flush the cookie press and continue. * c. otherwise, add the token to the cookie press, passing along the last character of the previous token. */ void findCookies( String cookieHeader ) { Vector tokens = getCookieTokens( cookieHeader ); for (int i = tokens.size() - 1; i >= 0; i--) { String token = (String) tokens.elementAt( i ); int equalsIndex = getEqualsIndex( token ); if (equalsIndex != -1) { _press.addTokenWithEqualsSign( this, token, equalsIndex ); } else if (isCookieReservedWord( token )) { _press.clear(); } else { _press.addToken( token, lastCharOf( (i == 0) ? "" : (String) tokens.elementAt( i - 1 ) ) ); } } }
/** * Extracts cookies from a cookie header. Works in conjunction with a cookie press class, which actually creates * the cookies and adds them to the jar as appropriate. * * 1. Parse the header into tokens, separated by ',' and ';' (respecting single and double quotes) * 2. Process tokens from the end: * a. if the token contains an '=' we have a name/value pair. Add them to the cookie press, which * will decide if it is a cookie name or an attribute name. * b. if the token is a reserved word, flush the cookie press and continue. * c. otherwise, add the token to the cookie press, passing along the last character of the previous token. */ void findCookies( String cookieHeader ) { Vector tokens = getCookieTokens( cookieHeader ); for (int i = tokens.size() - 1; i >= 0; i--) { String token = (String) tokens.elementAt( i ); int equalsIndex = getEqualsIndex( token ); if (equalsIndex != -1) { _press.addTokenWithEqualsSign( this, token, equalsIndex ); } else if (isCookieReservedWord( token )) { _press.clear(); } else { _press.addToken( token, lastCharOf( (i == 0) ? "" : (String) tokens.elementAt( i - 1 ) ) ); } } }
/** * add from a token * @param recipe - the recipe to use * @param token - the token to use * @param equalsIndex - the position of the equal sign */ void addTokenWithEqualsSign( CookieRecipe recipe, String token, int equalsIndex ) { String name = token.substring( 0, equalsIndex ).trim(); String value= token.substring( equalsIndex + 1 ).trim(); _value.insert( 0, value ); if (recipe.isCookieAttribute( name.toLowerCase() )) { _attributes.put( name.toLowerCase(), _value.toString() ); } else { addCookieIfValid( new Cookie( name, _value.toString(), _attributes ) ); _attributes.clear(); } _value.setLength(0); }
/** * Extracts cookies from a cookie header. Works in conjunction with a cookie press class, which actually creates * the cookies and adds them to the jar as appropriate. * * 1. Parse the header into tokens, separated by ',' and ';' (respecting single and double quotes) * 2. Process tokens from the end: * a. if the token contains an '=' we have a name/value pair. Add them to the cookie press, which * will decide if it is a cookie name or an attribute name. * b. if the token is a reserved word, flush the cookie press and continue. * c. otherwise, add the token to the cookie press, passing along the last character of the previous token. */ void findCookies( String cookieHeader ) { Vector tokens = getCookieTokens( cookieHeader ); for (int i = tokens.size() - 1; i >= 0; i--) { String token = (String) tokens.elementAt( i ); int equalsIndex = getEqualsIndex( token ); if (equalsIndex != -1) { _press.addTokenWithEqualsSign( this, token, equalsIndex ); } else if (isCookieReservedWord( token )) { _press.clear(); } else { _press.addToken( token, lastCharOf( (i == 0) ? "" : (String) tokens.elementAt( i - 1 ) ) ); } } }
/** * add from a token * @param recipe - the recipe to use * @param token - the token to use * @param equalsIndex - the position of the equal sign */ void addTokenWithEqualsSign( CookieRecipe recipe, String token, int equalsIndex ) { String name = token.substring( 0, equalsIndex ).trim(); String value= token.substring( equalsIndex + 1 ).trim(); _value.insert( 0, value ); if (recipe.isCookieAttribute( name.toLowerCase() )) { _attributes.put( name.toLowerCase(), _value.toString() ); } else { addCookieIfValid( new Cookie( name, _value.toString(), _attributes ) ); _attributes.clear(); } _value.setLength(0); }
/** * add from a token * @param recipe - the recipe to use * @param token - the token to use * @param equalsIndex - the position of the equal sign */ void addTokenWithEqualsSign( CookieRecipe recipe, String token, int equalsIndex ) { String name = token.substring( 0, equalsIndex ).trim(); String value= token.substring( equalsIndex + 1 ).trim(); _value.insert( 0, value ); if (recipe.isCookieAttribute( name.toLowerCase() )) { _attributes.put( name.toLowerCase(), _value.toString() ); } else { addCookieIfValid( new Cookie( name, _value.toString(), _attributes ) ); _attributes.clear(); } _value.setLength(0); }
/** * find the cookies in the given Header String array * @param cookieHeader - the strings to look for cookies * @param recipe - the recipe to use */ private void findCookies( String cookieHeader[], CookieRecipe recipe ) { for (int i = 0; i < cookieHeader.length; i++) { recipe.findCookies( cookieHeader[i] ); } }
/** * find the cookies in the given Header String array * @param cookieHeader - the strings to look for cookies * @param recipe - the recipe to use */ private void findCookies( String cookieHeader[], CookieRecipe recipe ) { for (int i = 0; i < cookieHeader.length; i++) { recipe.findCookies( cookieHeader[i] ); } }
/** * find the cookies in the given Header String array * @param cookieHeader - the strings to look for cookies * @param recipe - the recipe to use */ private void findCookies( String cookieHeader[], CookieRecipe recipe ) { for (int i = 0; i < cookieHeader.length; i++) { recipe.findCookies( cookieHeader[i] ); } }
/** * Returns the index (if any) of the equals sign separating a cookie name from the its value. * Equals signs at the end of the token are ignored in this calculation, since they may be * part of a Base64-encoded value. */ private int getEqualsIndex( String token ) { if (!token.endsWith( "==" )) { return token.indexOf( '=' ); } else { return getEqualsIndex( token.substring( 0, token.length()-2 ) ); } }
/** * Returns the index (if any) of the equals sign separating a cookie name from the its value. * Equals signs at the end of the token are ignored in this calculation, since they may be * part of a Base64-encoded value. */ private int getEqualsIndex( String token ) { if (!token.endsWith( "==" )) { return token.indexOf( '=' ); } else { return getEqualsIndex( token.substring( 0, token.length()-2 ) ); } }
/** * Returns the index (if any) of the equals sign separating a cookie name from the its value. * Equals signs at the end of the token are ignored in this calculation, since they may be * part of a Base64-encoded value. */ private int getEqualsIndex( String token ) { if (!token.endsWith( "==" )) { return token.indexOf( '=' ); } else { return getEqualsIndex( token.substring( 0, token.length()-2 ) ); } }
public void addTokenWithEqualsSign(CookieRecipe recipe, String token, int equalsIndex) { final String name = token.substring(0, equalsIndex).trim(); final String value = token.substring(equalsIndex + 1).trim(); StringBuffer _value = getFieldValue("_value", StringBuffer.class); _value.insert(0, value); HashMap _attributes = getFieldValue("_attributes", HashMap.class); if (recipe.isCookieAttribute(name.toLowerCase())) { _attributes.put(name.toLowerCase(), _value.toString()); } else { try { getAccessibleMethod(CookiePress.class, "addCookieIfValid", new Class[] { Cookie.class }).invoke(this, new Cookie(name, _value.toString(), _attributes)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } _attributes.clear(); } _value.setLength(0); }
private void findCookies(String cookieHeader[], CookieRecipe recipe) { for (String element : cookieHeader) { recipe.findCookies(element); } }
private void findCookies(String cookieHeader[], CookieRecipe recipe) { for (String element : cookieHeader) { recipe.findCookies(element); } }