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.fp.document.web.struts.ProcurementCardAction.java

protected int getSelectedContainer(HttpServletRequest request) {
    int selectedContainer = -1;
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        String lineNumber = StringUtils.substringBetween(parameterName, ".transactionEntries[", "].");
        selectedContainer = Integer.parseInt(lineNumber);
    }//w w  w  .  j av  a 2 s  . c o m

    return selectedContainer;
}

From source file:org.kuali.kfs.fp.document.web.struts.ProcurementCardAction.java

/**
 * Parses the method to call attribute to pick off the transaction line number which should have an action performed
 * on it./*from  www  .  j  a  va 2s .  c o  m*/
 *
 * @param request
 * @return
 */
protected int getTransactionLineIndex(HttpServletRequest request) {
    int selectedLine = -1;
    String parameterName = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        String lineNumber = StringUtils.substringBetween(parameterName, "document.transactionEntries[", "]");
        selectedLine = Integer.parseInt(lineNumber);
    }

    return selectedLine;
}

From source file:org.kuali.kfs.gl.batch.EnterpriseFeederFileSetType.java

/**
 * Return set of file user identifiers from a list of files
 * /* w w  w  .  j a v a 2s  .  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 OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX),
            new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX));

    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString,
                        EnterpriseFeederService.DATA_FILE_SUFFIX));
            } else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString,
                        EnterpriseFeederService.RECON_FILE_SUFFIX));
            } 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.gl.document.web.struts.CorrectionForm.java

/**
 * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
 *//*from  w  w w . j  a  va 2 s  .c om*/
@Override
public void populate(HttpServletRequest request) {
    super.populate(request);

    // Sync up the groups
    syncGroups();

    originEntrySearchResultTableMetadata = new KualiTableRenderFormMetadata();

    if (KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall())) {
        // look for the page number to switch to
        originEntrySearchResultTableMetadata.setSwitchToPageNumber(-1);

        // the param we're looking for looks like: methodToCall.switchToPage.1.x , where 1 is the page nbr
        String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "."
                + KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
        for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
            String parameterName = (String) i.nextElement();
            if (parameterName.startsWith(paramPrefix)) {
                String switchToPageNumberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
                originEntrySearchResultTableMetadata
                        .setSwitchToPageNumber(Integer.parseInt(switchToPageNumberStr));
            }
        }
        if (originEntrySearchResultTableMetadata.getSwitchToPageNumber() == -1) {
            throw new RuntimeException("Couldn't find page number");
        }
    }

    if (KFSConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall())) {
        originEntrySearchResultTableMetadata.setColumnToSortIndex(-1);

        // the param we're looking for looks like: methodToCall.sort.1.x , where 1 is the column to sort on
        String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "."
                + KFSConstants.TableRenderConstants.SORT_METHOD + ".";
        for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
            String parameterName = (String) i.nextElement();
            if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
                String columnToSortStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
                originEntrySearchResultTableMetadata.setColumnToSortIndex(Integer.parseInt(columnToSortStr));
            }
        }
        if (originEntrySearchResultTableMetadata.getColumnToSortIndex() == -1) {
            throw new RuntimeException("Couldn't find column to sort");
        }
    }

    // since the processInBatch option defaults to true, there's no built in POJO way to detect whether it's been unchecked
    // this code takes care of that
    if (StringUtils.isNotBlank(
            request.getParameter("processInBatch" + KFSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION))
            && StringUtils.isBlank(request.getParameter("processInBatch"))) {
        setProcessInBatch(false);
    }

    if (StringUtils.isNotBlank(
            request.getParameter("matchCriteriaOnly" + KFSConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION))
            && StringUtils.isBlank(request.getParameter("matchCriteriaOnly"))) {
        setMatchCriteriaOnly(false);
    }
}

From source file:org.kuali.kfs.gl.web.struts.BalanceInquiryLookupResults.java

/**
 * Named appropriately as it is intended to be called from a <code>{@link LookupForm}</code>
 * //from  w  w  w.  ja  v  a  2  s.c o  m
 * @param request HttpServletRequest
 */
