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

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

Introduction

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

Prototype

public static int indexOf(String str, String searchStr) 

Source Link

Document

Finds the first index within a String, handling null.

Usage

From source file:org.jenkinsci.plugins.jiraext.view.FirstWordOfCommitStrategy.java

/**
 * Parse a Jira ticket number, ie SSD-101, out of the given ChangeLogSet.Entry.
 *
 * Ticket number is assumed to be the first word of the commit message
 *
 * @param change - the change entry to/*from  ww w .j a v a2 s .  com*/
 * @return
 */
@Override
public List<JiraCommit> getJiraIssuesFromChangeSet(final ChangeLogSet.Entry change) {
    String msg = change.getMsg();
    String firstWordOfTicket;
    firstWordOfTicket = msg.substring(0, (msg.contains(" ") ? StringUtils.indexOf(msg, " ") : msg.length()));

    for (String validJiraPrefix : Config.getGlobalConfig().getJiraTickets()) {
        if (firstWordOfTicket.endsWith(":")) {
            firstWordOfTicket = firstWordOfTicket.substring(0, firstWordOfTicket.length() - 1);
        }
        if (firstWordOfTicket.startsWith(validJiraPrefix)) {
            return Arrays.asList(new JiraCommit(firstWordOfTicket, change));
        }
    }

    return null;
}

From source file:org.jenkinsci.plugins.jiraext.view.MentionedInCommitStrategy.java

/**
 * Parse Jira ticket numbers, ie SSD-101, out of the given ChangeLogSet.Entry.
 *
 * <p>Ticket number should be somewhere in the commit message</p>
 *
 * @param  change//from   ww w .  ja v  a 2  s  .  c o  m
 *
 * @return
 */
@Override
public List<JiraCommit> getJiraIssuesFromChangeSet(final ChangeLogSet.Entry change) {
    final List<JiraCommit> result = new ArrayList<>();
    final List<String> foundTickets = new ArrayList<>();

    for (String validJiraPrefix : Config.getGlobalConfig().getJiraTickets()) {
        String msg = change.getMsg();

        while (StringUtils.isNotEmpty(msg)) {
            final int foundPos = StringUtils.indexOf(msg, validJiraPrefix);

            if (foundPos == -1) {
                break;
            }

            final String firstOccurrence = msg.substring(foundPos + validJiraPrefix.length());
            final String regex = "^([0-9]*).*$";
            final Pattern pattern = Pattern.compile(regex);
            final Matcher matcher = pattern.matcher(firstOccurrence);
            matcher.matches();

            final String ticketNumber = matcher.group(1);

            if (StringUtils.isEmpty(ticketNumber)) {
                break;
            }

            final String resultingTicket = validJiraPrefix + ticketNumber;

            if (!foundTickets.contains(resultingTicket)) {
                foundTickets.add(resultingTicket);
                result.add(new JiraCommit(resultingTicket, change));
            }

            msg = firstOccurrence;
        }
    }

    return result;
}

From source file:org.jspringbot.keyword.config.ConfigHelper.java

