andruhon commented on a change in pull request #376: WICKET-6682 add CSP nonce support: DecoratingHeaderResponse approach URL: https://github.com/apache/wicket/pull/376#discussion_r303316003
########## File path: wicket-util/src/main/java/org/apache/wicket/util/value/AttributeMap.java ########## @@ -46,4 +48,76 @@ public AttributeMap(final Map<String, Object> map) { super(map); } + + /** + * Convenience method to put a value by {@link IAttributeMapKey} + * <p> + * see {@link #put(String, Object)} + */ + public Object put(IAttributeMapKey key, Object value) + { + return super.put(key.getAttributeKey(), value); + } + + /** + * Convenience method to add a value by {@link IAttributeMapKey} + * <p> + * see {@link #add(String, String)} + */ + public Object add(IAttributeMapKey key, String value) + { + return super.add(key.getAttributeKey(), value); + } + + /** + * Returns an {@link AttributeMap} containing single mapping. + * <p> + * Similar to {@link #of(Object, Object)}, but returns mutable map. + */ + public static AttributeMap of(IAttributeMapKey k1, String v1) + { + AttributeMap map = new AttributeMap(); + map.add(k1, v1); + return map; + } + + /** + * Returns an {@link AttributeMap} containing two mappings. + * <p> + * Similar to {@link #of(Object, Object)}, but returns mutable map. + */ + public static AttributeMap of(IAttributeMapKey k1, String v1, IAttributeMapKey k2, String v2) + { + AttributeMap map = new AttributeMap(); + map.add(k1, v1); + map.add(k2, v2); + return map; + } + + /** + * Returns an {@link AttributeMap} containing three mappings. + * <p> + * Similar to {@link #of(Object, Object)}, but returns mutable map. + */ + public static AttributeMap of(IAttributeMapKey k1, String v1, IAttributeMapKey k2, String v2, IAttributeMapKey k3, String v3) + { + AttributeMap map = new AttributeMap(); + map.add(k1, v1); + map.add(k2, v2); + map.add(k3, v3); + return map; + } + + /** + * Convenience method computing value for {@link IAttributeMapKey}. + * A convenience method for {@link #compute(Object, BiFunction)}, + * Which accepts simple supplier as value. + * <p> + * Doesn't add a mapping if computed value is <code>null</code> + */ + public Object compute(IAttributeMapKey key, Supplier supplier) Review comment: @martin-g The BiFunction would bring it to this look: `attrs.compute(key, (s, o) -> Application.getNonce())`, and the current look with a Supplier is `attrs.compute(key, Application::getNonce)`. I can switch to BiFunction if you insist. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services