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:net.radai.beanz.util.ReflectionUtil.java
public static Method findGetter(Class<?> clazz, String propName) { Set<String> expectedNames = new HashSet<>( Arrays.asList("get" + propName.substring(0, 1).toUpperCase(Locale.ROOT) + propName.substring(1), "is" + propName.substring(0, 1).toUpperCase(Locale.ROOT) + propName.substring(1) //bool props ));/*from w w w . ja v a 2s. com*/ for (Method method : clazz.getMethods()) { String methodName = method.getName(); if (!expectedNames.contains(methodName)) { continue; } if (method.getParameterCount() != 0) { continue; //getters take no arguments } Type returnType = method.getGenericReturnType(); if (returnType.equals(void.class)) { continue; //getters return something } if (methodName.startsWith("is") && !(returnType.equals(Boolean.class) || returnType.equals(boolean.class))) { continue; //isSomething() only valid for booleans } return method; } return null; }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
/** * Create MultiProtocolURL/*from w w w . java2 s .c om*/ * * decoding exception: if url string contains http url with char '%' the url string must be url encoded (percent-escaped) before * as internal encoding is skipped if url string contains '%'. * * @param url '%' char url encoded before * @throws MalformedURLException */ public MultiProtocolURL(String url) throws MalformedURLException { if (url == null) throw new MalformedURLException("url string is null"); this.hostAddress = null; this.contentDomain = null; // identify protocol url = url.trim(); if (url.startsWith("//")) { // patch for urls starting with "//" which can be found in the wild url = "http:" + url; } if (url.startsWith("\\\\")) { url = "smb://" + CommonPattern.BACKSLASH.matcher(url.substring(2)).replaceAll("/"); } if (url.length() > 1 && (url.charAt(1) == ':' && Character.isLetter(url.charAt(0)))) { // maybe a DOS drive path ( A: to z: ) url = "file://" + url; } if (url.length() > 0 && url.charAt(0) == '/') { // maybe a unix/linux absolute path url = "file://" + url; } int p = url.lastIndexOf("://", 5); // lastindexof to look only at the begin of url, up to "https://", if (p < 0) { if (url.length() > 7 && url.substring(0, 7).equalsIgnoreCase("mailto:")) { p = 6; } else { url = "http://" + url; p = 4; } } this.protocol = url.substring(0, p).toLowerCase(Locale.ROOT).trim().intern(); if (url.length() < p + 4) throw new MalformedURLException("URL not parseable: '" + url + "'"); if (!this.protocol.equals("file") && url.substring(p + 1, p + 3).equals("//")) { // identify host, userInfo and file for http and ftp protocol int q = url.indexOf('/', p + 3); if (q < 0) { // check for www.test.com?searchpart q = url.indexOf("?", p + 3); } else { // check that '/' was not in searchpart (example http://test.com?data=1/2/3) if (url.lastIndexOf("?", q) >= 0) { q = url.indexOf("?", p + 3); } } if (q < 0) { // check for www.test.com#fragment q = url.indexOf("#", p + 3); } int r; if (q < 0) { if ((r = url.indexOf('@', p + 3)) < 0) { this.host = url.substring(p + 3).intern(); this.userInfo = null; } else { this.host = url.substring(r + 1).intern(); this.userInfo = url.substring(p + 3, r); } this.path = "/"; } else { this.host = url.substring(p + 3, q).trim().intern(); if ((r = this.host.indexOf('@')) < 0) { this.userInfo = null; } else { this.userInfo = this.host.substring(0, r); this.host = this.host.substring(r + 1).intern(); } this.path = url.substring(q); // may result in "?searchpart" (resolveBackpath prepends a "/" ) } if (this.host.length() < 4 && !this.protocol.equals("file")) throw new MalformedURLException("host too short: '" + this.host + "', url = " + url); if (this.host.indexOf('&') >= 0) throw new MalformedURLException("invalid '&' in host"); this.path = resolveBackpath(this.path); // adds "/" if missing identPort(url, (isHTTP() ? 80 : (isHTTPS() ? 443 : (isFTP() ? 21 : (isSMB() ? 445 : -1))))); if (this.port < 0) { // none of known protocols (above) = unknown throw new MalformedURLException("unknown protocol: " + url); } identAnchor(); identSearchpart(); escape(); } else { url = UTF8.decodeURL(url); // normalization here // this is not a http or ftp url if (this.protocol.equals("mailto")) { // parse email url final int q = url.indexOf('@', p + 3); if (q < 0) { throw new MalformedURLException("wrong email address: " + url); } this.userInfo = url.substring(p + 1, q); this.host = url.substring(q + 1); this.path = ""; // TODO: quick fix, as not always checked for path != null this.port = -1; this.searchpart = null; this.anchor = null; } else if (this.protocol.equals("file")) { // parse file url (RFC 1738 file://host.domain/path file://localhost/path file:///path) // example unix file://localhost/etc/fstab // file:///etc/fstab // example windows file://localhost/c|/WINDOWS/clock.avi // file:///c|/WINDOWS/clock.avi // file://localhost/c:/WINDOWS/clock.avi // network file://hostname/path/to/the%20file.txt // local file:///c:/path/to/the%20file.txt String h = url.substring(p + 1); this.host = null; // host is ignored on file: protocol if (h.startsWith("///")) { //absolute local file path // no host given this.path = h.substring(2); // "/path" or "/c:/path" } else if (h.startsWith("//")) { // "//host/path" or "//host/c:/path" if (h.length() > 4 && h.charAt(3) == ':' && h.charAt(4) != '/' && h.charAt(4) != '\\') { // wrong windows path, after the doublepoint there should be a backslash. Let's add a slash, as it will be slash in the normal form h = h.substring(0, 4) + '/' + h.substring(4); } int q = h.indexOf('/', 2); if (q < 0 || h.length() > 3 && h.charAt(3) == ':') { // Missing root slash such as "path" or "c:/path" accepted, but the path attribute must by after all start with it this.path = "/" + h.substring(2); } else { this.host = h.substring(2, q); // TODO: handle "c:" ? if (this.host.equalsIgnoreCase(Domains.LOCALHOST)) this.host = null; this.path = h.substring(q); // "/path" } } else if (h.startsWith("/")) { // "/host/path" or "/host/c:/path" this.path = h; } this.userInfo = null; this.port = -1; this.searchpart = null; this.anchor = null; } else { throw new MalformedURLException("unknown protocol: " + url); } } // handle international domains if (!Punycode.isBasic(this.host)) try { this.host = toPunycode(this.host); } catch (final PunycodeException e) { } }
From source file:org.elasticsearch.plugins.PluginManagerIT.java
/** * Test for #7890//w w w .ja v a 2 s. c om */ public void testLocalPluginInstallWithBinAndConfigInAlreadyExistingConfigDir_7890() throws Exception { String pluginName = "fake-plugin"; Path pluginDir = createTempDir().resolve(pluginName); // create config/test.txt with contents 'version1' Files.createDirectories(pluginDir.resolve("config")); Files.write(pluginDir.resolve("config").resolve("test.txt"), "version1".getBytes(StandardCharsets.UTF_8)); String pluginUrl = createPlugin(pluginDir, "description", "fake desc", "name", pluginName, "version", "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); Path pluginConfigDir = environment.configFile().resolve(pluginName); assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); /* First time, our plugin contains: - config/test.txt (version1) */ assertFileContent(pluginConfigDir, "test.txt", "version1"); // We now remove the plugin assertStatusOk("remove " + pluginName); // We should still have test.txt assertFileContent(pluginConfigDir, "test.txt", "version1"); // Installing a new plugin version /* Second time, our plugin contains: - config/test.txt (version2) - config/dir/testdir.txt (version1) - config/dir/subdir/testsubdir.txt (version1) */ Files.write(pluginDir.resolve("config").resolve("test.txt"), "version2".getBytes(StandardCharsets.UTF_8)); Files.createDirectories(pluginDir.resolve("config").resolve("dir").resolve("subdir")); Files.write(pluginDir.resolve("config").resolve("dir").resolve("testdir.txt"), "version1".getBytes(StandardCharsets.UTF_8)); Files.write(pluginDir.resolve("config").resolve("dir").resolve("subdir").resolve("testsubdir.txt"), "version1".getBytes(StandardCharsets.UTF_8)); pluginUrl = createPlugin(pluginDir, "description", "fake desc", "name", pluginName, "version", "2.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertFileContent(pluginConfigDir, "test.txt", "version1"); assertFileContent(pluginConfigDir, "test.txt.new", "version2"); assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1"); assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1"); // Removing assertStatusOk("remove " + pluginName); assertFileContent(pluginConfigDir, "test.txt", "version1"); assertFileContent(pluginConfigDir, "test.txt.new", "version2"); assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1"); assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1"); // Installing a new plugin version /* Third time, our plugin contains: - config/test.txt (version3) - config/test2.txt (version1) - config/dir/testdir.txt (version2) - config/dir/testdir2.txt (version1) - config/dir/subdir/testsubdir.txt (version2) */ Files.write(pluginDir.resolve("config").resolve("test.txt"), "version3".getBytes(StandardCharsets.UTF_8)); Files.write(pluginDir.resolve("config").resolve("test2.txt"), "version1".getBytes(StandardCharsets.UTF_8)); Files.write(pluginDir.resolve("config").resolve("dir").resolve("testdir.txt"), "version2".getBytes(StandardCharsets.UTF_8)); Files.write(pluginDir.resolve("config").resolve("dir").resolve("testdir2.txt"), "version1".getBytes(StandardCharsets.UTF_8)); Files.write(pluginDir.resolve("config").resolve("dir").resolve("subdir").resolve("testsubdir.txt"), "version2".getBytes(StandardCharsets.UTF_8)); pluginUrl = createPlugin(pluginDir, "description", "fake desc", "name", pluginName, "version", "3.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version", System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin"); assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl)); assertFileContent(pluginConfigDir, "test.txt", "version1"); assertFileContent(pluginConfigDir, "test2.txt", "version1"); assertFileContent(pluginConfigDir, "test.txt.new", "version3"); assertFileContent(pluginConfigDir, "dir/testdir.txt", "version1"); assertFileContent(pluginConfigDir, "dir/testdir.txt.new", "version2"); assertFileContent(pluginConfigDir, "dir/testdir2.txt", "version1"); assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt", "version1"); assertFileContent(pluginConfigDir, "dir/subdir/testsubdir.txt.new", "version2"); }
From source file:business.security.control.OwmClient.java
/** * Get the weather forecast for a city// w ww . j a va 2 s . c o m * * @param cityId is the ID of the city * @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 WeatherForecastResponse forecastWeatherAtCity(int cityId) throws JSONException, IOException { String subUrl = String.format(Locale.ROOT, "forecast/city/%d?type=json&units=metric", cityId); JSONObject response = doQuery(subUrl); return new WeatherForecastResponse(response); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlElement.java
/** * Removes an attribute specified by name from this element. * @param attributeName the attribute attributeName *//*from w ww.ja v a 2 s . c o m*/ @Override public final void removeAttribute(final String attributeName) { final String value = getAttribute(attributeName); if (value == ATTRIBUTE_NOT_DEFINED) { return; } final HtmlPage htmlPage = getHtmlPageOrNull(); if (htmlPage != null) { htmlPage.removeMappedElement(this); } // TODO is this toLowerCase call needed? super.removeAttribute(attributeName.toLowerCase(Locale.ROOT)); if (htmlPage != null) { htmlPage.addMappedElement(this); final HtmlAttributeChangeEvent event = new HtmlAttributeChangeEvent(this, attributeName, value); fireHtmlAttributeRemoved(event); htmlPage.fireHtmlAttributeRemoved(event); } }
From source file:ch.cyberduck.core.ftp.FTPSession.java
@Override public void login(final HostPasswordStore keychain, final LoginCallback prompt, final CancelCallback cancel) throws BackgroundException { try {/*from w w w . java 2 s .c om*/ if (client.login(host.getCredentials().getUsername(), host.getCredentials().getPassword())) { if (host.getProtocol().isSecure()) { client.execPBSZ(0); // Negotiate data connection security client.execPROT(preferences.getProperty("ftp.tls.datachannel")); } if ("UTF-8".equals(host.getEncoding())) { if (client.hasFeature("UTF8")) { if (!FTPReply.isPositiveCompletion(client.sendCommand("OPTS UTF8 ON"))) { log.warn( String.format("Failed to negotiate UTF-8 charset %s", client.getReplyString())); } } } final TimeZone zone = host.getTimezone(); if (log.isInfoEnabled()) { log.info(String.format("Reset parser to timezone %s", zone)); } String system = null; //Unknown try { system = client.getSystemType(); if (system.toUpperCase(Locale.ROOT).contains(FTPClientConfig.SYST_NT)) { casesensitivity = Case.insensitive; } } catch (IOException e) { log.warn(String.format("SYST command failed %s", e.getMessage())); } listService = new FTPListService(this, keychain, prompt, system, zone); if (client.hasFeature(FTPCmd.MFMT.getCommand())) { timestamp = new FTPMFMTTimestampFeature(this); } else { timestamp = new FTPUTIMETimestampFeature(this); } permission = new FTPUnixPermissionFeature(this); if (client.hasFeature("SITE", "SYMLINK")) { symlink = new FTPSymlinkFeature(this); } } else { throw new FTPExceptionMappingService() .map(new FTPException(this.getClient().getReplyCode(), this.getClient().getReplyString())); } } catch (IOException e) { throw new FTPExceptionMappingService().map(e); } }
From source file:com.puppycrawl.tools.checkstyle.MainTest.java
@Test public void testExistingTargetFileWithViolations() throws Exception { exit.checkAssertionAfterwards(new Assertion() { @Override//from w w w .j a v a 2 s. com public void checkAssertion() throws IOException { String currentPath = new File(".").getCanonicalPath(); String expectedPath = currentPath + "/src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java".replace("/", File.separator); assertEquals(String.format(Locale.ROOT, "Starting audit...%n" + "%1$s:3:14: " + "warning: Name 'InputMain' must match pattern '^[a-z0-9]*$'.%n" + "%1$s:5:7: " + "warning: Name 'InputMainInner' must match pattern '^[a-z0-9]*$'.%n" + "Audit done.%n", expectedPath), systemOut.getLog()); assertEquals("", systemErr.getLog()); } }); Main.main("-c", "src/test/resources/com/puppycrawl/tools/checkstyle/config-classname2.xml", "src/test/resources/com/puppycrawl/tools/checkstyle/InputMain.java"); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.java
/** * Gets an event handler./*from w w w .j a v a2 s .c om*/ * @param eventName the event name (e.g. "click") * @return the handler function, {@code null} if the property is null or not a function */ public Function getEventHandler(final String eventName) { final Object handler = getEventHandlerProp(eventName.toLowerCase(Locale.ROOT)); if (handler instanceof Function) { return (Function) handler; } return null; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.java
/** * Defines an event handler (or maybe any other object). * @param eventName the event name (e.g. "onclick") * @param value the property ({@code null} to reset it) *///from w ww.ja v a2s . c om protected void setEventHandlerProp(final String eventName, final Object value) { getEventListenersContainer() .setEventHandlerProp(StringUtils.substring(eventName.toLowerCase(Locale.ROOT), 2), value); }
From source file:business.security.control.OwmClient.java
/** * Get the weather forecast for a city//from ww w .j a va 2 s. c o m * * @param cityName is the Name of the city * @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 WeatherForecastResponse forecastWeatherAtCity(String cityName) throws JSONException, IOException { String subUrl = String.format(Locale.ROOT, "forecast/city?q=%s&type=json&units=metric", cityName); JSONObject response = doQuery(subUrl); return new WeatherForecastResponse(response); }