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.kra.web.struts.action.SponsorHierarchyAction.java

@Override
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    super.refresh(mapping, form, request, response);
    SponsorHierarchyForm sponsorHierarchyForm = (SponsorHierarchyForm) form;
    String sponsors = Constants.EMPTY_STRING; // return to treeview - still a test
    if (sponsorHierarchyForm.getLookupResultsBOClassName() != null
            && sponsorHierarchyForm.getLookupResultsSequenceNumber() != null) {
        String lookupResultsSequenceNumber = sponsorHierarchyForm.getLookupResultsSequenceNumber();

        @SuppressWarnings("unchecked")
        Class<BusinessObject> lookupResultsBOClass = (Class<BusinessObject>) Class
                .forName(sponsorHierarchyForm.getLookupResultsBOClassName());

        LookupResultsService lookupService = KraServiceLocator.getService(LookupResultsService.class);
        String principalId = GlobalVariables.getUserSession().getPerson().getPrincipalId(); // LookupService.retrieveSelectedResultBOs checks that this is the user that persisted the BO
        Collection<BusinessObject> rawValues = lookupService
                .retrieveSelectedResultBOs(lookupResultsSequenceNumber, lookupResultsBOClass, principalId);
        int idx = 0;
        String idxString = StringUtils.substringBetween(sponsorHierarchyForm.getLookedUpCollectionName(), "[",
                "]");
        if (StringUtils.isNotBlank(idxString)) {
            idx = Integer.parseInt(idxString);
        }// ww w.  ja  va 2s  .c om
        List sponsorCodes = new ArrayList();
        sponsorHierarchyForm.getNewSponsors().set(0, new ArrayList());
        sponsorHierarchyForm.setSelectedSponsors(Constants.EMPTY_STRING);
        for (Iterator iter = rawValues.iterator(); iter.hasNext();) {
            Sponsor sponsor = (Sponsor) iter.next();
            if (!sponsorCodes.contains(sponsor.getSponsorCode())) {
                sponsorHierarchyForm.getNewSponsors().get(idx).add(sponsor);
                if (StringUtils.isBlank(sponsors)) {
                    sponsors = sponsor.getSponsorCode() + ":" + sponsor.getSponsorName();
                } else {
                    sponsors = sponsors + Constants.SPONSOR_HIERARCHY_SEPARATOR_C1C + sponsor.getSponsorCode()
                            + ":" + sponsor.getSponsorName();

                }
            }
        }
        sponsorHierarchyForm.setLookupResultsSequenceNumber(null);
    }

    if ((StringUtils.isNotBlank(sponsorHierarchyForm.getActionSelected())
            && (sponsorHierarchyForm.getActionSelected().equals("maint")
                    || sponsorHierarchyForm.getActionSelected().equals("new")))
            || StringUtils.isNotBlank(sponsors)) {
        sponsorHierarchyForm.setSelectedSponsors(sponsors);
        return mapping.findForward(LOOKUP);
    } else {
        return mapping.findForward(NEW);
    }
}

From source file:org.kuali.kra.web.struts.form.KraTransactionalDocumentFormBase.java

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

    // Hack to get panels with add/delete items that are editable after add (Protocol Participants, Special Review) to work correctly with validation.  
    // In this scenario, the user adds a couple of correctly formatted items but then changes one of the fields to an incorrect format and saves.  This will
    // cause validation errors, but if the user now tries to delete the errant entry, validation will fail because the validator in the Kuali Request 
    // Processor still detects the error in the message map.  We don't want validation to run for a delete method, so we need to clear the current error 
    // messages, preventing the validator from running and allowing the delete to go through.
    ///*w  w w.  j a v  a2  s .c  o m*/
    // This is detected by the existence of "validate0" on the methodToCall property (similar to finding the line number of a delete).
    String methodToCallAttribute = (String) request.getAttribute(KNSConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.contains(methodToCallAttribute, "validate")) {
        String validateParameter = StringUtils.substringBetween(methodToCallAttribute, ".validate", ".");
        if (StringUtils.equals("0", validateParameter)) {
            GlobalVariables.getMessageMap().clearErrorMessages();
        }
    }
}

From source file:org.kuali.maven.wagon.MimeTypeParser.java

/**
 * @param args/*  w  ww.  ja v a 2  s  .  c o m*/
 */
