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:mitm.common.net.NetUtils.java

/**
 * Parses the provided URL query and returns a map with all names to values. The values are URL decoded. If 
 * toLowercase is true the keys of the map will be converted to lowecase.
 * //from w  ww  .jav  a  2  s . c om
 * Example:
 * test=123&value=%27test%27&value=abc maps to test -> [123] and value -> ["test", abc]
 * @throws IOException 
 */
public static Map<String, String[]> parseQuery(String query, boolean toLowercase) throws IOException {
    Map<String, String[]> map = new HashMap<String, String[]>();

    if (query == null) {
        return map;
    }

    String[] elements = StringUtils.split(query, '&');

    for (String element : elements) {
        element = element.trim();

        if (StringUtils.isEmpty(element)) {
            continue;
        }

        String name;
        String value;

        int i = element.indexOf('=');

        if (i > -1) {
            name = StringUtils.substring(element, 0, i);
            value = StringUtils.substring(element, i + 1);
        } else {
            name = element;
            value = "";
        }

        name = StringUtils.trimToEmpty(name);
        value = StringUtils.trimToEmpty(value);

        if (toLowercase) {
            name = name.toLowerCase();
        }

        value = URLDecoder.decode(value, CharacterEncoding.UTF_8);

        String[] updated = (String[]) ArrayUtils.add(map.get(name), value);

        map.put(name, updated);
    }

    return map;
}

From source file:com.doculibre.constellio.lang.LangDetectorUtil.java

public String detect(String text) {
    String lang;//w  ww .jav  a  2 s. c o  m
    if (!ConstellioStringUtils.isEmpty(text)) {
        try {
            Detector detector = DetectorFactory.create();
            detector.append(text);
            lang = detector.detect();
        } catch (Throwable t) {
            LOGGER.warn("Problem while trying to detect lang for text (0,100): "
                    + StringUtils.substring(text, 0, 100));
            lang = null;
        }
    } else {
        lang = null;
    }
    return lang;
}

From source file:com.junly.common.enums.UserTypeEnums.java

/** <p class="detail">
* ???,/*ww  w .j a va  2  s. com*/
* </p>
* @author panwuhai
* @date 201667 
* @return 
*/
public static String toSelectJsonShow() {
    StringBuilder builder = new StringBuilder("[");
    for (UserTypeEnums activitie : UserTypeEnums.values()) {
        builder.append("{");
        builder.append("\"name\"").append(":\"").append(activitie.name()).append("\",");
        builder.append("\"code\"").append(":\"").append(activitie.getCode()).append("\",");
        builder.append("\"detail\"").append(":\"").append(activitie.getDetail()).append("\"},");
    }
    String result = StringUtils.substring(builder.toString(), 0, builder.length() - 1);
    return result + "]";
}

From source file:jp.go.nict.langrid.management.web.utility.StringUtil.java

/**
 * /*from ww w .java 2 s.c  om*/
 * 
 */
public static String getLimitStyle(String str, int count) {
    if (str == null)
        return "";
    String tempStr = "";
    int tempCount = count - 1;
    for (int i = 0; i < str.length(); i++) {
        tempStr += StringUtils.substring(str, i, i + 1);
        if (!isHalfSizeAlphaNumeral(tempStr)) {
            tempCount = i + count;
            tempStr = "";
        }
        if (i > tempCount - 1) {
            if (isHalfSizeAlphaNumeral(tempStr)) {
                return "word-break:break-all;";
            }
            tempCount = i + count;
            tempStr = "";
        }
    }
    return "";
}

From source file:com.abssh.util.PropertyFilter.java

/**
 * @param filterName/*from  www. j av  a 2 s. c  o  m*/
 *            ,???. eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value
 *            .
 */
