Example usage for java.util Locale Locale

List of usage examples for java.util Locale Locale

Introduction

In this page you can find the example usage for java.util Locale Locale.

Prototype

public Locale(String language) 

Source Link

Document

Construct a locale from a language code.

Usage

From source file:hu.petabyte.redflags.web.svc.FilterEmailSvc.java

public boolean sendFilterLetters(HttpServletRequest request, HttpServletResponse response) {

    List<UserFilter> userFilters = userFilterRepo.findBySubscribeTrueOrderByUserIdAsc();
    for (UserFilter userFilter : userFilters) {
        // System.out.println(userFilter);

        // get user:
        Account a = accountRepo.findOne(userFilter.getUserId());
        if (null == a) {
            continue;
        }//from  ww w.  j ava 2s . c  o m
        Locale loc = new Locale(a.getLang());

        // date filter is irrelevant:
        String filter = userFilter.getFilter();
        filter = filter.replaceAll("date:[\\d\\-]+(\\||$)", "");

        List<Filter> filters = new Filters(filter).asList();

        // injecting after filter to get only fresh ones:
        filters.add(new Filter("after", userFilter.getLastSentNumber() + "-" + userFilter.getLastSentYear()));

        // query:
        long count = noticesSvc.count(filters);
        // System.out.println("COUNT: " + count);
        if (0 == count) {
            continue;
        }
        List<Map<String, Object>> query = noticesSvc.query(10, 0, false, filters);

        Map<String, Object> root = new HashMap<String, Object>();
        root.put("user", a.getName());
        root.put("count", count);
        root.put("notices", query);
        root.put("date", df.format(new Date()));
        root.put("filters", filters);
        root.put("resultsUrl", urlPrefix + "/notices/10/1/?filter=" + userFilter.getFilter());
        root.put("unsubscribeUrl", urlPrefix + "/filter/" + userFilter.getId());
        root.put("urlPrefix", urlPrefix);
        root.put("contactAddress", contactAddress);

        String text = email.text("filter-email", root, request, response, loc);
        if (null != text) {
            String subject = msg.getMessage("filter.email.subject", null, loc) + " "
                    + (null == userFilter.getName() || userFilter.getName().trim().isEmpty()
                            ? "#" + userFilter.getId()
                            : userFilter.getName());
            String to = a.getEmailAddress();
            if (email.send(to, subject, text)) {
                // success
                filterSvc.fillLastNoticeId(userFilter);
                userFilterRepo.save(userFilter);
                // here we save the last notice ID
            }
        }

    } // filters
    return true;
}

From source file:com.xandrev.jdorg.main.ExecutorService.java

private ExecutorService() {
    executionTime = new Date();
    auditService = AuditImpl.getInstance();
    cfg = Configuration.getInstance();
    String organizerListString = cfg.getProperty(Constants.ORGANIZER_NAMES);
    manager = OrganizerManager.getInstance(organizerListString);
    organizerList = manager.getOrganizerList();
    finalDirectory = cfg.getProperty(Constants.FINAL_FOLDER);
    String language = cfg.getProperty(Constants.LANGUAGE);
    initialDirectory = cfg.getProperty(Constants.INITIAL_FOLDER);
    Locale locale = Locale.getDefault();
    if (language != null && !language.equals("")) {
        locale = new Locale(language);
    }/*from   w  w  w  .java 2s. co  m*/
    i18n = TextLocalizerManager.getInstance(locale);

}

From source file:com.acentic.cloudservices.session.web.PublicActions.java

private static Locale localefromString(String locale) {
    Locale l = null;// w w  w .j  a va 2s .c  o m
    String parts[] = locale.split("_", -1);
    if (parts.length == 1) {
        l = new Locale(parts[0]);
    } else if (parts.length == 2 || (parts.length == 3 && parts[2].startsWith("#"))) {
        l = new Locale(parts[0], parts[1]);
    } else {
        l = new Locale(parts[0], parts[1], parts[2]);
    }

    LOGGER.log(Level.DEBUG, "setting default locale to " + l.toString());
    return l;
}

From source file:ambroafb.general.GeneralConfig.java

private GeneralConfig(String lang) {
    this(new Locale(lang));
    this.language = lang;
}

From source file:se.vgregion.portal.medcontrol.MedControlViewControllerTest.java

@Test
public void testNullUserId() {
    // PortletPreferences
    mockPortletConfig.setResourceBundle(new Locale("sv"), null);
    ModelMap model = new ModelMap();
    assertEquals("medcontrol",
            medControlViewController.showMedControlNotifications(model, mockRenderRequest, mockRenderResponse));
    assertEquals(0, ((List) model.get("mine")).size());
}

From source file:org.openmrs.contrib.metadatarepository.webapp.filter.LocaleFilterTest.java

