List of usage examples for org.springframework.util StringUtils hasText
public static boolean hasText(@Nullable String str)
From source file:com.reactive.hzdfs.utils.EntityFinder.java
/** * //w w w . j a v a 2 s . c o m * @param provider * @param basePkg * @return * @throws ClassNotFoundException */ private static Set<Class<?>> findComponents(ClassPathScanningCandidateComponentProvider provider, String basePkg) throws ClassNotFoundException { Set<BeanDefinition> beans = null; String pkg = ""; try { pkg = StringUtils.hasText(basePkg) ? basePkg : EntityFinder.class.getPackage().getName(); beans = provider.findCandidateComponents(pkg); } catch (Exception e) { throw new ClassNotFoundException("Unable to scan for classes under given base package", new IllegalArgumentException("Package=> " + pkg, e)); } Set<Class<?>> classes = new HashSet<>(); if (beans != null && !beans.isEmpty()) { classes = new HashSet<>(beans.size()); for (BeanDefinition bd : beans) { classes.add(Class.forName(bd.getBeanClassName())); } } else { log.warn(">> Did not find any classes under the given base package [" + basePkg + "]"); } return classes; }
From source file:grails.plugins.crm.core.CustomDateEditor.java
@Override public void setAsText(final String text) throws IllegalArgumentException { if (!StringUtils.hasText(text)) { setValue(null); // Treat empty String as null value. } else {//from w ww .ja v a2s . co m Exception error = null; java.util.Date date = null; for (int i = 0; i < DATE_FORMATS.length; i++) { try { DateFormat df = new SimpleDateFormat(DATE_FORMATS[i]); df.setLenient(false); date = df.parse(text); } catch (ParseException ex) { if (error == null) { error = ex; } } if (date != null) { setValue(sql ? new java.sql.Date(date.getTime()) : date); error = null; break; // We've found a valid date. } } if (error != null) { throw new IllegalArgumentException("Could not parse date: " + error.getMessage()); } } }
From source file:org.springmodules.validation.bean.conf.loader.xml.handler.RegExpRuleElementHandler.java
protected AbstractValidationRule createValidationRule(Element element) { String expression = element.getAttribute(EXPRESSION_ATTR); if (!StringUtils.hasText(expression)) { throw new ValidationConfigurationException( "Element '" + ELEMENT_NAME + "' must have an 'expression' attribute"); }// w ww.ja v a 2 s . com return new RegExpValidationRule(expression); }
From source file:org.springdata.ehcache.config.EhcacheLookupFactoryBean.java
@Override public void afterPropertiesSet() { Assert.notNull(cacheManager, "CacheManager property must be set"); String cacheName = StringUtils.hasText(name) ? name : beanName; Assert.hasText(cacheName, "Name property must be set or bean name must be defined"); cache = cacheManager.getCache(cacheName); if (cache != null) { logger.info("Retrieved cache [" + cacheName + "] from cacheManager"); } else {//from ww w. j a v a 2 s .c o m cache = lookupFallback(cacheManager, cacheName); } }
From source file:com.phoenixnap.oss.ramlapisync.javadoc.ClassVisitor.java
/** * Visit classes and extract javadoc entries to be stored in the supplied JavaDocStore *//*ww w . j a v a 2 s.c o m*/ @Override public void visit(ClassOrInterfaceDeclaration n, String arg) { String javaDocContent = ""; // Pre process javaDoc to remove useless characters whilst keeping multiline formatting if (n.getComment() != null && n.getComment().getContent() != null) { javaDocContent = n.getComment().getContent().replaceAll("\\n *\\* *", "\n "); } // Only append javadoc if available if (StringUtils.hasText(javaDocContent)) { javaDoc.setClassJavaDoc(javaDocContent); } }
From source file:org.syncope.console.wicket.extensions.markup.html.repeater.data.table.TokenColumn.java
@Override public void populateItem(final Item<ICellPopulator<UserTO>> cellItem, final String componentId, final IModel<UserTO> rowModel) { if (StringUtils.hasText(rowModel.getObject().getToken())) { cellItem.add(new Label(componentId, new ResourceModel("tokenValued", "tokenValued"))); } else {//from w w w . j a v a2 s . c o m cellItem.add(new Label(componentId, new ResourceModel("tokenNotValued", "tokenNotValued"))); } }
From source file:com.turbospaces.namespace.SpaceConfigurationBeanDefinitionParser.java
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { String group = element.getAttribute("group"); String mappingContext = element.getAttribute("mappingContext"); String kryo = element.getAttribute("kryo"); String jChannel = element.getAttribute("jChannel"); if (StringUtils.hasText(group)) builder.addPropertyValue("group", group); if (StringUtils.hasText(mappingContext)) builder.addPropertyReference("mappingContext", mappingContext); if (StringUtils.hasText(kryo)) builder.addPropertyReference("kryo", kryo); if (StringUtils.hasText(jChannel)) builder.addPropertyReference("jChannel", jChannel); }
From source file:csns.web.validator.MessageValidator.java
@Override public void validate(Object target, Errors errors) { AbstractMessage message = (AbstractMessage) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "subject", "error.field.required"); String content = message.getContent(); if (!StringUtils.hasText(content)) errors.rejectValue("content", "error.field.required"); else if (!antiSamy.validate(message.getContent())) errors.rejectValue("content", "error.html.invalid"); }
From source file:csns.web.validator.CourseValidator.java
@Override public void validate(Object target, Errors errors) { Course course = (Course) target;//w w w . j av a 2 s. c o m ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.field.required"); String code = course.getCode(); if (!StringUtils.hasText(code)) errors.rejectValue("code", "error.field.required"); else if (!Pattern.matches("[A-Z]+\\d+[A-Z]?", code)) errors.rejectValue("code", "error.course.code.invalid"); else { Course c = courseDao.getCourse(code); if (c != null && !c.getId().equals(course.getId())) errors.rejectValue("code", "error.course.exists"); } }
From source file:ch.rasc.extclassgenerator.ProxyObject.java
protected ProxyObject(ModelBean model, OutputConfig config) { if (StringUtils.hasText(model.getIdProperty()) && !model.getIdProperty().equals("id")) { this.idParam = model.getIdProperty(); }//from ww w .j a v a 2 s.c o m if (model.isDisablePagingParameters()) { Object value; if (config.getOutputFormat() == OutputFormat.EXTJS4) { value = "undefined"; } else if (config.getOutputFormat() == OutputFormat.EXTJS5) { value = ""; } else { value = Boolean.FALSE; } this.pageParam = value; this.startParam = value; this.limitParam = value; } Map<String, Object> readerConfigObject = new LinkedHashMap<String, Object>(); if (StringUtils.hasText(model.getReader()) && !"json".equals(model.getReader())) { readerConfigObject.put("type", model.getReader()); } String rootPropertyName = config.getOutputFormat() == OutputFormat.EXTJS4 ? "root" : "rootProperty"; if (StringUtils.hasText(model.getRootProperty())) { readerConfigObject.put(rootPropertyName, model.getRootProperty()); } else if (model.isPaging()) { readerConfigObject.put(rootPropertyName, "records"); } if (StringUtils.hasText(model.getMessageProperty())) { readerConfigObject.put("messageProperty", model.getMessageProperty()); } if (StringUtils.hasText(model.getTotalProperty())) { readerConfigObject.put("totalProperty", model.getTotalProperty()); } if (StringUtils.hasText(model.getSuccessProperty())) { readerConfigObject.put("successProperty", model.getSuccessProperty()); } if (!readerConfigObject.isEmpty()) { this.reader = readerConfigObject; } Map<String, Object> writerConfigObject = new LinkedHashMap<String, Object>(); if (StringUtils.hasText(model.getWriter()) && !"json".equals(model.getWriter())) { writerConfigObject.put("type", model.getWriter()); } if (model.getWriteAllFields() != null && (config.getOutputFormat() == OutputFormat.EXTJS5 && model.getWriteAllFields() || !model.getWriteAllFields() && (config.getOutputFormat() == OutputFormat.EXTJS4 || config.getOutputFormat() == OutputFormat.TOUCH2))) { writerConfigObject.put("writeAllFields", model.getWriteAllFields()); } if (config.getOutputFormat() == OutputFormat.EXTJS5 && model.isClientIdPropertyAddToWriter() && StringUtils.hasText(model.getClientIdProperty())) { writerConfigObject.put("clientIdProperty", model.getClientIdProperty()); } if (!writerConfigObject.isEmpty()) { this.writer = writerConfigObject; } boolean hasApiMethods = false; ApiObject apiObject = new ApiObject(); if (StringUtils.hasText(model.getCreateMethod())) { hasApiMethods = true; apiObject.create = model.getCreateMethod(); } if (StringUtils.hasText(model.getUpdateMethod())) { hasApiMethods = true; apiObject.update = model.getUpdateMethod(); } if (StringUtils.hasText(model.getDestroyMethod())) { hasApiMethods = true; apiObject.destroy = model.getDestroyMethod(); } if (StringUtils.hasText(model.getReadMethod())) { if (hasApiMethods) { apiObject.read = model.getReadMethod(); } else { this.directFn = model.getReadMethod(); } } if (hasApiMethods) { this.api = apiObject; } }