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.googlecode.ehcache.annotations.integration.resolver.LoggingCacheResolverFactory.java

public CacheableCacheResolver getCacheResolver(Cacheable cacheable, Method method) {
    final Ehcache cache = this.getCache(cacheable.cacheName());
    final String exceptionCacheName = cacheable.exceptionCacheName();
    if (StringUtils.hasLength(exceptionCacheName)) {
        final Ehcache exceptionCache = this.getCache(exceptionCacheName);
        return new TestCacheableCacheResolver(cache, exceptionCache);
    }// w ww.  j a  v  a 2s.c  o  m

    return new TestCacheableCacheResolver(cache);
}

From source file:org.zilverline.core.TestFileSystemCollection.java

public void testNoURL() {
    FileSystemCollection col = new FileSystemCollection();
    assertNull(col.getUrlDefault());//from  w  w  w  .j a  v  a  2  s .  com
    col.setContentDir(new File(System.getProperty("java.io.tmpdir")));
    col.setUrl(null);
    assertTrue(new File(System.getProperty("java.io.tmpdir")).exists());
    assertTrue("need a URL", StringUtils.hasLength(col.getUrlDefault()));
    assertTrue(col.getUrlDefault().endsWith("/"));
}

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

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

    processStringAttribute(element, builder, PARAM_PASSWORD, "password");

    String scope = element.getAttribute(SCOPE_ATTRIBUTE);
    if (StringUtils.hasLength(scope)) {
        builder.setScope(scope);/*from  w  ww . j  a va2  s.c  o m*/
    }

}

From source file:org.cloudfoundry.tools.timeout.TimeoutProtectionHttpRequest.java

/**
 * Create a {@link TimeoutProtectionHttpRequest} from the specified {@link ServletRequest} or return <tt>null</tt>
 * if not possible.//www  . j  a v  a  2 s .  co  m
 * @param request the request
 * @return a {@link TimeoutProtectionHttpRequest} or <tt>null</tt>
 */
public static TimeoutProtectionHttpRequest get(ServletRequest request) {
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        for (Type type : Type.values()) {
            String uid = type.getUid(httpServletRequest);
            if (StringUtils.hasLength(uid))
                return new TimeoutProtectionHttpRequest(httpServletRequest, type, uid);
        }
    }
    return null;
}

From source file:uk.ac.gda.dls.client.views.RunCommandComposite.java