public void populate(HttpServletRequest request) {
    super.populate(request);

    if (StringUtils.isNotBlank(request.getParameter(KFSConstants.TableRenderConstants.VIEWED_PAGE_NUMBER))) {
        setViewedPageNumber(
                Integer.parseInt(request.getParameter(KFSConstants.TableRenderConstants.VIEWED_PAGE_NUMBER)));
    } else {
        setViewedPageNumber(0); // first page is page 0
    }

    if (KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD.equals(getMethodToCall(request))) {
        // look for the page number to switch to
        setSwitchToPageNumber(-1);

        // the param we're looking for looks like: methodToCall.switchToPage.1.x , where 1 is the page nbr
        String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "."
                + KFSConstants.TableRenderConstants.SWITCH_TO_PAGE_METHOD + ".";
        for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
            String parameterName = (String) i.nextElement();
            if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
                String switchToPageNumberStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
                setSwitchToPageNumber(Integer.parseInt(switchToPageNumberStr));
            }
        }
        if (getSwitchToPageNumber() == -1) {
            throw new RuntimeException("Couldn't find page number");
        }
    }

    if (KFSConstants.TableRenderConstants.SORT_METHOD.equals(getMethodToCall(request))) {
        setColumnToSortIndex(-1);

        // the param we're looking for looks like: methodToCall.sort.1.x , where 1 is the column to sort on
        String paramPrefix = KFSConstants.DISPATCH_REQUEST_PARAMETER + "."
                + KFSConstants.TableRenderConstants.SORT_METHOD + ".";
        for (Enumeration i = request.getParameterNames(); i.hasMoreElements();) {
            String parameterName = (String) i.nextElement();
            if (parameterName.startsWith(paramPrefix) && parameterName.endsWith(".x")) {
                String columnToSortStr = StringUtils.substringBetween(parameterName, paramPrefix, ".");
                setColumnToSortIndex(Integer.parseInt(columnToSortStr));
            }
        }
        if (getColumnToSortIndex() == -1) {
            throw new RuntimeException("Couldn't find column to sort");
        }
    }

    setPreviouslySelectedObjectIdSet(parsePreviouslySelectedObjectIds(request));
    setSelectedObjectIdSet(parseSelectedObjectIdSet(request));
    setDisplayedObjectIdSet(parseDisplayedObjectIdSet(request));

    setSearchUsingOnlyPrimaryKeyValues(parseSearchUsingOnlyPrimaryKeyValues(request));
    if (isSearchUsingOnlyPrimaryKeyValues()) {
        setPrimaryKeyFieldLabels(getLookupable().getPrimaryKeyFieldLabels());
    }
}

From source file:org.kuali.kfs.gl.web.struts.BalanceInquiryLookupResults.java

/**
 * Parses the method to call parameter passed in as a post parameter The parameter should be something like
 * methodToCall.sort.1.(::;true;::).x, this method will return the value between (::; and ;::) as a boolean
 * //from  ww  w .j  a v a 2  s.co m
 * @param methodToCallParam the method to call in a format described above
 * @return the value between the delimiters, false if there are no delimiters
 */
protected boolean parseSearchUsingOnlyPrimaryKeyValues(String methodToCallParam) {
    String searchUsingOnlyPrimaryKeyValuesStr = StringUtils.substringBetween(methodToCallParam,
            KFSConstants.METHOD_TO_CALL_PARM12_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM12_RIGHT_DEL);
    if (StringUtils.isBlank(searchUsingOnlyPrimaryKeyValuesStr)) {
        return false;
    }
    return Boolean.parseBoolean(searchUsingOnlyPrimaryKeyValuesStr);
}

From source file:org.kuali.kfs.module.ar.web.struts.ContractsGrantsInvoiceSummaryAction.java

