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:ch.cyberduck.core.s3.RequestEntityRestStorageService.java

public RequestEntityRestStorageService(final S3Session session, final Jets3tProperties properties,
        final HttpClientBuilder configuration) {
    super(session.getHost().getCredentials().isAnonymousLogin() ? null : new AWSCredentials(null, null) {
        @Override/* w w w .  ja va2 s .c o m*/
        public String getAccessKey() {
            return session.getHost().getCredentials().getUsername();
        }

        @Override
        public String getSecretKey() {
            return session.getHost().getCredentials().getPassword();
        }
    }, new PreferencesUseragentProvider().get(), null, properties);
    this.session = session;
    configuration.disableContentCompression();
    configuration.setRetryHandler(
            new S3HttpRequestRetryHandler(this, preferences.getInteger("http.connections.retry")));
    configuration.setRedirectStrategy(new DefaultRedirectStrategy() {
        @Override
        public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response,
                final HttpContext context) throws ProtocolException {
            if (response.containsHeader("x-amz-bucket-region")) {
                final String host = ((HttpUriRequest) request).getURI().getHost();
                if (!StringUtils.equals(session.getHost().getHostname(), host)) {
                    regionEndpointCache.putRegionForBucketName(
                            StringUtils
                                    .split(StringUtils.removeEnd(((HttpUriRequest) request).getURI().getHost(),
                                            session.getHost().getHostname()), ".")[0],
                            response.getFirstHeader("x-amz-bucket-region").getValue());
                }
            }
            return super.getRedirect(request, response, context);
        }
    });
    this.setHttpClient(configuration.build());
}

From source file:com.xpn.xwiki.objects.meta.MetaClass.java

@Override
public PropertyInterface get(String name) {
    PropertyInterface property = safeget(name);
    if (property == null) {
        // In previous versions the property name was the full Java class name of the property class implementation.
        // Extract the actual property name (the hint used to lookup the property class provider) by removing the
        // Java package prefix and the Class suffix.
        property = safeget(StringUtils.removeEnd(StringUtils.substringAfterLast(name, "."), "Class"));
    }//from w w w.  j  a  va 2 s .c  om
    return property;
}

From source file:gobblin.salesforce.SalesforceConnector.java

public String getFullUri(String resourcePath) {
    return StringUtils.removeEnd(getServiceBaseUrl(), "/") + StringUtils.removeEnd(resourcePath, "/");
}

From source file:io.wcm.wcm.ui.extjs.provider.AbstractPageProvider.java

/**
 * Determine root resource to list its children. (use resource for root page because root node does not have to be a
 * page but can be e.g. a nt:folder node)
 * @param request/*ww  w.ja  v  a 2  s. c  o m*/
 * @return Root resource or null if invalid resource was referenced
 */
protected final Resource getRootResource(SlingHttpServletRequest request) {
    String path = RequestParam.get(request, RP_PATH);
    if (StringUtils.isEmpty(path) && request.getResource() != null) {
        path = request.getResource().getPath();
    }
    if (StringUtils.isNotEmpty(path)) {
        path = StringUtils.removeEnd(path, "/" + JcrConstants.JCR_CONTENT);
        return request.getResourceResolver().getResource(path);
    }
    return null;
}

From source file:de.knightsoftnet.validators.shared.impl.PhoneNumberValueRestValidator.java

/**
 * {@inheritDoc} check if given string is a valid gln.
 *
 * @see javax.validation.ConstraintValidator#isValid(java.lang.Object,
 *      javax.validation.ConstraintValidatorContext)
 *//*  w  w  w  .  ja va  2 s. co  m*/
@Override
public final boolean isValid(final Object pvalue, final ConstraintValidatorContext pcontext) {
    final String valueAsString = Objects.toString(pvalue, null);

    if (StringUtils.isEmpty(valueAsString)) {
        // empty field is ok
        return true;
    }
    try {
        String countryCode = BeanUtils.getProperty(pvalue, this.fieldCountryCode);
        final String phoneNumber = BeanUtils.getProperty(pvalue, this.fieldPhoneNumber);
        if (StringUtils.isEmpty(phoneNumber)) {
            return true;
        }

        if (this.allowLowerCaseCountryCode) {
            countryCode = StringUtils.upperCase(countryCode);
        }
        final String url = StringUtils
                .removeEnd(StringUtils.removeEnd(StringUtils.removeEnd(GWT.getModuleBaseURL(), "/"),
                        GWT.getModuleName()), "/")
                + PhoneNumber.ROOT + PhoneNumber.VALIDATE //
                + "?" + Parameters.COUNTRY + "=" + countryCode //
                + "&" + Parameters.PHONE_NUMBER + "=" + this.urlEncode(phoneNumber) //
                + "&" + Parameters.DIN_5008 + "=" + PhoneNumberValueRestValidator.this.allowDin5008 //
                + "&" + Parameters.E123 + "=" + PhoneNumberValueRestValidator.this.allowE123 //
                + "&" + Parameters.URI + "=" + PhoneNumberValueRestValidator.this.allowUri //
                + "&" + Parameters.MS + "=" + PhoneNumberValueRestValidator.this.allowMs //
                + "&" + Parameters.COMMON + "=" + PhoneNumberValueRestValidator.this.allowCommon;
        final String restResult = CachedSyncHttpGetCall.syncRestCall(url);
        if (StringUtils.equalsIgnoreCase("TRUE", restResult)) {
            return true;
        }
        this.switchContext(pcontext);
        return false;
    } catch (final Exception ignore) {
        this.switchContext(pcontext);
        return false;
    }
}

