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:de.bund.bva.pliscommon.serviceapi.core.serviceimpl.ReflectiveExceptionMappingSource.java

/**
 * {@inheritDoc}//from  w  w  w . j  a  va2s . co m
 */
public Class<? extends PlisToException> getToExceptionClass(Method remoteBeanMethod,
        Class<? extends PlisException> exceptionClass) {

    String coreExceptionName = StringUtils.removeEnd(exceptionClass.getSimpleName(), "Exception");

    for (Class<?> toExceptionClass : remoteBeanMethod.getExceptionTypes()) {
        if (PlisToException.class.isAssignableFrom(toExceptionClass)) {
            String toExceptionName = StringUtils.removeEnd(toExceptionClass.getSimpleName(), "ToException");
            if (coreExceptionName.equals(toExceptionName)) {
                @SuppressWarnings("unchecked")
                Class<? extends PlisToException> castToExceptionClass = (Class<? extends PlisToException>) toExceptionClass;
                return castToExceptionClass;
            }
        }
    }

    throw new IllegalStateException("Keine TO-Exception fr die AWK-Exception " + exceptionClass
            + " in Serviceoperation " + getMethodSignatureString(remoteBeanMethod));
}

From source file:com.ctrip.infosec.rule.converter.Ip2ProvinceCityConverter.java

@Override
public void convert(PreActionEnums preAction, Map fieldMapping, RiskFact fact, String resultWrapper,
        boolean isAsync) throws Exception {
    PreActionParam[] fields = preAction.getFields();
    String ipFieldName = (String) fieldMapping.get(fields[0].getParamName());
    String ipFieldValue = valueAsString(fact.eventBody, ipFieldName);

    // prefix default value
    if (Strings.isNullOrEmpty(resultWrapper)) {
        resultWrapper = ipFieldName + "_IpArea";
    }/*from  w w  w.  j  a v  a  2 s.  c o m*/
    // 
    if (fact.eventBody.containsKey(resultWrapper)) {
        return;
    }

    // "8.8.8.8:80"
    ipFieldValue = StringUtils.trimToEmpty(ipFieldValue);
    ipFieldValue = StringUtils.removeStart(ipFieldValue, "\"");
    ipFieldValue = StringUtils.removeEnd(ipFieldValue, "\"");
    ipFieldValue = StringUtils.substringBefore(ipFieldValue, ":");

    if (StringUtils.isNotBlank(ipFieldValue) && !"127.0.0.1".equals(ipFieldValue)) {

        // 
        PropertyUtils.setNestedProperty(fact.eventBody, ipFieldName, ipFieldValue);

        Map params = ImmutableMap.of("ip", ipFieldValue);
        Map result = DataProxy.queryForMap(serviceName, operationName, params);
        if (result != null && !result.isEmpty()) {
            fact.eventBody.put(resultWrapper, result);
        } else {
            TraceLogger.traceLog("?. ip=" + ipFieldValue);
        }
    }
}

From source file:com.moviejukebox.tools.SearchEngineToolsTest.java

@Test
public void roundTripIMDB() {
    LOG.info("roundTripIMDB");
    SearchEngineTools search = new SearchEngineTools();

    // movie/* w w w. j  av a2 s .c om*/
    for (int i = 0; i < search.countSearchSites(); i++) {
        String engine = search.getCurrentSearchEngine();
        LOG.info("Testing {}", engine);
        String url = search.searchMovieURL("Avatar", "2009", "www.imdb.com/title");
        url = StringUtils.removeEnd(url, "/");
        assertEquals("Search engine '" + engine + "' failed", "http://www.imdb.com/title/tt0499549", url);
    }

    // TV show, must leave out the year and search for TV series
    for (int i = 0; i < search.countSearchSites(); i++) {
        String engine = search.getCurrentSearchEngine();
        LOG.info("Testing {}", engine);
        String url = search.searchMovieURL("Two and a Half Men", null, "www.imdb.com/title", "TV series");
        url = StringUtils.removeEnd(url, "/");
        assertEquals("Search engine '" + engine + "' failed", "http://www.imdb.com/title/tt0369179", url);
    }
}

From source file:com.kryptnostic.rhizome.configuration.amazon.AwsLaunchConfiguration.java

@JsonCreator
public AwsLaunchConfiguration(@JsonProperty(BUCKET_FIELD) String bucket,
        @JsonProperty(FOLDER_FIELD) Optional<String> folder,
        @JsonProperty(REGION_FIELD) Optional<String> region) {
    Preconditions.checkArgument(StringUtils.isNotBlank(bucket),
            "S3 bucket for configuration must be specified.");
    this.bucket = bucket;
    String rawFolder = folder.or(DEFAULT_FOLDER);

    while (StringUtils.endsWith(rawFolder, "/")) {
        StringUtils.removeEnd(rawFolder, "/");
    }//from w  w  w  . j  a  va  2  s. c  o  m
    // We shouldn't prefix
    if (StringUtils.isNotBlank(rawFolder)) {
        this.folder = rawFolder + "/";
    } else {
        this.folder = rawFolder;
    }

    this.region = region.isPresent() ? Optional.of(Regions.fromName(region.get())) : Optional.absent();
}

From source file:com.hybris.mobile.app.commerce.barcode.CommerceBarcodeCheckerFactory.java

/**
 * Return the product value if the barcode value matches one of the pre-configured regular expression
 *
 * @param barcodeValue/*w  w w .  j  a  v  a  2 s . co m*/
 * @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, Constants.BarCodeSymbology.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, Constants.BarCodeSymbology.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, Constants.BarCodeSymbology.EAN_8.getCodeSymbology())) {
        barcodeValue = StringUtils.removeEnd(barcodeValue, "0");
    }

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

}

