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

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

Introduction

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

Prototype

public static boolean startsWith(String str, String prefix) 

Source Link

Document

Check if a String starts with a specified prefix.

Usage

From source file:org.jspringbot.keyword.xml.XMLHelper.java

public void setXmlString(String xmlString) throws IOException, SAXException {
    this.xmlString = xmlString;

    if (StringUtils.startsWith(xmlString, "file:") || StringUtils.startsWith(xmlString, "classpath:")) {
        ResourceEditor editor = new ResourceEditor();
        editor.setAsText(xmlString);/*from  w ww  .  j a  v a 2  s.co  m*/
        Resource resource = (Resource) editor.getValue();

        xmlString = new String(IOUtils.toCharArray(resource.getInputStream()));
    }

    DOMParser parser = new DOMParser();
    parser.parse(new InputSource(new StringReader(xmlString)));

    LOG.createAppender().appendBold("XML String:").appendXML(XMLFormatter.prettyPrint(xmlString)).log();

    this.document = parser.getDocument();
}

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

/**
 * Overridden to setup document number link for document number properties and add Rice Path prefix
 * to the URL where necessary (cases where the Lookupable is called from the KFS context instead of the Rice context).
 *
 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getInquiryUrl(org.kuali.rice.krad.bo.BusinessObject, java.lang.String)
 *//*  w  w w.  ja va  2  s. c om*/
@Override
public HtmlData getInquiryUrl(BusinessObject bo, String propertyName) {
    AnchorHtmlData inquiryHref = new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);

    if (KFSPropertyConstants.DOCUMENT_NUMBER.equals(propertyName)) {
        String baseUrl = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(
                KFSConstants.WORKFLOW_URL_KEY) + "/" + KFSConstants.DOC_HANDLER_ACTION;
        Properties parameters = new Properties();
        parameters.put(KFSConstants.PARAMETER_DOC_ID,
                ObjectUtils.getPropertyValue(bo, propertyName).toString());
        parameters.put(KFSConstants.PARAMETER_COMMAND, KFSConstants.METHOD_DISPLAY_DOC_SEARCH_VIEW);

        inquiryHref.setHref(UrlFactory.parameterizeUrl(baseUrl, parameters));
    } else {
        inquiryHref = (AnchorHtmlData) super.getInquiryUrl(bo, propertyName);
        if (StringUtils.startsWith(inquiryHref.getHref(), KRADConstants.INQUIRY_ACTION)) {
            inquiryHref.setHref(KFSConstants.RICE_PATH_PREFIX + inquiryHref.getHref());
        }
    }

    return inquiryHref;
}

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//from  w  ww  . j av  a  2s.  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.kfs.sys.context.SpringConfigurationConsistencyCheckTest.java

public void testServicesShouldHaveParentBeans() {
    List<String> failingBeanNames = new ArrayList<String>();
    for (String beanName : SpringContext.applicationContext.getBeanDefinitionNames()) {
        // skip testing mock beans
        if (StringUtils.containsIgnoreCase(beanName, "mock")) {
            continue;
        }/*from   w ww  . j  a  v a 2 s . c  o m*/
        BeanDefinition beanDef = SpringContext.applicationContext.getBeanFactory().getBeanDefinition(beanName);
        // skip entries in the rice import files or in testing files
        if (StringUtils.contains(beanDef.getResourceDescription(), "spring-kfs-imported-rice-beans.xml")
                || StringUtils.contains(beanDef.getResourceDescription(), "-test.xml")) {
            continue;
        }
        String serviceClass = beanDef.getBeanClassName();
        if (StringUtils.contains(serviceClass, "service.impl") && //should be a service
                !StringUtils.startsWith(serviceClass, "org.kuali.rice") && //let rice test their code
                !beanDef.isAbstract()) { //abstract = parent

            try {
                BeanDefinition parentBean = SpringContext.applicationContext.getBeanFactory()
                        .getBeanDefinition(beanName + "-parentBean");
                String parentClass = parentBean.getBeanClassName();
            } catch (NoSuchBeanDefinitionException ex) {
                failingBeanNames.add(beanName + " : " + beanDef.getResourceDescription() + "\n");
            }
        }
    }
    assertEquals("The following service beans do not have \"-parentBean\"s:\n" + failingBeanNames, 0,
            failingBeanNames.size());
}

From source file:org.kuali.kpme.core.util.TKUtils.java

/**
 * Returns effectiveDate "from" date that's passed in through dateString.
 * /*from   w  ww. j a v a  2s  .  c o m*/
* The "from" dateString can either be from the format "fromDate..toDate" or ">=fromDate", otherwise an empty string is returned.
* 
 * @param dateString
 * @return
 */
