Java Code Examples for com.jfinal.kit.StrKit#notBlank()

The following examples show how to use com.jfinal.kit.StrKit#notBlank() . 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: ProductServiceImpl.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public Page<Product> findPage(Product product, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    if (StrKit.notBlank(product.getName())) {
        columns.like("name", "%"+product.getName()+"%");
    }
    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "id desc");
}
 
Example 2
Source File: MediaApi.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
/**
	 * 获取永久素材
	 * @param url 素材地址
	 * @return params post参数
	 * @return InputStream 流,考虑到这里可能返回json或file
	 * @throws IOException
	 */
	private static InputStream downloadMaterial(String url, String params) throws IOException {
		URL _url = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) _url.openConnection();
		// 连接超时
		conn.setConnectTimeout(25000);
		// 读取超时 --服务器响应比较慢,增大时间
		conn.setReadTimeout(25000);
		conn.setRequestMethod("POST");
		conn.setRequestProperty("Content-Type", "Keep-Alive");
		conn.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
		conn.setDoOutput(true);
		conn.setDoInput(true);
		conn.connect();
		if (StrKit.notBlank(params)) {
			OutputStream out = conn.getOutputStream();
			out.write(params.getBytes(DEFAULT_CHARSET));
			out.flush();
			IOUtils.closeQuietly(out);
		}
		InputStream input = conn.getInputStream();
//		// 关闭连接
//		if (conn != null) {
//			conn.disconnect();
//		}
		return input;
	}
 
Example 3
Source File: IndexController.java    From zooadmin with MIT License 5 votes vote down vote up
public void dologin() {
    ResultData result = new ResultData();
    String addr = getPara("addr");
    String password = getPara("password");
    String pwd = PropKit.use("user.properties").get("root");
    if (StrKit.isBlank(password) || !password.equals(pwd)) {
        result.setSuccess(false);
        result.setMessage("请输入正确的密码登陆!");
        renderJson(result);
    } else {
        if (StrKit.notBlank(addr)) {
            try {
                ZKPlugin zkPlugin = new ZKPlugin(addr);
                if (getSessionAttr("zk-client") == null) {
                    setSessionAttr("zk-client", zkPlugin.getClient());
                    setSessionAttr("addr", addr);
                }
            } catch (Exception e) {
                log.error("ZKPlugin error.", e);
                result.setSuccess(false);
                result.setMessage("连接到ZooKeeper失败,请复核!");
            }

        } else {
            result.setSuccess(false);
            result.setMessage("ZooKeeper 地址不能为空!");
        }
        renderJson(result);
    }
}
 
Example 4
Source File: WechatApis.java    From jboot with Apache License 2.0 5 votes vote down vote up
/**
 * http GET请求获得jsapi_ticket(有效期7200秒,开发者必须在自己的服务全局缓存jsapi_ticket)
 *
 * @param jsApiType jsApi类型
 * @return JsTicket
 */
public static JsTicket getTicket(JsApiType jsApiType) {
    String access_token = AccessTokenApi.getAccessTokenStr();
    String appId = ApiConfigKit.getApiConfig().getAppId();
    String key = appId + ':' + jsApiType.name();
    final ParaMap pm = ParaMap.create("access_token", access_token).put("type", jsApiType.name());

    // 2016.07.21修改By L.cm 为了更加方便扩展
    String jsTicketJson = ApiConfigKit.getAccessTokenCache().get(key);
    JsTicket jsTicket = null;
    if (StrKit.notBlank(jsTicketJson)) {
        jsTicket = new JsTicket(jsTicketJson);
    }
    if (null == jsTicket || !jsTicket.isAvailable()) {
        // 最多三次请求
        jsTicket = RetryUtils.retryOnException(3, new Callable<JsTicket>() {

            @Override
            public JsTicket call() throws Exception {
                return new JsTicket(HttpUtils.get(apiUrl, pm.getData()));
            }

        });

        if (null != jsApiType) {
            ApiConfigKit.getAccessTokenCache().set(key, jsTicket.getCacheJson());
        }

    }
    return jsTicket;
}
 