public void testSetLocaleInSessionWhenSessionNotNull() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("locale", "es");

    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setSession(new MockHttpSession(null));

    filter.doFilter(request, response, new MockFilterChain());

    // session not null, should result in not null
    Locale locale = (Locale) request.getSession().getAttribute(Constants.PREFERRED_LOCALE_KEY);
    assertNotNull(locale);/*from  w w  w .j a  v a 2s  . c  om*/
    assertNotNull(LocaleContextHolder.getLocale());
    assertEquals(new Locale("es"), locale);
}

From source file:com.hangum.tadpole.engine.manager.TadpoleSQLManager.java

/**
 * <pre>//from  w w  w.ja  v  a2s  .  c om
 * DB  ?.
 * 
 * ?     ???    .
 *    ?? " ' ? ?  .
 * 
 * </pre>
 * 
 * @param userDB
 * @return
 * @throws Exception
 */
public static SqlMapClient getInstance(final UserDBDAO userDB) throws TadpoleSQLManagerException {
    SqlMapClient sqlMapClient = null;
    Connection conn = null;

    //      synchronized (dbManager) {
    String searchKey = getKey(userDB);
    try {
        sqlMapClient = dbManager.get(searchKey);
        if (sqlMapClient == null) {

            // oracle ?   
            try {
                if (userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT
                        | userDB.getDBDefine() == DBDefine.TIBERO_DEFAULT) {
                    DriverManager.setLoginTimeout(10);

                    if (userDB.getLocale() != null && !"".equals(userDB.getLocale())) {
                        Locale.setDefault(new Locale(userDB.getLocale()));
                    }
                }
            } catch (Exception e) {
                logger.error("set locale error", e);
            }

            // connection pool ? .
            sqlMapClient = SQLMap.getInstance(userDB);
            dbManager.put(searchKey, sqlMapClient);

            // metadata   .
            conn = sqlMapClient.getDataSource().getConnection();

            // don't belive keyword. --;;
            setMetaData(searchKey, userDB, conn.getMetaData());
        }

    } catch (Exception e) {
        //            String strAddReqInfo = "";
        //            try {
        //               strAddReqInfo = RequestInfoUtils.requestInfo("db connection exception ", SessionManager.getEMAIL());
        //            } catch(Exception ee) {
        //               logger.error("request error", ee);
        //            }
        logger.error("===\n get DB Instance \n seq is " + userDB.getSeq() + "\n", e);

        dbManager.remove(searchKey);

        throw new TadpoleSQLManagerException(e);
    } finally {
        if (conn != null)
            try {
                conn.close();
            } catch (Exception e) {
            }
    }
    //      }

    return sqlMapClient;
}

From source file:cz.muni.fi.mushroomhunter.restclient.MushroomUpdateSwingWorker.java

@Override
protected Integer doInBackground() throws Exception {
    DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel();
    int selectedRow = restClient.getTblMushroom().getSelectedRow();

    RestTemplate restTemplate = new RestTemplate();

    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add(MediaType.ALL);/*from www .ja  v a 2 s. c om*/
    headers.setAccept(mediaTypeList);

    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity request = new HttpEntity<>(headers);

    ResponseEntity<MushroomDto> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow),
            HttpMethod.GET, request, MushroomDto.class);

    MushroomDto mushroomDto = responseEntity.getBody();

    mushroomDto.setName(restClient.getTfMushroomName().getText());

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy", new Locale("en_US"));

    //to create date object only month is used, day and year are fixed values
    String dateInString = "01-" + restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setStartOfOccurence(formatter.parse(dateInString));

    //to create date object only month is used, day and year are fixed values
    dateInString = "01-" + restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setEndOfOccurence(formatter.parse(dateInString));

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = ow.writeValueAsString(mushroomDto);
    request = new HttpEntity(json, headers);

    restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/mushroom", HttpMethod.PUT, request,
            MushroomDto.class);
    return selectedRow;
}

From source file:modelibra.swing.app.config.NatLang.java

/**
 * Sets the language with the location for text resources.
 * //  www  . j av  a2s  .  c  o  m
 * @param language
 *            language
 * @param textResources
 *            text resources
 */
public void setNaturalLanguage(String language, String textResources) {
    try {
        if ((language == null) || (language.equals("en"))) {
            locale = Locale.ENGLISH;
        } else if (language.equals("fr")) {
            locale = Locale.FRENCH;
        } else if (language.equals("ba")) {
            locale = new Locale("ba"); // bosnian language
        } else if (language.equals("hr")) {
            locale = new Locale("hr"); // croatian language
        } else if (language.equals("sr")) {
            locale = new Locale("sr"); // serbian language
        } else { // other languages are not supported, English used
            locale = Locale.ENGLISH;
        }
        resource = ResourceBundle.getBundle(textResources, locale);
    } catch (MissingResourceException e) {
        System.out.println(e.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}