You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2015/06/04 16:20:02 UTC
[8/9] wicket git commit: [WICKET-5909] Session style is not taken
into account when loading mounted resources.
[WICKET-5909] Session style is not taken into account when loading mounted resources.
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/b9f600f4
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/b9f600f4
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/b9f600f4
Branch: refs/heads/WICKET-5906-7.x
Commit: b9f600f44ccef68c5c644f1e13e8d3d5dbcf1033
Parents: 93ad80d
Author: Andrea Del Bene <“adelbene@apache.org”>
Authored: Wed Jun 3 15:10:13 2015 +0200
Committer: Andrea Del Bene <“adelbene@apache.org”>
Committed: Thu Jun 4 16:19:29 2015 +0200
----------------------------------------------------------------------
.../resource/PackageResourceReference.java | 1 +
.../apache/wicket/resource/ResourceUtil.java | 63 ++++++++++++++++----
.../org/apache/wicket/util/lang/Objects.java | 19 ++++--
.../org/apache/wicket/util/string/Strings.java | 21 ++++---
4 files changed, 81 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
index c7f8da1..e50dbc6 100644
--- a/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/request/resource/PackageResourceReference.java
@@ -125,6 +125,7 @@ public class PackageResourceReference extends ResourceReference
final PackageResource resource;
final Url url = RequestCycle.get().getRequest().getUrl();
+ //resource attributes (locale, style, variation) might be encoded in the URL
final UrlAttributes urlAttributes = ResourceUtil.decodeResourceReferenceAttributes(url);
if (CSS_EXTENSION.equals(extension))
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
index b94ad25..6e55197 100644
--- a/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
+++ b/wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java
@@ -37,30 +37,47 @@ import org.apache.wicket.util.string.Strings;
*/
public class ResourceUtil
{
-
- public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String attributes)
+ /**
+ * Reads resource reference attributes (style, locale, variation) encoded in the given string.
+ *
+ * @param encodedAttributes
+ * the string containing the resource attributes
+ * @return the encoded attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
+ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String encodedAttributes)
{
Locale locale = null;
String style = null;
String variation = null;
- if (Strings.isEmpty(attributes) == false)
+ if (Strings.isEmpty(encodedAttributes) == false)
{
- String split[] = Strings.split(attributes, '-');
+ String split[] = Strings.split(encodedAttributes, '-');
locale = parseLocale(split[0]);
if (split.length == 2)
{
- style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
+ style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
}
else if (split.length == 3)
{
- style = Strings.notEmpty(unescapeAttributesSeparator(split[1]), null);
- variation = Strings.notEmpty(unescapeAttributesSeparator(split[2]), null);
+ style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
+ variation = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[2]), null);
}
}
return new ResourceReference.UrlAttributes(locale, style, variation);
}
-
+
+ /**
+ * Reads resource reference attributes (style, locale, variation) encoded in the given URL.
+ *
+ * @param url
+ * the url containing the resource attributes
+ * @return the encoded attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(Url url)
{
Args.notNull(url, "url");
@@ -76,6 +93,15 @@ public class ResourceUtil
return new ResourceReference.UrlAttributes(null, null, null);
}
+ /**
+ * Encodes the given resource reference attributes returning the corresponding textual representation.
+ *
+ * @param attributes
+ * the resource reference attributes to encode
+ * @return the textual representation for the given attributes
+ *
+ * @see ResourceReference.UrlAttributes
+ */
public static String encodeResourceReferenceAttributes(ResourceReference.UrlAttributes attributes)
{
if (attributes == null ||
@@ -111,7 +137,17 @@ public class ResourceUtil
return res.toString();
}
}
-
+
+ /**
+ * Encodes the attributes of the given resource reference in the specified url.
+ *
+ * @param url
+ * the resource reference attributes to encode
+ * @param reference
+ *
+ * @see ResourceReference.UrlAttributes
+ * @see Url
+ */
public static void encodeResourceReferenceAttributes(Url url, ResourceReference reference)
{
String encoded = encodeResourceReferenceAttributes(reference.getUrlAttributes());
@@ -134,7 +170,14 @@ public class ResourceUtil
CharSequence tmp = Strings.replaceAll(attribute, "~", "~~");
return Strings.replaceAll(tmp, "-", "~");
}
-
+
+ /**
+ * Parses the string representation of a {@link java.util.Locale} (for example 'en_GB').
+ *
+ * @param locale
+ * the string representation of a {@link java.util.Locale}
+ * @return the corresponding {@link java.util.Locale} instance
+ */
public static Locale parseLocale(String locale)
{
if (Strings.isEmpty(locale))
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
index 42b14c5..787778b 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/lang/Objects.java
@@ -767,14 +767,25 @@ public final class Objects
}
/**
+ * Returns the original object if this one is != null. If the original object is null
+ * the default one is returned. The default object has no restriction, it might be itself null.
+ *
+ * @param originalObj
+ * the original object
+ * @param defaultObj
+ * the default object
+ * @return the original object if not null, the default one otherwise.
+ */
+ public static <T> T defaultIfNull(T originalObj, T defaultObj)
+ {
+ return originalObj != null ? originalObj : defaultObj;
+ }
+
+ /**
* Instantiation not allowed
*/
private Objects()
{
}
- public static <T> T defaultIfNull(T originalObj, T defaultObj)
- {
- return originalObj != null ? originalObj : defaultObj;
- }
}
http://git-wip-us.apache.org/repos/asf/wicket/blob/b9f600f4/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
----------------------------------------------------------------------
diff --git a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
index a9a54b9..3ac1c10 100755
--- a/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
+++ b/wicket-util/src/main/java/org/apache/wicket/util/string/Strings.java
@@ -1563,15 +1563,18 @@ public final class Strings
}
}
- public static String notEmpty(String originalString, String normalizedValue)
+ /**
+ * Returns the original string if this one is not empty (i.e. {@link #isEmpty(CharSequence)} returns false),
+ * otherwise the default one is returned. The default string might be itself an empty one.
+ *
+ * @param originalString
+ * the original sting value
+ * @param defaultValue
+ * the default string to return if the original is empty
+ * @return the original string value if not empty, the default one otherwise
+ */
+ public static String defaultIfEmpty(String originalString, String defaultValue)
{
- if (isEmpty(originalString))
- {
- return normalizedValue;
- }
- else
- {
- return originalString;
- }
+ return isEmpty(originalString) ? defaultValue : originalString;
}
}