public RunCommandComposite(Composite parent, int style, final ICommandRunner commandRunner, String label,
        final String command, final String commandObserver, final String jobTitle, String tooltip) {
    super(parent, style);

    final Display display = parent.getDisplay();
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(this);
    GridDataFactory.fillDefaults().applyTo(this);

    final Button btn = new Button(this, SWT.PUSH);
    btn.setText(label);//from  w  w  w  . j av  a 2 s  .co m
    btn.setToolTipText(tooltip);
    btn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            super.widgetSelected(e);
            btn.setEnabled(false);
            Job job = new Job(jobTitle) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    if (StringUtils.hasLength(commandObserver)) {
                        commandRunner.runCommand(command, commandObserver);
                    } else {
                        commandRunner.runCommand(command);
                    }
                    display.asyncExec(new Runnable() {
                        @Override
                        public void run() {
                            btn.setEnabled(true);
                        }
                    });
                    return Status.OK_STATUS;
                }
            };
            job.setUser(true);
            job.schedule();
        }
    });
}

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

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

    /* To check wheather or not the subject , severity and feedback is empty or not */
    Boolean feedbackMessage = false;
    String text = "";
    String subject = request.getParameter("subject");
    String severity = request.getParameter("severity");
    String feedback = request.getParameter("feedback");

    if (StringUtils.hasLength(subject) && StringUtils.hasLength(severity) && StringUtils.hasLength(severity)) {
        Object o = Context.getService(FeedbackService.class);
        FeedbackService service = (FeedbackService) o;
        Feedback s = new Feedback();

        s.setSubject(request.getParameter("subject"));
        s.setSeverity(request.getParameter("severity"));

        /* To get the Stacktrace of the page from which the feedback is submitted */
        StackTraceElement[] c = Thread.currentThread().getStackTrace();

        if ("Yes".equals(request.getParameter("pagecontext"))) {
            for (int i = 0; i < c.length; i++) {
                feedback = feedback + System.getProperty("line.separator") + c[i].getFileName()
                        + c[i].getMethodName() + c[i].getClass() + c[i].getLineNumber();
            }/*from ww  w . ja  v a 2 s .co  m*/
        }

        s.setContent(feedback);

        /* file upload in multiplerequest */
        if (request instanceof MultipartHttpServletRequest) {
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
            MultipartFile file = (MultipartFile) multipartRequest.getFile("file");

            if (!file.isEmpty()) {
                if (file.getSize() <= 5242880) {
                    if (file.getOriginalFilename().endsWith(".jpeg")
                            || file.getOriginalFilename().endsWith(".jpg")
                            || file.getOriginalFilename().endsWith(".gif")
                            || file.getOriginalFilename().endsWith(".png")) {
                        s.setMessage(file.getBytes());
                    } else {
                        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                                "feedback.notification.feedback.error");

                        return false;
                    }
                } else {
                    request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                            "feedback.notification.feedback.error");

                    return false;
                }
            }
        }

        /* Save the Feedback */
        service.saveFeedback(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                Context.getAdministrationService().getGlobalProperty("feedback.ui.notification"));

        if ("Yes".equals(Context.getUserContext().getAuthenticatedUser()
                .getUserProperty("feedback_notificationReceipt"))) {
            try {

                // Create Message
                Message message = new Message();

                message.setSender(
                        Context.getAdministrationService().getGlobalProperty("feedback.notification.email"));
                message.setRecipients(
                        Context.getUserContext().getAuthenticatedUser().getUserProperty("feedback_email"));
                message.setSubject("Feedback submission confirmation mail");
                message.setContent(Context.getAdministrationService().getGlobalProperty("feedback.notification")
                        + "Ticket Number: " + s.getFeedbackId() + " Subject :" + s.getSubject());
                message.setSentDate(new Date());

                // Send message
                Context.getMessageService().send(message);
            } catch (Exception e) {
                log.error("Unable to sent the email to the Email : "
                        + Context.getUserContext().getAuthenticatedUser().getUserProperty("feedback_email"));
            }
        }

        try {

            // Create Message
            Message message = new Message();

            message.setSender(
                    Context.getAdministrationService().getGlobalProperty("feedback.notification.email"));
            message.setRecipients(
                    Context.getAdministrationService().getGlobalProperty("feedback.admin.notification.email"));
            message.setSubject("New feedback submitted");
            message.setContent(
                    Context.getAdministrationService().getGlobalProperty("feedback.admin.notification")
                            + "Ticket Number: " + s.getFeedbackId() + " Subject : " + s.getSubject()
                            + " Take Action :" + request.getScheme() + "://" + request.getServerName() + ":"
                            + request.getServerPort() + request.getContextPath()
                            + "/module/feedback/feedback.form?feedbackId=" + s.getFeedbackId() + "#command");
            message.setSentDate(new Date());

            // Send message
            Context.getMessageService().send(message);
        } catch (Exception e) {
            log.error("Unable to sent the email to the Email : " + Context.getUserContext()
                    .getAuthenticatedUser().getUserProperty("feedback.admin.notification.email"));
        }

        feedbackMessage = true;
    }

    /* Reserved for future use for showing that the data is saved and the feedback is submitted */
    log.debug("Returning hello world text: " + text);

    return feedbackMessage;
}

From source file:org.openmrs.module.idgen.web.extension.IdentifierTableHeaderExtension.java

/**
 * @see Extension#getOverrideContent()//from   ww  w . jav a 2 s. c  om
 */
@Override
public String getOverrideContent(String bodyContent) {

    IdentifierSourceService iss = Context.getService(IdentifierSourceService.class);
    Map<PatientIdentifierType, AutoGenerationOption> autogen = new HashMap<PatientIdentifierType, AutoGenerationOption>();
    for (PatientIdentifierType pit : Context.getPatientService().getAllPatientIdentifierTypes()) {
        AutoGenerationOption option = iss.getAutoGenerationOption(pit);
        if (option != null && option.isAutomaticGenerationEnabled()) {
            autogen.put(pit, option);
        }
    }

    StringBuilder sb = new StringBuilder();

    if (!autogen.isEmpty()) {
        // solving IDGEN-11: when webapp_name is empty, double slashes cause wrong url
        // in 1.10+, use WebUtil.getContextPath(); See TRUNK-
        String contextPath = "";
        if (StringUtils.hasLength(WebConstants.WEBAPP_NAME)) {
            contextPath += "/" + WebConstants.WEBAPP_NAME;
        }

        if (ModuleUtil.compareVersion(OpenmrsConstants.OPENMRS_VERSION_SHORT, "1.7") < 0) {
            sb.append("<script src=\"" + contextPath
                    + "/moduleResources/idgen/jquery-1.3.2.min.js\" type=\"text/javascript\"></script>\n");
        }
        if (ModuleUtil.compareVersion(OpenmrsConstants.OPENMRS_VERSION_SHORT, "1.8") < 0) {
            sb.append("<script src=\"" + contextPath
                    + "/moduleResources/idgen/newPatientFormExtensions.js\" type=\"text/javascript\"></script>\n");
        } else {
            sb.append("<script src=\"" + contextPath
                    + "/moduleResources/idgen/shortPatientFormExtensions.js\" type=\"text/javascript\"></script>\n");
        }
        sb.append("<link href=\"" + contextPath
                + "/moduleResources/idgen/editPatientIdentifiers.css\" type=\"text/css\" rel=\"stylesheet\"\n/>");
        sb.append("<td id=\"idgenColumnHeader\">"
                + Context.getMessageSourceService().getMessage("idgen.autoGenerate") + "</td>");
    }

    return sb.toString();
}

