Java Code Examples for org.nutz.lang.Lang#isEmpty()

The following examples show how to use org.nutz.lang.Lang#isEmpty() . 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 File: MenuServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
@Override
public boolean checkMenuUnique(String id, String parentId, String menuName) {
    Cnd cnd =Cnd.NEW();
    if(Strings.isNotBlank(id)){
        cnd.and("id","!=",id);
    }
    if(Strings.isNotBlank(parentId)){
        cnd.and("parent_id","=",parentId);
    }
    if(Strings.isNotBlank(menuName)){
        cnd.and("menu_name", "=", menuName);
    }
    List<Menu> list = this.query(cnd);
    if (Lang.isEmpty(list)) {
        return true;
    }
    return false;
}
 
Example 2
Source File: DeptServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
@Override
public boolean checkDeptNameUnique(String id, String parentId, String menuName) {
    Cnd cnd =Cnd.NEW();
    if(Strings.isNotBlank(id)){
        cnd.and("id","!=",id);
    }
    if(Strings.isNotBlank(parentId)){
        cnd.and("parent_id","=",parentId);
    }
    if(Strings.isNotBlank(menuName)){
        cnd.and("dept_name", "=", menuName);
    }
    List<Dept> list = this.query(cnd);
    if (Lang.isEmpty(list)) {
        return true;
    }
    return false;
}
 
Example 3
Source File: RoleServiceImpl.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 校验角色名称是否唯一
 * @param roleName
 * @return
 */
@Override
public boolean checkRoleNameUnique(String id, String roleName, String roleKey) {
    Cnd cnd =Cnd.NEW();
    if(Strings.isNotBlank(id)){
        cnd.and("id","!=",id);
    }
    if(Strings.isNotBlank(roleName)){
        cnd.and("role_name", "=", roleName);
    }
    if(Strings.isNotBlank(roleKey)){
        cnd.and("role_key", "=", roleKey);
    }
    List<Role> roleList = this.query(cnd);
    if (Lang.isEmpty(roleList)) {
        return true;
    }
    return false;
}
 
Example 4
Source File: SimpleAuthorizingRealm.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
		UsernamePasswordToken upToken = (UsernamePasswordToken) token;
		if (Lang.isEmpty(upToken) || Strings.isEmpty(upToken.getUsername())) {
			throw Lang.makeThrow(AuthenticationException.class, "Account name is empty");
		}
		User user = userService.fetch(Cnd.where("login_name","=",upToken.getUsername()));
		if (Lang.isEmpty(user)) {
			throw Lang.makeThrow(UnknownAccountException.class, "Account [ %s ] not found", upToken.getUsername());
		}
		if (user.isStatus()) {
			throw Lang.makeThrow(LockedAccountException.class, "Account [ %s ] is locked.", upToken.getUsername());
		}
		SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user,
				user.getPassword().toCharArray(), ByteSource.Util.bytes(user.getSalt()), getName());
		info.setCredentialsSalt(ByteSource.Util.bytes(user.getSalt()));
//        info.
		return info;
	}
 
Example 5
Source File: XssSqlFilterProcessor.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 判断是否排除
 * @param request
 * @return
 */
