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

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

Introduction

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

Prototype

public static String substringBetween(String str, String open, String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:org.kuali.kfs.module.cab.document.web.struts.PurApLineForm.java

@Override
public void populate(HttpServletRequest request) {
    super.populate(request);

    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        // populate collection index
        String purApDocIndex = StringUtils.substringBetween(parameterName, CabConstants.DOT_DOC, ".");
        if (StringUtils.isNotBlank(purApDocIndex)) {
            this.setActionPurApDocIndex(Integer.parseInt(purApDocIndex));
        }//from w  w w. j  av  a  2 s.c  om
        String itemAssetIndex = StringUtils.substringBetween(parameterName, CabConstants.DOT_LINE, ".");
        if (StringUtils.isNotBlank(itemAssetIndex)) {
            this.setActionItemAssetIndex(Integer.parseInt(itemAssetIndex));
        }
    }

    if (this.purchaseOrderIdentifier != null) {
        PurchaseOrderDocument poDoc = this.getPurApInfoService()
                .getCurrentDocumentForPurchaseOrderIdentifier(this.purchaseOrderIdentifier);
        if (ObjectUtils.isNotNull(poDoc) && StringUtils.isNotBlank(poDoc.getDocumentNumber())) {
            this.purchaseOrderInquiryUrl = "purapPurchaseOrder.do?methodToCall=docHandler&docId="
                    + poDoc.getDocumentNumber() + "&command=displayDocSearchView";
        }
    }

    // clear up the documentNumber saved when submit CAMS doc
    this.setDocumentNumber(null);
}

From source file:org.kuali.kfs.module.cam.batch.AssetBarcodeInventoryInputFileType.java

/**
 * Return set of file user identifiers from a list of files
 * // w  w  w  .  j  a  va2  s.  co  m
 * @param user user who uploaded or will upload file
 * @param files list of files objects
 * @return Set containing all user identifiers from list of files
 * 
 * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
 */
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
    Set<String> extractedFileUserIdentifiers = new TreeSet<String>();

    StringBuilder buf = new StringBuilder();
    buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName())
            .append(FILE_NAME_PART_DELIMITER);
    String prefixString = buf.toString();

    IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);
    IOFileFilter suffixFilter = new SuffixFileFilter(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION);
    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString,
                        CamsConstants.BarCodeInventory.DATA_FILE_EXTENSION));
            } else {
                LOG.error("Unable to determine file user identifier for file name: " + fileName);
                throw new RuntimeException(
                        "Unable to determine file user identifier for file name: " + fileName);
            }
        }
    }

    return extractedFileUserIdentifiers;
}

From source file:org.kuali.kfs.module.ec.document.web.struts.CertificationReportAction.java

/**
 * sort the detail lines by column//  ww w  .  ja  v  a 2s. co m
 */
public ActionForward sortDetailLineByColumn(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    CertificationReportForm certificationReportForm = (CertificationReportForm) form;

    String methodToCallAttribute = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    String sortMethodName = EffortConstants.SORT_DETAIL_LINE_BY_COLUMN_METHOD_NAME + ".";
    String sortColumn = StringUtils.substringBetween(methodToCallAttribute, sortMethodName, ".");

    this.toggleSortOrder(certificationReportForm);
    this.sortDetailLine(certificationReportForm, certificationReportForm.getDetailLines(), sortColumn);

    if (this.isSummarizeDetailLinesRendered(certificationReportForm)) {
        this.sortDetailLine(certificationReportForm, certificationReportForm.getSummarizedDetailLines(),
                sortColumn);
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}

From source file:org.kuali.kfs.module.endow.document.web.struts.EndowmentTaxLotLinesDocumentActionBase.java

/**
 * Gets the index of the tax lot line to be deleted.
 * /*from w ww. j  av a 2  s .c o m*/
 * @param request
 * @return the index of the tax lot line to be deleted
 */
protected int getTaxLotToDelete(HttpServletRequest request) {
    int selectedTaxLot = -1;
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        String lotNumber = StringUtils.substringBetween(parameterName, ".taxLot", ".");
        selectedTaxLot = Integer.parseInt(lotNumber);
    }

    return selectedTaxLot;
}

