So this is what I have for now.

class MobileStreamLocator extends ResourceStreamLocator implements
IResourceStreamLocator {

public IResourceStream locate(final Class<?> clazz, String path, final
String style, final Locale locale,
final String extension) {

StringBuilder newExtensions = new StringBuilder();
newExtensions.append(extension);

// Are we running on a device mobile?
if (Session.get() instanceof MobileSession) {
MobileSession ms = (MobileSession) Session.get();
if (ms.isMobileSessionActive()) {
newExtensions = new StringBuilder();
String device = ms.getDeviceId();
if (device != null) {
newExtensions.append(device + "." + extension).append(",");
}
newExtensions.append(ms.getFallbackDeviceId() + "." +
extension).append(",");
newExtensions.append(extension);
}
}

return super.locate(clazz, path, style, locale, newExtensions.toString());
}

}

What this does is to try the following names:

1a. <path>_<style>_<locale>.<mobile>.<extension>
1b. <path>_<style>_<locale>.<fallback>.<extension>
1c. <path>_<style>_<locale>.<extension>

2a. <path>_<locale>.<mobile>.<extension>
2b. <path>_<locale>.<fallback>.<extension>
2c. <path>_<locale>.<extension>

3a. <path>_<style>.<mobile>.<extension>
3b. <path>_<style>.<fallback>.<extension>
3c. <path>_<style>.<extension>

4a. <path>.<mobile>.<extension>
4b. <path>.<fallback>.<extension>
4c. <path>.<extension>

Where <mobile> can be something like "android", "iphone", "blackberry", and
<fallback> can be something like "m" (for... duh... generic mobile).

What do you guys think of this?

Bruno Borges
www.brunoborges.com.br
+55 21 76727099

"The glory of great men should always be
measured by the means they have used to
acquire it."
 - Francois de La Rochefoucauld



On Mon, Mar 28, 2011 at 4:55 PM, Bruno Borges <[email protected]>wrote:

> I'm playing with Wurfl and mobile development on Wicket now and I was
> looking at ResourceNameIterator.
>
> It seems to be the best place to have an extended version of the resource
> stream locator algorithm.
>
> What I want to do is to get this:
>
> 1. <path>_<style>_<locale>_<mobile>.<extension>
> 2. <path>_<locale>_<mobile>.<extension>
> 3. <path>_<style>_<mobile>.<extension>
> 4. <path>_<style>_<locale>.<extension>
> 5. <path>_<mobile>.<extension>
> 6. <path>_<locale>.<extension>
> 7. <path>_<style>.<extension>
> 8. <path>.<extension>
>
> Where <mobile> is a mobile device based on Wurfl XML.
>
> Would also be a great contribution to Wicket's core this stream locator
> pattern.
>
>
> Bruno Borges
> www.brunoborges.com.br
> +55 21 76727099
>
> "The glory of great men should always be
> measured by the means they have used to
> acquire it."
>  - Francois de La Rochefoucauld
>
>

Reply via email to