public static String getFromDateString(String dateString) {
    String fromDateString = StringUtils.EMPTY;

    if (StringUtils.startsWith(dateString, ">=")) {
        fromDateString = StringUtils.substringAfter(dateString, ">=");
    } else if (StringUtils.contains(dateString, "..")) {
        fromDateString = StringUtils.substringBefore(dateString, "..");
    }

    return fromDateString;
}

From source file:org.kuali.kpme.core.util.TKUtils.java

/**
 * Returns effectiveDate "to" date that's passed in through dateString.
 * //from w  w  w  .  j  a  va 2s.com
 * The "to" dateString can either be from the format "fromDate..toDate" or "<=toDate", otherwise an empty string is returned.
 *
 * @param dateString
 * @return
 */
public static String getToDateString(String dateString) {
    String toDateString = StringUtils.EMPTY;

    if (StringUtils.startsWith(dateString, "<=")) {
        toDateString = StringUtils.substringAfter(dateString, "<=");
    } else if (StringUtils.contains(dateString, "..")) {
        toDateString = StringUtils.substringAfter(dateString, "..");
    }

    return toDateString;
}

From source file:org.kuali.kra.committee.web.struts.action.CommitteeMembershipAction.java

/**
 * @see org.kuali.kra.committee.web.struts.action.CommitteeAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from w w w .  jav  a  2  s . c  o m
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward actionForward = super.execute(mapping, form, request, response);

    ((CommitteeForm) form).getCommitteeHelper().prepareView();

    // reset member index for multi value lookups unless the multi value lookup is performed
    if (!StringUtils.equals((String) request.getAttribute("methodToCallAttribute"), "methodToCall.refresh.x")
            && (!StringUtils.startsWith((String) request.getAttribute("methodToCallAttribute"),
                    "methodToCall.performLookup."))) {
        ((CommitteeForm) form).getCommitteeHelper().setMemberIndex(-1);
    }

    return actionForward;
}

From source file:org.kuali.kra.common.committee.web.struts.action.CommitteeMembershipActionBase.java

/**
 * @see org.kuali.kra.common.committee.web.struts.action.CommitteeActionBase#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from   www  .j  ava2  s.  c  o  m
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActionForward actionForward = super.execute(mapping, form, request, response);

    ((CommitteeFormBase) form).getCommitteeHelper().prepareView();

    // reset member index for multi value lookups unless the multi value lookup is performed
    if (!StringUtils.equals((String) request.getAttribute("methodToCallAttribute"), "methodToCall.refresh.x")
            && (!StringUtils.startsWith((String) request.getAttribute("methodToCallAttribute"),
                    "methodToCall.performLookup."))) {
        ((CommitteeFormBase) form).getCommitteeHelper().setMemberIndex(-1);
    }

    return actionForward;
}

From source file:org.kuali.kra.lookup.UnitLookupableHelperServiceImpl.java

@Override
public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
    String campusCode = fieldValues.remove(CAMPUS_CODE_FIELD);
    List<? extends BusinessObject> searchResults = super.getSearchResults(fieldValues);

    List<Unit> filteredSearchResults = new ArrayList<Unit>();
    for (BusinessObject searchResult : searchResults) {
        Unit unit = (Unit) searchResult;
        if (StringUtils.startsWith(unit.getUnitNumber(), campusCode)) {
            filteredSearchResults.add(unit);
        }/*  w  w  w .  ja v  a 2 s .  co  m*/
    }

    return filteredSearchResults;
}

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

@Override
@SuppressWarnings("unchecked")
public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    ActionForward forward = super.refresh(mapping, form, request, response);

    String prefix = getSpecialReviewService().getProtocolSaveLocationPrefix(request.getParameterMap());
    ProposalDevelopmentForm proposalDevelopmentForm = (ProposalDevelopmentForm) form;

    ProposalSpecialReview proposalSpecialReview = null;

    if (StringUtils.startsWith(prefix, "specialReviewHelper.newSpecialReview")) {
        proposalSpecialReview = proposalDevelopmentForm.getSpecialReviewHelper().getNewSpecialReview();
    } else {/*from  www .j  a  v a  2s  .  c o  m*/
        int index = getSpecialReviewService().getProtocolIndex(prefix);
        if (index != -1) {
            proposalSpecialReview = proposalDevelopmentForm.getDocument().getDevelopmentProposal()
                    .getPropSpecialReviews().get(index);
        }
    }

    proposalDevelopmentForm.getSpecialReviewHelper().prepareProtocolLinkViewFields(proposalSpecialReview);

    return forward;
}