Search in sources :

Example 21 with Locale

use of java.util.Locale in project checkstyle by checkstyle.

the class CheckerTest method testClearNonexistentCache.

@Test
public void testClearNonexistentCache() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("simpleConfig");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);
    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefUtLogger(stream));
    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    checker.clearCache();
    // one more time, but cache does not exist
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}
Also used : Locale(java.util.Locale) Test(org.junit.Test)

Example 22 with Locale

use of java.util.Locale in project checkstyle by checkstyle.

the class CheckerTest method testCacheFile.

@Test
public void testCacheFile() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);
    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);
    final DefaultConfiguration checkerConfig = new DefaultConfiguration("checkstyleConfig");
    checkerConfig.addAttribute("charset", "UTF-8");
    checkerConfig.addChild(treeWalkerConfig);
    checkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath());
    final Checker checker = new Checker();
    final Locale locale = Locale.ROOT;
    checker.setLocaleCountry(locale.getCountry());
    checker.setLocaleLanguage(locale.getLanguage());
    checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    checker.configure(checkerConfig);
    checker.addListener(new BriefUtLogger(stream));
    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = CommonUtils.EMPTY_STRING_ARRAY;
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
    // one more time to reuse cache
    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);
}
Also used : Locale(java.util.Locale) Test(org.junit.Test)

Example 23 with Locale

use of java.util.Locale in project cucumber-jvm by cucumber.

the class ConvertersTest method setUp.

@Before
public void setUp() throws Exception {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    LocalizedXStreams transformers = new LocalizedXStreams(classLoader);
    en = transformers.get(Locale.US).getConverterLookup();
    no = transformers.get(new Locale("no")).getConverterLookup();
}
Also used : Locale(java.util.Locale) Before(org.junit.Before)

Example 24 with Locale

use of java.util.Locale in project elasticsearch by elastic.

the class DateProcessorFactoryTests method testParseLocale.

public void testParseLocale() throws Exception {
    DateProcessor.Factory factory = new DateProcessor.Factory();
    Map<String, Object> config = new HashMap<>();
    String sourceField = randomAsciiOfLengthBetween(1, 10);
    config.put("field", sourceField);
    config.put("formats", Collections.singletonList("dd/MM/yyyyy"));
    Locale locale = randomLocale(random());
    config.put("locale", locale.toLanguageTag());
    DateProcessor processor = factory.create(null, null, config);
    assertThat(processor.getLocale().toLanguageTag(), equalTo(locale.toLanguageTag()));
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 25 with Locale

use of java.util.Locale in project jetty.project by eclipse.

the class Request method getLocales.

/* ------------------------------------------------------------ */
/*
     * @see javax.servlet.ServletRequest#getLocales()
     */
@Override
public Enumeration<Locale> getLocales() {
    MetaData.Request metadata = _metaData;
    if (metadata == null)
        return Collections.enumeration(__defaultLocale);
    List<String> acceptable = metadata.getFields().getQualityCSV(HttpHeader.ACCEPT_LANGUAGE);
    // handle no locale
    if (acceptable.isEmpty())
        return Collections.enumeration(__defaultLocale);
    List<Locale> locales = acceptable.stream().map(language -> {
        language = HttpFields.stripParameters(language);
        String country = "";
        int dash = language.indexOf('-');
        if (dash > -1) {
            country = language.substring(dash + 1).trim();
            language = language.substring(0, dash).trim();
        }
        return new Locale(language, country);
    }).collect(Collectors.toList());
    return Collections.enumeration(locales);
}
Also used : Attributes(org.eclipse.jetty.util.Attributes) Enumeration(java.util.Enumeration) ServletException(javax.servlet.ServletException) Context(org.eclipse.jetty.server.handler.ContextHandler.Context) UrlEncoded(org.eclipse.jetty.util.UrlEncoded) MultiPartInputStreamParser(org.eclipse.jetty.util.MultiPartInputStreamParser) InetAddress(java.net.InetAddress) AsyncListener(javax.servlet.AsyncListener) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData) Map(java.util.Map) HttpStatus(org.eclipse.jetty.http.HttpStatus) HttpSession(javax.servlet.http.HttpSession) Collection(java.util.Collection) RequestDispatcher(javax.servlet.RequestDispatcher) ServletRequestAttributeEvent(javax.servlet.ServletRequestAttributeEvent) ServletRequestAttributeListener(javax.servlet.ServletRequestAttributeListener) IO(org.eclipse.jetty.util.IO) MultipartConfigElement(javax.servlet.MultipartConfigElement) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) EventListener(java.util.EventListener) List(java.util.List) Principal(java.security.Principal) ServletResponse(javax.servlet.ServletResponse) URIUtil(org.eclipse.jetty.util.URIUtil) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MimeTypes(org.eclipse.jetty.http.MimeTypes) BadMessageException(org.eclipse.jetty.http.BadMessageException) AttributesMap(org.eclipse.jetty.util.AttributesMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpScheme(org.eclipse.jetty.http.HttpScheme) ServletInputStream(javax.servlet.ServletInputStream) HttpVersion(org.eclipse.jetty.http.HttpVersion) Session(org.eclipse.jetty.server.session.Session) StringUtil(org.eclipse.jetty.util.StringUtil) ArrayList(java.util.ArrayList) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler) AsyncContext(javax.servlet.AsyncContext) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpURI(org.eclipse.jetty.http.HttpURI) Charset(java.nio.charset.Charset) Cookie(javax.servlet.http.Cookie) HttpFields(org.eclipse.jetty.http.HttpFields) ServletRequest(javax.servlet.ServletRequest) HttpCookie(org.eclipse.jetty.http.HttpCookie) MultiMap(org.eclipse.jetty.util.MultiMap) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) HostPortHttpField(org.eclipse.jetty.http.HostPortHttpField) HttpMethod(org.eclipse.jetty.http.HttpMethod) Part(javax.servlet.http.Part) HttpField(org.eclipse.jetty.http.HttpField) Log(org.eclipse.jetty.util.log.Log) DispatcherType(javax.servlet.DispatcherType) ServletContext(javax.servlet.ServletContext) BufferedReader(java.io.BufferedReader) Logger(org.eclipse.jetty.util.log.Logger) Collections(java.util.Collections) ServletRequestWrapper(javax.servlet.ServletRequestWrapper) InputStream(java.io.InputStream) Locale(java.util.Locale) MetaData(org.eclipse.jetty.http.MetaData)

Aggregations

Locale (java.util.Locale)2214 Test (org.junit.Test)262 ArrayList (java.util.ArrayList)179 HashMap (java.util.HashMap)108 ResourceBundle (java.util.ResourceBundle)83 SimpleDateFormat (java.text.SimpleDateFormat)78 Date (java.util.Date)77 MissingResourceException (java.util.MissingResourceException)68 IOException (java.io.IOException)67 TimeZone (java.util.TimeZone)63 File (java.io.File)50 Map (java.util.Map)49 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)49 Calendar (java.util.Calendar)46 Configuration (android.content.res.Configuration)41 LocaleList (android.os.LocaleList)39 HashSet (java.util.HashSet)39 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)39 HttpSession (javax.servlet.http.HttpSession)38 Resources (android.content.res.Resources)37