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); }
/** * may this cookie be sent to the given url? * @param url - the unform resource locator to check * @return true if the cookie is not expired and the path is accepted if a domain is set */ public boolean mayBeSentTo( URL url ) { if (getDomain() == null) return true; if (isExpired()) return false; return acceptHost( getDomain(), url.getHost() ) && acceptPath( getPath(), url.getPath() ); }
private boolean equals( Cookie other ) { return _name.equalsIgnoreCase( other._name ) && equalProperties( getDomain(), other.getDomain() ) && equalProperties( getPath(), other.getPath() ); }
/** * accept the given cookie * @param cookie * @return */ private boolean acceptCookie( Cookie cookie ) { if (cookie.getPath() == null) { cookie.setPath( getParentPath( _sourceURL.getPath() ) ); } else { int status = getPathAttributeStatus( cookie.getPath(), _sourceURL.getPath() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getPath(), cookie.getName() ); return false; } } if (cookie.getDomain() == null) { cookie.setDomain( _sourceURL.getHost() ); } else if (!CookieProperties.isDomainMatchingStrict() && cookie.getDomain().equalsIgnoreCase( _sourceURL.getHost() )) { cookie.setDomain( _sourceURL.getHost() ); } else { int status = getDomainAttributeStatus( cookie.getDomain(), _sourceURL.getHost() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getDomain(), cookie.getName() ); return false; } } return true; }
for (Iterator iterator = _globalCookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); _globalCookies.add( new Cookie( name, value ) );
/** * Returns the value of the cookie header to be sent to the specified URL. * Will return null if no compatible cookie is defined. **/ public String getCookieHeaderField( URL targetURL ) { if (_cookies.isEmpty() && _globalCookies.isEmpty()) return null; StringBuffer sb = new StringBuffer( DEFAULT_HEADER_SIZE ); HashSet restrictedCookies = new HashSet(); for (Iterator i = _cookies.iterator(); i.hasNext();) { Cookie cookie = (Cookie) i.next(); if (!cookie.mayBeSentTo( targetURL )) continue; restrictedCookies.add( cookie.getName() ); if (sb.length() != 0) sb.append( "; " ); sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ); } for (Iterator i = _globalCookies.iterator(); i.hasNext();) { Cookie cookie = (Cookie) i.next(); if (restrictedCookies.contains( cookie.getName() )) continue; if (sb.length() != 0) sb.append( "; " ); sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ); } return sb.length() == 0 ? null : sb.toString(); }
/** * Define a non-global cookie. This cookie can be overwritten by subsequent cookie definitions * in http headers. This cookie definition requires a domain and path. If a global cookie is * defined with the same name, this cookie is not added. */ public void putSingleUseCookie(String name, String value, String domain, String path) { for (Iterator iterator = _globalCookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) return; } for (Iterator iterator = _cookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) iterator.remove(); } _cookies.add( new Cookie( name, value, domain, path) ); }
/** * Constructs a cookie w/o any domain or path restrictions. * @param name - the name of the cookie * @param value - the value of the cookie * @param attributes - a map of attributes for the cookie */ Cookie( String name, String value, Map attributes ) { this( name, value ); for (Iterator iterator = attributes.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String attributeValue = (String) attributes.get( key ); if (key.equalsIgnoreCase( "path" )) { _path = attributeValue; } else if (key.equalsIgnoreCase( "domain" )) { _domain = attributeValue; } else if (key.equalsIgnoreCase( "max-age" )) { _expiredTime = System.currentTimeMillis() + getAgeInMsec( attributeValue ); } else if (key.equalsIgnoreCase( "expires" )) { _expiredTime = getAgeInMsecFromDate( attributeValue ); } } }
/** * Returns the name of all the active cookies in this cookie jar. **/ public String[] getCookieNames() { final int numGlobalCookies = _globalCookies.size(); String[] names = new String[ _cookies.size() + numGlobalCookies ]; for (int i = 0; i < numGlobalCookies; i++) { names[i] = ((Cookie) _globalCookies.get(i)).getName(); } for (int i = numGlobalCookies; i < names.length; i++) { names[i] = ((Cookie) _cookies.get( i-numGlobalCookies )).getName(); } return names; }
public boolean equals( Object obj ) { return obj.getClass() == getClass() && equals( (Cookie) obj ); }
/** * accept the given cookie * @param cookie * @return */ private boolean acceptCookie( Cookie cookie ) { if (cookie.getPath() == null) { cookie.setPath( getParentPath( _sourceURL.getPath() ) ); } else { int status = getPathAttributeStatus( cookie.getPath(), _sourceURL.getPath() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getPath(), cookie.getName() ); return false; } } if (cookie.getDomain() == null) { cookie.setDomain( _sourceURL.getHost() ); } else if (!CookieProperties.isDomainMatchingStrict() && cookie.getDomain().equalsIgnoreCase( _sourceURL.getHost() )) { cookie.setDomain( _sourceURL.getHost() ); } else { int status = getDomainAttributeStatus( cookie.getDomain(), _sourceURL.getHost() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getDomain(), cookie.getName() ); return false; } } return true; }
for (Iterator iterator = _globalCookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); _globalCookies.add( new Cookie( name, value ) );
/** * Returns the value of the cookie header to be sent to the specified URL. * Will return null if no compatible cookie is defined. **/ public String getCookieHeaderField( URL targetURL ) { if (_cookies.isEmpty() && _globalCookies.isEmpty()) return null; StringBuffer sb = new StringBuffer( DEFAULT_HEADER_SIZE ); HashSet restrictedCookies = new HashSet(); for (Iterator i = _cookies.iterator(); i.hasNext();) { Cookie cookie = (Cookie) i.next(); if (!cookie.mayBeSentTo( targetURL )) continue; restrictedCookies.add( cookie.getName() ); if (sb.length() != 0) sb.append( "; " ); sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ); } for (Iterator i = _globalCookies.iterator(); i.hasNext();) { Cookie cookie = (Cookie) i.next(); if (restrictedCookies.contains( cookie.getName() )) continue; if (sb.length() != 0) sb.append( "; " ); sb.append( cookie.getName() ).append( '=' ).append( cookie.getValue() ); } return sb.length() == 0 ? null : sb.toString(); }
/** * Define a non-global cookie. This cookie can be overwritten by subsequent cookie definitions * in http headers. This cookie definition requires a domain and path. If a global cookie is * defined with the same name, this cookie is not added. */ public void putSingleUseCookie(String name, String value, String domain, String path) { for (Iterator iterator = _globalCookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) return; } for (Iterator iterator = _cookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) iterator.remove(); } _cookies.add( new Cookie( name, value, domain, path) ); }
/** * Constructs a cookie w/o any domain or path restrictions. * @param name - the name of the cookie * @param value - the value of the cookie * @param attributes - a map of attributes for the cookie */ Cookie( String name, String value, Map attributes ) { this( name, value ); for (Iterator iterator = attributes.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); String attributeValue = (String) attributes.get( key ); if (key.equalsIgnoreCase( "path" )) { _path = attributeValue; } else if (key.equalsIgnoreCase( "domain" )) { _domain = attributeValue; } else if (key.equalsIgnoreCase( "max-age" )) { _expiredTime = System.currentTimeMillis() + getAgeInMsec( attributeValue ); } else if (key.equalsIgnoreCase( "expires" )) { _expiredTime = getAgeInMsecFromDate( attributeValue ); } } }
/** * Returns the name of all the active cookies in this cookie jar. **/ public String[] getCookieNames() { final int numGlobalCookies = _globalCookies.size(); String[] names = new String[ _cookies.size() + numGlobalCookies ]; for (int i = 0; i < numGlobalCookies; i++) { names[i] = ((Cookie) _globalCookies.get(i)).getName(); } for (int i = numGlobalCookies; i < names.length; i++) { names[i] = ((Cookie) _cookies.get( i-numGlobalCookies )).getName(); } return names; }
public boolean equals( Object obj ) { return obj.getClass() == getClass() && equals( (Cookie) obj ); }
/** * may this cookie be sent to the given url? * @param url - the unform resource locator to check * @return true if the cookie is not expired and the path is accepted if a domain is set */ public boolean mayBeSentTo( URL url ) { if (getDomain() == null) return true; if (isExpired()) return false; return acceptHost( getDomain(), url.getHost() ) && acceptPath( getPath(), url.getPath() ); }
/** * accept the given cookie * @param cookie * @return */ private boolean acceptCookie( Cookie cookie ) { if (cookie.getPath() == null) { cookie.setPath( getParentPath( _sourceURL.getPath() ) ); } else { int status = getPathAttributeStatus( cookie.getPath(), _sourceURL.getPath() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getPath(), cookie.getName() ); return false; } } if (cookie.getDomain() == null) { cookie.setDomain( _sourceURL.getHost() ); } else if (!CookieProperties.isDomainMatchingStrict() && cookie.getDomain().equalsIgnoreCase( _sourceURL.getHost() )) { cookie.setDomain( _sourceURL.getHost() ); } else { int status = getDomainAttributeStatus( cookie.getDomain(), _sourceURL.getHost() ); if (status != CookieListener.ACCEPTED) { reportCookieRejected( status, cookie.getDomain(), cookie.getName() ); return false; } } return true; }
for (Iterator iterator = _globalCookies.iterator(); iterator.hasNext();) { Cookie cookie = (Cookie) iterator.next(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); if (name.equals( cookie.getName() )) { foundCookie = true; if (value != null) { cookie.setValue(value); } else { iterator.remove(); _globalCookies.add( new Cookie( name, value ) );