/**
 * This method would create invoices for the list of awards. It calls the batch process to reuse the functionality to create the
 * invoices./*from   ww w .ja v a2 s  . com*/
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward createInvoices(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ContractsGrantsInvoiceSummaryForm contractsGrantsInvoiceSummaryForm = (ContractsGrantsInvoiceSummaryForm) form;
    ContractsGrantsInvoiceCreateDocumentService cgInvoiceDocumentCreateService = SpringContext
            .getBean(ContractsGrantsInvoiceCreateDocumentService.class);
    Person person = GlobalVariables.getUserSession().getPerson();
    String lookupResultsSequenceNumber = "";
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        lookupResultsSequenceNumber = StringUtils.substringBetween(parameterName, ".number", ".");
    }

    Collection<ContractsGrantsInvoiceLookupResult> lookupResults = getContractsGrantsInvoiceResultsFromLookupResultsSequenceNumber(
            lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId());
    // To retrieve the batch file directory name as "reports/cg"
    ModuleConfiguration systemConfiguration = SpringContext.getBean(KualiModuleService.class)
            .getModuleServiceByNamespaceCode("KFS-AR").getModuleConfiguration();

    String destinationFolderPath = StringUtils.EMPTY;
    List<String> batchFileDirectories = ((FinancialSystemModuleConfiguration) systemConfiguration)
            .getBatchFileDirectories();

    if (CollectionUtils.isNotEmpty(batchFileDirectories)) {
        destinationFolderPath = ((FinancialSystemModuleConfiguration) systemConfiguration)
                .getBatchFileDirectories().get(0);
    }

    String runtimeStamp = getDateTimeService().toDateTimeStringForFilename(new java.util.Date());
    contractsGrantsInvoiceSummaryForm.setAwardInvoiced(true);
    int validationErrors = 0;
    int validAwards = 0;

    // Create Invoices from list of Awards.
    List<ErrorMessage> errorMessages = null;
    for (ContractsGrantsInvoiceLookupResult contractsGrantsInvoiceLookupResult : lookupResults) {
        Collection<ContractsAndGrantsBillingAward> awards = contractsGrantsInvoiceLookupResult.getAwards();
        Collection<ContractsGrantsInvoiceDocumentErrorLog> contractsGrantsInvoiceDocumentErrorLogs = new ArrayList<ContractsGrantsInvoiceDocumentErrorLog>();
        awards = cgInvoiceDocumentCreateService.validateAwards(awards, contractsGrantsInvoiceDocumentErrorLogs,
                null, ArConstants.ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL.getCode());
        validationErrors += contractsGrantsInvoiceDocumentErrorLogs.size();
        validAwards += awards.size();
        if (awards.size() > 0) {
            errorMessages = cgInvoiceDocumentCreateService.createCGInvoiceDocumentsByAwards(awards,
                    ArConstants.ContractsAndGrantsInvoiceDocumentCreationProcessType.MANUAL);
        }
    }
    if (validationErrors > 0) {
        // At a minimum, show users a message that errors occurred, check report for details.
        KNSGlobalVariables.getMessageList()
                .add(ArKeyConstants.ContractsGrantsInvoiceConstants.ERROR_AWARDS_INVALID);
    }
    if (validAwards > 0) {
        KNSGlobalVariables.getMessageList().add(
                ArKeyConstants.ContractsGrantsInvoiceConstants.MESSAGE_CONTRACTS_GRANTS_INVOICE_BATCH_SENT);
    }

    if (ObjectUtils.isNotNull(errorMessages)) {
        KNSGlobalVariables.getMessageList().addAll(errorMessages);
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}

From source file:org.kuali.kfs.module.ar.web.struts.GenerateDunningLettersSummaryAction.java