From source file:com.devicehive.util.HiveValidator.java

public String buildMessage(Set<ConstraintViolation<?>> violations) {
    StringBuilder builder = new StringBuilder("Error! Validation failed: \n");
    for (ConstraintViolation<?> cv : violations) {
        builder.append(String.format("On property %s (value: %s): %s ; %n", cv.getPropertyPath(),
                cv.getInvalidValue(), cv.getMessage()));
    }/*from   w  w  w  . j  a v a2  s  .c om*/
    return StringUtils.removeEnd(builder.toString(), " \n");
}

From source file:com.sonicle.webtop.core.bol.OShare.java

public static String extractGroupNameFromKey(String key) {
    String s = StringUtils.removeEnd(key, KEYSUFFIX_ROOT);
    return StringUtils.removeEnd(s, KEYSUFFIX_FOLDER);
}

From source file:com.hbc.api.gateway.alizhifu.TransferSummary.java

public static String getTransferDetails(List<TransInfo> transInfoList, Double totalAmount) {
    StringBuilder transferDetails = new StringBuilder();
    final String comm = "|";
    Double checkPrice = 0.00d;/*  w  ww  . ja v  a2s.com*/
    for (TransInfo transInfo : transInfoList) {
        checkPrice = DoubleUtil.addDouble(checkPrice, transInfo.getActualAmount());
        transferDetails.append(transInfo.getTransNo()).append("^").append(transInfo.getPayeeAccount())
                .append("^").append(transInfo.getPayeeName()).append("^").append(transInfo.getActualAmount())
                .append("^").append(transInfo.getTransSubject()).append(comm);
    }
    if (!totalAmount.equals(checkPrice)) {
        throw new GatewayException(GatewayReturnCodeEnum.ERR_TRANS_PRICE_NOT_MATCH);
    }
    return StringUtils.removeEnd(transferDetails.toString(), comm);
}

From source file:alfio.manager.MollieManager.java

public String createCheckoutRequest(Event event, String reservationId, OrderSummary orderSummary,
        CustomerName customerName, String email, String billingAddress, Locale locale, boolean invoiceRequested,
        String vatCountryCode, String vatNr, PriceContainer.VatStatus vatStatus) throws Exception {

    String eventName = event.getShortName();

    String baseUrl = StringUtils.removeEnd(
            configurationManager.getRequiredValue(
                    Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.BASE_URL)),
            "/");

    String bookUrl = baseUrl + "/event/" + eventName + "/reservation/" + reservationId + "/book";

    Map<String, Object> payload = new HashMap<>();
    payload.put("amount", orderSummary.getTotalPrice()); // quite ugly, but the mollie api require json floating point...

    ////from  ww w  .j a v  a  2s .  c  o m
    String description = messageSource.getMessage(
            "reservation-email-subject", new Object[] {
                    configurationManager.getShortReservationID(event, reservationId), event.getDisplayName() },
            locale);
    payload.put("description", description);
    payload.put("redirectUrl", bookUrl);
    payload.put("webhookUrl",
            baseUrl + "/webhook/mollie/api/event/" + eventName + "/reservation/" + reservationId);

    Map<String, String> initialMetadata = new HashMap<>();
    initialMetadata.put("reservationId", reservationId);
    initialMetadata.put("email", email);
    initialMetadata.put("fullName", customerName.getFullName());
    if (StringUtils.isNotBlank(billingAddress)) {
        initialMetadata.put("billingAddress", billingAddress);
    }

    payload.put("metadata", initialMetadata);

    RequestBody body = RequestBody.create(MediaType.parse("application/json"), Json.GSON.toJson(payload));
    Request request = requestFor("https://api.mollie.nl/v1/payments", event).post(body).build();

    try (Response resp = client.newCall(request).execute()) {
        ResponseBody responseBody = resp.body();
        String respBody = responseBody != null ? responseBody.string() : "null";
        if (!resp.isSuccessful()) {
            String msg = "was not able to create a payment for reservation id " + reservationId + ": "
                    + respBody;
            log.warn(msg);
            throw new Exception(msg);
        } else {
            ticketReservationRepository.updateReservationStatus(reservationId,
                    TicketReservation.TicketReservationStatus.EXTERNAL_PROCESSING_PAYMENT.toString());
            Map<String, Object> res = Json.GSON.fromJson(respBody, (new TypeToken<Map<String, Object>>() {
            }).getType());
            @SuppressWarnings("unchecked")
            Map<String, String> links = (Map<String, String>) res.get("links");
            return links.get("paymentUrl");
        }
    }
}

From source file:io.freeswitch.command.OriginateCommand.java

@Override
public String argument() {
    AddVariable("origination_uuid", originateId.toString());
    AddVariable("ignore_early_media", "true");
    AddVariable("enable_heartbeat_events", String.valueOf(sessionHeartbeat));

    String variables = "";
    if (_channelVariables.isEmpty()) {
        for (ChannelVariable channelVariable : _channelVariables) {
            variables += channelVariable.toString() + ",";
        }//from  ww w  .  ja  v a2s .  co  m

        if (StringUtils.isEmpty(option))
            variables = "{" + StringUtils.removeEnd(variables, ",") + "}";
        else
            variables = "{" + option + "," + StringUtils.removeEnd(variables, ",") + "}";
    }

    return String.format("%1s %2s %3s", variables, _destination.toDialString(), _application.toDialString());

}