Example usage for java.util Locale ROOT

List of usage examples for java.util Locale ROOT

Introduction

In this page you can find the example usage for java.util Locale ROOT.

Prototype

Locale ROOT

To view the source code for java.util Locale ROOT.

Click Source Link

Document

Useful constant for the root locale.

Usage

From source file:com.gargoylesoftware.htmlunit.activex.javascript.msxml.XMLHTTPRequest.java

/**
 * Initializes the request and specifies the method, URL, and authentication information for the request.
 * @param method the HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND;
 *      for XMLHTTP, this parameter is not case-sensitive; the verbs TRACE and TRACK are not allowed.
 * @param url the requested URL; this can be either an absolute URL or a relative URL
 * @param asyncParam indicator of whether the call is asynchronous; the default is {@code true} (the call
 *     returns immediately); if set to {@code true}, attach an <code>onreadystatechange</code> property
 *     callback so that you can tell when the <code>send</code> call has completed
 * @param user the name of the user for authentication
 * @param password the password for authentication
 *///from w  w w. j a  v  a  2  s  .  c o  m
@JsxFunction
public void open(final String method, final Object url, final Object asyncParam, final Object user,
        final Object password) {
    if (method == null || "null".equals(method)) {
        throw Context.reportRuntimeError("Type mismatch (method is null).");
    }
    if (url == null || "null".equals(url)) {
        throw Context.reportRuntimeError("Type mismatch (url is null).");
    }
    state_ = STATE_UNSENT;
    openedMultipleTimes_ = webRequest_ != null;
    sent_ = false;
    webRequest_ = null;
    webResponse_ = null;
    if ("".equals(method) || "TRACE".equalsIgnoreCase(method)) {
        throw Context.reportRuntimeError("Invalid procedure call or argument (method is invalid).");
    }
    if ("".equals(url)) {
        throw Context.reportRuntimeError("Invalid procedure call or argument (url is empty).");
    }

    // defaults to true if not specified
    boolean async = true;
    if (asyncParam != Undefined.instance) {
        async = ScriptRuntime.toBoolean(asyncParam);
    }

    final String urlAsString = Context.toString(url);

    // (URL + Method + User + Password) become a WebRequest instance.
    containingPage_ = (HtmlPage) getWindow().getWebWindow().getEnclosedPage();

    try {
        final URL fullUrl = containingPage_.getFullyQualifiedUrl(urlAsString);

        final WebRequest request = new WebRequest(fullUrl);
        request.setCharset("UTF-8");
        request.setAdditionalHeader("Referer", containingPage_.getUrl().toExternalForm());

        request.setHttpMethod(HttpMethod.valueOf(method.toUpperCase(Locale.ROOT)));

        // password is ignored if no user defined
        final boolean userIsNull = null == user || Undefined.instance == user;
        if (!userIsNull) {
            final String userCred = user.toString();

            final boolean passwordIsNull = null == password || Undefined.instance == password;
            String passwordCred = "";
            if (!passwordIsNull) {
                passwordCred = password.toString();
            }

            request.setCredentials(new UsernamePasswordCredentials(userCred, passwordCred));
        }
        webRequest_ = request;
    } catch (final MalformedURLException e) {
        LOG.error("Unable to initialize XMLHTTPRequest using malformed URL '" + urlAsString + "'.");
        return;
    } catch (final IllegalArgumentException e) {
        LOG.error("Unable to initialize XMLHTTPRequest using illegal argument '" + e.getMessage() + "'.");
        webRequest_ = null;
    }
    // Async stays a boolean.
    async_ = async;
    // Change the state!
    setState(STATE_OPENED, null);
}

From source file:com.facebook.unity.FB.java

private static void LogMethodCall(String methodName, String paramsStr) {
    Log.v(TAG, String.format(Locale.ROOT, "%s(%s)", methodName, paramsStr));
}

From source file:ingest.utility.IngestUtilities.java

/**
 * Searches directory file list for the first shape file and returns the name (non-recursive)
 * // ww w . j ava2  s  .com
 * @param directoryPath
 *            Folder path to search
 * 
 * @return shape file name found in the directory
 */
public String findShapeFileName(String directoryPath) throws IOException {
    File[] files = new File(directoryPath).listFiles();
    for (int index = 0; index < files.length; index++) {
        String fileName = files[index].getName();
        if (fileName.toLowerCase(Locale.ROOT).endsWith(".shp"))
            return fileName;
    }

    throw new IOException("No shape file was found inside unzipped directory: " + directoryPath);
}

From source file:org.apache.manifoldcf.authorities.authorities.sharepoint.SharePointADAuthority.java