public static void main(final String[] args) {
    try {
        String filename = "C:/Program Files/Apache Software Foundation/Tomcat 6.0/conf/web.xml";
        String contents = IOUtils.toString(new FileInputStream(filename));
        String tomcatMimetypes = StringUtils.substringBetween(contents,
                "<!-- deployment descriptor.                                               -->",
                "<!-- ==================== Default Welcome File List ===================== -->");
        String[] tokens = StringUtils.splitByWholeSeparatorPreserveAllTokens(tomcatMimetypes, "<mime-mapping>");
        System.out.println(tokens.length);
        List<Mapping> mappings = new ArrayList<Mapping>();
        int count = 0;
        for (String token : tokens) {
            count++;
            if (count == 1) {
                continue;
            }
            Mapping m = new Mapping();
            String extension = StringUtils.substringBetween(token, "<extension>", "</extension>");
            String type = StringUtils.substringBetween(token, "<mime-type>", "</mime-type>");
            m.setExtension(extension);
            m.setType(type);
            // System.out.println("'" + token + "'" + " " + type + " " + extension);
            mappings.add(m);
        }
        Map<String, String> mimeTypes = new TreeMap<String, String>();
        for (Mapping mapping : mappings) {
            String extension = mimeTypes.get(mapping.getType());
            if (extension == null) {
                extension = mapping.getExtension();
            } else {
                extension += " " + mapping.getExtension();
            }
            mimeTypes.put(mapping.getType(), extension);
        }
        System.out.println(mappings.size() + " " + mimeTypes.size());
        System.out.println(getString(mimeTypes));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.kuali.ole.gl.document.web.struts.CorrectionForm.java

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

    // Sync up the groups
    syncGroups();

    originEntrySearchResultTableMetadata = new KualiTableRenderFormMetadata();

    if (OLEConstants.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 = OLEConstants.DISPATCH_REQUEST_PARAMETER + "."
                + OLEConstants.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 (OLEConstants.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 = OLEConstants.DISPATCH_REQUEST_PARAMETER + "."
                + OLEConstants.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" + OLEConstants.CHECKBOX_PRESENT_ON_FORM_ANNOTATION))
            && StringUtils.isBlank(request.getParameter("processInBatch"))) {
        setProcessInBatch(false);
    }

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

From source file:org.kuali.ole.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 . co  m*/
 * @param request HttpServletRequest
 */
public void populate(HttpServletRequest request) {
    super.populate(request);

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

    if (OLEConstants.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 = OLEConstants.DISPATCH_REQUEST_PARAMETER + "."
                + OLEConstants.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 (OLEConstants.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 = OLEConstants.DISPATCH_REQUEST_PARAMETER + "."
                + OLEConstants.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.ole.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  w w  w  .ja  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,
            OLEConstants.METHOD_TO_CALL_PARM12_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM12_RIGHT_DEL);
    if (StringUtils.isBlank(searchUsingOnlyPrimaryKeyValuesStr)) {
        return false;
    }
    return Boolean.parseBoolean(searchUsingOnlyPrimaryKeyValuesStr);
}

From source file:org.kuali.ole.module.purap.document.web.struts.AccountsPayableActionBase.java

/**
 * Will return an array of Strings containing 2 indexes, the first String is the item index and the second String is the account
 * index. These are obtained by parsing the method to call parameter from the request, between the word ".line" and "." The
 * indexes are separated by a semicolon (:)
 *
 * @param request The HttpServletRequest
 * @return An array of Strings containing pairs of two indices, an item index
 *///  w ww  .jav  a 2s  .  co m
protected String[] getSelectedItemNumber(HttpServletRequest request) {
    String itemString = new String();
    String parameterName = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        itemString = StringUtils.substringBetween(parameterName, ".line", ".");
    }
    String[] result = StringUtils.split(itemString, ":");

    return result;
}

From source file:org.kuali.ole.module.purap.document.web.struts.PurchasingAccountsPayableActionBase.java

/**
 * Will return an array of Strings containing 2 indexes, the first String is the item index and the second String is the account
 * index. These are obtained by parsing the method to call parameter from the request, between the word ".line" and "." The
 * indexes are separated by a semicolon (:)
 *
 * @param request The HttpServletRequest
 * @return An array of Strings containing pairs of two indices, an item index and a account index
 *///from w  w w.ja  va 2 s . co m
protected String[] getSelectedLineForAccounts(HttpServletRequest request) {
    String accountString = new String();
    String parameterName = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (StringUtils.isNotBlank(parameterName)) {
        accountString = StringUtils.substringBetween(parameterName, ".line", ".");
    }
    String[] result = StringUtils.split(accountString, ":");

    return result;
}

From source file:org.kuali.ole.module.purap.document.web.struts.PurchasingActionBase.java

public ActionForward useOffCampusAssetLocationBuildingByDocument(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase baseForm = (PurchasingFormBase) form;
    PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();

    String fullParameter = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
    String systemIndex = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM1_LEFT_DEL,
            OLEConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    String assetLocationIndex = StringUtils.substringBetween(fullParameter,
            OLEConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);

    CapitalAssetSystem system = document.getPurchasingCapitalAssetSystems().get(Integer.parseInt(systemIndex));

    if ("new".equals(assetLocationIndex)) {
        useOffCampusAssetLocationBuilding(baseForm.getNewPurchasingCapitalAssetLocationLine());
    } else {/*from  w w  w .j  a v  a 2s .  c o  m*/
        useOffCampusAssetLocationBuilding(
                system.getCapitalAssetLocations().get(Integer.parseInt(assetLocationIndex)));
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:org.kuali.ole.module.purap.document.web.struts.PurchasingActionBase.java

public ActionForward useOffCampusAssetLocationBuildingByItem(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase baseForm = (PurchasingFormBase) form;
    PurchasingDocument document = (PurchasingDocument) baseForm.getDocument();

    String fullParameter = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE);
    String assetItemIndex = StringUtils.substringBetween(fullParameter,
            OLEConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
    String assetLocationIndex = StringUtils.substringBetween(fullParameter,
            OLEConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);

    PurchasingCapitalAssetItem assetItem = document.getPurchasingCapitalAssetItems()
            .get(Integer.parseInt(assetItemIndex));
    CapitalAssetSystem system = assetItem.getPurchasingCapitalAssetSystem();

    if ("new".equals(assetLocationIndex)) {
        useOffCampusAssetLocationBuilding(system.getNewPurchasingCapitalAssetLocationLine());
    } else {//from w  ww  .ja  v  a  2s . com
        useOffCampusAssetLocationBuilding(
                system.getCapitalAssetLocations().get(Integer.parseInt(assetLocationIndex)));
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}