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:nz.co.senanque.madura.bundle.spring.ManagerBeanDefinitionParser.java

protected void doParse(Element element, BeanDefinitionBuilder bean) {
    String directory = element.getAttribute("directory");
    if (StringUtils.hasText(directory)) {
        bean.addPropertyValue("directory", directory);
    }/*from w  w w. j  a va 2 s  .  c om*/
    String id = element.getAttribute("id");
    if (!StringUtils.hasText(id)) {
        bean.addPropertyValue("id", "bundleManager");
    }
    String time = element.getAttribute("time");
    if (StringUtils.hasLength(time)) {
        bean.addPropertyValue("time", time);
    }
    String export = element.getAttribute("export");
    if (StringUtils.hasLength(export)) {
        bean.addPropertyValue("export", export);
    }
    String childFirst = element.getAttribute("childFirst");
    if (StringUtils.hasLength(childFirst)) {
        bean.addPropertyValue("childFirst", childFirst);
    }
}

From source file:com.neoteric.starter.jersey.swagger.SwaggerAutoConfiguration.java

@Bean
BeanConfig beanConfig() {/*from   w w  w .j av a2 s . com*/
    BeanConfig beanConfig = new BeanConfig();
    beanConfig.setPrettyPrint(swaggerProperties.isPrettyPrint());
    beanConfig.setVersion(swaggerProperties.getVersion());
    beanConfig.setContact(swaggerProperties.getContact());
    beanConfig.setTitle(swaggerProperties.getTitle());
    beanConfig.setDescription(swaggerProperties.getDescription());
    beanConfig.setSchemes(swaggerProperties.getSchemes());
    beanConfig.setLicense(swaggerProperties.getLicense());
    beanConfig.setLicenseUrl(swaggerProperties.getLicenseUrl());
    beanConfig.setResourcePackage(swaggerProperties.getResourcePackage());
    beanConfig.setSchemes(swaggerProperties.getSchemes());
    if (StringUtils.hasLength(jerseyProperties.getApplicationPath())) {
        beanConfig.setBasePath(jerseyProperties.getApplicationPath());
    }
    beanConfig.setScan(true);
    LOG.debug("{}Swagger enabled on {}", StarterConstants.LOG_PREFIX, swaggerProperties.getResourcePackage());
    return beanConfig;
}

From source file:org.openmrs.module.adminui.location.LocationServiceImpl.java

/**
 * @see org.openmrs.api.LocationService#saveLocation(org.openmrs.Location)
 *//*ww  w. ja va  2 s.  com*/
public Location saveLocation(Location location) throws APIException {
    if (location.getName() == null) {
        throw new APIException("Location name is required");
    }

    // Check for transient tags. If found, try to match by name and overwrite, otherwise throw exception.
    if (location.getTags() != null) {
        for (LocationTag tag : location.getTags()) {

            // only check transient (aka non-precreated) location tags
            if (tag.getLocationTagId() == null) {
                if (!StringUtils.hasLength(tag.getName()))
                    throw new APIException("A tag name is required");

                LocationTag existing = Context.getLocationService().getLocationTagByName(tag.getName());
                if (existing != null) {
                    location.removeTag(tag);
                    location.addTag(existing);
                } else
                    throw new APIException("Cannot add transient tags! "
                            + "Save all location tags to the database before saving this location");
            }
        }
    }

    CustomDatatypeUtil.saveAttributesIfNecessary(location);

    return dao.saveLocation(location);
}

From source file:org.ega_archive.elixircore.filter.CustomHiddenHttpMethodFilter.java

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

    String paramValue = request.getParameter(this.methodParam);
    if (("POST".equals(request.getMethod()) || "GET".equals(request.getMethod()))
            && StringUtils.hasLength(paramValue)) {
        String method = paramValue.toUpperCase(Locale.ENGLISH);
        HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
        filterChain.doFilter(wrapper, response);
    } else {//from   ww w .  j  ava 2  s  . co  m
        filterChain.doFilter(request, response);
    }
}

From source file:grails.plugin.cloudfoundry.GrailsHttpResponse.java

public HttpHeaders getHeaders() {
    if (headers == null) {
        headers = new HttpHeaders();
        // Header field 0 is the status line for most HttpURLConnections, but not on GAE
        String name = connection.getHeaderFieldKey(0);
        if (StringUtils.hasLength(name)) {
            headers.add(name, connection.getHeaderField(0));
        }//from w w  w  .  j  a v  a2s  .c  om
        int i = 1;
        while (true) {
            name = connection.getHeaderFieldKey(i);
            if (!StringUtils.hasLength(name)) {
                break;
            }
            headers.add(name, connection.getHeaderField(i));
            i++;
        }
    }
    return headers;
}

From source file:sample.mybatis.conf.DatabaseDriver.java

