Sets the value for the given cookie attribute. When a value is set via this method, the value returned by the attribute specific getter (if any) must be consistent with the value set via this method. @param name Name of attribute to set @param value Value of attribute @throws IllegalArgumentExcep
(String name, String value)
| 395 | * @since Servlet 6.0 |
| 396 | */ |
| 397 | public void setAttribute(String name, String value) { |
| 398 | if (name == null) { |
| 399 | throw new IllegalArgumentException(LSTRINGS.getString("cookie.attribute.invalidName.null")); |
| 400 | } |
| 401 | if (!validation.isToken(name)) { |
| 402 | String msg = LSTRINGS.getString("cookie.attribute.invalidName.notToken"); |
| 403 | throw new IllegalArgumentException(MessageFormat.format(msg, name)); |
| 404 | } |
| 405 | |
| 406 | if (name.equalsIgnoreCase(MAX_AGE)) { |
| 407 | if (value == null) { |
| 408 | setAttributeInternal(MAX_AGE, null); |
| 409 | } else { |
| 410 | // Integer.parseInt throws NFE if required |
| 411 | setMaxAge(Integer.parseInt(value)); |
| 412 | } |
| 413 | } else { |
| 414 | setAttributeInternal(name, value); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | |
| 419 | private void setAttributeInternal(String name, String value) { |