List of usage examples for java.util Locale ROOT
Locale ROOT
To view the source code for java.util Locale ROOT.
Click Source Link
From source file:com.puppycrawl.tools.checkstyle.AllChecksTest.java
@Test public void testAllChecksAreReferencedInConfigFile() throws Exception { final String configFilePath = "config/checkstyle_checks.xml"; final Set<Class<?>> checksFromClassPath = getCheckstyleChecks(); final Set<String> checksReferencedInConfig = getCheckStyleChecksReferencedInConfig(configFilePath); final Set<String> checksNames = getSimpleNames(checksFromClassPath); for (String check : checksNames) { if (!checksReferencedInConfig.contains(check)) { String errorMessage = String.format(Locale.ROOT, "%s is not referenced in checkstyle_checks.xml", check);/*from w ww . j av a2s . c o m*/ Assert.fail(errorMessage); } } }
From source file:com.github.tmyroadctfig.icloud4j.json.SerializableClientCookie.java
/** * Sets the domain attribute./*from ww w .j a v a 2s .c o m*/ * * @param domain The value of the domain attribute * * @see #getDomain */ @Override public void setDomain(final String domain) { if (domain != null) { cookieDomain = domain.toLowerCase(Locale.ROOT); } else { cookieDomain = null; } }
From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java
/** * If no value present, choose a empty string * * @param title/*from w w w .j a v a2 s .c o m*/ * @param link * @param description * @param language * @param imageUrl * @return */ private Component getSecondStage(Source s) { Label header = new Label(Language.get(Word.SOURCE)); header.addStyleName(ValoTheme.LABEL_H1); FormLayout forms = new FormLayout(); forms.setSizeFull(); TextField textFieldId = new TextField(Language.get(Word.ID)); textFieldId.setEnabled(false); textFieldId.setValue(s.getId()); textFieldId.setWidth("750px"); TextField textFieldName = new TextField(Language.get(Word.NAME)); textFieldName.setValue(s.getName()); textFieldName.setWidth("750px"); TextField textFieldDescription = new TextField(Language.get(Word.DESCRIPTION)); textFieldDescription.setValue(s.getDescription()); textFieldDescription.setWidth("750px"); TextField textFieldURL = new TextField(Language.get(Word.URL)); if (s.getUrl() != null) { textFieldURL.setValue(s.getUrl().toExternalForm()); } textFieldURL.setWidth("750px"); ComboBox<Category> comboBoxCategories = new ComboBox<>(Language.get(Word.CATEGORY), EnumSet.allOf(Category.class)); comboBoxCategories.setItemCaptionGenerator(c -> c.getName()); comboBoxCategories.setItemIconGenerator(c -> c.getIcon()); comboBoxCategories.setEmptySelectionAllowed(false); comboBoxCategories.setTextInputAllowed(false); comboBoxCategories.setWidth("375px"); if (s.getCategory() != null) { comboBoxCategories.setSelectedItem(s.getCategory()); } ComboBox<Locale> comboBoxLanguage = new ComboBox<>(Language.get(Word.LANGUAGE), getLanguages()); comboBoxLanguage.setItemCaptionGenerator(l -> l.getDisplayLanguage(VaadinSession.getCurrent().getLocale())); comboBoxLanguage.setEmptySelectionAllowed(false); comboBoxLanguage.setWidth("375px"); if (!s.getLanguage().isEmpty()) { Locale selected = new Locale(s.getLanguage()); comboBoxLanguage.setSelectedItem(selected); } Locale loc = VaadinSession.getCurrent().getLocale(); Map<String, Locale> countries = getCountries(); List<Locale> locales = countries.values().parallelStream() .sorted((l1, l2) -> l1.getDisplayCountry(loc).compareTo(l2.getDisplayCountry(loc))) .collect(Collectors.toList()); ComboBox<Locale> comboBoxCountry = new ComboBox<>(Language.get(Word.COUNTRY), locales); comboBoxCountry.setItemCaptionGenerator(l -> l.getDisplayCountry(VaadinSession.getCurrent().getLocale())); comboBoxCountry.setItemIconGenerator(l -> FamFamFlags.fromLocale(l)); comboBoxCountry.setEmptySelectionAllowed(false); comboBoxCountry.setWidth("375px"); if (!s.getCountry().isEmpty()) { comboBoxCountry.setSelectedItem(countries.getOrDefault(s.getCountry(), Locale.ROOT)); } Image imageLogo = new Image(Language.get(Word.LOGO)); TextField textFieldLogo = new TextField(Language.get(Word.LOGO_URL)); if (s.getLogo() != null) { textFieldLogo.setValue(s.getLogo().toExternalForm()); imageLogo.setSource(new ExternalResource(s.getLogo())); } textFieldLogo.addValueChangeListener(ce -> imageLogo.setSource(new ExternalResource(ce.getValue()))); textFieldLogo.setWidth("750px"); if (imageLogo.getHeight() > 125) { imageLogo.setHeight("125px"); } forms.addComponents(textFieldId, textFieldName, textFieldDescription, textFieldURL, comboBoxCategories, comboBoxLanguage, comboBoxCountry, textFieldLogo, imageLogo); Runnable cancel = () -> close(); Runnable next = () -> validateSecondStage(s, textFieldId.getValue(), textFieldName.getValue(), textFieldURL.getValue(), textFieldDescription.getValue(), comboBoxCategories.getSelectedItem().orElse(null), comboBoxLanguage.getSelectedItem().orElse(Locale.ROOT), comboBoxCountry.getSelectedItem().orElse(Locale.ROOT), textFieldLogo.getValue()); VerticalLayout windowLayout = new VerticalLayout(); windowLayout.addComponents(header, forms, getFooter(cancel, next)); windowLayout.setComponentAlignment(header, Alignment.MIDDLE_CENTER); return windowLayout; }
From source file:com.puppycrawl.tools.checkstyle.TreeWalkerTest.java
@Test public void testCacheFile() throws Exception { final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class); final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class); treeWalkerConfig.addAttribute("cacheFile", temporaryFolder.newFile().getPath()); treeWalkerConfig.addChild(checkConfig); final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration"); 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);// ww w . j ava 2 s .c om checker.addListener(new BriefLogger(stream)); final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath(); final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY; verify(checker, pathToEmptyFile, pathToEmptyFile, expected); // one more time to reuse cache verify(checker, pathToEmptyFile, pathToEmptyFile, expected); }
From source file:com.facebook.share.ShareApi.java
private String getGraphPath(final String pathAfterGraphNode) { try {/*w ww. j a va 2 s . c om*/ return String.format(Locale.ROOT, GRAPH_PATH_FORMAT, URLEncoder.encode(getGraphNode(), DEFAULT_CHARSET), pathAfterGraphNode); } catch (UnsupportedEncodingException e) { return null; } }
From source file:business.security.control.OwmClient.java
/** * Find current city weather within a bounding box * * @param northLat is the latitude of the geographic top left point of the * bounding box//from w w w . j ava 2s . c o m * @param westLon is the longitude of the geographic top left point of the * bounding box * @param southLat is the latitude of the geographic bottom right point of * the bounding box * @param eastLon is the longitude of the geographic bottom right point of * the bounding box * @throws JSONException if the response from the OWM server can't be parsed * @throws IOException if there's some network error or the OWM server * replies with a error. */ public WeatherStatusResponse currentWeatherAtCityBoundingBox(float northLat, float westLon, float southLat, float eastLon) throws IOException, JSONException { //, boolean cluster, OwmClient.Lang lang) { String subUrl = String.format(Locale.ROOT, "find/city?bbox=%f,%f,%f,%f&cluster=yes", Float.valueOf(northLat), Float.valueOf(westLon), Float.valueOf(southLat), Float.valueOf(eastLon)); JSONObject response = doQuery(subUrl); return new WeatherStatusResponse(response); }
From source file:org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerConnection.java
protected void call(HttpRequestBase method) throws ManifoldCFException { CallThread ct = new CallThread(httpClient, method); try {//ww w. j a v a 2 s . c o m ct.start(); try { ct.finishUp(); if (!checkResultCode(ct.getResultCode())) throw new ManifoldCFException(getResultDescription()); response = ct.getResponse(); } catch (InterruptedException e) { ct.interrupt(); throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED); } } catch (java.net.SocketTimeoutException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException( "SocketTimeoutException while calling " + method.getURI() + ": " + e.getMessage(), e); } catch (InterruptedIOException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("Interrupted: " + e.getMessage(), e, ManifoldCFException.INTERRUPTED); } catch (HttpException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("HttpException while calling " + method.getURI() + ": " + e.getMessage(), e); } catch (IOException e) { setResult(e.getClass().getSimpleName().toUpperCase(Locale.ROOT), Result.ERROR, e.getMessage()); throw new ManifoldCFException("IOException while calling " + method.getURI() + ": " + e.getMessage(), e); } }
From source file:com.gargoylesoftware.htmlunit.WebDriverTestCase.java
static Set<String> getBrowsersProperties() { if (BROWSERS_PROPERTIES_ == null) { try {/* w w w . j a v a 2 s . co m*/ final Properties properties = new Properties(); final File file = new File("test.properties"); if (file.exists()) { final FileInputStream in = new FileInputStream(file); try { properties.load(in); } finally { in.close(); } String browsersValue = properties.getProperty("browsers"); if (browsersValue == null || browsersValue.isEmpty()) { browsersValue = "hu"; } BROWSERS_PROPERTIES_ = new HashSet<>( Arrays.asList(browsersValue.replaceAll(" ", "").toLowerCase(Locale.ROOT).split(","))); CHROME_BIN_ = properties.getProperty("chrome.bin"); EDGE_BIN_ = properties.getProperty("edge.bin"); IE_BIN_ = properties.getProperty("ie.bin"); FF31_BIN_ = properties.getProperty("ff31.bin"); FF38_BIN_ = properties.getProperty("ff38.bin"); final boolean autofix = Boolean.parseBoolean(properties.getProperty("autofix")); System.setProperty(AUTOFIX_, Boolean.toString(autofix)); } } catch (final Exception e) { LOG.error("Error reading htmlunit.properties. Ignoring!", e); } if (BROWSERS_PROPERTIES_ == null) { BROWSERS_PROPERTIES_ = new HashSet<>(Arrays.asList("hu")); } if (BROWSERS_PROPERTIES_.contains("hu")) { BROWSERS_PROPERTIES_.add("hu-chrome"); BROWSERS_PROPERTIES_.add("hu-ff31"); BROWSERS_PROPERTIES_.add("hu-ff38"); BROWSERS_PROPERTIES_.add("hu-ie11"); } } return BROWSERS_PROPERTIES_; }
From source file:com.gargoylesoftware.htmlunit.httpclient.HtmlUnitBrowserCompatCookieSpec.java
/** * {@inheritDoc}//from ww w. j a v a2s . c om */ @Override public List<Cookie> parse(Header header, final CookieOrigin origin) throws MalformedCookieException { // first a hack to support empty headers final String text = header.getValue(); int endPos = text.indexOf(';'); if (endPos < 0) { endPos = text.indexOf('='); } else { final int pos = text.indexOf('='); if (pos > endPos) { endPos = -1; } else { endPos = pos; } } if (endPos < 0) { header = new BasicHeader(header.getName(), EMPTY_COOKIE_NAME + "=" + header.getValue()); } else if (endPos == 0 || StringUtils.isBlank(text.substring(0, endPos))) { header = new BasicHeader(header.getName(), EMPTY_COOKIE_NAME + header.getValue()); } final List<Cookie> cookies; final String headername = header.getName(); if (!headername.equalsIgnoreCase(SM.SET_COOKIE)) { throw new MalformedCookieException("Unrecognized cookie header '" + header.toString() + "'"); } final HeaderElement[] helems = header.getElements(); boolean versioned = false; boolean netscape = false; for (final HeaderElement helem : helems) { if (helem.getParameterByName("version") != null) { versioned = true; } if (helem.getParameterByName("expires") != null) { netscape = true; } } if (netscape || !versioned) { // Need to parse the header again, because Netscape style cookies do not correctly // support multiple header elements (comma cannot be treated as an element separator) final NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT; final CharArrayBuffer buffer; final ParserCursor cursor; if (header instanceof FormattedHeader) { buffer = ((FormattedHeader) header).getBuffer(); cursor = new ParserCursor(((FormattedHeader) header).getValuePos(), buffer.length()); } else { final String s = header.getValue(); if (s == null) { throw new MalformedCookieException("Header value is null"); } buffer = new CharArrayBuffer(s.length()); buffer.append(s); cursor = new ParserCursor(0, buffer.length()); } final HeaderElement elem = parser.parseHeader(buffer, cursor); final String name = elem.getName(); final String value = elem.getValue(); if (name == null || name.isEmpty()) { throw new MalformedCookieException("Cookie name may not be empty"); } final BasicClientCookie cookie = new BasicClientCookie(name, value); cookie.setPath(getDefaultPath(origin)); cookie.setDomain(getDefaultDomain(origin)); // cycle through the parameters final NameValuePair[] attribs = elem.getParameters(); for (int j = attribs.length - 1; j >= 0; j--) { final NameValuePair attrib = attribs[j]; final String s = attrib.getName().toLowerCase(Locale.ROOT); cookie.setAttribute(s, attrib.getValue()); final CookieAttributeHandler handler = findAttribHandler(s); if (handler != null) { handler.parse(cookie, attrib.getValue()); } } // Override version for Netscape style cookies if (netscape) { cookie.setVersion(0); } cookies = Collections.<Cookie>singletonList(cookie); } else { cookies = parse(helems, origin); } for (final Cookie c : cookies) { // re-add quotes around value if parsing as incorrectly trimmed them if (header.getValue().contains(c.getName() + "=\"" + c.getValue())) { ((BasicClientCookie) c).setValue('"' + c.getValue() + '"'); } } return cookies; }
From source file:android.net.http.HttpsConnection.java
/** * Opens the connection to a http server or proxy. * * @return the opened low level connection * @throws IOException if the connection fails for any reason. *///from ww w .j av a 2 s . c o m @Override AndroidHttpClientConnection openConnection(Request req) throws IOException { SSLSocket sslSock = null; if (mProxyHost != null) { // If we have a proxy set, we first send a CONNECT request // to the proxy; if the proxy returns 200 OK, we negotiate // a secure connection to the target server via the proxy. // If the request fails, we drop it, but provide the event // handler with the response status and headers. The event // handler is then responsible for cancelling the load or // issueing a new request. AndroidHttpClientConnection proxyConnection = null; Socket proxySock = null; try { proxySock = new Socket(mProxyHost.getHostName(), mProxyHost.getPort()); proxySock.setSoTimeout(60 * 1000); proxyConnection = new AndroidHttpClientConnection(); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setSocketBufferSize(params, 8192); proxyConnection.bind(proxySock, params); } catch (IOException e) { if (proxyConnection != null) { proxyConnection.close(); } String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to establish a connection to the proxy"; } throw new IOException(errorMessage); } StatusLine statusLine = null; int statusCode = 0; Headers headers = new Headers(); try { BasicHttpRequest proxyReq = new BasicHttpRequest("CONNECT", mHost.toHostString()); // add all 'proxy' headers from the original request, we also need // to add 'host' header unless we want proxy to answer us with a // 400 Bad Request for (Header h : req.mHttpRequest.getAllHeaders()) { String headerName = h.getName().toLowerCase(Locale.ROOT); if (headerName.startsWith("proxy") || headerName.equals("keep-alive") || headerName.equals("host")) { proxyReq.addHeader(h); } } proxyConnection.sendRequestHeader(proxyReq); proxyConnection.flush(); // it is possible to receive informational status // codes prior to receiving actual headers; // all those status codes are smaller than OK 200 // a loop is a standard way of dealing with them do { statusLine = proxyConnection.parseResponseHeader(headers); statusCode = statusLine.getStatusCode(); } while (statusCode < HttpStatus.SC_OK); } catch (ParseException e) { String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to send a CONNECT request"; } throw new IOException(errorMessage); } catch (HttpException e) { String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to send a CONNECT request"; } throw new IOException(errorMessage); } catch (IOException e) { String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to send a CONNECT request"; } throw new IOException(errorMessage); } if (statusCode == HttpStatus.SC_OK) { try { sslSock = (SSLSocket) getSocketFactory().createSocket(proxySock, mHost.getHostName(), mHost.getPort(), true); } catch (IOException e) { if (sslSock != null) { sslSock.close(); } String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to create an SSL socket"; } throw new IOException(errorMessage); } } else { // if the code is not OK, inform the event handler ProtocolVersion version = statusLine.getProtocolVersion(); req.mEventHandler.status(version.getMajor(), version.getMinor(), statusCode, statusLine.getReasonPhrase()); req.mEventHandler.headers(headers); req.mEventHandler.endData(); proxyConnection.close(); // here, we return null to indicate that the original // request needs to be dropped return null; } } else { // if we do not have a proxy, we simply connect to the host try { sslSock = (SSLSocket) getSocketFactory().createSocket(mHost.getHostName(), mHost.getPort()); sslSock.setSoTimeout(SOCKET_TIMEOUT); } catch (IOException e) { if (sslSock != null) { sslSock.close(); } String errorMessage = e.getMessage(); if (errorMessage == null) { errorMessage = "failed to create an SSL socket"; } throw new IOException(errorMessage); } } // do handshake and validate server certificates SslError error = CertificateChainValidator.getInstance().doHandshakeAndValidateServerCertificates(this, sslSock, mHost.getHostName()); // Inform the user if there is a problem if (error != null) { // handleSslErrorRequest may immediately unsuspend if it wants to // allow the certificate anyway. // So we mark the connection as suspended, call handleSslErrorRequest // then check if we're still suspended and only wait if we actually // need to. synchronized (mSuspendLock) { mSuspended = true; } // don't hold the lock while calling out to the event handler boolean canHandle = req.getEventHandler().handleSslErrorRequest(error); if (!canHandle) { throw new IOException("failed to handle " + error); } synchronized (mSuspendLock) { if (mSuspended) { try { // Put a limit on how long we are waiting; if the timeout // expires (which should never happen unless you choose // to ignore the SSL error dialog for a very long time), // we wake up the thread and abort the request. This is // to prevent us from stalling the network if things go // very bad. mSuspendLock.wait(10 * 60 * 1000); if (mSuspended) { // mSuspended is true if we have not had a chance to // restart the connection yet (ie, the wait timeout // has expired) mSuspended = false; mAborted = true; if (HttpLog.LOGV) { HttpLog.v("HttpsConnection.openConnection():" + " SSL timeout expired and request was cancelled!!!"); } } } catch (InterruptedException e) { // ignore } } if (mAborted) { // The user decided not to use this unverified connection // so close it immediately. sslSock.close(); throw new SSLConnectionClosedByUserException("connection closed by the user"); } } } // All went well, we have an open, verified connection. AndroidHttpClientConnection conn = new AndroidHttpClientConnection(); BasicHttpParams params = new BasicHttpParams(); params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8192); conn.bind(sslSock, params); return conn; }