Example usage for org.apache.commons.lang3 StringUtils removeEnd

List of usage examples for org.apache.commons.lang3 StringUtils removeEnd

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils removeEnd.

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:org.lazydog.jdnsaas.utility.ZoneUtility.java

/**
 * Get the IP (v4 or v6) address./*from w  ww  .jav a  2 s.  c o  m*/
 * 
 * @param  reverseTets  the IP address tets in reverse.  These are the octets (IPv4) or hextets (IPv6) not in the zone name.
 * 
 * @return  the IP (v4 or v6) address.
 */
public String getIpAddress(String reverseTets) {
    String reverseDomain = (this.isIpv4ReverseZone()) ? IPV4_REVERSE_DOMAIN : IPV6_REVERSE_DOMAIN;
    return StringUtils.reverseDelimited(
            reverseTets + LABEL_SEPARATOR
                    + StringUtils.removeEnd(this.relativeZoneName, LABEL_SEPARATOR + reverseDomain),
            LABEL_SEPARATOR.charAt(0));
}

From source file:org.lazydog.jdnsaas.utility.ZoneUtility.java

/**
 * Get the reverse tets.  //from www  .  j av a 2s.co  m
 * These are the octets (IPv4) or hextets (IPv6) not in the zone name.
 * 
 * @param  ipAddress  the IP (v4 or v6) address.
 * 
 * @return  the reverse tets.
 */
public String getReverseTets(String ipAddress) {
    String reverseDomain = (this.isIpv4ReverseZone()) ? IPV4_REVERSE_DOMAIN : IPV6_REVERSE_DOMAIN;
    return StringUtils.removeEnd(StringUtils.reverseDelimited(ipAddress, LABEL_SEPARATOR.charAt(0)),
            LABEL_SEPARATOR + StringUtils.removeEnd(this.relativeZoneName, LABEL_SEPARATOR + reverseDomain));
}

From source file:org.lazydog.jdnsaas.utility.ZoneUtility.java

/**
 * Relativize the name.//w  w  w . ja  v  a 2 s.  c o  m
 * The relative name is the name without the zone name and trailing dot.
 * 
 * @param  name  the name.
 * 
 * @return  the relative name.
 */
public String relativize(final String name) {

    String relativeName = name;

    if (name.endsWith(LABEL_SEPARATOR + this.getAbsoluteZoneName())) {
        relativeName = StringUtils.removeEnd(name, LABEL_SEPARATOR + this.getAbsoluteZoneName());
    } else if (name.endsWith(LABEL_SEPARATOR + this.relativeZoneName)) {
        relativeName = StringUtils.removeEnd(name, LABEL_SEPARATOR + this.relativeZoneName);
    } else if (name.equals(this.getAbsoluteZoneName()) || name.equals(this.relativeZoneName)) {
        relativeName = APEX;
    } else if (name.endsWith(LABEL_SEPARATOR)) {
        relativeName = StringUtils.removeEnd(name, LABEL_SEPARATOR);
    }

    return relativeName;
}

From source file:org.lealone.cluster.locator.PropertyFileSnitch.java

public void reloadConfiguration() throws ConfigurationException {
    HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>();

    Properties properties = new Properties();
    InputStream stream = null;/*  w w  w . ja v a 2  s  . com*/
    try {
        stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME);
        properties.load(stream);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
    } finally {
        FileUtils.closeQuietly(stream);
    }

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        if (key.equals("default")) {
            String[] newDefault = value.split(":");
            if (newDefault.length < 2)
                defaultDCRack = new String[] { "default", "default" };
            else
                defaultDCRack = new String[] { newDefault[0].trim(), newDefault[1].trim() };
        } else {
            InetAddress host;
            String hostString = key.replace("/", "");
            try {
                host = InetAddress.getByName(hostString);
            } catch (UnknownHostException e) {
                throw new ConfigurationException("Unknown host " + hostString, e);
            }
            String[] token = value.split(":");
            if (token.length < 2)
                token = new String[] { "default", "default" };
            else
                token = new String[] { token[0].trim(), token[1].trim() };
            reloadedMap.put(host, token);
        }
    }
    if (defaultDCRack == null && !reloadedMap.containsKey(Utils.getBroadcastAddress()))
        throw new ConfigurationException(String.format(
                "Snitch definitions at %s do not define a location for this node's broadcast address %s, "
                        + "nor does it provides a default",
                SNITCH_PROPERTIES_FILENAME, Utils.getBroadcastAddress()));

    if (logger.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<InetAddress, String[]> entry : reloadedMap.entrySet())
            sb.append(entry.getKey()).append(":").append(Arrays.toString(entry.getValue())).append(", ");
        logger.debug("Loaded network topology from property file: {}",
                StringUtils.removeEnd(sb.toString(), ", "));
    }

    endpointMap = reloadedMap;
    if (StorageService.instance != null) // null check tolerates circular dependency; see lealone-4145
        StorageService.instance.getTokenMetaData().invalidateCachedRings();

    if (gossipStarted)
        StorageService.instance.gossipSnitchInfo();
}

From source file:org.ligoj.app.plugin.build.jenkins.JenkinsPluginResource.java

/**
 * Return the color from the raw color of the job.
 *
 * @param color//www  . j  av a2s .  com
 *            Raw color node from the job status.
 * @return The color without 'anime' flag.
 */