From source file:org.kuali.kfs.module.ld.document.web.struts.BenefitExpenseTransferAction.java

/**
 * @param mapping ActionMapping//from w w  w  .ja v  a  2 s  .  c o  m
 * @param form ActionForm
 * @param request HttpServletRequest
 * @param response HttpServletResponse
 * @see org.kuali.rice.kns.web.struts.action.KualiAction#performLookup(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // parse out the business object name from our methodToCall parameter
    String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
    String boClassName = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);

    if (!StringUtils.equals(boClassName, LaborLedgerPendingEntry.class.getName())) {
        return super.performLookup(mapping, form, request, response);
    }

    String path = super.performLookup(mapping, form, request, response).getPath();
    path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, LaborConstants.LONG_ROW_TABLE_INRUIRY_ACTION);
    return new ActionForward(path, true);
}

From source file:org.kuali.kfs.module.ld.document.web.struts.ExpenseTransferDocumentActionBase.java

/**
 * Takes care of storing the action form in the user session and forwarding to the balance inquiry lookup action.
 *
 * @param mapping//from ww  w .ja v  a 2  s . co m
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward performBalanceInquiryLookup(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;

    // when we return from the lookup, our next request's method to call is going to be refresh
    financialDocumentForm.registerEditableProperty(KRADConstants.DISPATCH_REQUEST_PARAMETER);

    TransactionalDocument document = financialDocumentForm.getTransactionalDocument();

    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getContextPath();

    // parse out the important strings from our methodToCall parameter
    String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);

    // parse out business object class name for lookup
    String boClassName = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
    if (StringUtils.isBlank(boClassName)) {
        throw new RuntimeException("Illegal call to perform lookup, no business object class name specified.");
    }

    // build the parameters for the lookup url
    Properties parameters = new Properties();
    String conversionFields = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    if (StringUtils.isNotBlank(conversionFields)) {
        parameters.put(KFSConstants.CONVERSION_FIELDS_PARAMETER, conversionFields);
    }

    // pass values from form that should be pre-populated on lookup search
    String parameterFields = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
    if (StringUtils.isNotBlank(parameterFields)) {
        String[] lookupParams = parameterFields.split(KFSConstants.FIELD_CONVERSIONS_SEPERATOR);

        for (int i = 0; i < lookupParams.length; i++) {
            String[] keyValue = lookupParams[i].split(KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR);

            // hard-coded passed value
            if (StringUtils.contains(keyValue[0], "'")) {
                parameters.put(keyValue[1], StringUtils.replace(keyValue[0], "'", ""));
            }
            // passed value should come from property
            else if (StringUtils.isNotBlank(request.getParameter(keyValue[0]))) {
                parameters.put(keyValue[1], request.getParameter(keyValue[0]));
            }
        }
    }

    // grab whether or not the "return value" link should be hidden or not
    String hideReturnLink = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);
    if (StringUtils.isNotBlank(hideReturnLink)) {
        parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, hideReturnLink);
    }

    // anchor, if it exists
    if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) {
        parameters.put(KFSConstants.LOOKUP_ANCHOR, ((KualiForm) form).getAnchor());
    }

    // determine what the action path is
    String actionPath = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL,
            KFSConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL);
    if (StringUtils.isBlank(actionPath)) {
        throw new IllegalStateException(
                "The \"actionPath\" attribute is an expected parameter for the <kul:balanceInquiryLookup> tag - it "
                        + "should never be blank.");
    }

    // now add required parameters
    parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, "search");
    parameters.put(KFSConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
    parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName);
    parameters.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath + mapping.getPath() + ".do");
    //parameters.put(GeneralLedgerConstants.LookupableBeanKeys.SEGMENTED_LOOKUP_FLAG_NAME, Boolean.TRUE.toString());

    String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + actionPath, parameters);

    return new ActionForward(lookupUrl, true);
}

From source file:org.kuali.kfs.module.ld.document.web.struts.JournalVoucherAction.java

/**
 * @see org.kuali.rice.kns.web.struts.action.KualiAction#performLookup(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///  ww  w .  ja  v  a2s .  c o  m
@Override
public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // parse out the business object name from our methodToCall parameter
    String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
    String boClassName = StringUtils.substringBetween(fullParameter,
            KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);

    if (StringUtils.equals(boClassName, LaborLedgerPendingEntry.class.getName())) {
        String path = super.performLookup(mapping, form, request, response).getPath();
        path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, LaborConstants.LONG_ROW_TABLE_INRUIRY_ACTION);
        return new ActionForward(path, true);
    } else if (StringUtils.equals(boClassName, PositionData.class.getName())) {
        String path = super.performLookup(mapping, form, request, response).getPath();
        path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, KFSConstants.GL_MODIFIED_INQUIRY_ACTION);
        return new ActionForward(path, true);
    } else {
        return super.performLookup(mapping, form, request, response);
    }
}

From source file:org.kuali.kfs.module.purap.document.authorization.PurapAccountingLineAuthorizer.java

/**
 * Overrides the method in AccountingLineAuthorizerBase so that the add button would
 * have the line item number in addition to the rest of the insertxxxx String for
 * methodToCall when the user clicks on the add button.
 *
 * @param accountingLine/*from w w  w .  j a  v a  2  s .c o m*/
 * @param accountingLineProperty
 * @return
 */