/**
 * This method would create invoices for the list of awards. It calls the batch process to reuse the functionality to send
 * dunning letters//  w  ww .  j  a  va2 s  . c o  m
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward generateDunningLetters(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    GenerateDunningLettersSummaryForm dunningLetterDistributionSummaryForm = (GenerateDunningLettersSummaryForm) form;

    Person person = GlobalVariables.getUserSession().getPerson();
    DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
    String lookupResultsSequenceNumber = "";
    String parameterName = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        lookupResultsSequenceNumber = StringUtils.substringBetween(parameterName, ".number", ".");
    }

    Collection<GenerateDunningLettersLookupResult> lookupResults = getDunningLetterDistributionLookupResultsFromLookupResultsSequenceNumber(
            lookupResultsSequenceNumber, GlobalVariables.getUserSession().getPerson().getPrincipalId());
    byte[] finalReport = getDunningLetterDistributionService().createDunningLettersForAllResults(lookupResults);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    if (finalReport.length > 0 && getDunningLetterDistributionService().createZipOfPDFs(finalReport, baos)) {
        WebUtils.saveMimeOutputStreamAsFile(response, KFSConstants.ReportGeneration.ZIP_MIME_TYPE, baos,
                "Dunning_Letters_"
                        + getDateTimeService().toDateStringForFilename(getDateTimeService().getCurrentDate())
                        + KFSConstants.ReportGeneration.ZIP_FILE_EXTENSION);
        dunningLetterDistributionSummaryForm.setDunningLettersGenerated(true);
        return null;
    } else {
        KNSGlobalVariables.getMessageList()
                .add(ArKeyConstants.DunningCampaignConstantsAndErrors.MESSAGE_DUNNING_CAMPAIGN_BATCH_NOT_SENT);
        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }
}

From source file:org.kuali.kfs.module.bc.document.web.struts.OrganizationSelectionTreeAction.java

/**
 * Parses the report name from the methodToCall request parameter and retrieves the associated ReportMode.
 *
 * @param request - HttpServletRequest containing the methodToCall parameter
 * @param organizationSelectionTreeForm - OrganizationSelectionTreeForm to set report mode on
 * @return BudgetConstructionReportMode - mode associated with parsed report name
 *///from w  w  w . j  av  a2s .co  m
private BudgetConstructionReportMode setupReportMode(HttpServletRequest request,
        OrganizationSelectionTreeForm organizationSelectionTreeForm) {
    String fullParameter = (String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    String reportName = StringUtils.substringBetween(fullParameter, KRADConstants.METHOD_TO_CALL_PARM1_LEFT_DEL,
            KRADConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    organizationSelectionTreeForm.setReportMode(reportName);

    return BudgetConstructionReportMode
            .getBudgetConstructionReportModeByName(organizationSelectionTreeForm.getReportMode());
}

From source file:org.kuali.kfs.module.bc.document.web.struts.TempListLookupAction.java

/**
 * Parses the methodToCall parameter which contains the lock information in a known format. Populates a
 * BudgetConstructionLockSummary that represents the record to unlock.
 *
 * @param methodToCallString - request parameter containing lock information
 * @return lockSummary populated from request parameter
 *//*from  w  ww.j a  v a 2  s . co m*/
protected BudgetConstructionLockSummary populateLockSummary(String methodToCallString) {
    BudgetConstructionLockSummary lockSummary = new BudgetConstructionLockSummary();

    // parse lock fields from methodToCall parameter
    String lockType = StringUtils.substringBetween(methodToCallString,
            KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    String lockFieldsString = StringUtils.substringBetween(methodToCallString,
            KFSConstants.METHOD_TO_CALL_PARM9_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM9_RIGHT_DEL);
    String lockUser = StringUtils.substringBetween(methodToCallString,
            KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);

    // space was replaced by underscore for html
    lockSummary.setLockType(StringUtils.replace(lockType, "_", " "));
    lockSummary.setLockUserId(lockUser);

    // parse key fields
    StrTokenizer strTokenizer = new StrTokenizer(lockFieldsString, BCConstants.LOCK_STRING_DELIMITER);
    strTokenizer.setIgnoreEmptyTokens(false);
    String fiscalYear = strTokenizer.nextToken();
    if (fiscalYear != null) {
        lockSummary.setUniversityFiscalYear(Integer.parseInt(fiscalYear));
    }

    lockSummary.setChartOfAccountsCode(strTokenizer.nextToken());
    lockSummary.setAccountNumber(strTokenizer.nextToken());
    lockSummary.setSubAccountNumber(strTokenizer.nextToken());
    lockSummary.setPositionNumber(strTokenizer.nextToken());

    return lockSummary;
}