Java Code Examples for jodd.util.StringUtil
The following examples show how to use
jodd.util.StringUtil. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DAFramework Source File: AreaDao.java License: MIT License | 6 votes |
public EArea allArea(WMap query) { //处理查询条件 Criteria cnd = Cnd.cri(); cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) { cnd.where().andNotIn("id", query.get("extId").toString()); cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%"); } cnd.getOrderBy().asc("sort"); List<EArea> allAreas = query(cnd); List<ITreeNode<EArea>> allNodes = new ArrayList<>(); EArea root = new EArea(); root.setId(0L); allNodes.add(root); if (allAreas != null && !allAreas.isEmpty()) { allNodes.addAll(allAreas); } return (EArea) root.buildTree(allNodes); }
Example 2
Source Project: DAFramework Source File: UserController.java License: MIT License | 6 votes |
@RequestMapping(value = "/currInfo", method = RequestMethod.GET) public ActionResultObj getUser() { ActionResultObj result = new ActionResultObj(); // 获取当前用户 UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (StringUtil.isNotBlank(userDetails.getUsername())) { EUser currentUser = userDao.fetchByName(userDetails.getUsername()); EAccount account = accountDao.fetch(currentUser); EOrg org = orgDao.fetch(currentUser.getOrgId()); WMap map = new WMap(); map.put("userName", account != null ? account.getFullName() : currentUser.getUsername()); map.put("accountId", account != null ? account.getId() : ""); map.put("orgName", org.getName()); result.ok(map); } else { result.errorMsg("获取失败"); } return result; }
Example 3
Source Project: DAFramework Source File: UserController.java License: MIT License | 6 votes |
/** * 新增一个用户,同时增加account和user * * @param account * @return */ @RequestMapping(value = "/save") public ActionResultObj save(@RequestBody EAccount account) { ActionResultObj result = new ActionResultObj(); try { account = userDetailsService.saveUser(account); if (account.getId() != null && account.getId() != 0) { result.okMsg("保存成功!"); } else { result.errorMsg("保存失败!"); } } catch (Exception e) { LOG.error("保存失败,原因:" + e.getMessage()); result.error(e); EUser user = account.getUser(); if (user.getUsername() != null && StringUtil.isNotBlank(user.getUsername())) { if (userDetailsService.isUserExisted(user.getUsername())) { result.errorMsg("用户 " + user.getUsername() + " 已存在!"); } } } return result; }
Example 4
Source Project: DAFramework Source File: DictController.java License: MIT License | 6 votes |
@RequestMapping(value="type/{type}") public ActionResultObj findByType(@PathVariable String type){ ActionResultObj result = new ActionResultObj(); try{ if(StringUtil.isNotBlank(type)){ List<EDict> dictList = dictDao.query(Cnd.where("type", "=", type).and("del_flag", "=", Constans.POS_NEG.NEG).orderBy("sort", "asc")); //处理返回值 WMap map = new WMap(); map.put("type", type); map.put("data", dictList); result.ok(map); result.okMsg("查询成功!"); }else{ result.errorMsg("查询失败,字典类型不存在!"); } }catch(Exception e){ e.printStackTrace(); LOG.error("查询失败,原因:"+e.getMessage()); result.error(e); } return result; }
Example 5
Source Project: DAFramework Source File: MenuController.java License: MIT License | 6 votes |
@RequestMapping(value = "/allMenu", method = RequestMethod.POST) public ActionResultObj findAllmenu(@RequestBody SearchQueryJS queryJs) { ActionResultObj result = new ActionResultObj(); try { WMap query = queryJs.getQuery(); //处理查询条件 Criteria cnd = Cnd.cri(); cnd.where().andEquals("del_flag", Constans.POS_NEG.NEG); if (query.get("extId") != null && StringUtil.isNotBlank(query.get("extId").toString())) { cnd.where().andNotIn("id", query.get("extId").toString()); cnd.where().andNotLike("parent_ids", "%," + query.get("extId").toString() + ",%"); } cnd.getOrderBy().asc("sort"); List<EMenu> allMenus = menuDao.query(cnd); EMenu menu = menuDao.buildMenuTree(allMenus); WMap map = new WMap(); map.put("data", menu.getItems()); result.setData(map); result.okMsg("查询成功!"); } catch (Exception e) { e.printStackTrace(); LOG.error("查询失败,原因:" + e.getMessage()); result.error(e); } return result; }
Example 6
Source Project: DAFramework Source File: SysUserDetailsServiceTest.java License: MIT License | 6 votes |
@Test public void testFetchUserAuthoritiesPrincipal() { //principal==null时获取到guest权限信息 Set<String> authorities = userDetailsService.principalAuthorities(null); notNull(authorities, ""); isTrue(authorities.size() == 1, ""); isTrue("guest".equals(StringUtil.join(authorities, ",")), ""); //admin user时获取全部权限 UserPrincipal up = new UserPrincipal("watano"); authorities = userDetailsService.principalAuthorities(up); notNull(authorities, ""); isTrue(authorities.size() > 0, ""); isTrue(authorities.contains("pro_list"), ""); List<EAuthority> allAuthorities = authorityDao.query(); assertEquals(authorities.size(), allAuthorities.size()); }
Example 7
Source Project: web-data-extractor Source File: Jerry.java License: Apache License 2.0 | 6 votes |
/** * Gets the value of a style property for the first element * in the set of matched elements. Returns <code>null</code> * if set is empty. */ public String css(String propertyName) { if (nodes.length == 0) { return null; } propertyName = StringUtil.fromCamelCase(propertyName, '-'); String styleAttrValue = nodes[0].getAttribute("style"); if (styleAttrValue == null) { return null; } Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); return styles.get(propertyName); }
Example 8
Source Project: web-data-extractor Source File: Jerry.java License: Apache License 2.0 | 6 votes |
/** * Sets one or more CSS properties for the set of matched elements. * By passing an empty value, that property will be removed. * Note that this is different from jQuery, where this means * that property will be reset to previous value if existed. */ public Jerry css(String propertyName, String value) { propertyName = StringUtil.fromCamelCase(propertyName, '-'); for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
Example 9
Source Project: web-data-extractor Source File: Jerry.java License: Apache License 2.0 | 6 votes |
protected Map<String, String> createPropertiesMap(String attrValue, char propertiesDelimiter, char valueDelimiter) { if (attrValue == null) { return new LinkedHashMap<>(); } String[] properties = StringUtil.splitc(attrValue, propertiesDelimiter); LinkedHashMap<String, String> map = new LinkedHashMap<>(properties.length); for (String property : properties) { int valueDelimiterIndex = property.indexOf(valueDelimiter); if (valueDelimiterIndex != -1) { String propertyName = property.substring(0, valueDelimiterIndex).trim(); String propertyValue = property.substring(valueDelimiterIndex + 1).trim(); map.put(propertyName, propertyValue); } } return map; }
Example 10
Source Project: web-data-extractor Source File: Attribute.java License: Apache License 2.0 | 6 votes |
/** * Returns true if attribute is containing some value. */ public boolean isContaining(String include) { if (value == null) { return false; } if (splits == null) { splits = StringUtil.splitc(value, ' '); } for (String s : splits) { if (s.equals(include)) { return true; } } return false; }
Example 11
Source Project: web-data-extractor Source File: HtmlImplicitClosingRules.java License: Apache License 2.0 | 6 votes |
/** * Returns <code>true</code> if parent node tag can be closed implicitly. */ public boolean implicitlyCloseParentTagOnNewTag(String parentNodeName, String nodeName) { if (parentNodeName == null) { return false; } parentNodeName = parentNodeName.toLowerCase(); nodeName = nodeName.toLowerCase(); for (int i = 0; i < IMPLIED_ON_START.length; i += 2) { if (StringUtil.equalsOne(parentNodeName, IMPLIED_ON_START[i]) != -1) { if (StringUtil.equalsOne(nodeName, IMPLIED_ON_START[i + 1]) != -1) { return true; } } } return false; }
Example 12
Source Project: web-data-extractor Source File: HtmlImplicitClosingRules.java License: Apache License 2.0 | 6 votes |
/** * Returns <code>true</code> if current end tag (node name) closes the parent tag. */ public boolean implicitlyCloseParentTagOnTagEnd(String parentNodeName, String nodeName) { if (parentNodeName == null) { return false; } parentNodeName = parentNodeName.toLowerCase(); nodeName = nodeName.toLowerCase(); for (int i = 0; i < IMPLIED_ON_END.length; i += 2) { if (StringUtil.equalsOne(nodeName, IMPLIED_ON_END[i]) != -1) { if (StringUtil.equalsOne(parentNodeName, IMPLIED_ON_END[i + 1]) != -1) { return true; } } } return false; }
Example 13
Source Project: web-data-extractor Source File: DefaultClassLoaderStrategy.java License: Apache License 2.0 | 6 votes |
/** * Prepares classname for loading, respecting the arrays. * Returns <code>null</code> if class name is not an array. */ public static String prepareArrayClassnameForLoading(String className) { int bracketCount = StringUtil.count(className, '['); if (bracketCount == 0) { // not an array return null; } String brackets = StringUtil.repeat('[', bracketCount); int bracketIndex = className.indexOf('['); className = className.substring(0, bracketIndex); int primitiveNdx = getPrimitiveClassNameIndex(className); if (primitiveNdx >= 0) { className = String.valueOf(PRIMITIVE_BYTECODE_NAME[primitiveNdx]); return brackets + className; } else { return brackets + 'L' + className + ';'; } }
Example 14
Source Project: web-data-extractor Source File: DefaultClassLoaderStrategy.java License: Apache License 2.0 | 6 votes |
/** * Loads array class using component type. */ protected Class loadArrayClassByComponentType(String className, ClassLoader classLoader) throws ClassNotFoundException { int ndx = className.indexOf('['); int multi = StringUtil.count(className, '['); String componentTypeName = className.substring(0, ndx); Class componentType = loadClass(componentTypeName, classLoader); if (multi == 1) { return Array.newInstance(componentType, 0).getClass(); } int[] multiSizes; if (multi == 2) { multiSizes = new int[]{0, 0}; } else if (multi == 3) { multiSizes = new int[]{0, 0, 0}; } else { multiSizes = (int[]) Array.newInstance(int.class, multi); } return Array.newInstance(componentType, multiSizes).getClass(); }
Example 15
Source Project: maven-framework-project Source File: Variable.java License: MIT License | 6 votes |
public Map<String, Object> getVariableMap() { Map<String, Object> vars = new HashMap<String, Object>(); ConvertUtils.register(new DateConverter(), java.util.Date.class); if (StringUtil.isBlank(keys)) { return vars; } String[] arrayKey = keys.split(","); String[] arrayValue = values.split(","); String[] arrayType = types.split(","); for (int i = 0; i < arrayKey.length; i++) { String key = arrayKey[i]; String value = arrayValue[i]; String type = arrayType[i]; Class<?> targetType = Enum.valueOf(PropertyType.class, type).getValue(); Object objectValue = ConvertUtils.convert(value, targetType); vars.put(key, objectValue); } return vars; }
Example 16
Source Project: netty-pubsub Source File: ZKReceiver.java License: MIT License | 5 votes |
/** * ��ȡ����broker * @return */ public Set<String> getActiveBroker(){ List<String> childrens = zkc.getChildren(ZkConstants.ZK_ROOT_PATH); HashSet<String> hashSet = new HashSet<>(); childrens.forEach((c)->{ String data=zkc.readData(ZkConstants.ZK_ROOT_PATH+"/"+c); if(!StringUtil.isEmpty(data)){ hashSet.add(data); } }); return hashSet; }
Example 17
Source Project: netty-pubsub Source File: BrokeServer.java License: MIT License | 5 votes |
@Override public void start() { ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.group(boss, worker).channel(NioServerSocketChannel.class) .childHandler(new ChanelInitializerHandler()) .childOption(ChannelOption.SO_KEEPALIVE, true); try { ChannelFuture channelFuture; if(!StringUtil.isEmpty(config.getConfig().getHost())){ channelFuture=serverBootstrap.bind(config.getConfig().getHost(),Integer.parseInt(config.getConfig().getPort())).sync(); }else{ channelFuture = serverBootstrap.bind(Integer.parseInt(config.getConfig().getPort())).sync(); } channelFuture.addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(Future<? super Void> future) throws Exception { if(future.isSuccess()||future.isDone()){ LOGGER.info("��broker��������ip->"+config.getConfig().getHost()+" port->"+config.getConfig().getPort()); }else{ LOGGER.info("��broker������ʧ��"); } } }); //�ж��Ƿ�����Ⱥ if(config.getConfig().getEnableCluster()){ //��������Ⱥģʽ��������ע��zookeeper ServerConfig serverConfig = config.getConfig(); ZkRegister.getInstance().register(serverConfig.getZkRootPath()+"/broker_",serverConfig.getHost()+":"+serverConfig.getPort()); } channelFuture.channel().closeFuture().sync(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally { stop(); } }
Example 18
Source Project: ueboot Source File: XSSUtil.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 校验 是否是非法XSS攻击字符 * * @param value 需要校验的字符串 * @return 校验后的字符串 */ public static String checkXssStr(String value) { if (StringUtil.isNotBlank(value) && sqlInject(value)) { logger.error("提交参数存在非法字符!,value:{}", value); throw new RuntimeException("提交参数存在非法字符!value:" + value); } value = scriptingFilter(value); return value; }
Example 19
Source Project: ueboot Source File: ResourcesController.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:resources:save") @PostMapping(value = "/save") public Response<Void> save(@RequestBody ResourcesReq req) { Resources entity = null; if (req.getId() == null) { entity = new Resources(); } else { entity = resourcesService.get(req.getId()); } BeanUtils.copyProperties(req, entity); //菜单样式配置 Map<String, String> theme = new HashMap<>(); if (StringUtil.isNotBlank(req.getIconName())) { theme.put("iconName", req.getIconName()); } if (StringUtil.isNotBlank(req.getFontColor())) { theme.put("fontColor", req.getFontColor()); } if (theme.size() > 0) { entity.setThemeJson(JSON.toJSONString(theme)); } else { entity.setThemeJson(null); } if (req.getParentId() != 0L) { Resources parent = resourcesService.findById(req.getParentId()); Assert.notNull(parent, "父节点不存在"); entity.setParent(parent); entity.setParentName(parent.getName()); } else { entity.setParent(null); entity.setParentName(null); } resourcesService.save(entity); // 保存/修改资源日志记录 String optUserName = (String) SecurityUtils.getSubject().getPrincipal(); this.shiroEventListener.saveResourceEvent(optUserName, req.getName()); return new Response<>(); }
Example 20
Source Project: ueboot Source File: UserController.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@RequiresPermissions("ueboot:user:save") @PostMapping(value = "/save") public Response<Void> save(@RequestBody UserReq req) { User entity = null; if (req.getId() == null) { entity = new User(); User user = this.userService.findByUserName(req.getUserName()); if (user != null) { throw new BusinessException("当前用户名已经存在,不能重复添加!"); } } else { entity = userService.findById(req.getId()); } BeanUtils.copyProperties(req, entity, "password"); if (StringUtil.isNotBlank(req.getPassword())) { entity.setPassword(PasswordUtil.sha512(entity.getUserName(), req.getPassword())); if (req.getCredentialExpiredDate() == null) { JDateTime dateTime = new JDateTime(); //默认密码过期日期为x个月,x个月后要求更换密码 Date expiredDate = dateTime.addMonth(this.shiroService.getPasswordExpiredMonth()).convertToDate(); entity.setCredentialExpiredDate(expiredDate); } } //解锁 if(!req.isLocked()){ String key = MessageFormat.format(RetryLimitHashedCredentialsMatcher .PASSWORD_RETRY_CACHE,req.getUserName()); redisTemplate.delete(key); } userService.save(entity); // 保存用户日志记录 String optUserName = (String) SecurityUtils.getSubject().getPrincipal(); this.shiroEventListener.saveUserEvent(optUserName, req.getUserName()); return new Response<>(); }
Example 21
Source Project: DAFramework Source File: SysUserDetailsService.java License: MIT License | 5 votes |
/** * 重新设置角色对应的权限信息 * * @param roleName * @param allAuthorities */ public void updateRoleAuthorities(String roleName, String... allAuthorities) { if (allAuthorities != null) { String queryStr = ""; for (String a : allAuthorities) { queryStr += "'" + a + "',"; } queryStr = StringUtil.cutSuffix(queryStr, ","); List<EAuthority> authorities = authorityDao.query(Cnd.where("name", "in", queryStr)); ERole role = roleDao.fetchByName(roleName); role.setAuthorities(authorities); roleDao.updateAuthorities(role); } }
Example 22
Source Project: DAFramework Source File: EArea.java License: MIT License | 5 votes |
public List<Long> getPids() { if (!StringUtil.equals(parentIds, ",0,")) { pids = new ArrayList<>(); parentIds = StringUtil.replace(parentIds, ",0,", ""); String[] pidsStr = StringUtil.split(parentIds, ","); for (String pidStr : pidsStr) { if (StringUtil.isNotBlank(pidStr) && !StringUtil.equals(pidStr, "0")) { pids.add(Long.parseLong(pidStr)); } } return pids; } return new ArrayList<>(); }
Example 23
Source Project: DAFramework Source File: EMenu.java License: MIT License | 5 votes |
public List<Long> getPids() { if (!StringUtil.equals(parentIds, ",0,")) { pids = new ArrayList<>(); parentIds = StringUtil.replace(parentIds, ",0,", ""); String[] pidsStr = StringUtil.split(parentIds, ","); for (String pidStr : pidsStr) { if (StringUtil.isNotBlank(pidStr) && !StringUtil.equals(pidStr, "0")) { pids.add(Long.parseLong(pidStr)); } } return pids; } return new ArrayList<>(); }
Example 24
Source Project: DAFramework Source File: TreeNode.java License: MIT License | 5 votes |
public static void main(String[] args) { try { String text = "功能界面设计"; System.out.println(StringUtil.escapeJava(text)); } catch (Exception e) { e.printStackTrace(); } }
Example 25
Source Project: DAFramework Source File: TextUtils.java License: MIT License | 5 votes |
public static String repeat(String tpl, List<String> items, String rmEndStr) { StringBuffer sb = new StringBuffer(); for (String item : items) { sb.append(StringUtil.replace(tpl, "${0}", item)); } String code = sb.toString().trim(); if (rmEndStr != null && code.endsWith(rmEndStr)) { code = code.substring(0, code.length() - rmEndStr.length()); } return code; }
Example 26
Source Project: DAFramework Source File: TextUtils.java License: MIT License | 5 votes |
public static String[] rebuildArray(String[] arr) { if (arr != null) { List<String> list = new ArrayList<String>(Arrays.asList(arr)); for (Iterator<String> iter = list.iterator(); iter.hasNext(); ) { String s = iter.next(); if (StringUtil.isEmpty(s)) { iter.remove(); } } String[] newArr = new String[list.size()]; return list.toArray(newArr); } return new String[0]; }
Example 27
Source Project: DAFramework Source File: TextUtils.java License: MIT License | 5 votes |
public static Long[] parseLongs(String text) { List<Long> randIds = new ArrayList<Long>(); if (text != null) { for (String strBID : StringUtil.split(text, "|")) { if (strBID != null && !strBID.trim().equals("")) { randIds.add(Long.parseLong(strBID)); } } } return randIds.toArray(new Long[]{}); }
Example 28
Source Project: DAFramework Source File: TextUtils.java License: MIT License | 5 votes |
public static Long parseId(Object id) { if (id == null) { return null; } if (id instanceof String && !StringUtil.isBlank((String) id)) { return Long.parseLong((String) id); } else if (id instanceof Number) { return ((Number) id).longValue(); } return -1l; }
Example 29
Source Project: DAFramework Source File: TextUtils.java License: MIT License | 5 votes |
public static boolean match(String text, String regex) { regex = StringUtil.replace(regex, "\\", "\\\\"); regex = StringUtil.replace(regex, ".", "\\."); regex = StringUtil.replace(regex, "[", "\\["); regex = StringUtil.replace(regex, "]", "\\]"); regex = StringUtil.replace(regex, "(", "\\("); regex = StringUtil.replace(regex, ")", "\\)"); regex = StringUtil.replace(regex, "?", ".+"); regex = StringUtil.replace(regex, "*", ".*"); return text.matches(regex); }
Example 30
Source Project: DAFramework Source File: MoneyUtil.java License: MIT License | 5 votes |
public static Long parseLong(Object number) { if (number != null && number instanceof Number) { return ((Number) number).longValue(); } else if (number != null && number instanceof BigDecimal) { return ((Number) number).longValue(); } else if (number != null && StringUtil.isNotBlank(number.toString())) { return Long.parseLong(number.toString().trim()); } return null; }