@SuppressWarnings("unchecked")
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 = propertyNameStr.split(PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    // entity property.
    if (value != null && (value.getClass().isArray() || Collection.class.isInstance(value)
            || value.toString().split(",").length > 1)) {
        // IN ?
        Object[] vObjects = null;
        if (value.getClass().isArray()) {
            vObjects = (Object[]) value;
        } else if (Collection.class.isInstance(value)) {
            vObjects = ((Collection) value).toArray();
        } else {
            vObjects = value.toString().split(",");
        }
        this.propertyValue = new Object[vObjects.length];
        for (int i = 0; i < vObjects.length; i++) {
            propertyValue[i] = ReflectionUtils.convertValue(vObjects[i], propertyType);
        }
    } else {
        Object tObject = ReflectionUtils.convertValue(value, propertyType);
        if (tObject != null && matchType == MatchType.LE && propertyType.getName().equals("java.util.Date")) {
            // LED ??tObject2010-08-13 00:00:00
            // ?2010-08-13 23:59:59
            Date leDate = (Date) tObject;
            Calendar c = GregorianCalendar.getInstance();
            c.setTime(leDate);
            c.set(Calendar.HOUR_OF_DAY, 23);
            c.set(Calendar.MINUTE, 59);
            c.set(Calendar.SECOND, 59);
            tObject = c.getTime();
        } else if (tObject != null && matchType == MatchType.LEN
                && propertyType.getName().equals("java.util.Date")) {
            // LED ??tObject2010-08-13 00:00:00
            // ?2010-08-13 23:59:59
            //            Date leDate = (Date) tObject;
            //            Calendar c = GregorianCalendar.getInstance();
            //            c.setTime(leDate);
            //            tObject = c.getTime();
        } else if (tObject != null && matchType == MatchType.LIKE) {
            tObject = ((String) tObject).replace("%", "\\%").replace("_", "\\_");
        }
        this.propertyValue = new Object[] { tObject };
    }
}

From source file:com.hangum.tadpole.engine.sql.parser.ddl.ParserDDL.java

/**
 * getObjectName// w ww. ja  va 2  s  . c o m
 * 
 * @param matcher
 * @param sql
 * @return
 */
private String getObjectName(Matcher matcher, String sql) {
    int intEndIndex = matcher.end(1);
    int intContentLength = matcher.group(1).length();

    if (logger.isDebugEnabled()) {
        logger.debug("===DDL Parser======================================");
        logger.debug("SQL :" + sql);
        logger.debug("object name: " + matcher.group(1));
        logger.debug("intContentLength : " + intContentLength);
        logger.debug("intEndIndex : " + intEndIndex);
        logger.debug("start index: " + (intEndIndex - intContentLength));
        logger.debug("===DDL Parser======================================");
    }

    String objctName = StringUtils.substring(sql, (intEndIndex - intContentLength), intEndIndex);
    objctName = StringUtils.remove(objctName, "\"");
    objctName = StringUtils.remove(objctName, "'");
    objctName = StringUtils.remove(objctName, "`");

    return objctName;
}

From source file:com.hangum.tadpole.engine.sql.parser.UpdateDeleteParser.java

/**
 * getObjectName//from   www .ja v  a  2  s .  c o m
 * 
 * @param matcher
 * @param sql
 * @return
 */
private String getObjectName(Matcher matcher, String sql) {
    int intEndIndex = matcher.end(1);
    int intContentLength = matcher.group(1).length();

    //      if(logger.isDebugEnabled()) {
    //         logger.debug("===DDL Parser======================================");
    //         logger.debug("SQL :" + sql);
    //         logger.debug("object name: " + matcher.group(1));
    //         logger.debug("intContentLength : " + intContentLength );
    //         logger.debug("intEndIndex : " + intEndIndex );
    //         logger.debug("start index: " + (intEndIndex - intContentLength));
    //         logger.debug("===DDL Parser======================================");
    //      }

    String objctName = StringUtils.substring(sql, (intEndIndex - intContentLength), intEndIndex);
    objctName = StringUtils.remove(objctName, "\"");
    objctName = StringUtils.remove(objctName, "'");
    objctName = StringUtils.remove(objctName, "`");

    return objctName;
}

From source file:mitm.djigzo.web.utils.PasswordCodecImpl.java

