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:org.guess.core.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*  w  w w  . j ava  2s  .  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, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

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

From source file:org.gvnix.web.datatables.util.DatatablesUtils.java

/**
 * Constructs the {@code HtmlTable} used to export the data.
 * <p />//  w  w w . java  2s.  co m
 * It uses the parameters of the request to check if the column is
 * exportable or not, these parameters are named:
 * <ul>
 * <li>{@code [export_type_extension]ExportColumns}, where
 * <emp>[export_type_extension]</emp> is the extension of the format to
 * export, for example: {@code csvExportColumns}</li>
 * <li>{@code allExportColumns}</li>
 * </ul>
 * <p />
 * Also uses the parameter {@code columnsTitle} to indicate the title of
 * each column, this parameter has as value a {@code String} with the format
 * of a Map as follows:
 * 
 * <pre>
 * {property1||value1, property2||value2, ... , propertyN||valueN}
 * </pre>
 * 
 * @param data the data to make the {@code HtmlTable}.
 * @param criterias the {@code DatatablesCriterias}.
 * @param exportConf the {@code ExportConf}.
 * @param request the {@code HttpServletRequest}.
 * @return the {@code HtmlTable} used to export the data.
 */
public static HtmlTable makeHtmlTable(List<Map<String, String>> data, DatatablesCriterias criterias,
        ExportConf exportConf, HttpServletRequest request) {

    ColumnStep tableBuilder = new HtmlTableBuilder<Map<String, String>>().newBuilder("tableId", data, request);

    // Obtain exportable columns
    String exportTypeExtension = StringUtils.lowerCase(exportConf.getType().getExtension());
    String thisFormatExportColumnsStr = request.getParameter(exportTypeExtension.concat("ExportColumns"));
    if (StringUtils.isEmpty(thisFormatExportColumnsStr)) {
        thisFormatExportColumnsStr = "";
    }
    String allFormatExportColumnsStr = request.getParameter("allExportColumns");
    if (StringUtils.isEmpty(allFormatExportColumnsStr)) {
        allFormatExportColumnsStr = "";
    }
    List<String> thisFormatExporColumns = Arrays.asList(StringUtils.split(thisFormatExportColumnsStr, ","));
    List<String> allFormatExportColumns = Arrays.asList(StringUtils.split(allFormatExportColumnsStr, ","));

    BeforeEndStep columns = null;
    if (!allFormatExportColumns.isEmpty() || !thisFormatExporColumns.isEmpty()) {

        // Obtain the column titles
        Map<String, String> columnsTitleMap = new HashMap<String, String>();
        String columnsTitleStr = request.getParameter("columnsTitle");
        columnsTitleStr = StringUtils.substring(columnsTitleStr, 1, (columnsTitleStr.length() - 1));
        List<String> columnsTitleList = Arrays.asList(StringUtils.split(columnsTitleStr, ","));
        for (String columnsTitle : columnsTitleList) {
            String[] columsTitleArray = StringUtils.split(columnsTitle, "||");
            if (columsTitleArray.length == 2) {
                columnsTitleMap.put(columsTitleArray[0].trim(), columsTitleArray[1].trim());
            }
        }

        List<ColumnDef> columnDefs = criterias.getColumnDefs();
        for (ColumnDef columnDef : columnDefs) {
            String columnProperty = columnDef.getName();
            if (allFormatExportColumns.contains(columnProperty)
                    || thisFormatExporColumns.contains(columnProperty)) {
                String columnTitle = columnsTitleMap.get(columnProperty);
                if (StringUtils.isBlank(columnTitle)) {
                    columnTitle = columnProperty;
                }
                columnTitle = StringUtils.replace(columnTitle, "~~", ",");
                columns = tableBuilder.column().fillWithProperty(columnProperty).title(columnTitle);
            }
        }
    }
    if (columns == null) {
        columns = tableBuilder.column().fillWithProperty("-").title("---");
    }

    return columns.configureExport(exportConf).build();
}

From source file:org.gvnix.web.datatables.util.impl.DatatablesUtilsBeanImpl.java

/**
 * {@inheritDoc}/*  w  ww. j  a v a 2  s.  co  m*/
 */
