@@ -57,24 +57,12 @@ public class ResourceUtil
57
57
*/
58
58
public static ResourceReference .UrlAttributes decodeResourceReferenceAttributes (String encodedAttributes )
59
59
{
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 ;
63
65
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
- }
78
66
return new ResourceReference .UrlAttributes (locale , style , variation );
79
67
}
80
68
@@ -114,37 +102,18 @@ public static ResourceReference.UrlAttributes decodeResourceReferenceAttributes(
114
102
public static String encodeResourceReferenceAttributes (ResourceReference .UrlAttributes attributes )
115
103
{
116
104
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 ))
130
106
{
131
- res .append ('-' );
132
- res .append (escapeAttributesSeparator (attributes .getStyle ()));
107
+ return null ;
133
108
}
134
- if (! Strings . isEmpty ( attributes . getVariation ()))
109
+ else
135
110
{
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 ();
145
116
}
146
- return res .toString ();
147
- }
148
117
}
149
118
150
119
/**
0 commit comments