public void init() throws IOException {
    ResourceEditor editor = new ResourceEditor();
    editor.setAsText("classpath:config/");
    Resource configDirResource = (Resource) editor.getValue();

    boolean hasConfigDirectory = true;
    boolean hasConfigProperties = true;

    if (configDirResource != null) {
        try {/* ww w . j a v  a2s.  c  o  m*/
            File configDir = configDirResource.getFile();

            if (configDir.isDirectory()) {
                File[] propertiesFiles = configDir.listFiles(new FileFilter() {
                    @Override
                    public boolean accept(File file) {
                        return StringUtils.endsWith(file.getName(), ".properties")
                                || StringUtils.endsWith(file.getName(), ".xml");
                    }
                });

                for (File propFile : propertiesFiles) {
                    String filename = propFile.getName();
                    String name = StringUtils.substring(filename, 0, StringUtils.indexOf(filename, "."));

                    addProperties(name, propFile);
                }
            }
        } catch (IOException e) {
            hasConfigDirectory = false;
        }
    }

    editor.setAsText("classpath:config.properties");
    Resource configPropertiesResource = (Resource) editor.getValue();

    if (configPropertiesResource != null) {
        try {
            File configPropertiesFile = configPropertiesResource.getFile();

            if (configPropertiesFile.isFile()) {
                Properties configs = new Properties();

                configs.load(new FileReader(configPropertiesFile));

                for (Map.Entry entry : configs.entrySet()) {
                    String name = (String) entry.getKey();
                    editor.setAsText(String.valueOf(entry.getValue()));

                    try {
                        Resource resource = (Resource) editor.getValue();
                        addProperties(name, resource.getFile());
                    } catch (Exception e) {
                        throw new IOException(String.format("Unable to load config '%s'.", name), e);
                    }
                }
            }
        } catch (IOException e) {
            hasConfigProperties = false;
        }
    }

    if (!hasConfigDirectory && !hasConfigProperties) {
        LOGGER.warn("No configuration found.");
    }
}

From source file:org.kuali.kfs.module.ar.businessobject.lookup.ContractsGrantsInvoiceDocumentErrorLogLookupableHelperServiceImpl.java

/**
 * Manipulate fields for search criteria in order to get the results the user really wants.
 *
 * @param fieldValues/*  w w  w .ja v a2  s.  c  o m*/
 * @return updated search criteria fieldValues
 */
protected Map<String, String> updateFieldValuesForSearchCriteria(Map<String, String> fieldValues) {
    Map<String, String> newFieldValues = new HashMap<>();
    newFieldValues.putAll(fieldValues);

    // Add wildcard character to start and end of accounts field so users can search for single account
    // within the delimited list of accounts without having to add the wildcards explicitly themselves.
    String accounts = newFieldValues
            .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS);
    if (StringUtils.isNotBlank(accounts)) {
        // only add wildcards if they haven't already been added (for some reason this method gets called twice when generating the pdf report)
        if (!StringUtils.startsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) {
            accounts = KFSConstants.WILDCARD_CHARACTER + accounts;
        }
        if (!StringUtils.endsWith(accounts, KFSConstants.WILDCARD_CHARACTER)) {
            accounts += KFSConstants.WILDCARD_CHARACTER;
        }
    }
    newFieldValues.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ACCOUNTS,
            accounts);

    // Increment to error date by one day so that the correct results are retrieved.
    // Since the error date is stored as both a date and time in the database records with an error date
    // the same as the error date the user enters on the search criteria aren't retrieved without this modification.
    String errorDate = newFieldValues
            .get(ArPropertyConstants.ContractsGrantsInvoiceDocumentErrorLogLookupFields.ERROR_DATE_TO);

    int index = StringUtils.indexOf(errorDate, SearchOperator.LESS_THAN_EQUAL.toString());
    if (index == StringUtils.INDEX_NOT_FOUND) {
        index = StringUtils.indexOf(errorDate, SearchOperator.BETWEEN.toString());
        if (index != StringUtils.INDEX_NOT_FOUND) {
            incrementErrorDate(newFieldValues, errorDate, index);
        }
    } else {
        incrementErrorDate(newFieldValues, errorDate, index);
    }

    return newFieldValues;
}

From source file:org.kuali.kra.proposaldevelopment.web.struts.action.ProposalDevelopmentQuestionsAction.java

/**
 * This is specifically for 'lookup' return a value.
 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from   w w w.  j a va 2  s .c  o  m*/
