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:org.apache.solr.handler.IndexFetcher.java

private String getDateAsStr(Date d) {
    return new SimpleDateFormat(SnapShooter.DATE_FMT, Locale.ROOT).format(d);
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * Generates a normal form of the URL./*from w  w w. j a va 2s .c om*/
 * For file: url it normalizes also path delimiter to be '/' (replace possible Windows '\'
 * @param excludeAnchor
 * @param removeSessionID
 * @return
 */
public String toNormalform(final boolean excludeAnchor, final boolean removeSessionID) {
    boolean defaultPort = false;
    if (this.protocol.equals("mailto")) {
        return this.protocol + ":" + this.userInfo + "@" + this.host;
    } else if (isHTTP()) {
        if (this.port < 0 || this.port == 80) {
            defaultPort = true;
        }
    } else if (isHTTPS()) {
        if (this.port < 0 || this.port == 443) {
            defaultPort = true;
        }
    } else if (isFTP()) {
        if (this.port < 0 || this.port == 21) {
            defaultPort = true;
        }
    } else if (isSMB()) {
        if (this.port < 0 || this.port == 445) {
            defaultPort = true;
        }
    } else if (isFile()) {
        defaultPort = true;
    }
    String urlPath = this.getFile(excludeAnchor, removeSessionID);
    String h = getHost();
    final StringBuilder u = new StringBuilder(
            20 + (urlPath == null ? 0 : urlPath.length()) + ((h == null) ? 0 : h.length()));
    u.append(this.protocol);
    u.append("://");
    if (h != null) {
        if (this.userInfo != null && !(this.isFTP() && this.userInfo.startsWith(FTPClient.ANONYMOUS))) {
            u.append(this.userInfo);
            u.append("@");
        }
        u.append(h.toLowerCase(Locale.ROOT));
    }
    if (!defaultPort) {
        u.append(":");
        u.append(this.port);
    }
    if (isFile() && urlPath.indexOf('\\') >= 0) { // normalize windows backslash (important for hash computation)
        urlPath = urlPath.replace('\\', '/');
    }
    u.append(urlPath);
    String result = u.toString();

    return result;
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java

/**
 * Returns the domain name of the server that served the document, or {@code null} if the server
 * cannot be identified by a domain name.
 * @return the domain name of the server that served the document
 * @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-2250147">
 * W3C documentation</a>/*from   w  w w.  j  a v a  2  s .c  o  m*/
 */
@JsxGetter
public String getDomain() {
    if (domain_ == null) {
        URL url = getPage().getUrl();
        if (url == WebClient.URL_ABOUT_BLANK) {
            final WebWindow w = getWindow().getWebWindow();
            if (w instanceof FrameWindow) {
                url = ((FrameWindow) w).getEnclosingPage().getUrl();
            } else {
                return null;
            }
        }
        domain_ = url.getHost();
        if (getBrowserVersion().hasFeature(JS_DOCUMENT_DOMAIN_IS_LOWERCASE)) {
            domain_ = domain_.toLowerCase(Locale.ROOT);
        }
    }

    return domain_;
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * Generates a normal form of the url, without the protocol part,
 * except the skipped protocol part this is identical with toNormalform()
 * @see #toNormalform(boolean)/*from   www.  jav  a  2s  . c om*/
 * @param excludeAnchor, exclude anchor part
 * @param removeSessionID, exclude session id
 * @return example "www.host.com:8080/path/file.html"
 * @see #toNormalform(boolean, boolean)
 */
public String urlstub(final boolean excludeAnchor, final boolean removeSessionID) {
    // generates a normal form of the URL
    boolean defaultPort = false;
    if (this.protocol.equals("mailto")) {
        return this.userInfo + "@" + this.host;
    } else if (isHTTP()) {
        if (this.port < 0 || this.port == 80) {
            defaultPort = true;
        }
    } else if (isHTTPS()) {
        if (this.port < 0 || this.port == 443) {
            defaultPort = true;
        }
    } else if (isFTP()) {
        if (this.port < 0 || this.port == 21) {
            defaultPort = true;
        }
    } else if (isSMB()) {
        if (this.port < 0 || this.port == 445) {
            defaultPort = true;
        }
    } else if (isFile()) {
        defaultPort = true;
    }
    String urlPath = this.getFile(excludeAnchor, removeSessionID);
    String h = getHost();
    final StringBuilder u = new StringBuilder(20 + urlPath.length() + ((h == null) ? 0 : h.length()));
    if (h != null) {
        if (this.userInfo != null && !(this.isFTP() && this.userInfo.startsWith(FTPClient.ANONYMOUS))) {
            u.append(this.userInfo);
            u.append("@");
        }
        u.append(h.toLowerCase(Locale.ROOT));
    }
    if (!defaultPort) {
        u.append(":");
        u.append(this.port);
    }
    u.append(urlPath);
    String result = u.toString();

    return result;
}

From source file:com.facebook.GraphRequest.java

private void serializeToBatch(JSONArray batch, Map<String, Attachment> attachments)
        throws JSONException, IOException {
    JSONObject batchEntry = new JSONObject();

    if (this.batchEntryName != null) {
        batchEntry.put(BATCH_ENTRY_NAME_PARAM, this.batchEntryName);
        batchEntry.put(BATCH_ENTRY_OMIT_RESPONSE_ON_SUCCESS_PARAM, this.batchEntryOmitResultOnSuccess);
    }//from  www  .j av  a 2 s .c  o  m
    if (this.batchEntryDependsOn != null) {
        batchEntry.put(BATCH_ENTRY_DEPENDS_ON_PARAM, this.batchEntryDependsOn);
    }

    String relativeURL = getUrlForBatchedRequest();
    batchEntry.put(BATCH_RELATIVE_URL_PARAM, relativeURL);
    batchEntry.put(BATCH_METHOD_PARAM, httpMethod);
    if (this.accessToken != null) {
        String token = this.accessToken.getToken();
        Logger.registerAccessToken(token);
    }

    // Find all of our attachments. Remember their names and put them in the attachment map.
    ArrayList<String> attachmentNames = new ArrayList<String>();
    Set<String> keys = this.parameters.keySet();
    for (String key : keys) {
        Object value = this.parameters.get(key);
        if (isSupportedAttachmentType(value)) {
            // Make the name unique across this entire batch.
            String name = String.format(Locale.ROOT, "%s%d", ATTACHMENT_FILENAME_PREFIX, attachments.size());
            attachmentNames.add(name);
            attachments.put(name, new Attachment(this, value));
        }
    }

    if (!attachmentNames.isEmpty()) {
        String attachmentNamesString = TextUtils.join(",", attachmentNames);
        batchEntry.put(ATTACHED_FILES_PARAM, attachmentNamesString);
    }

    if (this.graphObject != null) {
        // Serialize the graph object into the "body" parameter.
        final ArrayList<String> keysAndValues = new ArrayList<String>();
        processGraphObject(this.graphObject, relativeURL, new KeyValueSerializer() {
            @Override
            public void writeString(String key, String value) throws IOException {
                keysAndValues.add(String.format(Locale.US, "%s=%s", key, URLEncoder.encode(value, "UTF-8")));
            }
        });
        String bodyValue = TextUtils.join("&", keysAndValues);
        batchEntry.put(BATCH_BODY_PARAM, bodyValue);
    }

    batch.put(batchEntry);
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java

/**
 * Sets the domain of this document./*from   w w  w . j a  v a2 s . com*/
 *
 * Domains can only be set to suffixes of the existing domain
 * with the exception of setting the domain to itself.
 * <p>
 * The domain will be set according to the following rules:
 * <ol>
 * <li>If the newDomain.equalsIgnoreCase(currentDomain) the method returns with no error.</li>
 * <li>If the browser version is netscape, the newDomain is downshifted.</li>
 * <li>The change will take place if and only if the suffixes of the
 *       current domain and the new domain match AND there are at least
 *       two domain qualifiers e.g. the following transformations are legal
 *       d1.d2.d3.gargoylesoftware.com may be transformed to itself or:
 *          d2.d3.gargoylesoftware.com
 *             d3.gargoylesoftware.com
 *                gargoylesoftware.com
 *
 *        transformation to:        com
 *        will fail
 * </li>
 * </ol>
 * </p>
 * TODO This code could be modified to understand country domain suffixes.
 * The domain www.bbc.co.uk should be trimmable only down to bbc.co.uk
 * trimming to co.uk should not be possible.
 * @param newDomain the new domain to set
 */
@JsxSetter
public void setDomain(final String newDomain) {
    final BrowserVersion browserVersion = getBrowserVersion();

    // IE (at least 6) doesn't allow to set domain of about:blank
    if (WebClient.URL_ABOUT_BLANK == getPage().getUrl()
            && browserVersion.hasFeature(JS_DOCUMENT_SETTING_DOMAIN_THROWS_FOR_ABOUT_BLANK)) {
        throw Context.reportRuntimeError("Illegal domain value, cannot set domain from \""
                + WebClient.URL_ABOUT_BLANK + "\" to: \"" + newDomain + "\".");
    }

    final String currentDomain = getDomain();
    if (currentDomain.equalsIgnoreCase(newDomain)) {
        return;
    }

    if (newDomain.indexOf('.') == -1) {
        throw Context.reportRuntimeError("Illegal domain value, cannot set domain from: \"" + currentDomain
                + "\" to: \"" + newDomain + "\" (new domain has to contain a dot).");
    }

    if (currentDomain.indexOf('.') > -1
            && !currentDomain.toLowerCase(Locale.ROOT).endsWith("." + newDomain.toLowerCase(Locale.ROOT))) {
        throw Context.reportRuntimeError("Illegal domain value, cannot set domain from: \"" + currentDomain
                + "\" to: \"" + newDomain + "\"");
    }

    // Netscape down shifts the case of the domain
    if (browserVersion.hasFeature(JS_DOCUMENT_DOMAIN_IS_LOWERCASE)) {
        domain_ = newDomain.toLowerCase(Locale.ROOT);
    } else {
        domain_ = newDomain;
    }
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

public static final boolean isCGI(final String extension) {
    return extension != null && extension.length() > 0
            && "cgi.exe".indexOf(extension.toLowerCase(Locale.ROOT)) >= 0;
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

/**
 * @deprecated use a mimetype considering methode (e.g. Document.getContentDomain() == ContentDomain.IMAGE or else Classification.isImageExtension() )
 *//*from   www .  j  a v  a  2 s  .  co  m*/
@Deprecated
public static final boolean isImage(final String extension) {
    return extension != null && extension.length() > 0
            && Response.docTypeExt(extension.toLowerCase(Locale.ROOT)) == Response.DT_IMAGE;
}

From source file:net.yacy.cora.document.id.MultiProtocolURL.java

public final boolean isIndividual() {
    final String q = unescape(this.path.toLowerCase(Locale.ROOT));
    for (final String sid : sessionIDnames.keySet()) {
        if (q.startsWith(sid.toLowerCase(Locale.ROOT) + "="))
            return true;
        final int p = q.indexOf("&" + sid.toLowerCase(Locale.ROOT) + "=", 0);
        if (p >= 0)
            return true;
    }/*from   w w  w  .j  a v a 2 s  .  c om*/
    int pos;
    return ((pos = q.indexOf("sid", 0)) > 0
            && (q.charAt(--pos) == '?' || q.charAt(pos) == '&' || q.charAt(pos) == ';')
            && (pos += 5) < q.length() && (q.charAt(pos) != '&' && q.charAt(--pos) == '=')) ||

            ((pos = q.indexOf("sessionid", 0)) > 0 && (pos += 10) < q.length()
                    && (q.charAt(pos) != '&' && (q.charAt(--pos) == '=' || q.charAt(pos) == '/')))
            ||

            ((pos = q.indexOf("phpsessid", 0)) > 0 && (pos += 10) < q.length()
                    && (q.charAt(pos) != '&' && (q.charAt(--pos) == '=' || q.charAt(pos) == '/')));
}