Example 5
Source File: ServletKit.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
public static String getUrl(HttpServletRequest request) {
    String url = request.getRequestURL().toString();
    String parmas = request.getQueryString();
    if (StrKit.notBlank(parmas)) {
        url = url + "?" + parmas;
    }
    return url;
}
 
Example 6
Source File: ModelRedisMapping.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
public void put(String tableName, String cacheName) {
	//remove old cachename
	String oldCacheName = this.modelToRedisMap.get(tableName);
	if (StrKit.notBlank(oldCacheName)) {
		this.caches.remove(oldCacheName);
	}
	this.modelToRedisMap.put(tableName, cacheName);
	if (!this.tables.contains(tableName)) {
		this.tables.add(tableName);	
	}
	if (!this.caches.contains(cacheName)) {
		this.caches.add(cacheName);
	}
}
 
Example 7
Source File: HtmlToJson.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
private HtmlToJson(String html, Params params) {
    this.html = html;
    this.params = params;
    this.idx = 0;
    this.needAbsUrl = StrKit.notBlank(params.getBaseUri());
    this.clean();
}
 
Example 8
Source File: HtmlToJson.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 处理textNode类型的节点 里面可能带着左侧空格的 都需要把空格转为空格节点
 *
 * @param jsonNodes
 * @param tag
 * @param wholeText
 */
private void processMutilTextNode(JSONArray jsonNodes, String tag, String wholeText) {
    if (wholeText.startsWith(" ") && wholeText.length() > 1 && StrKit.notBlank(wholeText)) {
        String trimText = wholeText.trim();
        int index = wholeText.indexOf(trimText);
        jsonNodes.add(processTextNode(tag, wholeText.substring(0, index)));
        jsonNodes.add(processTextNode(tag, wholeText.substring(index)));
    } else {
        jsonNodes.add(processTextNode(tag, wholeText));
    }
}
 
Example 9
Source File: UserServiceImpl.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public Page<User> findPage(User user, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    if (StrKit.notBlank(user.getName())) {
        columns.like("name", "%"+user.getName()+"%");
    }
    if (StrKit.notBlank(user.getPhone())) {
        columns.like("phone", "%"+user.getPhone()+"%");
    }
    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "id desc");
}
 
Example 10
Source File: DataServiceImpl.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public Page<Data> findPage(Data data, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    if (StrKit.notBlank(data.getType())) {
        columns.like("type", "%"+data.getType()+"%");
    }
    if (StrKit.notBlank(data.getTypeDesc())) {
        columns.like("typeDesc", "%"+data.getTypeDesc()+"%");
    }
    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "type asc ,orderNo asc");
}
 
Example 11
Source File: IndexController.java    From zooadmin with MIT License 5 votes vote down vote up
public void dologin() {
    ResultData result = new ResultData();
    String addr = getPara("addr");
    String password = getPara("password");
    String pwd = PropKit.use("user.properties").get("root");
    if (StrKit.isBlank(password) || !password.equals(pwd)) {
        result.setSuccess(false);
        result.setMessage("请输入正确的密码登陆!");
        renderJson(result);
    } else {
        if (StrKit.notBlank(addr)) {
            try {
                ZKPlugin zkPlugin = new ZKPlugin(addr);
                if (getSessionAttr("zk-client") == null) {
                    setSessionAttr("zk-client", zkPlugin.getClient());
                    setSessionAttr("addr", addr);
                }
            } catch (Exception e) {
                log.error("ZKPlugin error.", e);
                result.setSuccess(false);
                result.setMessage("连接到ZooKeeper失败,请复核!");
            }

        } else {
            result.setSuccess(false);
            result.setMessage("ZooKeeper 地址不能为空!");
        }
        renderJson(result);
    }
}
 
Example 12
Source File: ResServiceImpl.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public Page<Res> findPage(Res sysRes, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    columns.eq("pid", sysRes.getPid() == null ? 0L : sysRes.getPid());
    if (StrKit.notBlank(sysRes.getName())) {
        columns.like("name", "%"+sysRes.getName()+"%");
    }
    if (StrKit.notBlank(sysRes.getUrl())) {
        columns.like("url", "%"+sysRes.getUrl()+"%");
    }

    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "seq asc");
}
 
