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.wormsim.utils.Utils.java
/** * Returns the distribution associated with the specified string. See the * handbook for details of what is accepted. Or the code... * * @param str The string representing a distribution * * @return The distribution/* w ww .j av a 2s. com*/ */ public static RealDistribution readRealDistribution(String str) { if (str.matches("[0-9]+(.[0-9]*)?")) { // I.E. a number return new ConstantRealDistribution(Double.valueOf(str)); } else { int index = str.indexOf('('); String prefix = str.substring(0, index).toLowerCase(Locale.ROOT); switch (prefix) { case "n": case "norm": case "normal": { int comma_index = str.indexOf(',', index); return new NormalDistribution(Double.valueOf(str.substring(index + 1, comma_index).trim()), Double.valueOf(str.substring(comma_index + 1, str.length() - 2).trim())); } case "u": case "uni": case "uniform": { int comma_index = str.indexOf(',', index); return new UniformRealDistribution(Double.valueOf(str.substring(index + 1, comma_index - 1)), Double.valueOf(str.substring(comma_index).trim())); } default: throw new IllegalArgumentException( "Unrecognised distribution form, see handbook for details. " + "Provided \"" + str + "\"."); } } }
From source file:org.apache.manifoldcf.authorities.authorities.sharepoint.SharePointADAuthority.java
/** Get the AD-derived access tokens for a user and domain */ protected List<String> getADTokens(String userPart, String domainPart, String userName) throws NameNotFoundException, NamingException, ManifoldCFException { // Now, look through the rules for the matching domain controller String domainController = null; for (DCRule rule : dCRules) { String suffix = rule.getSuffix(); if (suffix.length() == 0 || domainPart.toLowerCase(Locale.ROOT).endsWith(suffix.toLowerCase(Locale.ROOT)) && (suffix.length() == domainPart.length() || domainPart.charAt((domainPart.length() - suffix.length()) - 1) == '.')) { domainController = rule.getDomainControllerName(); break; }//from w ww . j a va 2s .c o m } if (domainController == null) // No AD user return null; // Look up connection parameters DCConnectionParameters dcParams = dCConnectionParameters.get(domainController); if (dcParams == null) // No AD user return null; // Use the complete fqn if the field is the "userPrincipalName" String userBase; String userACLsUsername = dcParams.getUserACLsUsername(); if (userACLsUsername != null && userACLsUsername.equals("userPrincipalName")) { userBase = userName; } else { userBase = userPart; } //Build the DN searchBase from domain part StringBuilder domainsb = new StringBuilder(); int j = 0; while (true) { if (j > 0) domainsb.append(","); int k = domainPart.indexOf(".", j); if (k == -1) { domainsb.append("DC=").append(ldapEscape(domainPart.substring(j))); break; } domainsb.append("DC=").append(ldapEscape(domainPart.substring(j, k))); j = k + 1; } // Establish a session with the selected domain controller LdapContext ctx = createDCSession(domainController); //Get DistinguishedName (for this method we are using DomainPart as a searchBase ie: DC=qa-ad-76,DC=metacarta,DC=com") String searchBase = getDistinguishedName(ctx, userBase, domainsb.toString(), userACLsUsername); if (searchBase == null) return null; //specify the LDAP search filter String searchFilter = "(objectClass=user)"; //Create the search controls for finding the access tokens SearchControls searchCtls = new SearchControls(); //Specify the search scope, must be base level search for tokenGroups searchCtls.setSearchScope(SearchControls.OBJECT_SCOPE); //Specify the attributes to return String returnedAtts[] = { "tokenGroups", "objectSid" }; searchCtls.setReturningAttributes(returnedAtts); //Search for tokens. Since every user *must* have a SID, the "no user" detection should be safe. NamingEnumeration answer = ctx.search(searchBase, searchFilter, searchCtls); List<String> theGroups = new ArrayList<String>(); String userToken = userTokenFromLoginName(domainPart + "\\" + userPart); if (userToken != null) theGroups.add(userToken); //Loop through the search results while (answer.hasMoreElements()) { SearchResult sr = (SearchResult) answer.next(); //the sr.GetName should be null, as it is relative to the base object Attributes attrs = sr.getAttributes(); if (attrs != null) { try { for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) { Attribute attr = (Attribute) ae.next(); for (NamingEnumeration e = attr.getAll(); e.hasMore();) { String sid = sid2String((byte[]) e.next()); String token = attr.getID().equals("objectSid") ? userTokenFromSID(sid) : groupTokenFromSID(sid); theGroups.add(token); } } } catch (NamingException e) { throw new ManifoldCFException(e.getMessage(), e); } } } if (theGroups.size() == 0) return null; // User is in AD, so add the 'everyone' group theGroups.add(everyoneGroup()); return theGroups; }
From source file:business.security.control.OwmClient.java
/** * Get the weather history of a city./*w w w . ja v a 2 s. c om*/ * * @param cityId is the OWM city ID * @param type is the history type (frequency) to use. */ public WeatherHistoryCityResponse historyWeatherAtCity(int cityId, HistoryType type) throws JSONException, IOException { if (type == HistoryType.UNKNOWN) { throw new IllegalArgumentException("Can't do a historic request for unknown type of history."); } String subUrl = String.format(Locale.ROOT, "history/city/%d?type=%s", cityId, type); JSONObject response = doQuery(subUrl); return new WeatherHistoryCityResponse(response); }
From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java
/** * <p>/*from w ww . j av a 2s .com*/ * Converts all the delimiter separated words in a String into capitalized * words, that is each word is made up of a titlecase character and then a * series of lowercase characters. * </p> * * <p> * The delimiters represent a set of characters understood to separate * words. The first string character and the first non-delimiter character * after a delimiter will be capitalized. * </p> * * <p> * A <code>null</code> input String returns <code>null</code>. * Capitalization uses the Unicode title case, normally equivalent to upper * case. * </p> * * <pre> * WordUtils.capitalizeFully(null, *) = null * WordUtils.capitalizeFully("", *) = "" * WordUtils.capitalizeFully(*, null) = * * WordUtils.capitalizeFully(*, new char[0]) = * * WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine" * </pre> * * @param str * the String to capitalize, may be null * @param delimiters * set of characters to determine capitalization, null means * whitespace * @return capitalized String, <code>null</code> if null String input * @since 2.1 */ public static String capitalizeFully(String str, final char... delimiters) { final int delimLen = delimiters == null ? -1 : delimiters.length; if (StringUtils.isEmpty(str) || delimLen == 0) { return str; } str = str.toLowerCase(Locale.ROOT); return capitalize(str, delimiters); }
From source file:org.elasticsearch.xpack.ml.integration.DatafeedJobsRestIT.java
private void addNetworkData(String index) throws IOException { // Create index with source = enabled, doc_values = enabled, stored = false + multi-field String mappings = "{" + " \"mappings\": {" + " \"doc\": {" + " \"properties\": {" + " \"timestamp\": { \"type\":\"date\"}," + " \"host\": {" + " \"type\":\"text\"," + " \"fields\":{" + " \"text\":{\"type\":\"text\"}," + " \"keyword\":{\"type\":\"keyword\"}" + " }" + " }," + " \"network_bytes_out\": { \"type\":\"long\"}" + " }" + " }" + " }" + "}"; client().performRequest("put", index, Collections.emptyMap(), new StringEntity(mappings, ContentType.APPLICATION_JSON)); String docTemplate = "{\"timestamp\":%d,\"host\":\"%s\",\"network_bytes_out\":%d}"; Date date = new Date(1464739200735L); for (int i = 0; i < 120; i++) { long byteCount = randomNonNegativeLong(); String jsonDoc = String.format(Locale.ROOT, docTemplate, date.getTime(), "hostA", byteCount); client().performRequest("post", index + "/doc", Collections.emptyMap(), new StringEntity(jsonDoc, ContentType.APPLICATION_JSON)); byteCount = randomNonNegativeLong(); jsonDoc = String.format(Locale.ROOT, docTemplate, date.getTime(), "hostB", byteCount); client().performRequest("post", index + "/doc", Collections.emptyMap(), new StringEntity(jsonDoc, ContentType.APPLICATION_JSON)); date = new Date(date.getTime() + 10_000); }/*www. ja va 2s. c o m*/ // Ensure all data is searchable client().performRequest("post", "_refresh"); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlForm.java
private boolean isValidForSubmission(final HtmlElement element, final SubmittableElement submitElement) { final String tagName = element.getTagName(); if (!SUBMITTABLE_ELEMENT_NAMES.contains(tagName)) { return false; }//from w w w . ja v a2s . c o m if (element.hasAttribute("disabled")) { return false; } // clicked input type="image" is submitted even if it hasn't a name if (element == submitElement && element instanceof HtmlImageInput) { return true; } if (!HtmlIsIndex.TAG_NAME.equals(tagName) && !element.hasAttribute("name")) { return false; } if (!HtmlIsIndex.TAG_NAME.equals(tagName) && "".equals(element.getAttribute("name"))) { return false; } if (element instanceof HtmlInput) { final String type = element.getAttribute("type").toLowerCase(Locale.ROOT); if ("radio".equals(type) || "checkbox".equals(type)) { return ((HtmlInput) element).isChecked(); } } if (HtmlSelect.TAG_NAME.equals(tagName)) { return ((HtmlSelect) element).isValidForSubmission(); } return true; }
From source file:org.elasticsearch.client.RequestTests.java
public void testUpdate() throws IOException { XContentType xContentType = randomFrom(XContentType.values()); Map<String, String> expectedParams = new HashMap<>(); String index = randomAsciiOfLengthBetween(3, 10); String type = randomAsciiOfLengthBetween(3, 10); String id = randomAsciiOfLengthBetween(3, 10); UpdateRequest updateRequest = new UpdateRequest(index, type, id); updateRequest.detectNoop(randomBoolean()); if (randomBoolean()) { BytesReference source = RandomObjects.randomSource(random(), xContentType); updateRequest.doc(new IndexRequest().source(source, xContentType)); boolean docAsUpsert = randomBoolean(); updateRequest.docAsUpsert(docAsUpsert); if (docAsUpsert) { expectedParams.put("doc_as_upsert", "true"); }//w ww. j a va2 s .c o m } else { updateRequest.script(new Script("_value + 1")); updateRequest.scriptedUpsert(randomBoolean()); } if (randomBoolean()) { BytesReference source = RandomObjects.randomSource(random(), xContentType); updateRequest.upsert(new IndexRequest().source(source, xContentType)); } if (randomBoolean()) { String routing = randomAsciiOfLengthBetween(3, 10); updateRequest.routing(routing); expectedParams.put("routing", routing); } if (randomBoolean()) { String parent = randomAsciiOfLengthBetween(3, 10); updateRequest.parent(parent); expectedParams.put("parent", parent); } if (randomBoolean()) { String timeout = randomTimeValue(); updateRequest.timeout(timeout); expectedParams.put("timeout", timeout); } else { expectedParams.put("timeout", ReplicationRequest.DEFAULT_TIMEOUT.getStringRep()); } if (randomBoolean()) { WriteRequest.RefreshPolicy refreshPolicy = randomFrom(WriteRequest.RefreshPolicy.values()); updateRequest.setRefreshPolicy(refreshPolicy); if (refreshPolicy != WriteRequest.RefreshPolicy.NONE) { expectedParams.put("refresh", refreshPolicy.getValue()); } } if (randomBoolean()) { int waitForActiveShards = randomIntBetween(0, 10); updateRequest.waitForActiveShards(waitForActiveShards); expectedParams.put("wait_for_active_shards", String.valueOf(waitForActiveShards)); } if (randomBoolean()) { long version = randomLong(); updateRequest.version(version); if (version != Versions.MATCH_ANY) { expectedParams.put("version", Long.toString(version)); } } if (randomBoolean()) { VersionType versionType = randomFrom(VersionType.values()); updateRequest.versionType(versionType); if (versionType != VersionType.INTERNAL) { expectedParams.put("version_type", versionType.name().toLowerCase(Locale.ROOT)); } } if (randomBoolean()) { int retryOnConflict = randomIntBetween(0, 5); updateRequest.retryOnConflict(retryOnConflict); if (retryOnConflict > 0) { expectedParams.put("retry_on_conflict", String.valueOf(retryOnConflict)); } } if (randomBoolean()) { randomizeFetchSourceContextParams(updateRequest::fetchSource, expectedParams); } Request request = Request.update(updateRequest); assertEquals("/" + index + "/" + type + "/" + id + "/_update", request.endpoint); assertEquals(expectedParams, request.params); assertEquals("POST", request.method); HttpEntity entity = request.entity; assertNotNull(entity); assertTrue(entity instanceof ByteArrayEntity); UpdateRequest parsedUpdateRequest = new UpdateRequest(); XContentType entityContentType = XContentType.fromMediaTypeOrFormat(entity.getContentType().getValue()); try (XContentParser parser = createParser(entityContentType.xContent(), entity.getContent())) { parsedUpdateRequest.fromXContent(parser); } assertEquals(updateRequest.scriptedUpsert(), parsedUpdateRequest.scriptedUpsert()); assertEquals(updateRequest.docAsUpsert(), parsedUpdateRequest.docAsUpsert()); assertEquals(updateRequest.detectNoop(), parsedUpdateRequest.detectNoop()); assertEquals(updateRequest.fetchSource(), parsedUpdateRequest.fetchSource()); assertEquals(updateRequest.script(), parsedUpdateRequest.script()); if (updateRequest.doc() != null) { assertToXContentEquivalent(updateRequest.doc().source(), parsedUpdateRequest.doc().source(), xContentType); } else { assertNull(parsedUpdateRequest.doc()); } if (updateRequest.upsertRequest() != null) { assertToXContentEquivalent(updateRequest.upsertRequest().source(), parsedUpdateRequest.upsertRequest().source(), xContentType); } else { assertNull(parsedUpdateRequest.upsertRequest()); } }
From source file:com.gargoylesoftware.htmlunit.CodeStyleTest.java
/** * Checks the year in LICENSE.txt./*from ww w. ja v a 2 s .c om*/ */ private void licenseYear() throws IOException { final List<String> lines = FileUtils.readLines(new File("LICENSE.txt")); if (!lines.get(1).contains("Copyright (c) 2002-" + Calendar.getInstance(Locale.ROOT).get(Calendar.YEAR))) { addFailure("Incorrect year in LICENSE.txt"); } }
From source file:business.security.control.OwmClient.java
/** * Get the weather history of a city.// w w w.j a v a 2s. c o m * * @param stationId is the OWM station ID * @param type is the history type (frequency) to use. */ public WeatherHistoryStationResponse historyWeatherAtStation(int stationId, HistoryType type) throws JSONException, IOException { if (type == HistoryType.UNKNOWN) { throw new IllegalArgumentException("Can't do a historic request for unknown type of history."); } String subUrl = String.format(Locale.ROOT, "history/station/%d?type=%s", stationId, type); JSONObject response = doQuery(subUrl); return new WeatherHistoryStationResponse(response); }
From source file:grails.plugins.sitemapper.impl.XmlEntryWriter.java
protected void printAlternateLink(String locationUrl, String language) throws IOException { String xml = String.format("<%s rel=\"alternate\" hreflang=\"%s\" href=\"%s\"/>", ALT_LINK, language.toLowerCase(Locale.ROOT), locationUrl); output.append(xml);//ww w.j a va 2s . c om }