List of usage examples for java.util Locale Locale
public Locale(String language)
From source file:eu.delving.core.util.TestLocalizedFieldNames.java
@Test public void backAndForth() { LocalizedFieldNames.Lookup lookup = localizedFieldNames.createLookup(Arrays.asList("dc.title")); final Locale english = new Locale("en"); String title = lookup.toLocalizedName("dc_title", english); Assert.assertEquals("Title", title); String fieldName = lookup.toFieldName(title, english); Assert.assertEquals("dc_title", fieldName); }
From source file:modelinspector.collectors.MostFrequentWordsCollector.java
public MostFrequentWordsCollector(String aLanguage, int aCutoff, boolean aCaseSensitive, String aFile, String aEncoding) {//from w ww . ja v a 2s . c o m cutoff = aCutoff; language = new Locale(aLanguage); String key = aLanguage + "-" + aCaseSensitive; setShowSample(true); wordList = wordLists.get(key); if (wordList == null) { wordList = new Object2IntOpenHashMap<>(); // The file read is sorted by frequency try (InputStream is = new FileInputStream(aFile)) { LineIterator i = IOUtils.lineIterator(is, aEncoding); int n = 1; while (i.hasNext()) { String[] fields = i.nextLine().split("\t"); String word = aCaseSensitive ? fields[0] : fields[0].toLowerCase(language); // System.out.println(word + " - " + n); // Record the word and its rank - since a word may appear in different // frequencies with different POSes, we need to make sure we don't overwrite // a frequent POS with an infrequent one. We only consider the most frequent // POS for a word. if (!wordList.containsKey(word)) { wordList.put(word, n); } n++; } } catch (IOException e) { throw new RuntimeException(e); } wordList.defaultReturnValue(Integer.MAX_VALUE); wordLists.put(key, wordList); } }
From source file:fi.helsinki.opintoni.util.CoursePageUriBuilderTest.java
@Test public void thatFinnishUrisAreLocalized() { LocaleContextHolder.setLocale(new Locale("fi")); CoursePageCourseImplementation coursePage = createCoursePage(); assertThat(coursePageUriBuilder.getLocalizedUri(coursePage)).isEqualTo("http://courses.helsinki.fi/fi/123"); }
From source file:modelinspector.collectors.RequireAllCollector.java
public RequireAllCollector(String aName, String aLanguage, File aFile, String aEncoding, boolean aCaseSensitive) { name = aName;/* w w w .ja v a2 s .c om*/ required = new HashSet<>(); language = new Locale(aLanguage); caseSensitive = aCaseSensitive; try (InputStream is = new FileInputStream(aFile)) { LineIterator i = IOUtils.lineIterator(is, aEncoding); while (i.hasNext()) { String[] fields = i.nextLine().split("\t"); String word = caseSensitive ? fields[0] : fields[0].toLowerCase(); required.add(word); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:intelligent.wiki.editor.spring.Config.java
@Bean public WikiOperations wikiOperations() { return new WikiFacade(new Locale("uk")); }
From source file:dk.nsi.haiba.epimibaimporter.message.MessageResolver.java
public String getMessage(String name) { return messageSource.getMessage(name, null, new Locale("DA_DK")); }
From source file:cz.muni.fi.mushroomhunter.restclient.MushroomCreateSwingWorker.java
@Override protected Void doInBackground() throws Exception { MushroomDto mushroomDto = new MushroomDto(); mushroomDto.setName(restClient.getTfMushroomName().getText()); mushroomDto.setType(cz.fi.muni.pa165.mushroomhunter.api.Type .valueOf(restClient.getComboBoxMushroomType().getSelectedItem().toString())); //to create date object only month is used, day and year are fixed values String dateInString = restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString() + " 1, 2000"; SimpleDateFormat formatter = new SimpleDateFormat("MMMM d, yyyy", new Locale("en_US")); mushroomDto.setStartOfOccurence(formatter.parse(dateInString)); //to create date object only month is used, day and year are fixed values dateInString = restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString() + " 1, 2000"; mushroomDto.setEndOfOccurence(formatter.parse(dateInString)); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);//from w w w. j av a 2 s .c om headers.setAccept(mediaTypeList); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(mushroomDto); String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD; byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity(json, headers); RestTemplate restTemplate = new RestTemplate(); Long[] result = restTemplate.postForObject(RestClient.SERVER_URL + "pa165/rest/mushroom", request, Long[].class); System.out.println("Id of the created mushroom: " + result[0]); RestClient.getMushroomIDs().add(result[0]); return null; }
From source file:org.springframework.cloud.netflix.ribbon.apache.HttpClientStatusCodeExceptionTest.java
@Test public void getResponse() throws Exception { CloseableHttpResponse response = mock(CloseableHttpResponse.class); doReturn(new Locale("en")).when(response).getLocale(); Header foo = new BasicHeader("foo", "bar"); Header[] headers = new Header[] { foo }; doReturn(headers).when(response).getAllHeaders(); StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1), 200, "Success"); doReturn(statusLine).when(response).getStatusLine(); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream("foo".getBytes())); entity.setContentLength(3);//from www. j a va 2 s. co m doReturn(entity).when(response).getEntity(); HttpEntity copiedEntity = HttpClientUtils.createEntity(response); HttpClientStatusCodeException ex = new HttpClientStatusCodeException("service", response, copiedEntity, new URI("http://service.com")); assertEquals("en", ex.getResponse().getLocale().toString()); assertArrayEquals(headers, ex.getResponse().getAllHeaders()); assertEquals("Success", ex.getResponse().getStatusLine().getReasonPhrase()); assertEquals(200, ex.getResponse().getStatusLine().getStatusCode()); assertEquals("http", ex.getResponse().getStatusLine().getProtocolVersion().getProtocol()); assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMajor()); assertEquals(1, ex.getResponse().getStatusLine().getProtocolVersion().getMinor()); assertEquals("foo", EntityUtils.toString(ex.getResponse().getEntity())); verify(response, times(1)).close(); }
From source file:eu.delving.core.util.ThemeCookieLocaleResolver.java
@Override protected Locale determineDefaultLocale(HttpServletRequest request) { final PortalTheme portalTheme = themeHandler.getByRequest(request); return new Locale(portalTheme.getDefaultLanguage()); }
From source file:de.cosmocode.commons.converter.LocaleLanguageIsoConverter.java
@Override public String toThreeLetter(String iso6391) { Preconditions.checkNotNull(iso6391, "iso6391 must not be null"); if (Patterns.ISO_639_1.matcher(iso6391).matches()) { // ISO 639-1 to ISO 639-2 (two-letter to three-letter) try {//from w w w . ja v a 2s . c om return new Locale(iso6391).getISO3Language(); } catch (MissingResourceException e) { throw new IsoConversionException("No known three-letter language code for " + iso6391, e); } } else if (Patterns.ISO_639_2.matcher(iso6391).matches()) { // already ISO 639-2 (three letter) return iso6391; } else if (StringUtils.isBlank(iso6391)) { // this is here for convenience, to allow empty languages return TrimMode.EMPTY.apply(iso6391); } else { throw new IllegalArgumentException("given language code must be either iso 639-1 or iso 639-2"); } }