Example usage for org.springframework.util StringUtils hasLength

List of usage examples for org.springframework.util StringUtils hasLength

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasLength.

Prototype

public static boolean hasLength(@Nullable String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:com.qpark.eip.core.failure.FailureAssert.java

/**
 * Assert that the given text does not contain the given substring.
 *
 * <pre class="code">//  w ww  .ja va  2s.c om
 * Assert.doesNotContain(name, &quot;rod&quot;, &quot;Name must not contain 'rod'&quot;);
 * </pre>
 *
 * @param textToSearch
 *            the text to search
 * @param substring
 *            the substring to find within the text
 * @param errorCode
 *            the error code to use if the assertion fails
 * @param data
 *            additional information to the error code.
 */
public static void doesNotContain(final String textToSearch, final String substring, final String errorCode,
        final Object... data) {
    if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring)
            && textToSearch.indexOf(substring) != -1) {
        BaseFailureHandler.throwFailureException(errorCode, textToSearch, data);
    }
}

From source file:org.openmrs.module.patientnarratives.web.controller.ModuleSettingsController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {

    Boolean alert = null;/*w  ww. j a v a2  s . co m*/
    String formType = request.getParameter("formType");
    String formID = request.getParameter("formID");
    String patientID = request.getParameter("patientID");
    String encType = request.getParameter("encType");

    if (StringUtils.hasLength(formType)) {
        GlobalProperty globalProperty = new GlobalProperty();
        globalProperty.setProperty("patientnarratives.formtype");
        globalProperty.setPropertyValue(formType);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        alert = true;
    }

    if (StringUtils.hasLength(formID)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("patientnarratives.formid");
        globalProperty.setPropertyValue(formID);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        alert = true;
    }

    if (StringUtils.hasLength(patientID)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("patientnarratives.patientid");
        globalProperty.setPropertyValue(patientID);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        alert = true;
    }

    if (StringUtils.hasLength(encType)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("patientnarratives.enctype");
        globalProperty.setPropertyValue(encType);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        alert = true;
    }

    if ((alert != null) && (alert == true)) {
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "patientnarratives.module.settings.alert");
    }

    return "Not Yet";
}

From source file:com.jklas.sample.petclinic.validation.OwnerValidator.java

public void validate(Object obj, Errors errors) {
    Owner owner = (Owner) obj;
    ValidationUtils.rejectIfEmpty(errors, "firstName", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "lastName", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "address", "required", "required");
    ValidationUtils.rejectIfEmpty(errors, "city", "required", "required");
    String telephone = owner.getTelephone();
    if (!StringUtils.hasLength(telephone)) {
        errors.rejectValue("telephone", "required", "required");
    } else {/*from w  w  w.ja  va2 s  . c o m*/
        for (int i = 0; i < telephone.length(); ++i) {
            if ((Character.isDigit(telephone.charAt(i))) == false) {
                errors.rejectValue("telephone", "nonNumeric", "non-numeric");
                break;
            }
        }
    }
}

From source file:uk.ac.gda.devices.mythen.visualisation.commands.AddSrsFilesCommand.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    MythenDataControlView controlView = MythenDataControlView.getInstance();

    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    FileDialog fileDialog = new FileDialog(shell, SWT.SINGLE);
    String srsFilename = fileDialog.open();

    if (StringUtils.hasLength(srsFilename)) {
        try {/*from w  w  w . jav  a2  s.com*/
            MythenSrsFileLoader loader = new MythenSrsFileLoader();
            String[] filenames = loader.load(srsFilename);
            for (String filenameWithoutSuffix : filenames) {
                String filenameWithSuffix = filenameWithoutSuffix + ".dat";
                controlView.addFileToTable(filenameWithSuffix);
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    return null;
}

From source file:com.mycompany.projetsportmanager.filter.XHttpMethodOverrideFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    String headerValue = request.getHeader(this.headerParam);
    if ("POST".equals(request.getMethod()) && StringUtils.hasLength(headerValue)) {
        String method = headerValue.toUpperCase(Locale.ENGLISH);
        HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
        filterChain.doFilter(wrapper, response);
    } else {/*from   www  .  j av a2  s . c  o  m*/
        filterChain.doFilter(request, response);
    }
}

From source file:org.jolokia.jvmagent.spring.config.AgentBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    Element config = DomUtils.getChildElementByTagName(element, "config");
    if (config != null) {
        builder.addPropertyValue("config",
                parserContext.getDelegate().parseCustomElement(config, builder.getRawBeanDefinition()));
    }/*from w ww  . j a  va2s .  com*/
    String lookupConfig = element.getAttribute("lookupConfig");
    if (StringUtils.hasLength(lookupConfig)) {
        builder.addPropertyValue("lookupConfig", Boolean.parseBoolean(lookupConfig));
    } else {
        builder.addPropertyValue("lookupConfig", false);
    }
    String systemPropertiesMode = element.getAttribute("systemPropertiesMode");
    if (StringUtils.hasLength(systemPropertiesMode)) {
        builder.addPropertyValue("systemPropertiesMode", systemPropertiesMode);
    }
}