/**
 * Find a {@link DatabaseDriver} for the given URL.
 * @param url JDBC URL/*  w  w  w  .jav a2 s .co  m*/
 * @return driver class name or {@link #UNKNOWN} if not found
 */
public static DatabaseDriver fromJdbcUrl(String url) {
    if (StringUtils.hasLength(url)) {
        Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
        String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase();
        for (DatabaseDriver driver : values()) {
            String prefix = ":" + driver.name().toLowerCase() + ":";
            if (driver != UNKNOWN && urlWithoutPrefix.startsWith(prefix)) {
                return driver;
            }
        }
    }
    return UNKNOWN;
}

From source file:org.ff4j.spring.namespace.FF4jBeanDefinitionParser.java

/** {@inheritDoc} **/
protected void postProcess(final BeanDefinitionBuilder definitionBuilder, final Element ff4jTag) {
    super.postProcess(definitionBuilder, ff4jTag);
    logger.debug("Initialization from <ff4j:ff4j> TAG");
    // If filename is present ff4j will be initialized with both features and properties inmemory.
    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_FILENAME))) {
        String fileName = ff4jTag.getAttribute(ATT_FF4J_FILENAME);
        InMemoryFeatureStore imfs = new InMemoryFeatureStore(fileName);
        InMemoryPropertyStore imps = new InMemoryPropertyStore(fileName);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("featureStore", imfs);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("propertiesStore", imps);
        logger.debug("... Setting in-memory stores : " + imfs.readAll().size() + " feature(s), "
                + imps.readAllProperties().size() + " propertie(s)");
    }/* w w  w .j  a  va  2s  .com*/

    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE))) {
        String autocreate = ff4jTag.getAttribute(ATT_FF4J_AUTOCREATE);
        logger.debug("... Setting autocreate property to '" + autocreate + "'");
    }

    if (StringUtils.hasLength(ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER))) {
        String authManagerBeanId = ff4jTag.getAttribute(ATT_FF4J_AUTH_MANAGER);
        RuntimeBeanReference refSolution = new RuntimeBeanReference(authManagerBeanId);
        definitionBuilder.getBeanDefinition().getPropertyValues().addPropertyValue("authorizationsManager",
                refSolution);
        logger.debug("... Setting authorizationManager with " + authManagerBeanId);
    }

    logger.debug("... Initialization done");

}

From source file:org.openmrs.module.feedback.web.PredefinedSubjectFormController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {
    Boolean feedbackMessage = false;
    Object o = Context.getService(FeedbackService.class);
    FeedbackService service = (FeedbackService) o;
    String text = "";
    String predefinedsubjectid = request.getParameter("predefinedsubjectid");
    String sortWeight = request.getParameter("sortWeight");
    String predefinedSubject = request.getParameter("predefinedsubject");

    if (!StringUtils.hasLength(predefinedsubjectid)
            || (service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid)) == null)) {

        /* Just log this for the statistics */
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.predefinedSubject.deleted");
    } else if ((predefinedsubjectid != null) && "1".equals(request.getParameter("delete"))) {

        /* delete the element */
        PredefinedSubject s = new PredefinedSubject();

        s = service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid));
        service.deletePredefinedSubject(s);
        text = predefinedsubjectid;/*from   w  ww.j  ava  2  s  .  c  o m*/
    } else if ((predefinedsubjectid != null) && "1".equals(request.getParameter("save"))) {

        /* save the element */
        PredefinedSubject s = service.getPredefinedSubject(Integer.parseInt(predefinedsubjectid));

        /** This makes sure that the Predefined Subject value always remain less then or equal to 50 */
        s.setSubject(request.getParameter("predefinedsubject"));

        if (isInt(sortWeight)) {
            s.setSortWeight(Integer.parseInt(sortWeight));
        }

        /* Service Method to save the data */
        service.savePredefinedSubject(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.predefinedSubject.saved");
        text = predefinedsubjectid;
    }

    log.debug("Returning hello world text: " + text);

    return text;
}

From source file:org.openmrs.module.feedback.web.AddSeverityFormController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {
    Boolean feedbackMessage = false;
    String sortWeight = request.getParameter("sortWeight");
    String text = "Not used";
    String severity = request.getParameter("severity");
    Object o = Context.getService(FeedbackService.class);
    FeedbackService service = (FeedbackService) o;
    Severity s = new Severity();

    /* This checks to make sure that severity can't be empty or NULL */
    if (StringUtils.hasLength(severity) && StringUtils.hasLength(sortWeight)) {
        if (isInt(sortWeight)) {
            s.setSortWeight(Integer.parseInt(sortWeight));
        } else {//from   w  w w  .jav a 2  s  . com
            request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    "feedback.notification.number.error");

            return text;
        }

        /** This makes sure that the Severity value always remain less then or equal to 50 */
        s.setSeverity(severity);
        service.saveSeverity(s);

        /** Notifies to the Controller that the predefined subject has been successfully added with the help of getStatus */
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.severity.added");
    } else if (StringUtils.hasLength(severity) && !StringUtils.hasLength(sortWeight)) {
        s.setSeverity(severity);
        service.saveSeverity(s);

        /** Notifies to the Controller that the predefined subject has been successfully added with the help of getStatus */
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.severity.added");
    }

    log.debug("Returning hello world text: " + text);

    return text;
}

From source file:org.zalando.baigan.context.ConfigurationContextProviderRegistryImpl.java

@Override
@Nonnull//from w w  w . j  a  v  a2s. c o  m
public Collection<ContextProvider> getProvidersFor(@Nonnull final String contextName) {
    Preconditions.checkArgument(StringUtils.hasLength(contextName),
            "Attempt to access value for an empty context name!");
    return ImmutableSet.copyOf(providerMap.get(contextName));
}