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

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

Introduction

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

Prototype

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

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

Usage

From source file:de.hybris.platform.integration.cis.tax.populators.CisLineItemPopulator.java

@Override
public void populate(final OndemandDiscountedOrderEntry source, final CisLineItem target)
        throws ConversionException {
    if (source == null || source.getOrderEntry() == null || target == null) {
        throw new ConversionException("AbstractOrderEntry and target have to be specified");
    }//from w ww.j a va2 s.  c o m

    target.setId(source.getOrderEntry().getEntryNumber());
    target.setItemCode(source.getOrderEntry().getProduct().getCode());
    // currently for avalara the limit of this field is 255
    target.setProductDescription(StringUtils.substring(source.getOrderEntry().getProduct().getName(), 0, 255));
    target.setQuantity(Integer.valueOf(source.getOrderEntry().getQuantity().intValue()));
    target.setUnitPrice(source.getDiscountedUnitPrice());
    target.setTaxCode(getTaxCodeStrategy().getTaxCodeForCodeAndOrder(
            source.getOrderEntry().getProduct().getCode(), source.getOrderEntry().getOrder()));
}

From source file:gate.termraider.util.AbstractBank.java

public String shortScoreDescription() {
    String result = "";
    if (this.scoreProperty != null) {
        result = this.scoreProperty;
        if (result.endsWith("Score")) {
            result = StringUtils.substring(result, 0, -5);
        }/* ww w  .  j ava2 s . c om*/
    }
    return result;
}

From source file:com.prowidesoftware.swift.model.mt.AckSystemMessage.java

public String getErrorLine() {
    final Tag t = super.m.getBlock4().getTagByName("405");
    if (t == null)
        return null;
    return StringUtils.substring(t.getValue(), 3, 6);
}

From source file:com.hangum.tadpole.rdb.core.viewers.connections.ManagerLabelProvider.java

/**
 * user label text//from  w  ww.  j a  v a  2s  .  c  om
 * 
 * @param userDB
 * @return
 */
public static String getDBText(UserDBDAO userDB) {
    String retText = "";
    if (PublicTadpoleDefine.DBOperationType.PRODUCTION.toString().equals(userDB.getOperation_type())) {
        retText = String.format("%s [%s] %s", PRODUCTION_SERVER_START_TAG,
                StringUtils.substring(userDB.getOperation_type(), 0, 1), END_TAG);
        //      } else {
        //         retText = String.format("%s [%s] %s", DEVELOPMENT_SERVER_START_TAG, StringUtils.substring(userDB.getOperation_type(), 0, 1), END_TAG);
    }

    if (PermissionChecker.isDBAdminRole(userDB)) {
        retText += String.format("%s (%s@%s)", userDB.getDisplay_name(), userDB.getUsers(), userDB.getDb()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    } else {

        // ?? ? ?? ?.
        if (PermissionChecker.isProductBackup(userDB)) {
            retText += userDB.getDisplay_name();
            //   ?  ? ?.
        } else {
            retText += String.format("%s (%s@%s)", userDB.getDisplay_name(), userDB.getUsers(), userDB.getDb()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$            
        }
    }

    return retText;
}

From source file:com.receipts.services.ExportService.java

public InputStream createExportFile(Store store) {
    InputStream is = null;/*ww w . j a v  a2s  .c om*/

    String storeId = store.getStoreId();
    String storeIdStr = StringUtils.leftPad(storeId, 3, "0");

    Date storeDate = store.getStoreDate();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String storeDateStr = sdf.format(storeDate);

    DecimalFormatSymbols dfs = new DecimalFormatSymbols();
    dfs.setDecimalSeparator('.');

    StringBuilder sb = new StringBuilder();
    for (Receipt receipt : store.getReceipts()) {
        if (receipt.isComplete()) {
            String receiptId = receipt.getId().toString();
            String receiptTime = receipt.getReceiptTime();

            for (Product product : receipt.getProducts()) {
                // Store Id: 3 chars
                storeIdStr = StringUtils.substring(storeIdStr, 0, 3);
                sb.append(storeIdStr);

                // Product Name: 32 chars
                String productName = StringUtils.substring(product.getProductName(), 0, 32);
                String productNameStr = StringUtils.rightPad(productName, 32);
                sb.append(productNameStr);

                String productPrice = new DecimalFormat("0000.00", dfs).format(product.getProductPrice());
                String productPriceStr = StringUtils.leftPad(productPrice, 7, "0");
                sb.append(productPriceStr);

                // Receipt Id: 10 chars
                String receiptIdStr = StringUtils.leftPad(StringUtils.substring(receiptId, 0, 10), 10);
                sb.append(receiptIdStr);

                sb.append(storeDateStr);

                sb.append(receiptTime);

                String productQuantity = new DecimalFormat("#0.000", dfs).format(product.getProductQuantity());
                String productQuantityStr = StringUtils.leftPad(productQuantity, 6, "0");
                sb.append(productQuantityStr);

                sb.append(System.getProperty("line.separator"));
            }
        }
    }

    is = IOUtils.toInputStream(sb.toString());

    return is;
}

From source file:com.streamreduce.util.SqsQueueNameFormatter.java

/**
 * Creates an environmental specific queue name from a desired queue name. The environment prefix will be
 * prepended to original queue name.//w  w w .j av a  2s. c  o  m
 *
 * This method accepts a non-blank queue name and environment as parameters.  Once these two values are joined
 * with a "-" any characters that are invalid for use in an SQS queue name are replaced transformed with dashes
 * (only alphanumerics, dashes, and underscores are allowed).
 *
 * Additionally, if the passed in environment prefix is "dev" then the prefix will also include the hostname
 * of the machine being used (used for developer workstations using SQS).
 *
 * The final String returned will no exceed the maximum length of a valid SQS name, so any characters above that
 * length will be trimmed off.
 *
 * @param originalQueueName A string representing the desired queue name, before cleanup.
 * @param environmentPrefix A prefix representing an environment that nodeable is deployed to.
 * @return String representing a valid SQS queue name with an environmental prefix prepended to the queue name.
 */
public static String formatSqsQueueName(String originalQueueName, String environmentPrefix) {
    if (StringUtils.isBlank(originalQueueName) || StringUtils.isBlank(environmentPrefix)) {
        throw new IllegalArgumentException("queueName and environmentPrefix must be non-blank");
    }
    String queueNameWithPrefix = addMachineNameToPrefixIfNeeded(environmentPrefix) + "-" + originalQueueName;
    String modifiedQueueName = queueNameWithPrefix.trim().replaceAll("[^a-zA-Z1-9_-]", "-");

    return StringUtils.substring(modifiedQueueName, 0, MAX_LENGTH_OF_SQS_QUEUE);
}

From source file:com.manpowergroup.cn.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*w  w w . j  a  v a  2 s .c  o  m*/
 *                   eg LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object 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 + ",??.");

    this.propertyValue = value;
}