private String toStatus(final String color) {
    return StringUtils.removeEnd(StringUtils.defaultString(color, "disabled"), "_anime");
}

From source file:org.ligoj.app.plugin.km.confluence.ConfluencePluginResource.java

/**
 * Validate the space configuration and return the corresponding details.
 * //  www  .j a v a  2 s.  c o  m
 * @param parameters
 *            the space parameters.
 * @return Space's details.
 */
protected Space validateSpace(final Map<String, String> parameters) throws IOException {
    final String baseUrl = StringUtils.removeEnd(parameters.get(PARAMETER_URL), "/");

    CurlRequest[] requests = null;

    try {
        // Validate the space key and get activity
        requests = validateSpaceInternal(parameters, "/rest/api/space/",
                "/plugins/recently-updated/changes.action?theme=social&pageSize=1&spaceKeys=");

        // Parse the space details
        final Map<String, Object> details = objectMapper.readValue(requests[0].getResponse(), TYPE_SPACE_REF);

        // Build the full space object
        return toSpace(baseUrl, details, requests[1].getResponse(), requests[0].getProcessor());
    } finally {
        // Close the processor
        closeQuietly(requests);
    }
}

From source file:org.ligoj.app.plugin.km.confluence.ConfluencePluginResource.java

/**
 * Validate the space configuration and return the corresponding details.
 *//*from  ww  w  .ja  va2 s. c o m*/
protected CurlRequest[] validateSpaceInternal(final Map<String, String> parameters,
        final String... partialRequests) {
    final String url = StringUtils.removeEnd(parameters.get(PARAMETER_URL), "/");
    final String space = ObjectUtils.defaultIfNull(parameters.get(PARAMETER_SPACE), "0");
    final CurlRequest[] result = new CurlRequest[partialRequests.length];
    for (int i = 0; i < partialRequests.length; i++) {
        result[i] = new CurlRequest(HttpMethod.GET, url + partialRequests[i] + space, null);
        result[i].setSaveResponse(true);
    }

    // Prepare the sequence of HTTP requests to Confluence
    final ConfluenceCurlProcessor processor = new ConfluenceCurlProcessor();
    authenticate(parameters, processor);

    // Execute the requests
    processor.process(result);

    // Get the space if it exists
    if (result[0].getResponse() == null) {
        // Invalid couple PKEY and id
        throw new ValidationJsonException(PARAMETER_SPACE, "confluence-space", parameters.get(PARAMETER_SPACE));
    }
    return result;
}

From source file:org.ligoj.app.plugin.km.confluence.ConfluencePluginResource.java

/**
 * Map API JSON Space and history values to a bean.
 */// www. ja v  a2s . c om
private Space toSpace(final String baseUrl, final Map<String, Object> spaceRaw, final String history,
        final CurlProcessor processor) throws MalformedURLException {
    final Space space = toSpaceLight(spaceRaw);
    final String hostUrl = StringUtils.removeEnd(baseUrl, new java.net.URL(baseUrl).getPath());

    // Check the activity if available
    final Matcher matcher = ACTIVITY_PATTERN.matcher(StringUtils.defaultString(history));
    if (matcher.find()) {
        // Activity has been found
        final SpaceActivity activity = new SpaceActivity();
        getAvatar(processor, activity, hostUrl + matcher.group(1));
        activity.setAuthor(toSimpleUser(matcher.group(2), matcher.group(3)));
        activity.setPageUrl(hostUrl + matcher.group(4));
        activity.setPage(matcher.group(5));
        activity.setMoment(matcher.group(6));
        space.setActivity(activity);
    }
    return space;
}

From source file:org.ligoj.app.plugin.km.confluence.ConfluencePluginResource.java

/**
 * Return a Jenkins's resource. Return <code>null</code> when the resource
 * is not found./*  w ww.j  a v a2s  . co  m*/
 */
protected String getConfluenceResource(final CurlProcessor processor, final String url, final String resource) {
    // Get the resource using the preempted authentication
    final CurlRequest request = new CurlRequest(HttpMethod.GET, StringUtils.removeEnd(url, "/") + resource,
            null);
    request.setSaveResponse(true);

    // Execute the requests
    processor.process(request);
    processor.close();
    return request.getResponse();
}

From source file:org.ligoj.app.plugin.vm.azure.AbstractAzureToolPluginResource.java

/**
 * Return an Azure resource. Return <code>null</code> when the resource is not found. Authentication should be
 * proceeded before for authenticated query.
 * //from   w w w.j a v  a  2  s.  c  o m
 * @param processor
 *            The processor used to query the resource.
 * @param method
 *            The HHTTP method.
 * @param url
 *            The base URL.
 * @param resource
 *            The internal resource URL appended to the base URL parameter. DUplicate '/' are handled.
 * @return The requested azure resource or <code>null</code> when the resource is not found.
 */
protected String execute(final CurlProcessor processor, final String method, final String url,
        final String resource) {
    // Get the resource using the preempted authentication
    final CurlRequest request = new CurlRequest(method, StringUtils.removeEnd(
            StringUtils.appendIfMissing(url, "/") + StringUtils.removeStart(resource, "/"), "/"), null);
    request.setSaveResponse(true);

    // Execute the requests
    processor.process(request);
    return request.getResponse();
}