List of usage examples for org.springframework.util StringUtils hasText
public static boolean hasText(@Nullable String str)
From source file:org.springmodules.cache.config.BeanReferenceParserImpl.java
/** * @see BeanReferenceParser#parse(Element,ParserContext,boolean) *//*from w w w . j a v a 2s . co m*/ public Object parse(Element element, ParserContext parserContext, boolean registerInnerBean) { String refId = element.getAttribute("refId"); if (StringUtils.hasText(refId)) { return new RuntimeBeanReference(refId); } Element beanElement = null; List beanElements = DomUtils.getChildElementsByTagName(element, "bean"); if (!CollectionUtils.isEmpty(beanElements)) { beanElement = (Element) beanElements.get(0); } if (beanElement == null) { throw new IllegalStateException("The XML element " + StringUtils.quote(element.getNodeName()) + " should either have a " + "reference to an already registered bean definition or contain a " + "bean definition"); } BeanDefinitionHolder holder = parserContext.getDelegate().parseBeanDefinitionElement(beanElement); String beanName = holder.getBeanName(); if (registerInnerBean && StringUtils.hasText(beanName)) { BeanDefinitionRegistry registry = parserContext.getRegistry(); BeanDefinition beanDefinition = holder.getBeanDefinition(); registry.registerBeanDefinition(beanName, beanDefinition); return new RuntimeBeanReference(beanName); } return holder; }
From source file:org.opensprout.osaf.web.support.PageNavigation.java
public PageNavigation(OrderPage orderPage, HttpServletRequest req, String uriprefix) { this.rowCount = orderPage.getRowcount(); this.pageSize = orderPage.getPagesize(); this.page = orderPage.getPage(); this.order = orderPage.getOrder(); this.ord = "order=" + this.order; // this.ord = orders.generateOrdersParamString(); // this.ordValue = orders.generateOrdersParamValue(); this.searchParams = extractSearchParamsExceptPageParams(req); this.uriprefix = !StringUtils.hasText(uriprefix) ? "" : uriprefix; }
From source file:com.googlecode.spring.appengine.api.factory.QueueFactoryBean.java
@Override public void afterPropertiesSet() throws Exception { if (StringUtils.hasText(name)) { queue = QueueFactory.getQueue(name); } else {// ww w . jav a 2 s. c o m queue = QueueFactory.getDefaultQueue(); } }
From source file:org.openmrs.web.controller.encounter.AddressTemplateController.java
/** * Add a new AddressTemplate (quickly, without a dedicated page) *//*from www . j a va 2 s . co m*/ @RequestMapping("/admin/locations/addressTemplateAdd") public String add(@RequestParam("xml") String xml, WebRequest request) { if (!StringUtils.hasText(xml) || "".equals(xml.trim())) { request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("AddressTemplate.error.empty"), WebRequest.SCOPE_SESSION); } else { try { //To test whether this is a valid conversion AddressTemplate test = Context.getSerializationService().getDefaultSerializer().deserialize(xml, AddressTemplate.class); List<String> requiredElements = test.getRequiredElements(); if (requiredElements != null) { for (String fieldName : requiredElements) { try { PropertyUtils.getProperty(new PersonAddress(), fieldName); } catch (Exception e) { //wrong field declared in template request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage( "AddressTemplate.error.fieldNotDeclaredInTemplate", new Object[] { fieldName }, Context.getLocale()), WebRequest.SCOPE_SESSION); return "redirect:addressTemplate.form"; } } } Context.getLocationService().saveAddressTemplate(xml); request.setAttribute(WebConstants.OPENMRS_MSG_ATTR, Context.getMessageSourceService().getMessage("AddressTemplate.saved"), WebRequest.SCOPE_SESSION); } catch (Exception e) { String errmsg1 = e.getCause().toString(); if (errmsg1.contains("must be terminated by the matching")) { String errmsg2 = e.getCause().getCause().toString(); request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("AddressTemplate.error.elementInvalid", new Object[] { errmsg1.split("\"")[1], errmsg2.split(";")[1].split(":")[1] }, Context.getLocale()), WebRequest.SCOPE_SESSION); } else if (errmsg1.split("\n")[0].endsWith("null")) { for (String part : errmsg1.split("\n")) { if (part.startsWith("path")) { request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage( "AddressTemplate.error.nameOrValueInvalid", new Object[] { part.split(":")[1] }, Context.getLocale()), WebRequest.SCOPE_SESSION); break; } } } else if (errmsg1.contains("UnknownFieldException") || errmsg1.contains("must be terminated by the matching")) { for (String part : errmsg1.split("\n")) { if (part.startsWith("path")) { request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage( "AddressTemplate.error.wrongFieldName", new Object[] { part.split("/")[part.split("/").length - 1] }, Context.getLocale()), WebRequest.SCOPE_SESSION); break; } } } else { request.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, Context.getMessageSourceService().getMessage("AddressTemplate.error"), WebRequest.SCOPE_SESSION); } request.setAttribute(WebConstants.OPENMRS_ADDR_TMPL, xml, WebRequest.SCOPE_SESSION); } } return "redirect:addressTemplate.form"; }
From source file:com.orange.cloud.servicebroker.filter.securitygroups.config.CloudfoundryClientConfig.java
@Bean DefaultConnectionContext connectionContext(CloudFoundryClientSettings cloudFoundryClientSettings) { DefaultConnectionContext.Builder connectionContext = DefaultConnectionContext.builder() .apiHost(cloudFoundryClientSettings.getHost()).sslHandshakeTimeout(Duration.ofSeconds(30)) .skipSslValidation(cloudFoundryClientSettings.getSkipSslValidation()); if (StringUtils.hasText(cloudFoundryClientSettings.getProxyHost())) { ProxyConfiguration.Builder proxyConfiguration = ProxyConfiguration.builder() .host(cloudFoundryClientSettings.getProxyHost()) .port(cloudFoundryClientSettings.getProxyPort()); if (StringUtils.hasText(cloudFoundryClientSettings.getProxyUsername())) { proxyConfiguration.password(cloudFoundryClientSettings.getProxyPassword()) .username(cloudFoundryClientSettings.getProxyUsername()); }//from w ww . j a v a2s .c om connectionContext.proxyConfiguration(proxyConfiguration.build()); } return connectionContext.build(); }
From source file:org.springmodules.cache.provider.ehcache.EhCacheModelValidator.java
/** * @throws InvalidCacheModelException if the given model does not specify a cache. * @see AbstractCacheModelValidator#validateCachingModelProperties(Object) */// w ww. j ava2s.c om protected void validateCachingModelProperties(Object cachingModel) throws InvalidCacheModelException { EhCacheCachingModel model = (EhCacheCachingModel) cachingModel; if (!StringUtils.hasText(model.getCacheName())) { throw new InvalidCacheModelException("Cache name should not be empty"); } }
From source file:fr.xebia.xke.test.jdbc.datasource.H2InitializingDriverManagerDataSource.java
/** * Implementation of <code>InitializingBean</code> *///from ww w . ja va2 s .co m @Override @SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { if (getDriver() == null && !StringUtils.hasText(driverClassName)) { setDriverClass((Class<? extends Driver>) ClassUtils.forName(DRIVER_CLASS_NAME, ClassUtils.getDefaultClassLoader())); } if (!StringUtils.hasText(getUrl())) { setUrl(URL); } if (!StringUtils.hasText(getUsername())) { setUsername(USERNAME); } if (!StringUtils.hasText(getPassword())) { setPassword(PASSWORD); } super.afterPropertiesSet(); }
From source file:org.cloudfoundry.identity.uaa.error.JsonAwareAuthenticationEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { response.addHeader("WWW-Authenticate", String.format("%s realm=\"%s\"", typeName, realmName)); String accept = request.getHeader("Accept"); boolean json = false; if (StringUtils.hasText(accept)) { for (MediaType mediaType : MediaType.parseMediaTypes(accept)) { if (mediaType.includes(MediaType.APPLICATION_JSON)) { json = true;/*from www . j av a 2s . c om*/ break; } } } if (json) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setContentType(MediaType.APPLICATION_JSON_VALUE); response.getWriter().append(String.format("{\"error\":\"%s\"}", authException.getMessage())); } else { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); } }
From source file:net.nikey.interceptor.LoginRequiredInterceptor.java
@Override public Object before(Invocation inv) throws Exception { // all non-root requests get analyzed Cookie[] cookies = inv.getRequest().getCookies(); if (!ObjectUtils.isEmpty(cookies)) { for (Cookie cookie : cookies) { if (RETWIS_COOKIE.equals(cookie.getName())) { String auth = cookie.getValue(); String name = user.findNameForAuth(auth); if (StringUtils.hasText(name)) { String uid = user.findUid(name); if (StringUtils.hasText(uid)) { inv.addModel("isSignedIn", true); inv.addModel("uid", uid); NikeySecurity.setUser(name, uid); return super.before(inv); }//from w w w .j av a 2 s .co m } } } } inv.addModel("isSignedIn", false); return super.before(inv); }
From source file:com.artivisi.iso8583.persistence.service.MapperServiceImpl.java
@Override public Mapper findMapperById(String id) { if (!StringUtils.hasText(id)) { return null; }/*from w w w .j ava 2 s. c o m*/ Mapper m = mapperDao.findOne(id); if (m != null) { m.getDataElement().size(); } return m; }