@Override
public HtmlTable makeHtmlTable(List<Map<String, String>> data, DatatablesCriterias criterias,
        ExportConf exportConf, HttpServletRequest request) {

    ColumnStep tableBuilder = new HtmlTableBuilder<Map<String, String>>().newBuilder("tableId", data, request);

    // Obtain exportable columns
    String exportTypeExtension = StringUtils.lowerCase(exportConf.getType().getExtension());
    String thisFormatExportColumnsStr = request.getParameter(exportTypeExtension.concat("ExportColumns"));
    if (StringUtils.isEmpty(thisFormatExportColumnsStr)) {
        thisFormatExportColumnsStr = "";
    }
    String allFormatExportColumnsStr = request.getParameter("allExportColumns");
    if (StringUtils.isEmpty(allFormatExportColumnsStr)) {
        allFormatExportColumnsStr = "";
    }
    List<String> thisFormatExporColumns = Arrays.asList(StringUtils.split(thisFormatExportColumnsStr, ","));
    List<String> allFormatExportColumns = Arrays.asList(StringUtils.split(allFormatExportColumnsStr, ","));

    BeforeEndStep columns = null;
    if (!allFormatExportColumns.isEmpty() || !thisFormatExporColumns.isEmpty()) {

        // Obtain the column titles
        Map<String, String> columnsTitleMap = new HashMap<String, String>();
        String columnsTitleStr = request.getParameter("columnsTitle");
        columnsTitleStr = StringUtils.substring(columnsTitleStr, 1, (columnsTitleStr.length() - 1));
        List<String> columnsTitleList = Arrays.asList(StringUtils.split(columnsTitleStr, ","));
        for (String columnsTitle : columnsTitleList) {
            String[] columsTitleArray = StringUtils.split(columnsTitle, "||");
            if (columsTitleArray.length == 2) {
                columnsTitleMap.put(columsTitleArray[0].trim(), columsTitleArray[1].trim());
            }
        }

        List<ColumnDef> columnDefs = criterias.getColumnDefs();
        for (ColumnDef columnDef : columnDefs) {
            String columnProperty = columnDef.getName();
            if (allFormatExportColumns.contains(columnProperty)
                    || thisFormatExporColumns.contains(columnProperty)) {
                String columnTitle = columnsTitleMap.get(columnProperty);
                if (StringUtils.isBlank(columnTitle)) {
                    columnTitle = columnProperty;
                }
                columnTitle = StringUtils.replace(columnTitle, "~~", ",");
                columns = tableBuilder.column().fillWithProperty(columnProperty).title(columnTitle);
            }
        }
    }
    if (columns == null) {
        columns = tableBuilder.column().fillWithProperty("-").title("---");
    }

    return columns.configureExport(exportConf).build();
}

From source file:org.jamocha.classloading.Loader.java

private static String filePathToClassName(final String filePath) {
    return StringUtils.substring(filePath.replace('/', '.').replace('\\', '.'), 0, -".class".length());
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a LogItem object are valid for the
 * database.//from  w w w.ja va  2s.  c  o  m
 */
protected void validateLogItem(LogItem logItem) throws WikiException {
    checkLength(logItem.getUserDisplayName(), 200);
    checkLength(logItem.getLogParamString(), 500);
    logItem.setLogComment(StringUtils.substring(logItem.getLogComment(), 0, 200));
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a RecentChange object are valid for the
 * database./*from   w w  w . j  av a2s  .  com*/
 */
protected void validateRecentChange(RecentChange change) throws WikiException {
    checkLength(change.getTopicName(), 200);
    checkLength(change.getAuthorName(), 200);
    checkLength(change.getVirtualWiki(), 100);
    change.setChangeComment(StringUtils.substring(change.getChangeComment(), 0, 200));
    checkLength(change.getParamString(), 500);
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a Role object are valid for the
 * database./*from  w  w w. j  a  v a2  s  . co  m*/
 */
protected void validateRole(Role role) throws WikiException {
    checkLength(role.getAuthority(), 30);
    role.setDescription(StringUtils.substring(role.getDescription(), 0, 200));
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a TopicVersion object are valid for the
 * database./*from  w w w.j  a  va2  s  . com*/
 */
protected void validateTopicVersion(TopicVersion topicVersion) throws WikiException {
    checkLength(topicVersion.getAuthorDisplay(), 100);
    checkLength(topicVersion.getVersionParamString(), 500);
    topicVersion.setEditComment(StringUtils.substring(topicVersion.getEditComment(), 0, 200));
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a WikiFileVersion object are valid for
 * the database.//ww w  . j  a  v  a 2 s.  co m
 */
protected void validateWikiFileVersion(WikiFileVersion wikiFileVersion) throws WikiException {
    checkLength(wikiFileVersion.getUrl(), 200);
    checkLength(wikiFileVersion.getMimeType(), 100);
    checkLength(wikiFileVersion.getAuthorDisplay(), 100);
    wikiFileVersion.setUploadComment(StringUtils.substring(wikiFileVersion.getUploadComment(), 0, 200));
}

From source file:org.jamwiki.db.AnsiDataValidator.java

/**
 * Validate that all fields of a WikiGroup object are valid for the
 * database.//from   w w  w.j a  v a 2 s . c  o m
 */
protected void validateWikiGroup(WikiGroup group) throws WikiException {
    checkLength(group.getName(), 30);
    group.setDescription(StringUtils.substring(group.getDescription(), 0, 200));
}