From source file:edu.uchicago.duo.validator.DeviceExistDuoValidator.java

@Override
public void validate(Object target, Errors errors) {
    DuoPersonObj duoPersonObj = (DuoPersonObj) target;
    String userName;/*www  .ja  va2s . c  o m*/
    String tokenId;
    String phoneId = null;

    if (duoPersonObj.getChoosenDevice().matches("mobile|landline")) {
        userName = duoPhoneService.getObjByParam(duoPersonObj.getCompletePhonenumber(),
                duoPersonObj.getLandLineExtension(), "username");
        if (userName != null && userName.equals(duoPersonObj.getUsername())) {
            errors.rejectValue("phonenumber", "DeviceExistDuoValidator.alreadyReg");
        } else if (userName != null) {
            errors.rejectValue("phonenumber", "DeviceExistDuoValidator.belongSomeoneElse");
        } else {
            phoneId = duoPhoneService.createObjByParam(duoPersonObj.getCompletePhonenumber(), "landline", null,
                    null, duoPersonObj.getLandLineExtension());
            if (StringUtils.hasLength(phoneId)) {
                duoPhoneService.deleteObj(phoneId, null);
            } else {
                errors.rejectValue("phonenumber", "DeviceExistDuoValidator.badnumber");
            }
        }
    }

    if (duoPersonObj.getChoosenDevice().matches("token")) {
        userName = duoTokenService.getObjByParam(duoPersonObj.getTokenSerial(), duoPersonObj.getTokenType(),
                "username");
        tokenId = duoTokenService.getObjByParam(duoPersonObj.getTokenSerial(), duoPersonObj.getTokenType(),
                "tokenId");

        if (tokenId == null) {
            errors.rejectValue("tokenSerial", "DeviceExistDuoValidator.deviceNotInDB");
        } else if (userName != null && userName.toLowerCase().contains(duoPersonObj.getUsername())) {
            errors.rejectValue("tokenSerial", "DeviceExistDuoValidator.alreadyReg");
        } else if (userName != null) {
            errors.rejectValue("tokenSerial", "DeviceExistDuoValidator.belongSomeoneElse");
        }
    }

}

From source file:com.mastercard.test.spring.security.WithUserDetailsSecurityContextFactory.java

public SecurityContext createSecurityContext(WithUserDetails withUser) {
    String beanName = withUser.userDetailsServiceBeanName();
    UserDetailsService userDetailsService = StringUtils.hasLength(beanName)
            ? this.beans.getBean(beanName, UserDetailsService.class)
            : this.beans.getBean(UserDetailsService.class);
    String username = withUser.value();
    Assert.hasLength(username, "value() must be non empty String");
    UserDetails principal = userDetailsService.loadUserByUsername(username);
    Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(),
            principal.getAuthorities());
    SecurityContext context = SecurityContextHolder.createEmptyContext();
    context.setAuthentication(authentication);
    return context;
}

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

@Override
protected void doParse(final Element element, final ParserContext parserContext,
        final BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);
    Properties parsedProps = parserContext.getDelegate().parsePropsElement(element);
    builder.addPropertyValue("properties", parsedProps);
    String scope = element.getAttribute(SCOPE_ATTRIBUTE);
    if (StringUtils.hasLength(scope)) {
        builder.setScope(scope);/*from   w w  w . ja  v a  2  s .com*/
    }
    final String encryptorBeanName = element.getAttribute(ENCRYPTOR_ATTRIBUTE);
    if (StringUtils.hasText(encryptorBeanName)) {
        builder.addPropertyReference("encryptor", encryptorBeanName);
    }
}