From source file:org.smf4j.spring.CounterConfig.java

CounterConfig(CounterType counterType, Element element) {
    this.counterType = counterType;
    this.contentionType = ContentionType.from(element);
    this.durationType = DurationType.from(element);
    this.intervalsType = IntervalsType.from(element);

    String tmp = element.getAttribute(TIMEWINDOW_ATTR);
    if (StringUtils.hasLength(tmp)) {
        try {/*from www  . j  a  v a  2  s .c  o  m*/
            timeWindow = Integer.parseInt(tmp);
        } catch (NumberFormatException e) {
            timeWindow = null;
        }
    }
    tmp = element.getAttribute(INTERVALS_ATTR);
    if (StringUtils.hasLength(tmp)) {
        try {
            numIntervals = Integer.parseInt(tmp);
        } catch (NumberFormatException e) {
            numIntervals = null;
        }
    }
}

From source file:org.jasypt.spring31.xml.encryption.AbstractEncryptablePropertyLoadingBeanDefinitionParser.java

@Override
protected void doParse(final Element element, final BeanDefinitionBuilder builder) {

    String location = element.getAttribute("location");
    if (StringUtils.hasLength(location)) {
        String[] locations = StringUtils.commaDelimitedListToStringArray(location);
        builder.addPropertyValue("locations", locations);
    }// ww w.j a  v  a  2s  . c o m

    String propertiesRef = element.getAttribute("properties-ref");
    if (StringUtils.hasLength(propertiesRef)) {
        builder.addPropertyReference("properties", propertiesRef);
    }

    String fileEncoding = element.getAttribute("file-encoding");
    if (StringUtils.hasLength(fileEncoding)) {
        builder.addPropertyReference("fileEncoding", fileEncoding);
    }

    String order = element.getAttribute("order");
    if (StringUtils.hasLength(order)) {
        builder.addPropertyValue("order", Integer.valueOf(order));
    }

    builder.addPropertyValue("ignoreResourceNotFound",
            Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));

    builder.addPropertyValue("localOverride", Boolean.valueOf(element.getAttribute("local-override")));

    builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
}

From source file:com.buaa.lzy.data.jpa.service.CityServiceImpl.java

@Override
public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) {

    Assert.notNull(criteria, "Criteria must not be null");
    String name = criteria.getName();

    if (!StringUtils.hasLength(name)) {
        return this.cityRepository.findAll(null);
    }//from w  w w.  ja v  a  2  s . co m

    String country = "";
    int splitPos = name.lastIndexOf(",");

    if (splitPos >= 0) {
        country = name.substring(splitPos + 1);
        name = name.substring(0, splitPos);
    }

    return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(),
            country.trim(), pageable);
}

From source file:uiak.exper.gisamt.service.BusinessFunctionServiceImpl.java

@Override
public Page<BusinessFunction> find(BusinessFunctionSearchCriteria criteria, Pageable pageable) {

    Assert.notNull(criteria, "Criteria must not be null");
    String name = criteria.getName();

    if (!StringUtils.hasLength(name)) {
        return this.businessFunctionRepository.findAll((Pageable) null);
    }/* w  ww . ja v  a 2 s.c o m*/

    String level = "";
    int splitPos = name.lastIndexOf(",");

    if (splitPos >= 0) {
        level = name.substring(splitPos + 1);
        name = name.substring(0, splitPos);
    }

    return this.businessFunctionRepository.findByNameContainingAndLevelContainingAllIgnoringCase(name.trim(),
            level.trim(), pageable);
}