private void storeCookieToDomainStore(Map<String, Cookie> domainStore, String cookieString) { // the specification dictates that the first name/value pair // in the string is the cookie name and value, so let's handle // them as a special case: Cookie cookie = null; StringTokenizer st = new StringTokenizer(cookieString, COOKIE_VALUE_DELIMITER); while (st.hasMoreTokens()) { String token = st.nextToken(); int index = token.indexOf(NAME_VALUE_SEPARATOR); if (index < 0 || index >= token.length()) { if (cookie == null) { // e Logger.e(TAG, "Invalid cookie string: " + cookieString); return; } Logger.v(TAG, "Not a value/pair, ignore for now as we don't use it: " + token); continue; } // value pair String name = token.substring(0, index).toLowerCase(Locale.US); String value = token.substring(index + 1); if (cookie == null) { cookie = new Cookie(value); domainStore.put(name, cookie); } if (EXPIRES.equals(name)) { cookie.expires = value; } else if (PATH.equals(name)) { cookie.path = value; } /*else { // don't have any use for this part of the cookie // ... }*/ } }
/** * the method called by the DefaultCookiePolicyHandler. * * @return true if the cookie should be accepted */ public synchronized boolean accept(Cookie cookie, DefaultCookiePolicyHandler h, String server) { // set the new values name_value_label.setText(cookie.getName() + "=" + cookie.getValue()); domain_value.setText(cookie.getDomain()); path_value.setText(cookie.getPath()); if (cookie.expires() == null) expires_value.setText("never"); else expires_value.setText(cookie.expires().toString()); int pos = 2; if (cookie.isSecure()) add(secure_note, constr, pos++); if (cookie.discard()) add(discard_note, constr, pos++); if (cookie instanceof Cookie2) { Cookie2 cookie2 = (Cookie2) cookie; // set ports list if (cookie2.getPorts() != null) { ((GridLayout) left_panel.getLayout()).setRows(5); left_panel.add(ports_label, 2); ((GridLayout) right_panel.getLayout()).setRows(5); int[] ports = cookie2.getPorts(); StringBuffer plist = new StringBuffer(); plist.append(ports[0]); for (int idx = 1; idx < ports.length; idx++) { plist.append(", "); plist.append(ports[idx]); } ports_value.setText(plist.toString()); right_panel.add(ports_value, 2); } // set comment url if (cookie2.getCommentURL() != null) { c_url_note.setText("For more info on this cookie see: " + cookie2.getCommentURL()); add(c_url_note, constr, pos++); } // set comment if (cookie2.getComment() != null) { comment_value.setText(cookie2.getComment()); add(comment_label, constr, pos++); add(comment_value, constr, pos++); } } // invalidate all labels, so that new values are displayed correctly name_value_label.invalidate(); domain_value.invalidate(); ports_value.invalidate(); path_value.invalidate(); expires_value.invalidate(); left_panel.invalidate(); right_panel.invalidate(); secure_note.invalidate(); discard_note.invalidate(); c_url_note.invalidate(); comment_value.invalidate(); invalidate(); // set default domain test domain.setText(cookie.getDomain()); // display setResizable(true); pack(); setResizable(false); setLocation( (screen.width - getPreferredSize().width) / 2, (int) ((screen.height - getPreferredSize().height) / 2 * .7)); setVisible(true); default_focus.requestFocus(); // wait for user input try { wait(); } catch (InterruptedException e) { } setVisible(false); // reset popup remove(secure_note); remove(discard_note); left_panel.remove(ports_label); ((GridLayout) left_panel.getLayout()).setRows(4); right_panel.remove(ports_value); ((GridLayout) right_panel.getLayout()).setRows(4); remove(c_url_note); remove(comment_label); remove(comment_value); // handle accept/reject domain buttons if (accept_domain) { String dom = domain.getText().trim().toLowerCase(); if (accept) h.addAcceptDomain(dom); else h.addRejectDomain(dom); } return accept; }