//TODO: Fix for multiple modules
@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward forward = super.refresh(mapping, form, request, response);
    if (request.getParameter("refreshCaller") != null
            && request.getParameter("refreshCaller").toString().equals("kualiLookupable")) {
        // Lookup field 'onchange' is not working if it is return a value from 'lookup', so do it on server side
        for (Object obj : request.getParameterMap().keySet()) {
            if (StringUtils.indexOf((String) obj, "questionnaireHelper.answerHeaders[") == 0) {
                ((ProposalDevelopmentForm) form).getQuestionnaireHelper()
                        .updateChildIndicator(Integer.parseInt(StringUtils.substringBetween((String) obj,
                                "questionnaireHelper.answerHeaders[", "].answers[")));
            } else if (StringUtils.indexOf((String) obj, "s2sQuestionnaireHelper.answerHeaders[") == 0) {
                ((ProposalDevelopmentForm) form).getS2sQuestionnaireHelper()
                        .updateChildIndicator(Integer.parseInt(StringUtils.substringBetween((String) obj,
                                "s2sQuestionnaireHelper.answerHeaders[", "].answers[")));
            }
        }
    }
    return forward;
}

From source file:org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm.java

/**
 * This overridden method .../* w ww .  ja  v  a  2  s  .  c o  m*/
 * 
 * @see KualiDocumentFormBase#shouldPropertyBePopulatedInForm(java.lang.String, javax.servlet.http.HttpServletRequest)
 */
@Override
public boolean shouldPropertyBePopulatedInForm(String requestParameterName, HttpServletRequest request) {
    // the user clicked on a document initiation link
    //add delete check for 3070
    String methodToCallActionName = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
    if (StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION)
            || StringUtils.equals(methodToCallActionName, KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) {
        return true;
    }
    if (StringUtils.indexOf(methodToCallActionName, KRADConstants.TOGGLE_INACTIVE_METHOD) == 0) {
        return true;
    }
    return super.shouldPropertyBePopulatedInForm(requestParameterName, request);
}

From source file:org.kuali.rice.kns.web.struts.form.KualiMaintenanceForm.java

/**
 * This overridden method .../* ww w  .ja v  a  2s. c  om*/
 * 
 * @see KualiDocumentFormBase#shouldMethodToCallParameterBeUsed(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest)
 */
@Override
public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName,
        String methodToCallParameterValue, HttpServletRequest request) {
    // the user clicked on a document initiation link
    if (StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_COPY_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_EDIT_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEW_METHOD_TO_CALL)
            || StringUtils.equals(methodToCallParameterValue, KRADConstants.MAINTENANCE_NEWWITHEXISTING_ACTION)
            || StringUtils.equals(methodToCallParameterValue,
                    KRADConstants.MAINTENANCE_DELETE_METHOD_TO_CALL)) {
        return true;
    }
    if (StringUtils.indexOf(methodToCallParameterName,
            KRADConstants.DISPATCH_REQUEST_PARAMETER + "." + KRADConstants.TOGGLE_INACTIVE_METHOD) == 0) {
        return true;
    }
    return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue,
            request);
}

From source file:org.kuali.rice.krad.labs.transactional.LabsLookupSecurityTravelAuthorizationDocumentBase.java

/**
 * Tests the case in which the a new conversion field is added so that a field that is not referenced in either the
 * data dictionary or the Uif (the traveler type code) appears in the email address field, which is not secured.
 *
 * @throws Exception//from  w  ww .  java  2s. c om
 */
protected void testTransactionalLookupSecurityAddHiddenConversionField() throws Exception {
    waitAndClick(By.id("travelerQuickfinder_quickfinder_act"));
    waitForPageToLoad();

    int splitPosition = StringUtils.indexOf(driver.getCurrentUrl(), CONVERSION_FIELDS)
            + CONVERSION_FIELDS.length();
    String before = StringUtils.substring(driver.getCurrentUrl(), 0, splitPosition);
    String after = StringUtils.substring(driver.getCurrentUrl(), splitPosition);
    String newUrl = before + ERRANT_CONVERSION_FIELD + after;
    open(newUrl);
    waitForPageToLoad();

    waitAndClickSearch3();
    waitAndClickReturnValue();

    assertElementPresentByName(EMAIL_ADDRESS_NAME);
    WebElement element = findElement(By.name(EMAIL_ADDRESS_NAME));
    String emailAddress = element.getAttribute("value");

    assertTrue("Non-secure field emailAddress was not empty", StringUtils.isBlank(emailAddress));
}

