Skip to content

Commit 021c9e7

Browse files
author
Peter Lamby
committed
WICKET-6993 - Use new encoding mechanism
We can now use the encoding mechanism introduced in the previous commit to simplify the encoding and decoding of the entire resource attributes.
1 parent 4911b27 commit 021c9e7

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

wicket-core/src/main/java/org/apache/wicket/resource/ResourceUtil.java

+13-44
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,12 @@ public class ResourceUtil
5757
*/
5858
public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(String encodedAttributes)
5959
{
60-
Locale locale = null;
61-
String style = null;
62-
String variation = null;
60+
String[] decodeAttributes = decodeStringParts(encodedAttributes);
61+
62+
Locale locale = decodeAttributes.length > 0 ? parseLocale(decodeAttributes[0]) : null;
63+
String style = decodeAttributes.length > 1 ? decodeAttributes[1] : null;
64+
String variation = decodeAttributes.length > 2 ? decodeAttributes[2] : null;
6365

64-
if (Strings.isEmpty(encodedAttributes) == false)
65-
{
66-
String split[] = Strings.split(encodedAttributes, '-');
67-
locale = parseLocale(split[0]);
68-
if (split.length == 2)
69-
{
70-
style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
71-
}
72-
else if (split.length == 3)
73-
{
74-
style = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[1]), null);
75-
variation = Strings.defaultIfEmpty(unescapeAttributesSeparator(split[2]), null);
76-
}
77-
}
7866
return new ResourceReference.UrlAttributes(locale, style, variation);
7967
}
8068

@@ -114,37 +102,18 @@ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(
114102
public static String encodeResourceReferenceAttributes(ResourceReference.UrlAttributes attributes)
115103
{
116104
if (attributes == null ||
117-
(attributes.getLocale() == null && attributes.getStyle() == null && attributes.getVariation() == null))
118-
{
119-
return null;
120-
}
121-
else
122-
{
123-
StringBuilder res = new StringBuilder(32);
124-
if (attributes.getLocale() != null)
125-
{
126-
res.append(attributes.getLocale());
127-
}
128-
boolean styleEmpty = Strings.isEmpty(attributes.getStyle());
129-
if (!styleEmpty)
105+
(attributes.getLocale() == null && attributes.getStyle() == null && attributes.getVariation() == null))
130106
{
131-
res.append('-');
132-
res.append(escapeAttributesSeparator(attributes.getStyle()));
107+
return null;
133108
}
134-
if (!Strings.isEmpty(attributes.getVariation()))
109+
else
135110
{
136-
if (styleEmpty)
137-
{
138-
res.append("--");
139-
}
140-
else
141-
{
142-
res.append('-');
143-
}
144-
res.append(escapeAttributesSeparator(attributes.getVariation()));
111+
StringBuilder res = new StringBuilder(32);
112+
res.append(encodeStringPart(attributes.getLocale() == null ? null : attributes.getLocale().toString()));
113+
res.append(encodeStringPart(attributes.getStyle()));
114+
res.append(encodeStringPart(attributes.getVariation()));
115+
return res.toString();
145116
}
146-
return res.toString();
147-
}
148117
}
149118

150119
/**

0 commit comments

Comments
 (0)