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:org.apache.solr.util.SolrCLI.java
private static final String uptime(long uptimeMs) { if (uptimeMs <= 0L) return "?"; long numDays = (uptimeMs >= MS_IN_DAY) ? (long) Math.floor(uptimeMs / MS_IN_DAY) : 0L; long rem = uptimeMs - (numDays * MS_IN_DAY); long numHours = (rem >= MS_IN_HOUR) ? (long) Math.floor(rem / MS_IN_HOUR) : 0L; rem = rem - (numHours * MS_IN_HOUR); long numMinutes = (rem >= MS_IN_MIN) ? (long) Math.floor(rem / MS_IN_MIN) : 0L; rem = rem - (numMinutes * MS_IN_MIN); long numSeconds = Math.round(rem / 1000); return String.format(Locale.ROOT, "%d days, %d hours, %d minutes, %d seconds", numDays, numHours, numMinutes, numSeconds);/*from w ww. j av a 2s . c o m*/ }
From source file:com.gargoylesoftware.htmlunit.javascript.host.xml.XMLHttpRequestTest.java
/** * @throws Exception if the test fails// ww w . j av a 2 s . c o m */ @Test public void isAuthorizedHeader() throws Exception { assertTrue(XMLHttpRequest.isAuthorizedHeader("Foo")); assertTrue(XMLHttpRequest.isAuthorizedHeader("Content-Type")); final String[] headers = { "accept-charset", "accept-encoding", "connection", "content-length", "cookie", "cookie2", "content-transfer-encoding", "date", "expect", "host", "keep-alive", "referer", "te", "trailer", "transfer-encoding", "upgrade", "user-agent", "via" }; for (final String header : headers) { assertFalse(XMLHttpRequest.isAuthorizedHeader(header)); assertFalse(XMLHttpRequest.isAuthorizedHeader(header.toUpperCase(Locale.ROOT))); } assertFalse(XMLHttpRequest.isAuthorizedHeader("Proxy-")); assertFalse(XMLHttpRequest.isAuthorizedHeader("Proxy-Control")); assertFalse(XMLHttpRequest.isAuthorizedHeader("Proxy-Hack")); assertFalse(XMLHttpRequest.isAuthorizedHeader("Sec-")); assertFalse(XMLHttpRequest.isAuthorizedHeader("Sec-Hack")); }
From source file:com.udojava.evalex.Expression.java
/** * Check that the expression has enough numbers and variables to fit the * requirements of the operators and functions, also check * for only 1 result stored at the end of the evaluation. *//*w ww.j av a 2 s . c o m*/ private void validate(List<String> rpn) { /*- * Thanks to Norman Ramsey: * http://http://stackoverflow.com/questions/789847/postfix-notation-validation */ // each push on to this stack is a new function scope, with the value of each // layer on the stack being the count of the number of parameters in that scope Stack<Integer> stack = new Stack<>(); // push the 'global' scope stack.push(0); for (final String token : rpn) { if (operators.containsKey(token)) { if (stack.peek() < 2) { throw new ExpressionException("Missing parameter(s) for operator " + token); } // pop the operator's 2 parameters and add the result stack.set(stack.size() - 1, stack.peek() - 2 + 1); } else if (mainVars.containsKey(token)) { stack.set(stack.size() - 1, stack.peek() + 1); } else if (functions.containsKey(token.toUpperCase(Locale.ROOT))) { LazyFunction f = functions.get(token.toUpperCase(Locale.ROOT)); int numParams = stack.pop(); if (!f.numParamsVaries() && numParams != f.getNumParams()) { throw new ExpressionException("Function " + token + " expected " + f.getNumParams() + " parameters, got " + numParams); } if (stack.size() <= 0) { throw new ExpressionException("Too many function calls, maximum scope exceeded"); } // push the result of the function stack.set(stack.size() - 1, stack.peek() + 1); } else if ("(".equals(token)) { stack.push(0); } else { stack.set(stack.size() - 1, stack.peek() + 1); } } if (stack.size() > 1) { throw new ExpressionException("Too many unhandled function parameter lists"); } else if (stack.peek() > 1) { throw new ExpressionException("Too many numbers or variables"); } else if (stack.peek() < 1) { throw new ExpressionException("Empty expression"); } }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
/** * get the hpath plus search field plus anchor (if wanted) * see http://www.ietf.org/rfc/rfc1738.txt for naming. * if there is no search and no anchor the result is identical to getPath * this is defined according to http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URL.html#getFile() * @param excludeAnchor// w ww . j a v a2s. c om * @param removeSessionID * @return */ public String getFile(final boolean excludeAnchor, final boolean removeSessionID) { if (this.searchpart == null) { if (excludeAnchor || this.anchor == null) return this.path; final StringBuilder sb = new StringBuilder(120); sb.append(this.path); sb.append('#'); sb.append(this.anchor); return sb.toString(); } String q = this.searchpart; if (removeSessionID) { for (final String sid : sessionIDnames.keySet()) { if (q.toLowerCase(Locale.ROOT).startsWith(sid.toLowerCase(Locale.ROOT) + "=")) { final int p = q.indexOf('&'); if (p < 0) { if (excludeAnchor || this.anchor == null) return this.path; final StringBuilder sb = new StringBuilder(120); sb.append(this.path); sb.append('#'); sb.append(this.anchor); return sb.toString(); } q = q.substring(p + 1); continue; } final int p = q.toLowerCase(Locale.ROOT).indexOf("&" + sid.toLowerCase(Locale.ROOT) + "=", 0); if (p < 0) continue; final int p1 = q.indexOf('&', p + 1); if (p1 < 0) { q = q.substring(0, p); } else { q = q.substring(0, p) + q.substring(p1); } } } final StringBuilder sb = new StringBuilder(120); sb.append(this.path); sb.append('?'); sb.append(q); if (excludeAnchor || this.anchor == null) return sb.toString(); sb.append('#'); sb.append(this.anchor); return sb.toString(); }
From source file:com.gargoylesoftware.htmlunit.util.EncodingSniffer.java
/** * Translates the given encoding label into a normalized form * according to <a href="http://encoding.spec.whatwg.org/#encodings">Reference</a>. * @param encodingLabel the label to translate * @return the normalized encoding name or null if not found *//*from ww w . j a v a 2s.c om*/ public static String translateEncodingLabel(final String encodingLabel) { if (null == encodingLabel) { return null; } final String encLC = encodingLabel.trim().toLowerCase(Locale.ROOT); final String enc = ENCODING_FROM_LABEL.get(encLC); if (encLC.equals(enc)) { return encodingLabel; } return enc; }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
/** * Get extension out of a filename in lowercase * cuts off query part/*from ww w. j a va 2 s . c o m*/ * @param fileName * @return extension or "" */ public static String getFileExtension(final String fileName) { int p = fileName.lastIndexOf('.'); if (p < 0) return ""; final int q = fileName.lastIndexOf('?'); if (q < 0) { return fileName.substring(p + 1).toLowerCase(Locale.ROOT); } // check last dot in query part if (p > q) { p = fileName.lastIndexOf('.', q); if (p < 0) return ""; } return fileName.substring(p + 1, q).toLowerCase(Locale.ROOT); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlFormTest.java
/** * Utility for {@link #submitRequestCharset()} * @param headerCharset the charset for the content type header if not null * @param metaCharset the charset for the meta http-equiv content type tag if not null * @param formCharset the charset for the form's accept-charset attribute if not null * @param expectedRequestCharset the charset expected for the form submission * @throws Exception if the test fails//from w w w . j a v a2 s .c om */ private void submitRequestCharset(final String headerCharset, final String metaCharset, final String formCharset, final String expectedRequestCharset) throws Exception { final String formAcceptCharset; if (formCharset == null) { formAcceptCharset = ""; } else { formAcceptCharset = " accept-charset='" + formCharset + "'"; } final String metaContentType; if (metaCharset == null) { metaContentType = ""; } else { metaContentType = "<meta http-equiv='Content-Type' content='text/html; charset=" + metaCharset + "'>\n"; } final String html = "<html><head><title>foo</title>\n" + metaContentType + "</head><body>\n" + "<form name='form1' method='post' action='foo'" + formAcceptCharset + ">\n" + "<input type='text' name='textField' value='foo'/>\n" + "<input type='text' name='nonAscii' value='Flo\u00DFfahrt'/>\n" + "<input type='submit' name='button' value='foo'/>\n" + "</form></body></html>"; final WebClient client = getWebClientWithMockWebConnection(); final MockWebConnection webConnection = getMockWebConnection(); String contentType = "text/html"; if (headerCharset != null) { contentType += ";charset=" + headerCharset; } webConnection.setDefaultResponse(html, 200, "ok", contentType); final HtmlPage page = client.getPage(getDefaultUrl()); final String firstPageEncoding = StringUtils.defaultString(metaCharset, headerCharset) .toUpperCase(Locale.ROOT); assertEquals(firstPageEncoding, page.getPageEncoding()); final HtmlForm form = page.getFormByName("form1"); form.getInputByName("button").click(); assertEquals(expectedRequestCharset, webConnection.getLastWebRequest().getCharset()); }
From source file:com.gargoylesoftware.htmlunit.html.DomElement.java
private String fixName(final String name) { if (caseSensitive_) { return name; }// w w w.j a v a 2 s. c om return name.toLowerCase(Locale.ROOT); }
From source file:net.yacy.cora.document.id.MultiProtocolURL.java
public InetAddress getInetAddress() { if (this.hostAddress != null) return this.hostAddress; if (this.host == null) return null; // this may happen for file:// urls this.hostAddress = Domains.dnsResolve(this.host.toLowerCase(Locale.ROOT)); return this.hostAddress; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage.java
/** * If a refresh has been specified either through a meta tag or an HTTP * response header, then perform that refresh. * @throws IOException if an IO problem occurs *//*from w ww .j a v a 2 s . c o m*/ private void executeRefreshIfNeeded() throws IOException { // If this page is not in a frame then a refresh has already happened, // most likely through the JavaScript onload handler, so we don't do a // second refresh. final WebWindow window = getEnclosingWindow(); if (window == null) { return; } final String refreshString = getRefreshStringOrNull(); if (refreshString == null || refreshString.isEmpty()) { return; } final double time; final URL url; int index = StringUtils.indexOfAnyBut(refreshString, "0123456789"); final boolean timeOnly = index == -1; if (timeOnly) { // Format: <meta http-equiv='refresh' content='10'> try { time = Double.parseDouble(refreshString); } catch (final NumberFormatException e) { LOG.error("Malformed refresh string (no ';' but not a number): " + refreshString, e); return; } url = getUrl(); } else { // Format: <meta http-equiv='refresh' content='10;url=http://www.blah.com'> try { time = Double.parseDouble(refreshString.substring(0, index).trim()); } catch (final NumberFormatException e) { LOG.error("Malformed refresh string (no valid number before ';') " + refreshString, e); return; } index = refreshString.toLowerCase(Locale.ROOT).indexOf("url=", index); if (index == -1) { LOG.error("Malformed refresh string (found ';' but no 'url='): " + refreshString); return; } final StringBuilder buffer = new StringBuilder(refreshString.substring(index + 4)); if (StringUtils.isBlank(buffer.toString())) { //content='10; URL=' is treated as content='10' url = getUrl(); } else { if (buffer.charAt(0) == '"' || buffer.charAt(0) == 0x27) { buffer.deleteCharAt(0); } if (buffer.charAt(buffer.length() - 1) == '"' || buffer.charAt(buffer.length() - 1) == 0x27) { buffer.deleteCharAt(buffer.length() - 1); } final String urlString = buffer.toString(); try { url = getFullyQualifiedUrl(urlString); } catch (final MalformedURLException e) { LOG.error("Malformed URL in refresh string: " + refreshString, e); throw e; } } } final int timeRounded = (int) time; getWebClient().getRefreshHandler().handleRefresh(this, url, timeRounded); }