From source file:org.kuali.rice.krad.uif.widget.RichTable.java

/**
 * Builds column options for sorting/*from  w ww . ja  va  2 s . c o m*/
 *
 * @param collectionGroup
 */
protected void buildTableOptions(CollectionGroup collectionGroup) {
    checkMutable(false);

    LayoutManager layoutManager = collectionGroup.getLayoutManager();
    final boolean useServerPaging = collectionGroup.isUseServerPaging();

    if (templateOptions.isEmpty()) {
        setTemplateOptions(new HashMap<String, String>());
    }

    // if sub collection exists, don't allow the table sortable
    if (!collectionGroup.getSubCollections().isEmpty()) {
        setDisableTableSort(true);
    }

    if (!isDisableTableSort()) {
        // if rendering add line, skip that row from col sorting
        if (collectionGroup.isRenderAddLine() && !Boolean.TRUE.equals(collectionGroup.getReadOnly())
                && !((layoutManager instanceof TableLayoutManager)
                        && ((TableLayoutManager) layoutManager).isSeparateAddLine())) {

            templateOptions.put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS,
                    "[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]");
        }

        StringBuilder tableColumnOptions = new StringBuilder("[");

        int colIndex = 0;
        int actionIndex = UifConstants.TableLayoutValues.ACTIONS_COLUMN_RIGHT_INDEX;
        boolean actionFieldVisible = collectionGroup.isRenderLineActions()
                && !Boolean.TRUE.equals(collectionGroup.getReadOnly());

        if (layoutManager instanceof TableLayoutManager) {
            actionIndex = ((TableLayoutManager) layoutManager).getActionColumnIndex();
        }

        if (actionIndex == UifConstants.TableLayoutValues.ACTIONS_COLUMN_LEFT_INDEX && actionFieldVisible) {
            String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
            tableColumnOptions.append(options + ",");
            colIndex++;
        }

        // handle sequence field
        if (layoutManager instanceof TableLayoutManager
                && ((TableLayoutManager) layoutManager).isRenderSequenceField()) {
            Class<?> dataTypeClass = Number.class;

            if (((TableLayoutManager) layoutManager).getSequenceFieldPrototype() instanceof DataField) {
                DataField dataField = (DataField) ((TableLayoutManager) layoutManager)
                        .getSequenceFieldPrototype();
                dataTypeClass = ObjectPropertyUtils.getPropertyType(collectionGroup.getCollectionObjectClass(),
                        dataField.getPropertyName());
                // check to see if field has custom sort type
                if (dataField.getSortAs() != null && dataField.getSortAs().length() > 0) {
                    if (dataField.getSortAs().equals(UifConstants.TableToolsValues.DATE)) {
                        dataTypeClass = java.sql.Date.class;
                    } else if (dataField.getSortAs().equals(UifConstants.TableToolsValues.NUMERIC)) {
                        dataTypeClass = Number.class;
                    } else if (dataField.getSortAs().equals(UifConstants.TableToolsValues.STRING)) {
                        dataTypeClass = String.class;
                    }
                }
            }

            // don't allow sorting of sequence field - why?
            // auto sequence column is never sortable
            tableColumnOptions.append("{" + sortable(false) + "," + sortType(getSortType(dataTypeClass)) + ","
                    + sortDataType(UifConstants.TableToolsValues.DOM_TEXT) + mData(useServerPaging, colIndex)
                    + "," + targets(colIndex) + "},");
            colIndex++;

            if (actionIndex == 2 && actionFieldVisible) {
                String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                tableColumnOptions.append(options + ",");
                colIndex++;
            }
        }

        // skip select field if enabled
        if (collectionGroup.isIncludeLineSelectionField()) {
            String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
            tableColumnOptions.append(options + ",");
            colIndex++;
        }

        // if data dictionary defines aoColumns, copy here and skip default sorting/visibility behaviour
        if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMNS))) {
            // get the contents of the JS array string
            String jsArray = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMNS);
            int startBrace = StringUtils.indexOf(jsArray, "[");
            int endBrace = StringUtils.lastIndexOf(jsArray, "]");
            tableColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ",");

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) {
                String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                tableColumnOptions.append(options);
            } else {
                tableColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableColumnOptions.toString(), ","));
            }

            tableColumnOptions.append("]");
            templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMNS, tableColumnOptions.toString());
        } else if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS))
                && forceAoColumnDefsOverride) {
            String jsArray = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
            int startBrace = StringUtils.indexOf(jsArray, "[");
            int endBrace = StringUtils.lastIndexOf(jsArray, "]");
            tableColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ",");

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) {
                String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                tableColumnOptions.append(options);
            } else {
                tableColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableColumnOptions.toString(), ","));
            }

            tableColumnOptions.append("]");
            templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS, tableColumnOptions.toString());
        } else if (layoutManager instanceof TableLayoutManager) {
            List<Field> rowFields = ((TableLayoutManager) layoutManager).getFirstRowFields();

            // build column defs from the the first row of the table
            for (Component component : rowFields) {
                if (actionFieldVisible && colIndex + 1 == actionIndex) {
                    String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                    tableColumnOptions.append(options + ",");
                    colIndex++;
                }

                // for FieldGroup, get the first field from that group
                if (component instanceof FieldGroup) {
                    component = ((FieldGroup) component).getItems().get(0);
                }

                if (component instanceof DataField) {
                    DataField field = (DataField) component;

                    // if a field is marked as invisible in hiddenColumns, append options and skip sorting
                    if (getHiddenColumns() != null && getHiddenColumns().contains(field.getPropertyName())) {
                        tableColumnOptions.append("{" + visible(false) + "," + mData(useServerPaging, colIndex)
                                + targets(colIndex) + "},");
                    } else if (getSortableColumns() != null && !getSortableColumns().isEmpty()) {
                        // if specified as a column as sortable then add it
                        if (getSortableColumns().contains(field.getPropertyName())) {
                            tableColumnOptions
                                    .append(getDataFieldColumnOptions(colIndex, collectionGroup, field) + ",");
                        } else { // else designate it as not sortable
                            tableColumnOptions.append("{" + sortable(false) + ","
                                    + mData(useServerPaging, colIndex) + targets(colIndex) + "},");
                        }
                    } else { // sortable columns not defined
                        String options = getDataFieldColumnOptions(colIndex, collectionGroup, field);
                        tableColumnOptions.append(options + ",");
                    }
                    colIndex++;
                } else if (component instanceof MessageField) {
                    if (component.getDataAttributes() != null && UifConstants.RoleTypes.ROW_GROUPING
                            .equals(component.getDataAttributes().get(UifConstants.DataAttributes.ROLE))) {
                        // Grouping column is never shown, so skip
                        tableColumnOptions.append("{" + visible(false) + "," + mData(useServerPaging, colIndex)
                                + targets(colIndex) + "},");
                    } else {
                        String options = constructTableColumnOptions(colIndex, true, useServerPaging,
                                String.class, UifConstants.TableToolsValues.DOM_TEXT);
                        tableColumnOptions.append(options + ",");
                    }
                    colIndex++;
                } else if (component instanceof LinkField) {
                    LinkField linkField = (LinkField) component;

                    Class<?> dataTypeClass = String.class;
                    // check to see if field has custom sort type
                    if (linkField.getSortAs() != null && linkField.getSortAs().length() > 0) {
                        if (linkField.getSortAs().equals(UifConstants.TableToolsValues.DATE)) {
                            dataTypeClass = java.sql.Date.class;
                        } else if (linkField.getSortAs().equals(UifConstants.TableToolsValues.NUMERIC)) {
                            dataTypeClass = Number.class;
                        } else if (linkField.getSortAs().equals(UifConstants.TableToolsValues.STRING)) {
                            dataTypeClass = String.class;
                        }
                    }

                    String options = constructTableColumnOptions(colIndex, true, useServerPaging, dataTypeClass,
                            UifConstants.TableToolsValues.DOM_TEXT);
                    tableColumnOptions.append(options + ",");
                    colIndex++;
                } else {
                    String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                    tableColumnOptions.append(options + ",");
                    colIndex++;
                }
            }

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= colIndex)) {
                String options = constructTableColumnOptions(colIndex, false, useServerPaging, null, null);
                tableColumnOptions.append(options);
            } else {
                tableColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableColumnOptions.toString(), ","));
            }

            // merge the aoColumnDefs passed in
            if (!StringUtils.isEmpty(templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS))) {
                String origAoOptions = templateOptions.get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS).trim();
                origAoOptions = StringUtils.removeStart(origAoOptions, "[");
                origAoOptions = StringUtils.removeEnd(origAoOptions, "]");
                tableColumnOptions.append("," + origAoOptions);
            }

            tableColumnOptions.append("]");
            templateOptions.put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS, tableColumnOptions.toString());
        }
    }
}