@Override
public PasswordAndSalt getPasswordAndSalt(String encodedPassword) {
    if (encodedPassword == null) {
        return null;
    }/*from   ww w .j  a  v  a  2 s.c o  m*/

    int i = encodedPassword.indexOf(':');

    if (i == -1) {
        throw new IllegalArgumentException("Password seems not to be encoded");
    }

    String salt = StringUtils.substring(encodedPassword, 0, i);
    String hashedPassword = StringUtils.substring(encodedPassword, i + 1);

    if (salt == null || StringUtils.isEmpty(hashedPassword)) {
        throw new IllegalArgumentException("Password seems not to be encoded");
    }

    return new PasswordAndSaltImpl(hashedPassword, salt);
}

From source file:net.shopxx.plugin.ccbPayment.CcbPaymentPlugin.java

@Override
public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) {
    PluginConfig pluginConfig = getPluginConfig();
    PaymentLog paymentLog = getPaymentLog(sn);
    Map<String, Object> parameterMap = new LinkedHashMap<String, Object>();
    parameterMap.put("MERCHANTID", pluginConfig.getAttribute("partner"));
    parameterMap.put("POSID", pluginConfig.getAttribute("posId"));
    parameterMap.put("BRANCHID", pluginConfig.getAttribute("branchId"));
    parameterMap.put("ORDERID", sn);
    parameterMap.put("PAYMENT", paymentLog.getAmount().setScale(2).toString());
    parameterMap.put("CURCODE", "01");
    parameterMap.put("TXCODE", "520100");
    parameterMap.put("REMARK1", "shopxx");
    parameterMap.put("REMARK2", "");
    if (StringUtils.equals(pluginConfig.getAttribute("isPhishing"), "true")) {
        String key = pluginConfig.getAttribute("key");
        parameterMap.put("TYPE", "1");
        parameterMap.put("PUB", StringUtils.substring(key, -30, key.length()));
        parameterMap.put("GATEWAY", "");
        parameterMap.put("CLIENTIP", request.getRemoteAddr());
        parameterMap.put("REGINFO", "");
        parameterMap.put("PROINFO", "");
        parameterMap.put("REFERER", "");
    }/*from  w  w  w.  ja va 2s.com*/
    parameterMap.put("MAC", generateSign(parameterMap));
    parameterMap.remove("PUB");
    return parameterMap;
}

From source file:com.pearson.openideas.cq5.components.content.ArticleContributorInfo.java

/**
 * {@inheritDoc}//from www  .j a  va2s  .  c  o m
 */
@Override
public void init() {

    if (getProperties() == null) {
        log.warn("No Properties");
        renderForPublish = false;
    } else {
        setLeadContributor(getProperties().get(PROPERTY_CONTRIBUTOR_CHOICE, ""));
        setContributorUrl(getProperties().get(PROPERTY_CONTRIBUTOR_URL, ""));

        TagManager tagManager = getResourceResolver().adaptTo(TagManager.class);
        Tag[] tagsFromComponent = tagManager.getTags(getCurrentResource());
        if (tagsFromComponent != null && tagsFromComponent.length > 0) {
            String tagID = tagsFromComponent[0].getTagID();

            Tag tag = tagManager.resolve(tagID);
            if (tag != null) {
                Iterator<Resource> resourceIterator = tag.find();
                int count = 1;
                while (resourceIterator.hasNext()) {
                    String path = resourceIterator.next().getPath();
                    log.debug("item #" + count + ": " + path);
                    if (path.contains("dam")) {
                        imageUrl = StringUtils.substring(path, 0, path.lastIndexOf("/jcr"));
                        log.debug("image url: " + imageUrl);
                        setImageUrl(imageUrl);
                    }
                }

                setContributorBio(tag.getDescription());
                setContributorName(tag.getTitle());
            } else {
                log.warn("Could not resolve the tag id: " + tagID);
            }
        } else {
            log.info("No tags in contributor component");
        }

        if (StringUtils.isNotBlank(contributorBio)) {
            renderForPublish = true;
        }
    }
}