@Override
protected String getAddMethod(AccountingLine accountingLine, String accountingLineProperty) {
    final String infix = getActionInfixForNewAccountingLine(accountingLine, accountingLineProperty);
    String lineNumber = null;
    if (accountingLineProperty.equals(PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE)) {
        lineNumber = "-2";
    } else {
        lineNumber = StringUtils.substringBetween(accountingLineProperty, "[", "]");
    }
    return "insert" + infix + "Line.line" + lineNumber + "." + "anchoraccounting" + infix + "Anchor";
}

From source file:org.kuali.kfs.module.purap.document.authorization.PurapAccountingLineAuthorizer.java

/**
 * Overrides the method in AccountingLineAuthorizerBase so that the delete button would have both
 * the line item number and the accounting line number for methodToCall when the user clicks on
 * the delete button.//w ww .j a  v a 2 s .com
 *
 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getDeleteLineMethod(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String, java.lang.Integer)
 */
@Override
protected String getDeleteLineMethod(AccountingLine accountingLine, String accountingLineProperty,
        Integer accountingLineIndex) {
    final String infix = getActionInfixForExtantAccountingLine(accountingLine, accountingLineProperty);
    String lineNumber = StringUtils.substringBetween(accountingLineProperty, "item[", "].sourceAccountingLine");
    if (lineNumber == null) {
        lineNumber = "-2";
    }
    String accountingLineNumber = StringUtils.substringBetween(accountingLineProperty, "sourceAccountingLine[",
            "]");
    return "delete" + infix + "Line.line" + lineNumber + ":" + accountingLineNumber + ".anchoraccounting"
            + infix + "Anchor";
}

From source file:org.kuali.kfs.module.purap.document.authorization.PurapAccountingLineAuthorizer.java

/**
 * Overrides the method in AccountingLineAuthorizerBase so that the balance inquiry button would
 * have both the line item number and the accounting line number for methodToCall when the user
 * clicks on the balance inquiry button.
 * @see org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizerBase#getBalanceInquiryMethod(org.kuali.kfs.sys.businessobject.AccountingLine, java.lang.String, java.lang.Integer)
 *//*from w w w. j  a va 2  s  .com*/
@Override
protected String getBalanceInquiryMethod(AccountingLine accountingLine, String accountingLineProperty,
        Integer accountingLineIndex) {
    final String infix = getActionInfixForNewAccountingLine(accountingLine, accountingLineProperty);
    String lineNumber = StringUtils.substringBetween(accountingLineProperty, "item[", "].sourceAccountingLine");
    if (lineNumber == null) {
        lineNumber = "-2";
    }
    String accountingLineNumber = StringUtils.substringBetween(accountingLineProperty, "sourceAccountingLine[",
            "]");
    return "performBalanceInquiryFor" + infix + "Line.line" + ":" + lineNumber + ":" + accountingLineNumber
            + ".anchoraccounting" + infix + "existingLineLineAnchor" + accountingLineNumber;
}