From source file:org.kuali.student.common.uif.widget.KSRichTable.java

/**
 * Builds column options for sorting/*from  ww  w . j av a2s. com*/
 *
 * @param collectionGroup
 */
@Override
protected void buildTableOptions(CollectionGroup collectionGroup) {
    LayoutManager layoutManager = collectionGroup.getLayoutManager();
    final boolean isUseServerPaging = collectionGroup.isUseServerPaging();

    // if sub collection exists, don't allow the table sortable
    if (!collectionGroup.getSubCollections().isEmpty()) {
        setDisableTableSort(true);
    }

    if (!isDisableTableSort()) {
        // if rendering add line, skip that row from col sorting
        if (collectionGroup.isRenderAddLine() && !collectionGroup.isReadOnly()
                && !((layoutManager instanceof TableLayoutManager)
                        && ((TableLayoutManager) layoutManager).isSeparateAddLine())) {
            Map<String, String> oTemplateOptions = this.getTemplateOptions();

            if (oTemplateOptions == null) {
                setTemplateOptions(oTemplateOptions = new HashMap<String, String>());
            }

            oTemplateOptions.put(UifConstants.TableToolsKeys.SORT_SKIP_ROWS,
                    "[" + UifConstants.TableToolsValues.ADD_ROW_DEFAULT_INDEX + "]");
        }

        StringBuilder tableToolsColumnOptions = new StringBuilder("[");

        int columnIndex = 0;
        int actionIndex = UifConstants.TableLayoutValues.ACTIONS_COLUMN_RIGHT_INDEX;
        boolean actionFieldVisible = collectionGroup.isRenderLineActions() && !collectionGroup.isReadOnly();

        if (layoutManager instanceof TableLayoutManager) {
            actionIndex = ((TableLayoutManager) layoutManager).getActionColumnIndex();
        }

        if (actionIndex == UifConstants.TableLayoutValues.ACTIONS_COLUMN_LEFT_INDEX && actionFieldVisible) {
            String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging, null,
                    null);
            tableToolsColumnOptions.append(actionColOptions + " , ");
            columnIndex++;
        }

        if (layoutManager instanceof TableLayoutManager
                && ((TableLayoutManager) layoutManager).isRenderSequenceField()) {

            //add mData handling if using a json data source
            String mDataOption = "";
            if (collectionGroup.isUseServerPaging() || isForceLocalJsonData()) {
                mDataOption = "\"" + UifConstants.TableToolsKeys.MDATA
                        + "\" : function(row,type,newVal){ return _handleColData(row,type,'c" + columnIndex
                        + "',newVal);}, ";
            }

            tableToolsColumnOptions.append("{\"" + UifConstants.TableToolsKeys.SORTABLE + "\" : " + false
            // auto sequence column is never sortable
                    + ", \"" + UifConstants.TableToolsKeys.SORT_TYPE + "\" : \""
                    + UifConstants.TableToolsValues.NUMERIC + "\", " + mDataOption + "\""
                    + UifConstants.TableToolsKeys.TARGETS + "\": [" + columnIndex + "]}, ");
            columnIndex++;
            if (actionIndex == 2 && actionFieldVisible) {
                String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging,
                        null, null);
                tableToolsColumnOptions.append(actionColOptions + " , ");
                columnIndex++;
            }
        }

        // skip select field if enabled
        if (collectionGroup.isIncludeLineSelectionField()) {
            String colOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging, null, null);
            tableToolsColumnOptions.append(colOptions + " , ");
            columnIndex++;
        }

        // if data dictionary defines aoColumns, copy here and skip default sorting/visibility behaviour
        if (!StringUtils.isEmpty(getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMNS))) {
            // get the contents of the JS array string
            String jsArray = getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMNS);
            int startBrace = StringUtils.indexOf(jsArray, "[");
            int endBrace = StringUtils.lastIndexOf(jsArray, "]");
            tableToolsColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ", ");

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= columnIndex)) {
                String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging,
                        null, null);
                tableToolsColumnOptions.append(actionColOptions);
            } else {
                tableToolsColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableToolsColumnOptions.toString(), ", "));
            }

            tableToolsColumnOptions.append("]");
            getTemplateOptions().put(UifConstants.TableToolsKeys.AO_COLUMNS,
                    tableToolsColumnOptions.toString());
        } else if (!StringUtils.isEmpty(getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS))
                && isForceAoColumnDefsOverride()) {
            String jsArray = getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS);
            int startBrace = StringUtils.indexOf(jsArray, "[");
            int endBrace = StringUtils.lastIndexOf(jsArray, "]");
            tableToolsColumnOptions.append(StringUtils.substring(jsArray, startBrace + 1, endBrace) + ", ");

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= columnIndex)) {
                String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging,
                        null, null);
                tableToolsColumnOptions.append(actionColOptions);
            } else {
                tableToolsColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableToolsColumnOptions.toString(), ", "));
            }

            tableToolsColumnOptions.append("]");
            getTemplateOptions().put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS,
                    tableToolsColumnOptions.toString());
        } else if (layoutManager instanceof TableLayoutManager) {
            List<Field> rowFields = ((TableLayoutManager) layoutManager).getFirstRowFields();

            // build column defs from the the first row of the table
            for (Component component : rowFields) {
                if (actionFieldVisible && columnIndex + 1 == actionIndex) {
                    String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging,
                            null, null);
                    tableToolsColumnOptions.append(actionColOptions + " , ");
                    columnIndex++;
                }

                //add mData handling if using a json data source
                String mDataOption = "";
                if (collectionGroup.isUseServerPaging() || isForceLocalJsonData()) {
                    mDataOption = "\"" + UifConstants.TableToolsKeys.MDATA
                            + "\" : function(row,type,newVal){ return _handleColData(row,type,'c" + columnIndex
                            + "',newVal);}, ";
                }

                // for FieldGroup, get the first field from that group
                if (component instanceof FieldGroup) {
                    component = ((FieldGroup) component).getItems().get(0);
                }

                Map<String, String> componentDataAttributes;
                if (component instanceof DataField) {
                    DataField field = (DataField) component;

                    // if a field is marked as invisible in hiddenColumns, append options and skip sorting
                    if (getHiddenColumns() != null && getHiddenColumns().contains(field.getPropertyName())) {
                        tableToolsColumnOptions.append("{" + UifConstants.TableToolsKeys.VISIBLE + ": "
                                + UifConstants.TableToolsValues.FALSE + ", " + mDataOption + "\""
                                + UifConstants.TableToolsKeys.TARGETS + "\": [" + columnIndex + "]" + "}, ");
                        // if sortableColumns is present and a field is marked as sortable or unspecified
                    } else if (getSortableColumns() != null && !getSortableColumns().isEmpty()) {
                        if (getSortableColumns().contains(field.getPropertyName())) {
                            tableToolsColumnOptions.append(
                                    getDataFieldColumnOptions(columnIndex, collectionGroup, field) + ", ");
                        } else {
                            tableToolsColumnOptions.append("{'" + UifConstants.TableToolsKeys.SORTABLE + "': "
                                    + UifConstants.TableToolsValues.FALSE + ", " + mDataOption + "\""
                                    + UifConstants.TableToolsKeys.TARGETS + "\": [" + columnIndex + "]"
                                    + "}, ");
                        }
                    } else {// sortable columns not defined
                        String colOptions = getDataFieldColumnOptions(columnIndex, collectionGroup, field);
                        tableToolsColumnOptions.append(colOptions + " , ");
                    }
                    columnIndex++;
                } else if ((component instanceof MessageField)
                        && (componentDataAttributes = component.getDataAttributes()) != null
                        && UifConstants.RoleTypes.ROW_GROUPING
                                .equals(componentDataAttributes.get(UifConstants.DataAttributes.ROLE))) {
                    //Grouping column is never shown, so skip
                    tableToolsColumnOptions.append("{" + UifConstants.TableToolsKeys.VISIBLE + ": "
                            + UifConstants.TableToolsValues.FALSE + ", " + mDataOption + "\""
                            + UifConstants.TableToolsKeys.TARGETS + "\": [" + columnIndex + "]" + "}, ");
                    columnIndex++;
                    // start KS customization (to allow message field sorting) - KSENROLL-4999
                } else if (component instanceof MessageField) {
                    componentDataAttributes = component.getDataAttributes();
                    //For message field, sort as a regular String
                    String sortType = "";
                    if (componentDataAttributes != null) {
                        sortType = componentDataAttributes.get("sortType");
                    }
                    if (StringUtils.isBlank(sortType)) {
                        sortType = UifConstants.TableToolsValues.DOM_TEXT;
                    }
                    String colOptions = constructTableColumnOptions(columnIndex, true, isUseServerPaging,
                            String.class, sortType);
                    tableToolsColumnOptions.append(colOptions + " , ");
                    columnIndex++;
                    // end KS customization (to allow message field sorting) - KSENROLL-4999
                } else if (component instanceof LinkField) {
                    String colOptions = constructTableColumnOptions(columnIndex, true, isUseServerPaging,
                            String.class, UifConstants.TableToolsValues.DOM_TEXT);
                    tableToolsColumnOptions.append(colOptions + " , ");
                    columnIndex++;
                } else {
                    String colOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging, null,
                            null);
                    tableToolsColumnOptions.append(colOptions + " , ");
                    columnIndex++;
                }

            }

            if (actionFieldVisible && (actionIndex == -1 || actionIndex >= columnIndex)) {
                String actionColOptions = constructTableColumnOptions(columnIndex, false, isUseServerPaging,
                        null, null);
                tableToolsColumnOptions.append(actionColOptions);
            } else {
                tableToolsColumnOptions = new StringBuilder(
                        StringUtils.removeEnd(tableToolsColumnOptions.toString(), ", "));
            }
            //merge the aoColumnDefs passed in
            if (!StringUtils.isEmpty(getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS))) {
                String origAoOptions = getTemplateOptions().get(UifConstants.TableToolsKeys.AO_COLUMN_DEFS)
                        .trim();
                origAoOptions = StringUtils.removeStart(origAoOptions, "[");
                origAoOptions = StringUtils.removeEnd(origAoOptions, "]");
                tableToolsColumnOptions.append("," + origAoOptions);
            }

            tableToolsColumnOptions.append("]");
            getTemplateOptions().put(UifConstants.TableToolsKeys.AO_COLUMN_DEFS,
                    tableToolsColumnOptions.toString());
        }
    }
}