protected static String groupTokenFromSID(String SID) {
    return "c:0+.w|" + SID.toLowerCase(Locale.ROOT);
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlForm.java

/**
 * Same as {@link #getElementsByAttribute(String, String, String)} but
 * ignoring elements that are contained in a nested form.
 *//*  w  ww.  j a  v a2  s.  c  o  m*/
@SuppressWarnings("unchecked")
private <E extends HtmlElement> List<E> getFormElementsByAttribute(final String elementName,
        final String attributeName, final String attributeValue) {

    final List<E> list = new ArrayList<>();
    final String lowerCaseTagName = elementName.toLowerCase(Locale.ROOT);

    for (final HtmlElement next : getFormHtmlElementDescendants()) {
        if (next.getTagName().equals(lowerCaseTagName)) {
            final String attValue = next.getAttribute(attributeName);
            if (attValue != null && attValue.equals(attributeValue)) {
                list.add((E) next);
            }
        }
    }
    return list;
}

From source file:org.apache.manifoldcf.authorities.authorities.sharepoint.SharePointADAuthority.java

protected static String userTokenFromSID(String SID) {
    return "i:0+.w|" + SID.toLowerCase(Locale.ROOT);
}

From source file:org.elasticsearch.plugins.PluginManagerIT.java

public void testLocalPluginInstallWithBinOnly_7152() throws Exception {
    String pluginName = "fake-plugin";
    Path pluginDir = createTempDir().resolve(pluginName);
    // create bin/tool
    Files.createDirectories(pluginDir.resolve("bin"));
    Files.createFile(pluginDir.resolve("bin").resolve("tool"));
    ;//from  w ww. j a  v  a2  s . c om
    String pluginUrl = createPlugin(pluginDir, "description", "fake desc", "name", "fake-plugin", "version",
            "1.0", "elasticsearch.version", Version.CURRENT.toString(), "java.version",
            System.getProperty("java.specification.version"), "jvm", "true", "classname", "FakePlugin");

    Path binDir = environment.binFile();
    Path pluginBinDir = binDir.resolve(pluginName);

    assertStatusOk(String.format(Locale.ROOT, "install %s --verbose", pluginUrl));
    assertThatPluginIsListed(pluginName);
    assertDirectoryExists(pluginBinDir);
}

From source file:com.puppycrawl.tools.checkstyle.CheckerTest.java

@Test
public void testCacheFileChangeInConfig() throws Exception {
    final DefaultConfiguration checkConfig = createCheckConfig(HiddenFieldCheck.class);

    final DefaultConfiguration treeWalkerConfig = createCheckConfig(TreeWalker.class);
    treeWalkerConfig.addChild(checkConfig);

    final DefaultConfiguration checkerConfig = new DefaultConfiguration("configuration");
    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);/*from   w  w  w  .jav a 2 s  .  com*/
    checker.addListener(new BriefUtLogger(stream));

    final String pathToEmptyFile = temporaryFolder.newFile("file.java").getPath();
    final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;

    verify(checker, pathToEmptyFile, pathToEmptyFile, expected);

    // update Checker config
    checker.destroy();
    checker.configure(checkerConfig);

    final Checker otherChecker = new Checker();
    otherChecker.setLocaleCountry(locale.getCountry());
    otherChecker.setLocaleLanguage(locale.getLanguage());
    otherChecker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
    otherChecker.configure(checkerConfig);
    otherChecker.addListener(new BriefUtLogger(stream));
    // here is diff with previous checker
    checkerConfig.addAttribute("fileExtensions", "java,javax");

    // one more time on updated config
    verify(otherChecker, pathToEmptyFile, pathToEmptyFile, expected);
}

From source file:net.yacy.crawler.retrieval.HTTPLoader.java