private boolean handleExcludeURL(HttpServletRequest request) {
    if (!enabled) {
        return true;
    }
    if (excludes == null || Lang.isEmpty(excludes)) {
        return false;
    }
    String url = request.getServletPath();
    for (String pattern : excludes) {
        Pattern p = Pattern.compile("^" + pattern);
        Matcher m = p.matcher(url);
        if (m.find()) {
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: RedisAccessTokenStore.java    From nutzwx with Apache License 2.0 5 votes vote down vote up
@Override
public WxAccessToken get() {
    Jedis jedis = null;
    try {
        jedis = jedisPool.getResource();
        if (tokenKey == null) {
            throw new RuntimeException("Redis token key should not be null!");
        }
        Map<String, String> hash = jedis.hgetAll(tokenKey);
        if (Lang.isEmpty(hash)) {
            log.warnf("could not find a valid token in redis with key [%s]", tokenKey);
            return null;
        }
        WxAccessToken at = new WxAccessToken();// 从redis中拿出3个值组装成WxAccessToken返回
        at.setToken(hash.get("token"));
        at.setLastCacheTimeMillis(Long.valueOf(hash.get("lastCacheMillis")));
        at.setExpires(Integer.valueOf(hash.get("expires")));
        log.debugf("wx access_token fetched from redis with the key [%s] : \n %s",
                tokenKey,
                Json.toJson(at, JsonFormat.nice()));
        return at;
    } catch (Exception e) {
        log.error(e);
    } finally {
        // jedisPool.returnResource(jedis); //这是老版本归还连接的方法 已经deprecated
        jedis.close();// 2.9.0的方法直接close
    }
    return null;
}
 
Example 7
Source File: NewsMsg.java    From mpsdk4j with Apache License 2.0 5 votes vote down vote up
public List<Article> getArticles() {
    if (!Lang.isEmpty(articles) && articles.size() > 10) {
        this.articles = articles.subList(0, 10);
        setCount(10);
    }
    else {
        this.setCount(articles.size());
    }
    return articles;
}
 
Example 8
Source File: Reflections.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
public static Class<?> getUserClass(Object instance) {
	if(Lang.isEmpty(instance)){
		throw new IllegalArgumentException("Instance must not be null");
	}
	Class clazz = instance.getClass();
	if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
		Class<?> superClass = clazz.getSuperclass();
		if (superClass != null && !Object.class.equals(superClass)) {
			return superClass;
		}
	}
	return clazz;

}
 
Example 9
Source File: Base64Utils.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 将文件转换成 base64字段
 * @param tempFile
 * @return
 */
public static String fileBase64(TempFile tempFile, Long maxLength) {
    // source file
    File file = tempFile.getFile();
    if(maxLength == null){
        maxLength =MAX_LENGTH;
    }
    if(Lang.isEmpty(file) || maxLength < file.length()){
        new IOException("文件超出限制");
    }
    return fileBase64(file);
}
 
Example 10
Source File: UserServiceImpl.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkLoginNameUnique(String name) {
    List<User> list = this.query(Cnd.where("login_name", "=", name));
    if (Lang.isEmpty(list)) {
        return true;
    }
    return false;
}
 
Example 11
Source File: WechatAPIImpl.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
private String mergeAPIUrl(String url, Object... values) {
    if (!Lang.isEmpty(values)) {
        return wechatAPIURL + String.format(url, values);
    }
    return wechatAPIURL + url;
}
 
Example 12
Source File: WechatAPIImpl.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
private String mergeCgiBinUrl(String url, Object... values) {
    if (!Lang.isEmpty(values)) {
        return cgiBinURL + String.format(url, values);
    }
    return cgiBinURL + url;
}
 
Example 13
Source File: WechatAPIImpl.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
/**
 * 微信API响应输出
 * @param url   地址
 * @param methodType    请求方式 1:HTTP_GET, 2:HTTP_POST
 * @param body          POST数据内容
 * @param errorMsg      错误信息
 * @param params        错误信息参数
 * @return              {@link APIResult}
 */
protected APIResult wechatServerResponse(String url, int methodType, Object body, String errorMsg, Object... params) {
    APIResult ar = APIResult.create("{\"errCode\":0,\"errMsg\":\"OK\"}");
    for (int i=0; i < RETRY_COUNT; i++) {
        switch (methodType) {
            case 1:
                ar = APIResult.create(HttpTool.get(url));
                break;
            case 2:
                ar = APIResult.create(HttpTool.post(url, (String)body));
                break;
            case 3:
                ar = APIResult.create(HttpTool.upload(url, (File) body));
                break;
            case 4:
                Object tmp = HttpTool.download(url);
                if(tmp instanceof File) {
                    ar.getContent().put("file", tmp);
                } else {
                    ar = APIResult.create((String) tmp);
                }
                break;
            default:
                break;
        }

        if (ar != null && ar.isSuccess()) {
            return ar;
        }

        log.errorf("第%d尝试与微信服务器建立%s通讯.", (i+1), (methodType == HTTP_GET ? "HTTP GET" : "HTTP POST"));
        if (params == null){
            log.errorf(errorMsg, mpAct.getMpId());
        } else {
            Object[] args = new Object[params.length+1];
            args[0] = mpAct.getMpId();
            System.arraycopy(params, 0, args, 1, params.length);
            log.errorf(errorMsg, args);
            if (ar != null && !Lang.isEmpty(ar.getErrCNMsg())) {
                log.errorf(ar.getErrCNMsg());
            }
        }
    }

    throw Lang.wrapThrow(new WechatAPIException(ar.getJson()));
}
 
Example 14
Source File: HttpTool.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
public static Object download(String url) {
    if (log.isDebugEnabled()) {
        log.debugf("Download url: %s, default timeout: %d", url, CONNECT_TIME_OUT);
    }

    try {
        Response resp = Http.get(url);
        if (resp.isOK()) {
            String cd = resp.getHeader().get("Content-disposition");
            if (log.isInfoEnabled()) {
                log.infof("Get download file info: %s", cd);
            }

            if (Lang.isEmpty(cd)) {
                return resp.getContent();
            }

            cd = cd.substring(cd.indexOf(FILE_NAME_FLAG) + FILE_NAME_FLAG.length());
            String tmp = cd.startsWith("\"") ? cd.substring(1) : cd;
            tmp = tmp.endsWith("\"") ? cd.replace("\"", "") : cd;
            String filename = tmp.substring(0, tmp.lastIndexOf("."));
            String fileext = tmp.substring(tmp.lastIndexOf("."));
            if (log.isInfoEnabled()) {
                log.infof("Download file name: %s", filename);
                log.infof("Download file ext: %s", fileext);
            }

            File tmpfile = File.createTempFile(filename, fileext);
            InputStream is = resp.getStream();
            OutputStream os = new FileOutputStream(tmpfile);
            Streams.writeAndClose(os, is);
            return tmpfile;
        }

        throw Lang.wrapThrow(new RuntimeException(String.format("Download file [%s] failed. status: %d, content: %s",
                                                                url,
                                                                resp.getStatus(),
                                                                resp.getContent())));
    }
    catch (Exception e) {
        throw Lang.wrapThrow(e);
    }
}
 
Example 15
Source File: JSTicket.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
public boolean isAvailable() {
    if (!Lang.isEmpty(ticket) && this.expiresIn >= System.currentTimeMillis()) {
        return true;
    }
    return false;
}
 
Example 16
Source File: WebOauth2Result.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
public boolean isAvailable() {
    if (!Lang.isEmpty(accessToken) && this.expiresIn >= System.currentTimeMillis()) {
        return true;
    }
    return false;
}
 
Example 17
Source File: AccessToken.java    From mpsdk4j with Apache License 2.0 4 votes vote down vote up
public boolean isAvailable() {
    if (!Lang.isEmpty(accessToken) && this.expiresIn >= System.currentTimeMillis()) {
        return true;
    }
    return false;
}
 
Example 18
Source File: BaseServiceImpl.java    From NutzSite with Apache License 2.0 2 votes vote down vote up
/**
 * 默认页码
 *
 * @param pageNumber
 * @return
 */
protected int getPageNumber(Integer pageNumber) {
    return Lang.isEmpty(pageNumber) ? 1 : pageNumber;
}