Example 13
Source File: RoleServiceImpl.java    From jboot-admin with Apache License 2.0 5 votes vote down vote up
@Override
public Page<Role> findPage(Role sysRole, int pageNumber, int pageSize) {
    Columns columns = Columns.create();

    if (StrKit.notBlank(sysRole.getName())) {
        columns.like("name", "%"+sysRole.getName()+"%");
    }

    return DAO.paginateByColumns(pageNumber, pageSize, columns.getList(), "seq asc");
}
 
Example 14
Source File: AppServiceGenerator.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
public static void doGenerate() {
    AppServiceGeneratorConfig config = Jboot.config(AppServiceGeneratorConfig.class);

    System.out.println(config.toString());

    if (StrKit.isBlank(config.getModelpackage())) {
        System.err.println("jboot.admin.service.ge.modelpackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServicepackage())) {
        System.err.println("jboot.admin.service.ge.servicepackage 不可为空");
        System.exit(0);
    }

    String modelPackage = config.getModelpackage();
    String servicepackage = config.getServicepackage();

    System.out.println("start generate...");
    System.out.println("generate dir:" + servicepackage);

    DataSource dataSource = CodeGenHelpler.getDatasource();

    AppMetaBuilder metaBuilder = new AppMetaBuilder(dataSource);

    if (StrKit.notBlank(config.getRemovedtablenameprefixes())) {
        metaBuilder.setRemovedTableNamePrefixes(config.getRemovedtablenameprefixes().split(","));
    }

    if (StrKit.notBlank(config.getExcludedtableprefixes())) {
        metaBuilder.setSkipPre(config.getExcludedtableprefixes().split(","));
    }

    List<TableMeta> tableMetaList = metaBuilder.build();
    CodeGenHelpler.excludeTables(tableMetaList, config.getExcludedtable());

    new JbootServiceInterfaceGenerator(servicepackage, modelPackage).generate(tableMetaList);

    System.out.println("service generate finished !!!");

}
 
Example 15
Source File: AppServiceImplGenerator.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
public static void doGenerate() {
    AppServiceImplGeneratorConfig config = Jboot.config(AppServiceImplGeneratorConfig.class);

    System.out.println(config.toString());

    if (StrKit.isBlank(config.getModelpackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.modelpackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServicepackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.servicepackage 不可为空");
        System.exit(0);
    }

    if (StrKit.isBlank(config.getServiceimplpackage())) {
        System.err.println("jboot.admin.serviceimpl.ge.serviceimplpackage 不可为空");
        System.exit(0);
    }

    String modelPackage = config.getModelpackage();
    String servicepackage = config.getServicepackage();
    String serviceimplpackage = config.getServiceimplpackage();

    System.out.println("start generate...");
    System.out.println("generate dir:" + servicepackage);

    DataSource dataSource = CodeGenHelpler.getDatasource();

    AppMetaBuilder metaBuilder = new AppMetaBuilder(dataSource);

    if (StrKit.notBlank(config.getRemovedtablenameprefixes())) {
        metaBuilder.setRemovedTableNamePrefixes(config.getRemovedtablenameprefixes().split(","));
    }

    if (StrKit.notBlank(config.getExcludedtableprefixes())) {
        metaBuilder.setSkipPre(config.getExcludedtableprefixes().split(","));
    }

    List<TableMeta> tableMetaList = metaBuilder.build();
    CodeGenHelpler.excludeTables(tableMetaList, config.getExcludedtable());

    new AppJbootServiceImplGenerator(servicepackage , modelPackage, serviceimplpackage).generate(tableMetaList);

    System.out.println("service generate finished !!!");

}
 
Example 16
Source File: TypeKit.java    From jfinal-ext3 with Apache License 2.0 4 votes vote down vote up
public static Object convert(String value, Class<?> type, String format) {
     if (StrKit.notBlank(value)) {
         if (String.class.equals(type)) {
             return value;
         }
         
         if (Integer.class.equals(type) || int.class.equals(type)) {
             return Integer.parseInt(value);
         }
         
         if (Double.class.equals(type) || double.class.equals(type)) {
             return Double.parseDouble(value);
         }
         
         if (Float.class.equals(type) || float.class.equals(type)) {
	return Float.parseFloat(value);
}
         
         if (Boolean.class.equals(type) || boolean.class.equals(type)) {
             String valueLower = value.toLowerCase();
             if (valueLower.equals("true") || valueLower.equals("false")) {
                 return Boolean.parseBoolean(value.toLowerCase());
             }
             Integer integer = Integer.parseInt(value);
             if (integer == 0) {
                 return false;
             } else {
                 return true;
             }
         }
         
         if (Long.class.equals(type) || long.class.equals(type)) {
             return Long.parseLong(value);
         }
         
         if (BigInteger.class.equals(type)) {
	return (new BigInteger(value));
}
         
         if (byte[].class.equals(type)) {
	return value.getBytes();
}
         
         if (Short.class.equals(type)) {
	return Short.parseShort(value);
}
         
         if (Byte.class.equals(type)) {
	return Byte.parseByte(value);
}
         
         if (Date.class.equals(type) 
         		|| java.sql.Date.class.equals(type)
         		|| java.sql.Time.class.equals(type)
         		|| java.sql.Timestamp.class.equals(type)) {
         	Date date = null;
             if (value.contains("-") || value.contains("/") || value.contains(":")) {
                 date = getSimpleDateFormatDate(value, format);
             } else {
                 Double d = Double.parseDouble(value);
                 date = HSSFDateUtil.getJavaDate(d, true);
             }
             if (java.sql.Date.class.equals(type)) {
             	return new java.sql.Date(date.getTime());
	}
             if (java.sql.Time.class.equals(type)) {
		return new java.sql.Time(date.getTime());
	}
             if (java.sql.Timestamp.class.equals(type)) {
		return new java.sql.Timestamp(date.getTime());
	}
             return date;
         }
         
         if (BigDecimal.class.equals(type)) {
             return new BigDecimal(value);
         }
     }
     return null;
 }
 
Example 17
Source File: JbootRedirectRender.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public String buildFinalUrl() {
	String ret;
	// 如果一个url为/login/connect?goto=http://www.jfinal.com,则有错误
	// ^((https|http|ftp|rtsp|mms)?://)$   ==> indexOf 取值为 (3, 5)
	if (contextPath != null && (url.indexOf("://") == -1 || url.indexOf("://") > 5)) {
		ret = contextPath + url;
	} else {
		ret = url;
	}
	
	if (withQueryString) {
		String queryString = request.getQueryString();
		if (queryString != null) {
			if (ret.indexOf('?') == -1) {
				ret = ret + "?" + queryString;
			} else {
				ret = ret + "&" + queryString;
			}
		}
	}
	
	// 跳过 http/https 已指定过协议类型的 url,用于支持跨域名重定向
	if (ret.toLowerCase().startsWith("http")) {
		return ret;
	}
	
	/**
	 * 注意:nginx 代理 https 的场景,需要使用如下配置:
	 *       proxy_set_header X-Forwarded-Proto $scheme;
	 *       proxy_set_header X-Forwarded-Port $server_port;
	 */
	if ("https".equalsIgnoreCase(request.getHeader("X-Forwarded-Proto"))) {
		String serverName = request.getServerName();
		
		/**
		 * 获取 nginx 端通过配置 proxy_set_header X-Forwarded-Port $server_port;
		 * 传递过来的端口号,保障重定向时端口号是正确的
		 */
		String port = request.getHeader("X-Forwarded-Port");
		if (StrKit.notBlank(port)) {
			serverName = serverName + ":" + port;
		}
		
		if (ret.charAt(0) != '/') {
			return "https://" + serverName + "/" + ret;
		} else {
			return "https://" + serverName + ret;
		}
		
	} else {
		return ret;
	}
}
 
Example 18
Source File: UserServiceImpl.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean updateUser(User user, Long[] roles) {
    String pwd = user.getPwd();
    if (StrKit.notBlank(pwd)) {
        String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex();
        SimpleHash hash = new SimpleHash("md5", pwd, salt2, 2);
        pwd = hash.toHex();
        user.setPwd(pwd);
        user.setSalt2(salt2);
    } else {
        user.remove("pwd");
    }

    user.setLastUpdTime(new Date());
    user.setNote("修改系统用户");

    return Db.tx(new IAtom() {
        @Override
        public boolean run() throws SQLException {
            if (!user.update()) {
                return false;
            }

            userRoleService.deleteByUserId(user.getId());

            if (roles != null) {
                List<UserRole> list = new ArrayList<UserRole>();
                for (Long roleId : roles) {
                    UserRole userRole = new UserRole();
                    userRole.setUserId(user.getId());
                    userRole.setRoleId(roleId);
                    list.add(userRole);
                }

                int[] rets = userRoleService.batchSave(list);
                for (int ret : rets) {
                    if (ret < 1) {
                        return false;
                    }
                }
            }
            return true;
        }
    });
}
 
Example 19
Source File: UserServiceImpl.java    From jboot-admin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean saveUser(User user, Long[] roles) {
    String pwd = user.getPwd();

    if (StrKit.notBlank(pwd)) {
        String salt2 = new SecureRandomNumberGenerator().nextBytes().toHex();
        SimpleHash hash = new SimpleHash("md5", pwd, salt2, 2);
        pwd = hash.toHex();
        user.setPwd(pwd);
        user.setSalt2(salt2);
    }

    user.setOnlineStatus(UserOnlineStatus.OFFLINE);
    user.setCreatedate(new Date());
    user.setLastUpdTime(new Date());
    user.setNote("保存系统用户");

    return Db.tx(new IAtom() {
        @Override
        public boolean run() throws SQLException {
            if (!user.save()) {
                return false;
            }

            if (roles != null) {
                List<UserRole> list = new ArrayList<UserRole>();
                for (Long roleId : roles) {
                    UserRole userRole = new UserRole();
                    userRole.setUserId(user.getId());
                    userRole.setRoleId(roleId);
                    list.add(userRole);
                }
                int[] rets = userRoleService.batchSave(list);

                for (int ret : rets) {
                    if (ret < 1) {
                        return false;
                    }
                }
            }
            return true;
        }
    });
}
 
Example 20
Source File: AppModelGenerator.java    From jboot-admin with Apache License 2.0 3 votes vote down vote up
public static void doGenerate() {
    AppModelGeneratorConfig config = Jboot.config(AppModelGeneratorConfig.class);

    System.out.println(config.toString());

    if (StrKit.isBlank(config.getModelpackage())) {
        System.err.println("jboot.admin.model.ge.modelpackage 不可为空");
        System.exit(0);
    }

    String modelPackage = config.getModelpackage();
    String baseModelPackage = modelPackage + ".base";

    String modelDir = PathKit.getWebRootPath() + "/src/main/java/" + modelPackage.replace(".", "/");
    String baseModelDir = PathKit.getWebRootPath() + "/src/main/java/" + baseModelPackage.replace(".", "/");

    System.out.println("start generate...");
    System.out.println("generate dir:" + modelDir);

    DataSource dataSource = CodeGenHelpler.getDatasource();

    AppMetaBuilder metaBuilder = new AppMetaBuilder(dataSource);

    if (StrKit.notBlank(config.getRemovedtablenameprefixes())) {
        metaBuilder.setRemovedTableNamePrefixes(config.getRemovedtablenameprefixes().split(","));
    }

    if (StrKit.notBlank(config.getExcludedtableprefixes())) {
        metaBuilder.setSkipPre(config.getExcludedtableprefixes().split(","));
    }

    List<TableMeta> tableMetaList = metaBuilder.build();
    CodeGenHelpler.excludeTables(tableMetaList, config.getExcludedtable());

    new JbootBaseModelGenerator(baseModelPackage, baseModelDir).generate(tableMetaList);
    new JbootModelGenerator(modelPackage, baseModelPackage, modelDir).generate(tableMetaList);

    System.out.println("entity generate finished !!!");

}