From source file:jp.ac.tokushima_u.is.ll.common.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*w ww.  j a  v  a  2  s  .co m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final Object 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 = ReflectionUtils.convertValue(value, propertyType);
}

From source file:biblivre3.cataloging.bibliographic.IndexDAO.java

public final boolean insert(IndexTable table, List<IndexDTO> indexList) {
    if (indexList == null && indexList.isEmpty()) {
        return false;
    }/*w w w.  jav  a  2s.c o  m*/

    Connection con = null;
    try {
        con = getDataSource().getConnection();
        StringBuilder sql = new StringBuilder();
        sql.append(" INSERT INTO ").append(table.getTableName());
        sql.append(" (index_word, record_serial) ");
        sql.append(" VALUES (?, ?);");

        PreparedStatement pst = con.prepareStatement(sql.toString());

        for (IndexDTO index : indexList) {
            pst.setString(1, StringUtils.substring(index.getWord(), 0, 511));
            pst.setInt(2, index.getRecordSerial());
            pst.addBatch();
        }

        pst.executeBatch();
    } catch (BatchUpdateException bue) {
        log.error(bue.getNextException(), bue);
        throw new ExceptionUser("ERROR_BIBLIO_DAO_EXCEPTION");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ExceptionUser("ERROR_BIBLIO_DAO_EXCEPTION");
    } finally {
        closeConnection(con);
    }
    return true;
}

From source file:gov.nih.nci.cabig.caaers.domain.ajax.StudyAjaxableDomainObject.java

/**
 * Gets the truncated display name.//  w  w w .ja  va 2  s .  com
 *
 * @return the truncated display name
 */
public String getTruncatedDisplayName() {
    String identifier = this.getCcIdentifierValue() == null ? "" : " ( " + this.getCcIdentifierValue() + " ) ";
    String suffix = "";
    String studyTitle = this.getShortTitle();
    int end = studyTitle.length();
    if (end > 30) {
        end = 30;
        suffix = "...";
    }
    studyTitle = StringUtils.substring(studyTitle, 0, end);
    studyTitle = studyTitle + suffix;
    return identifier + studyTitle;
}