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

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

Introduction

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

Prototype

public static String substring(final String str, int start, int end) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start/end n characters from the end of the String.

The returned substring starts with the character in the start position and ends before the end position.

Usage

From source file:kenh.expl.functions.Substring.java

public String process(String str, int start, int end) {
    return StringUtils.substring(str, start, end);
}

From source file:de.micromata.genome.logging.DocLogEntryKey.java

/**
 * Strip const message.// www  .  ja v  a  2  s .  c o  m
 *
 * @param msg the msg
 * @return the string
 */
private String stripConstMessage(String msg) {
    String smsg = StringUtils.substring(msg, 0, 10);
    int idx = StringUtils.indexOfAny(smsg, ",:.(");
    if (idx == -1) {
        return smsg;
    }
    return smsg.substring(0, idx);
}

From source file:com.oncore.calorders.rest.service.helper.ContactHelper.java

public static void setAddressZipCode(Address address, String zipCode) {
    zipCode = zipCode.replace("-", "");
    address.setAdrZip5(StringUtils.substring(zipCode, 0, 5));

    if (zipCode.length() == 9) {
        address.setAdrZip4(StringUtils.substring(zipCode, 5, 9));
    }/*w  w w .  j av  a2s  . c o m*/
}

From source file:com.alliander.osgp.adapter.protocol.iec61850.infra.messaging.Iec61850LogItemRequestMessage.java

public Iec61850LogItemRequestMessage(final String deviceIdentification, final boolean incoming,
        final boolean valid, final RegisterDeviceRequest message, final int payloadMessageSerializedSize) {
    this.deviceIdentification = deviceIdentification;
    this.incoming = incoming;
    this.valid = valid;
    this.payloadMessageSerializedSize = payloadMessageSerializedSize;

    // Truncate the log-items to max length.
    this.encodedMessage = StringUtils.substring(bytesToCArray(message.toByteArray()), 0, MAX_MESSAGE_LENGTH);
    this.decodedMessage = StringUtils.substring(message.toString(), 0, MAX_MESSAGE_LENGTH);
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.messaging.OslpLogItemRequestMessage.java

public OslpLogItemRequestMessage(final String organisationIdentification, final String deviceUid,
        final String deviceIdentification, final boolean incoming, final boolean valid, final Message message,
        final int payloadMessageSerializedSize) {
    this.organisationIdentification = organisationIdentification;
    this.deviceUid = deviceUid;
    this.deviceIdentification = deviceIdentification;
    this.incoming = incoming;
    this.valid = valid;
    this.payloadMessageSerializedSize = payloadMessageSerializedSize;

    // Truncate the log-items to max length.
    this.encodedMessage = StringUtils.substring(bytesToCArray(message.toByteArray()), 0, MAX_MESSAGE_LENGTH);
    this.decodedMessage = StringUtils.substring(message.toString(), 0, MAX_MESSAGE_LENGTH);
}

From source file:com.alliander.osgp.webdevicesimulator.domain.entities.OslpLogItem.java

public OslpLogItem(final byte[] deviceUid, final String deviceIdentification, final boolean incoming,
        final Message message) {
    this.deviceUid = Base64.encodeBase64String(deviceUid);
    this.deviceIdentification = deviceIdentification;
    this.incoming = incoming;

    // Truncate the logitems to length
    this.encodedMessage = StringUtils.substring(OslpLogItem.bytesToCArray(message.toByteArray()), 0,
            MAX_MESSAGE_LENGTH);//from  w w w .j a v a  2s  . co m
    this.decodedMessage = StringUtils.substring(message.toString(), 0, MAX_MESSAGE_LENGTH);
}

From source file:com.eryansky.common.orm.PropertyFilter.java

/**
 * @param filterName ,???. //from  ww  w .j  a v  a  2  s. c  om
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    Assert.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:com.im.web.base.PropertyFilter.java

/**
 * @param filterName ,???. //  w  ww . j  a  v a2  s  . c o m
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    //      Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    //      this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:am.ik.categolj2.core.web.accesslog.AccessLogMethodArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    String xTrack = StringUtils.substring((String) request.getAttribute("X-Track"), 0, 32);
    String method = request.getMethod();
    String uri = StringUtils.substring(request.getRequestURI(), 0, 128);
    String query = StringUtils.substring(request.getQueryString(), 0, 128);
    String remoteAddress = RemoteAddresses.getRemoteAddress(request);
    String userAgent = UserAgents.getUserAgent(request);
    DateTime accessDate = dateFactory.newDateTime();
    return new AccessLog(null, method, uri, query, remoteAddress, userAgent, xTrack, accessDate);
}

From source file:com.thinkmore.framework.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*w  ww  .  j  av  a  2  s .  c  o  m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtil.convertStringToObject(value, propertyType);
}