Repository: wicket
Updated Branches:
  refs/heads/master 0f4b60ac4 -> 88a071e43


WICKET-5771 Ability to escape resource bundle messages added with wicket:message

Non functional improvements:
fix javadoc errors, cache and reuse local variable, extract constants for the 
attributes, Java 7 diamonds


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/88a071e4
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/88a071e4
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/88a071e4

Branch: refs/heads/master
Commit: 88a071e439e0b8be668632ba19d7e4cc23dcd16a
Parents: 0f4b60a
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Sun Nov 23 23:57:51 2014 +0100
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Sun Nov 23 23:57:51 2014 +0100

----------------------------------------------------------------------
 .../markup/resolver/WicketMessageResolver.java  | 24 +++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/88a071e4/wicket-core/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
 
b/wicket-core/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
index 267626d..d2f841f 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/resolver/WicketMessageResolver.java
@@ -35,6 +35,7 @@ import org.apache.wicket.request.Response;
 import org.apache.wicket.response.StringResponse;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
+import org.apache.wicket.util.value.IValueMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -84,7 +85,7 @@ import org.slf4j.LoggerFactory;
  * It is possible to switch between logging a warning and throwing an 
exception if either the
  * property key/value or any of the variables can not be found.
  *
- * @see 
org.apache.wicket.settings.IResourceSettings#setThrowExceptionOnMissingResource(boolean)
+ * @see 
org.apache.wicket.settings.ResourceSettings#setThrowExceptionOnMissingResource(boolean)
  * @author Juergen Donnerstag
  * @author John Ray
  */
@@ -104,6 +105,16 @@ public class WicketMessageResolver implements 
IComponentResolver
         */
        private static final String DEFAULT_VALUE = 
"DEFAULT_WICKET_MESSAGE_RESOLVER_VALUE";
 
+       /**
+        * The name of the attribute that defines the resource key
+        */
+       public static final String KEY_ATTRIBUTE = "key";
+
+       /**
+        * The name of the attribute that defines whether the resource value 
should be HTML escaped
+        */
+       public static final String ESCAPE_ATTRIBUTE = "escape";
+
        @Override
        public Component resolve(final MarkupContainer container, final 
MarkupStream markupStream,
                final ComponentTag tag)
@@ -113,14 +124,15 @@ public class WicketMessageResolver implements 
IComponentResolver
                        WicketTag wtag = (WicketTag)tag;
                        if (wtag.isMessageTag())
                        {
-                               String messageKey = 
wtag.getAttributes().getString("key");
-                               if ((messageKey == null) || 
(messageKey.trim().length() == 0))
+                               IValueMap attributes = wtag.getAttributes();
+                               String messageKey = 
attributes.getString(KEY_ATTRIBUTE);
+                               if (Strings.isEmpty(messageKey))
                                {
                                        throw new MarkupException(
                                                "Wrong format of 
<wicket:message key='xxx'>: attribute 'key' is missing");
                                }
 
-                               boolean escape = 
wtag.getAttributes().getBoolean("escape");
+                               boolean escape = 
attributes.getBoolean(ESCAPE_ATTRIBUTE);
 
                                final String id = "_message_" + 
container.getPage().getAutoIndex();
                                MessageContainer label = new 
MessageContainer(id, messageKey, escape);
@@ -168,10 +180,10 @@ public class WicketMessageResolver implements 
IComponentResolver
                 * @param messageKey
                 * @param escapeValue
                 */
-               public MessageContainer(final String id, final String 
messageKey, boolean escapeValue)
+               private MessageContainer(final String id, final String 
messageKey, boolean escapeValue)
                {
                        // The message key becomes the model
-                       super(id, new Model<String>(messageKey));
+                       super(id, new Model<>(messageKey));
                        this.escapeValue = escapeValue;
 
                        setEscapeModelStrings(false);

Reply via email to