Example usage for org.apache.wicket Session getLocale

List of usage examples for org.apache.wicket Session getLocale

Introduction

In this page you can find the example usage for org.apache.wicket Session getLocale.

Prototype

public Locale getLocale() 

Source Link

Document

Get this session's locale.

Usage

From source file:almira.sample.web.MainApplication.java

License:Apache License

@Override
public final Session newSession(org.apache.wicket.request.Request request,
        org.apache.wicket.request.Response response) {
    Session session = super.newSession(request, response);

    // make sure we get rid of 'country' to match keys in the language
    // choice component
    session.setLocale(new Locale(session.getLocale().getLanguage()));

    return session;
}

From source file:org.geoserver.web.GeoServerApplication.java

License:Open Source License

@Override
public Session newSession(Request request, Response response) {
    Session s = new GeoServerSession(request);
    if (s.getLocale() == null)
        s.setLocale(Locale.ENGLISH);
    return s;//  w  ww  .j av  a  2 s  .  c o  m
}

From source file:org.hippoecm.frontend.plugins.standards.icon.BrowserStyle.java

License:Apache License

private static boolean customResourceExists(final String packageResourcePath, final Session session) {
    final String customResourceKey = packageResourcePath + session.getLocale() + session.getStyle();
    if (!customPackageResourceExists.containsKey(customResourceKey)) {
        Boolean resourceExists = PackageResource.exists(BrowserStyle.class, packageResourcePath,
                session.getLocale(), session.getStyle(), null);
        customPackageResourceExists.put(customResourceKey, resourceExists);
        return resourceExists;
    } else {//w  w w.  ja v  a 2 s  . c o  m
        return customPackageResourceExists.get(customResourceKey);
    }
}

From source file:org.hippoecm.frontend.plugins.standards.icon.BrowserStyle.java

License:Apache License

private static ResourceReference createResourceReference(final String path, final Session session) {
    return new PackageResourceReference(BrowserStyle.class, path, session.getLocale(), session.getStyle(),
            null);//ww  w.j a  v a  2s. c  o  m
}

From source file:org.hippoecm.frontend.plugins.standards.util.ByteSizeFormatterTest.java

License:Apache License

@Before
public void before() throws Exception {
    Session session = EasyMock.createNiceMock(Session.class);
    EasyMock.expect(session.getLocale()).andReturn(Locale.FRANCE).anyTimes();
    EasyMock.replay(session);//from   w  w  w. j  a  v  a 2  s .  co  m
    ThreadContext.setSession(session);
}

From source file:org.hippoecm.frontend.plugins.standards.util.ByteSizeFormatterTest.java

License:Apache License

@Test
public void testSizeFormattingInUSALocale() throws Exception {
    Session session = EasyMock.createNiceMock(Session.class);
    EasyMock.expect(session.getLocale()).andReturn(Locale.US).anyTimes();
    EasyMock.replay(session);//from ww w .  jav a2  s.c om
    ThreadContext.setSession(session);

    long size = 1024 + 512 + 32; // 1.5.. (with more fractions, but rounded to 1.5) KB
    ByteSizeFormatter formatter = new ByteSizeFormatter(1);
    assertEquals("1.5 KB", formatter.format(size));
}

From source file:org.hippoecm.frontend.plugins.standards.util.ByteSizeFormatterTest.java

License:Apache License

@Test
public void testSizeFormattingInFranceLocale() throws Exception {
    Session session = EasyMock.createNiceMock(Session.class);
    EasyMock.expect(session.getLocale()).andReturn(Locale.FRANCE).anyTimes();
    EasyMock.replay(session);/* w  w w . ja  v  a2s. c o m*/
    ThreadContext.setSession(session);

    long size = 1024 + 512 + 32; // 1.5.. (with more fractions, but rounded to 1.5) KB
    ByteSizeFormatter formatter = new ByteSizeFormatter(1);
    assertEquals("1,5 KB", formatter.format(size));
}

From source file:org.obiba.onyx.wicket.model.SpringStringResourceModel.java

License:Open Source License

protected Object load() {
    // Initialize information that we need to work successfully

    Session session = Session.get();
    if (session != null) {
        locale = session.getLocale();
    }// ww w .ja  v  a  2s.co  m
    Application application = Application.get();
    if (application instanceof SpringWebApplication) {
        context = ((SpringWebApplication) application).getSpringContextLocator().getSpringContext();
    } else if (application instanceof ISpringWebApplication) {
        context = ((ISpringWebApplication) application).getSpringContextLocator().getSpringContext();
    }

    if (locale == null || context == null) {
        throw new WicketRuntimeException(
                "Cannot attach a string resource model without a Session context or a valid Application context because that is required to get a Spring application Context");
    }
    return getStringResource();
}

From source file:org.wicketstuff.js.ext.ExtObservableHelper.java

License:Apache License

static JSONObject renderResources(final IExtObservable extObservable, Class<?> baseClass) throws JSONException {
    JSONObject resources = new JSONObject();

    IPropertiesFactory propertiesFactory = Application.get().getResourceSettings().getPropertiesFactory();
    Session session = Session.get();
    String style = session.getStyle();
    Locale locale = session.getLocale();

    Class<?> clazz = extObservable.getClass();
    while (clazz != baseClass) {
        String path = clazz.getName().replace('.', '/');
        ResourceNameIterator iter = new ResourceNameIterator(path, style, null, locale, null, false);
        while (iter.hasNext()) {
            String newPath = iter.next();

            final Properties props = propertiesFactory.load(clazz, newPath);
            if (props != null) {
                ValueMap all = props.getAll();
                for (Map.Entry<String, Object> entry : all.entrySet()) {
                    if (!resources.has(entry.getKey())) {
                        resources.put(entry.getKey(), entry.getValue());
                    }/*from w ww  .  j  av  a2  s. com*/
                }
            }
        }
        clazz = clazz.getSuperclass();
    }
    return resources;
}