From source file:com.ufukuzun.myth.dialect.builder.AjaxEventBindingBuilder.java

private static String getIdsWithQuote(Arguments arguments, String attributeValue, boolean process,
        boolean encode) {
    List<String> ids = ExpressionUtils.splitIdFragments(attributeValue);

    StringBuilder stringBuilder = new StringBuilder();
    for (String each : ids) {
        String id = each;/* w ww . ja v a  2 s.co  m*/
        if (process) {
            id = ElementAndAttrUtils.getProcessedAttributeValue(arguments, each);
        }
        if (encode) {
            id = new String(Base64.encodeBase64(each.getBytes()));
        }
        stringBuilder.append("\"").append(id).append("\", ");
    }

    return StringUtils.removeEnd(stringBuilder.toString(), ", ");
}

From source file:com.wesleyhome.dao.processor.model.EntityInfo.java

public String packageName() {
    return StringUtils.removeEnd(fullEntityClassName, "." + entityName);
}

From source file:com.infinities.keystone4j.policy.Rules.java

private static List<Entry<String, BaseCheck>> parseTokenize(String rule) {
    String[] tokens = rule.split("\\s+");

    List<Entry<String, BaseCheck>> entrys = Lists.newArrayList();

    for (String token : tokens) {
        token = token.trim();/*  w w w.  j a  va 2s  .c  o m*/
        if (Strings.isNullOrEmpty(token)) {
            continue;
        }
        String clean = StringUtils.removeStart(token, "(");
        int range = token.length() - clean.length();
        // logger.debug("lstrip: {}, range:{}", new Object[] { clean, range
        // });
        for (int i = 0; i < range; i++) {
            BaseCheck check = new StringCheck("(");
            entrys.add(Maps.immutableEntry("(", check));
        }

        if (Strings.isNullOrEmpty(clean)) {
            continue;
        } else {
            token = clean;
        }

        clean = StringUtils.removeEnd(token, ")");
        int trail = token.length() - clean.length();
        // logger.debug("rstrip: {}, trail:{}", new Object[] { clean, trail
        // });
        String lowered = clean.toLowerCase();
        if (logicOperators.contains(lowered)) {
            BaseCheck check = new StringCheck(clean);
            entrys.add(Maps.immutableEntry(lowered, check));
        } else if (!Strings.isNullOrEmpty(clean)) {
            if (token.length() >= 2 && ((token.charAt(0) == '\"' && token.charAt(token.length()) == '\"')
                    || (token.charAt(0) == '\'' && token.charAt(token.length()) == '\''))) {
                BaseCheck check = new StringCheck(token.substring(1, token.length() - 1));
                entrys.add(Maps.immutableEntry("string", check));
            } else {
                entrys.add(Maps.immutableEntry("check", parseCheck(clean)));
            }
        }

        for (int i = 0; i < trail; i++) {
            BaseCheck check = new StringCheck(")");
            entrys.add(Maps.immutableEntry(")", check));
        }
    }

    return entrys;
}

From source file:com.hybris.mobile.factory.barcode.IntentBarcodeFactory.java

/**
 * Return the product value if the barcode value matches one of the pre-configured regular expression
 * //from  w  w w .ja v a  2 s.c  o m
 * @param barcodeValue
 * @param barcodeSymbology
 * @return
 */
private static String getProductCode(String barcodeValue, String barcodeSymbology) {

    // For product codes, we have to remove the leading/trailing 0 of specific barcode symbologies

    // These barcodes have leading '0's and a trailing '0' that needs to be accounted for (stripped out).
    if (StringUtils.equals(barcodeSymbology, BarCodeSymbologyEnums.EAN_13.getCodeSymbology())) {
        barcodeValue = StringUtils.stripStart(barcodeValue, "0");
        barcodeValue = StringUtils.removeEnd(barcodeValue, "0");
    }
    // These barcodes have leading '0's that needs to be accounted for (stripped out).
    else if (StringUtils.equals(barcodeSymbology, BarCodeSymbologyEnums.ITF.getCodeSymbology())) {
        barcodeValue = StringUtils.stripStart(barcodeValue, "0");
    }
    // These barcodes have a trailing '0' that needs to be accounted for (stripped out).
    else if (StringUtils.equals(barcodeSymbology, BarCodeSymbologyEnums.EAN_8.getCodeSymbology())) {
        barcodeValue = StringUtils.removeEnd(barcodeValue, "0");
    }

    // Trying to get a product code from the barcode value
    return RegexUtil.getProductCode(barcodeValue);

}

From source file:com.erudika.scoold.core.Profile.java

@JsonIgnore
public User getUser() {
    if (user == null) {
        user = client()//from w  ww .j a  v a2s. c  om
                .read(getCreatorid() == null ? StringUtils.removeEnd(getId(), Config.SEPARATOR + "profile")
                        : getCreatorid());
    }
    return user;
}