List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:org.jolokia.support.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 www. j av a2s . c om Element log = DomUtils.getChildElementByTagName(element, "log"); if (log != null) { LogBeanDefinitionParser logParser = new LogBeanDefinitionParser(); builder.addPropertyValue("logHandler", logParser.parseInternal(log, parserContext)); } for (String lookupKey : new String[] { "lookupConfig", "lookupServices" }) { String lookup = element.getAttribute(lookupKey); builder.addPropertyValue(lookupKey, StringUtils.hasLength(lookup) && Boolean.parseBoolean(lookup)); } String systemPropertiesMode = element.getAttribute("systemPropertiesMode"); if (StringUtils.hasLength(systemPropertiesMode)) { builder.addPropertyValue("systemPropertiesMode", systemPropertiesMode); } String exposeApplicationContext = element.getAttribute("exposeApplicationContext"); if (StringUtils.hasLength(exposeApplicationContext)) { builder.addPropertyValue("exposeApplicationContext", exposeApplicationContext); } }
From source file:io.pivotal.cla.mvc.admin.ClaForm.java
public void setDescription(String description) { if (StringUtils.hasLength(description)) { this.description = description; } }
From source file:com.stehno.sjdbcx.support.SqlResolver.java
/** * Uses the Sql and JdbcRepository annotations to resolve the SQL string to be used. * * @param prototype the repository prototype class * @param method the method to resolve SQL for * @return the String of SQL/*ww w . j ava 2 s .c o m*/ */ public String resolve(final Class prototype, final Method method) { final JdbcRepository jdbcAnno = AnnotationUtils.findAnnotation(prototype, JdbcRepository.class); final Sql sqlAnno = AnnotationUtils.getAnnotation(method, Sql.class); if (shouldLookupSql(jdbcAnno, sqlAnno)) { final String sqlKey = StringUtils.hasLength(sqlAnno.value()) ? sqlAnno.value() : method.getName().toLowerCase(); final Resource resource = determineResolverResource(prototype, jdbcAnno); final String sql = resolve(resource).getProperty(sqlKey); log.debug("Resolved SQL ({}) for repository ({}) from resource ({}) property ({})", sql, prototype, resource, sqlKey); return sql; } else { return sqlAnno.value(); } }
From source file:com.mastercard.test.spring.security.WithMockUserSecurityContextFactory.java
public SecurityContext createSecurityContext(WithMockUser withUser) { String username = StringUtils.hasLength(withUser.username()) ? withUser.username() : withUser.value(); if (username == null) { throw new IllegalArgumentException( withUser + " cannot have null username on both username and value properites"); }//from ww w. java 2s . c o m List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); for (String authority : withUser.authorities()) { grantedAuthorities.add(new SimpleGrantedAuthority(authority)); } if (grantedAuthorities.isEmpty()) { for (String role : withUser.roles()) { if (role.startsWith("ROLE_")) { throw new IllegalArgumentException("roles cannot start with ROLE_ Got " + role); } grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + role)); } } else if (!(withUser.roles().length == 1 && "USER".equals(withUser.roles()[0]))) { throw new IllegalStateException("You cannot define roles attribute " + Arrays.asList(withUser.roles()) + " with authorities attribute " + Arrays.asList(withUser.authorities())); } User principal = new User(username, withUser.password(), true, true, true, true, grantedAuthorities); Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities()); SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(authentication); return context; }
From source file:com.github.zhanhb.ckfinder.connector.support.XmlExceptionHandler.java
@Override public void handleException(HttpServletRequest request, HttpServletResponse response, CKFinderContext context, ConnectorException connectorException) throws IOException { HttpSession session = request.getSession(false); String userRole = session == null ? null : (String) session.getAttribute(context.getUserRoleName()); Connector.Builder connector = Connector.builder(); String currentFolder = connectorException.getCurrentFolder(); ResourceType type = connectorException.getType(); int errorNum = connectorException.getErrorCode().getCode(); if (type != null) { String typeName = type.getName(); connector.resourceType(typeName); if (StringUtils.hasLength(currentFolder)) { connector.currentFolder(/* www.java 2 s.co m*/ CurrentFolder.builder().path(currentFolder).url(type.getUrl() + currentFolder) .acl(context.getAccessControl().getAcl(typeName, currentFolder, userRole)).build()); } } connector.error(Error.builder().number(errorNum).value(connectorException.getMessage()).build()); String result = XmlCreator.INSTANCE.toString(connector.build()); response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setHeader("Cache-Control", "no-cache"); try (PrintWriter out = response.getWriter()) { out.write(result); } }
From source file:io.isoft.reg.service.StaffDictServiceImpl.java
@Override public Page<StaffDict> findStaffs(StaffDictSearchCriteria criteria, Pageable pageable) { Assert.notNull(criteria, "Criteria must not be null"); String deptCode = criteria.getDeptCode(); if (!StringUtils.hasLength(deptCode)) { return this.staffDictRepository.findAll(null); }/*from ww w . j a v a 2s . co m*/ return this.staffDictRepository.findByDeptCode(deptCode, pageable); }
From source file:com.carfinance.core.filter.HiddenHttpMethodFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { logger.debug("@@@@@@@@@@@@@@@@@@@??@@@@@@@@@@@@@@@@@@@"); logger.debug("@@@@@@@@@@@@@@@@@@@ " + request.getMethod().toUpperCase() + "@@@@@@@@@@@@@@@@@@@"); String paramValue = request.getParameter(this.methodParam); if ("POST".equals(request.getMethod()) && StringUtils.hasLength(paramValue)) { String method = paramValue.toUpperCase(Locale.ENGLISH); logger.debug("@@@@@@@@???" + method + "@@@@@@@@"); HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method); filterChain.doFilter(wrapper, response); } else {/*w ww . ja v a 2 s .co m*/ logger.debug("@@@@@@@@@@@@@@@@@@@@???@@@@@@@@@@@@@@@@@@@@"); filterChain.doFilter(request, response); } }
From source file:com.gigaspaces.persistency.archive.MongoArchiveOperationHandlerBeanDefinitionParser.java
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); String gigaSpace = element.getAttribute(GIGA_SPACE_REF); if (StringUtils.hasLength(gigaSpace)) { builder.addPropertyReference(GIGA_SPACE, gigaSpace); }//from w w w . j a va2s .co m String config_ref = element.getAttribute(CONFIG_REF); if (StringUtils.hasLength(config_ref)) { builder.addPropertyReference(CONFIG, config_ref); } String db = element.getAttribute(MONGO_DB); if (StringUtils.hasLength(db)) { builder.addPropertyValue(DB, db); } }
From source file:com.starit.diamond.server.service.DiskService.java
public void saveToDisk(ConfigInfo configInfo) throws IOException { if (configInfo == null) throw new IllegalArgumentException("configInfo?"); if (!StringUtils.hasLength(configInfo.getDataId()) || StringUtils.containsWhitespace(configInfo.getDataId())) throw new IllegalArgumentException("dataId"); if (!StringUtils.hasLength(configInfo.getGroup()) || StringUtils.containsWhitespace(configInfo.getGroup())) throw new IllegalArgumentException("group"); if (!StringUtils.hasLength(configInfo.getContent())) throw new IllegalArgumentException("content"); final String basePath = WebUtils.getRealPath(servletContext, Constants.BASE_DIR); createDirIfNessary(basePath);/*from w w w .j a va 2 s . co m*/ final String groupPath = WebUtils.getRealPath(servletContext, Constants.BASE_DIR + "/" + configInfo.getGroup()); createDirIfNessary(groupPath); String group = configInfo.getGroup(); String dataId = configInfo.getDataId(); dataId = SystemConfig.encodeDataIdForFNIfUnderWin(dataId); final String dataPath = WebUtils.getRealPath(servletContext, Constants.BASE_DIR + "/" + group + "/" + dataId); File targetFile = createFileIfNessary(dataPath); File tempFile = File.createTempFile(group + "-" + dataId, ".tmp"); FileOutputStream out = null; PrintWriter writer = null; try { out = new FileOutputStream(tempFile); BufferedOutputStream stream = new BufferedOutputStream(out); writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream, Constants.ENCODE))); configInfo.dump(writer); writer.flush(); } catch (Exception e) { log.error("??, tempFile:" + tempFile + ",targetFile:" + targetFile, e); } finally { if (writer != null) writer.close(); } String cacheKey = generateCacheKey(configInfo.getGroup(), configInfo.getDataId()); // if (this.modifyMarkCache.putIfAbsent(cacheKey, true) == null) { try { // ??? if (!FileUtils.contentEquals(tempFile, targetFile)) { try { // TODO ?, ??? , ?? FileUtils.copyFile(tempFile, targetFile); } catch (Throwable t) { log.error("??, tempFile:" + tempFile + ", targetFile:" + targetFile, t); SystemConfig.system_pause(); throw new RuntimeException(); } } tempFile.delete(); } finally { // this.modifyMarkCache.remove(cacheKey); } } else throw new ConfigServiceException("??"); }
From source file:com.oembedler.moon.graphql.engine.dfs.GraphQLMethodParameters.java
@Override protected String getParameterName(int idx, MethodParameter methodParameter) { String inputParameterName = null; GraphQLIn graphQLIn = methodParameter.getParameterAnnotation(GraphQLIn.class); if (graphQLIn != null && StringUtils.hasLength(graphQLIn.value())) { inputParameterName = graphQLIn.value(); }/*from w w w . j a v a2s .com*/ return inputParameterName; }