Package org.xnap.commons.i18n

Examples of org.xnap.commons.i18n.I18n


        if (localesCache.keySet().contains(locale)) {
            return localesCache.get(locale);
        }

        I18n i18n = I18nFactory.getI18n(I18nHelper.class, locale,
                org.xnap.commons.i18n.I18nFactory.FALLBACK);

        // The language returned is not the same as the requested by the user
        if (!locale.getLanguage().equals(
                i18n.getResources().getLocale().getLanguage())) {
            // Force it to be default language
            i18n = getDefaultI18n();
        }
        localesCache.put(Locales.getCurrent(), i18n);
View Full Code Here


        }
        return null;
    }

    private static I18n getDefaultI18n() {
        I18n i18n = localesCache.get(defaultLang);
        if (i18n == null) {
            i18n = I18nFactory.getI18n(I18nHelper.class, defaultLang,
                    org.xnap.commons.i18n.I18nFactory.FALLBACK);
        }
        return i18n;
View Full Code Here

    public static I18n getI18n() {
        if (localesCache.keySet().contains(Locales.getCurrent())) {
            return localesCache.get(Locales.getCurrent());
        }

        I18n i18n = I18nFactory.getI18n(I18nHelper.class, "app.i18n.Messages", Locales.getCurrent(),
                org.xnap.commons.i18n.I18nFactory.FALLBACK);
        localesCache.put(Locales.getCurrent(), i18n);

        return i18n;
    }
View Full Code Here

    public void setUp() {
        MockitoAnnotations.initMocks(this);
        headers = new HttpHeadersImpl();
        headers.setRequestHeaders(new MultivaluedMapImpl<String, String>());
        when(request.getHttpHeaders()).thenReturn(headers);
        I18n i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
        when(injector.getInstance(I18n.class)).thenReturn(i18n);
        this.auth = new TrustedUserAuth(userService, injector);
    }
View Full Code Here

    public void setUp() {
        MockitoAnnotations.initMocks(this);
        headers = new HttpHeadersImpl();
        headers.setRequestHeaders(new MultivaluedMapImpl<String, String>());
        when(request.getHttpHeaders()).thenReturn(headers);
        I18n i18n = I18nFactory.getI18n(getClass(), Locale.US, I18nFactory.FALLBACK);
        when(injector.getInstance(I18n.class)).thenReturn(i18n);
        this.auth = new BasicAuth(userService, injector);
    }
View Full Code Here

        @Override
        public Consumer lookup(String key) {
            initialize();
            if (deletedConsumerCurator.countByConsumerUuid(key) > 0) {
                log.debug("Key " + key + " is deleted, throwing GoneException");
                I18n i18n = injector.getInstance(I18n.class);
                throw new GoneException(i18n.tr("Unit {0} has been deleted", key), key);
            }

            return consumerCurator.findByUuid(key);
        }
View Full Code Here

    }

    @Override
    public I18n get() {
        Locale locale = (request.getLocale() == null) ? Locale.US : request.getLocale();
        I18n i18n;

        // If the locale does not exist, xnap is pretty inefficient.
        // This cache will hold the records more efficiently.
        //
        // Make sure to keep the access wrapped in synchronized so we can
View Full Code Here

        super(userServiceAdapter, injector);
    }

    @Override
    public Principal getPrincipal(HttpRequest request) {
        I18n i18n = injector.getInstance(I18n.class);
        try {
            String auth = AuthUtil.getHeader(request, "Authorization");

            if (auth != null && auth.toUpperCase().startsWith("BASIC ")) {
                String userpassEncoded = auth.substring(6);
                String[] userpass = new String(Base64
                    .decodeBase64(userpassEncoded)).split(":", 2);
                String username = userpass[0];
                String password = null;
                if (userpass.length > 1) {
                    password = userpass[1];
                }

                log.debug("check for: " + username + " - password of length #" +
                    (password == null ? 0 : password.length()) + " = <omitted>");

                if (userServiceAdapter.validateUser(username, password)) {
                    Principal principal = createPrincipal(username);
                    if (log.isDebugEnabled()) {
                        log.debug("principal created for user '" + username);
                    }

                    return principal;
                }
                else {
                    throw new UnauthorizedException(i18n.tr("Invalid Credentials"));
                }
            }
        }
        catch (CandlepinException e) {
            if (log.isDebugEnabled()) {
                log.debug("Error getting principal " + e);
            }
            throw e;
        }
        catch (Exception e) {
            if (log.isDebugEnabled()) {
                log.debug("Error getting principal " + e);
            }
            throw new ServiceUnavailableException(i18n
                .tr("Error contacting user service"));
        }
        return null;
    }
View Full Code Here

    private Entitlement entStacked1, entStacked2;

    @Before
    public void setUp() {
        Locale locale = new Locale("en_US");
        I18n i18n = I18nFactory.getI18n(getClass(), "org.candlepin.i18n.Messages", locale,
            I18nFactory.FALLBACK);
        generator = new StatusReasonMessageGenerator(i18n);
        owner = new Owner("test");
        consumer = new Consumer();
        consumer.setType(new ConsumerType(ConsumerType.ConsumerTypeEnum.SYSTEM));
View Full Code Here

    private ParameterDescriptor desc;

    @Before
    public void setUp() throws Exception {
        I18n i18n = new I18nProvider(mockReq).get();
        desc = new ParameterDescriptor(i18n, "test-name", "test-desc");
    }
View Full Code Here

TOP

Related Classes of org.xnap.commons.i18n.I18n

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.