private Response load(final Request request, CrawlProfile profile, final int retryCount, final int maxFileSize,
        final BlacklistType blacklistType, final ClientIdentification.Agent agent) throws IOException {

    if (retryCount < 0) {
        this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                FailCategory.TEMPORARY_NETWORK_FAILURE, "retry counter exceeded", -1);
        throw new IOException(
                "retry counter exceeded for URL " + request.url().toString() + ". Processing aborted.$");
    }/* w  w  w  .  j ava2 s . c  o  m*/

    DigestURL url = request.url();

    final String host = url.getHost();
    if (host == null || host.length() < 2)
        throw new IOException("host is not well-formed: '" + host + "'");
    final String path = url.getFile();
    int port = url.getPort();
    final boolean ssl = url.getProtocol().equals("https");
    if (port < 0)
        port = (ssl) ? 443 : 80;

    // check if url is in blacklist
    final String hostlow = host.toLowerCase(Locale.ROOT);
    if (blacklistType != null && Switchboard.urlBlacklist.isListed(blacklistType, hostlow, path)) {
        this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                FailCategory.FINAL_LOAD_CONTEXT, "url in blacklist", -1);
        throw new IOException(
                "CRAWLER Rejecting URL '" + request.url().toString() + "'. URL is in blacklist.$");
    }

    // resolve yacy and yacyh domains
    final AlternativeDomainNames yacyResolver = this.sb.peers;
    if (yacyResolver != null) {
        final String yAddress = yacyResolver.resolve(host);
        if (yAddress != null) {
            url = new DigestURL(url.getProtocol() + "://" + yAddress + path);
        }
    }

    // take a file from the net
    Response response = null;

    // create a request header
    final RequestHeader requestHeader = createRequestheader(request, agent);

    // HTTP-Client
    final HTTPClient client = new HTTPClient(agent);
    client.setRedirecting(false); // we want to handle redirection ourselves, so we don't index pages twice
    client.setTimout(this.socketTimeout);
    client.setHeader(requestHeader.entrySet());

    // send request
    final byte[] responseBody = client.GETbytes(url,
            sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin"),
            sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, ""), maxFileSize, false);
    final int statusCode = client.getHttpResponse().getStatusLine().getStatusCode();
    final ResponseHeader responseHeader = new ResponseHeader(statusCode,
            client.getHttpResponse().getAllHeaders());
    String requestURLString = request.url().toNormalform(true);

    // check redirection
    if (statusCode > 299 && statusCode < 310) {

        final DigestURL redirectionUrl = extractRedirectURL(request, profile, url,
                client.getHttpResponse().getStatusLine(), responseHeader, requestURLString);

        if (this.sb.getConfigBool(SwitchboardConstants.CRAWLER_FOLLOW_REDIRECTS, true)) {
            // we have two use cases here: loading from a crawl or just loading the url. Check this:
            if (profile != null && !CrawlSwitchboard.DEFAULT_PROFILES.contains(profile.name())) {
                // put redirect url on the crawler queue to repeat a double-check
                /* We have to clone the request instance and not to modify directly its URL, 
                 * otherwise the stackCrawl() function would reject it, because detecting it as already in the activeWorkerEntries */
                Request redirectedRequest = new Request(request.initiator(), redirectionUrl,
                        request.referrerhash(), request.name(), request.appdate(), request.profileHandle(),
                        request.depth(), request.timezoneOffset());
                String rejectReason = this.sb.crawlStacker.stackCrawl(redirectedRequest);
                // in the end we must throw an exception (even if this is not an error, just to abort the current process
                if (rejectReason != null) {
                    throw new IOException("CRAWLER Redirect of URL=" + requestURLString + " aborted. Reason : "
                            + rejectReason);
                }
                throw new IOException("CRAWLER Redirect of URL=" + requestURLString + " to "
                        + redirectionUrl.toNormalform(false) + " placed on crawler queue for double-check");

            }

            // if we are already doing a shutdown we don't need to retry crawling
            if (Thread.currentThread().isInterrupted()) {
                this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                        FailCategory.FINAL_LOAD_CONTEXT, "server shutdown", statusCode);
                throw new IOException("CRAWLER Redirect of URL=" + requestURLString
                        + " aborted because of server shutdown.$");
            }

            // retry crawling with new url
            request.redirectURL(redirectionUrl);
            return load(request, profile, retryCount - 1, maxFileSize, blacklistType, agent);
        }
        // we don't want to follow redirects
        this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                FailCategory.FINAL_PROCESS_CONTEXT, "redirection not wanted", statusCode);
        throw new IOException("REJECTED UNWANTED REDIRECTION '" + client.getHttpResponse().getStatusLine()
                + "' for URL '" + requestURLString + "'$");
    } else if (responseBody == null) {
        // no response, reject file
        this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                FailCategory.TEMPORARY_NETWORK_FAILURE, "no response body", statusCode);
        throw new IOException("REJECTED EMPTY RESPONSE BODY '" + client.getHttpResponse().getStatusLine()
                + "' for URL '" + requestURLString + "'$");
    } else if (statusCode == 200 || statusCode == 203) {
        // the transfer is ok

        // we write the new cache entry to file system directly
        final long contentLength = responseBody.length;
        ByteCount.addAccountCount(ByteCount.CRAWLER, contentLength);

        // check length again in case it was not possible to get the length before loading
        if (maxFileSize >= 0 && contentLength > maxFileSize) {
            this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                    FailCategory.FINAL_PROCESS_CONTEXT, "file size limit exceeded", statusCode);
            throw new IOException("REJECTED URL " + request.url() + " because file size '" + contentLength
                    + "' exceeds max filesize limit of " + maxFileSize + " bytes. (GET)$");
        }

        // create a new cache entry
        response = new Response(request, requestHeader, responseHeader, profile, false, responseBody);

        return response;
    } else {
        // if the response has not the right response type then reject file
        this.sb.crawlQueues.errorURL.push(request.url(), request.depth(), profile,
                FailCategory.TEMPORARY_NETWORK_FAILURE, "wrong http status code", statusCode);
        throw new IOException("REJECTED WRONG STATUS TYPE '" + client.getHttpResponse().getStatusLine()
                + "' for URL '" + requestURLString + "'$");
    }
}