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

The following examples show how to use org.nutz.lang.Strings#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: MenuController.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
@At
@POST
@Ok("json")
@RequiresPermissions("sys:menu:edit")
@Slog(tag="菜单", after="修改保存菜单")
public Object editDo(@Param("..") Menu menu, @Param("parentId") String parentId, Errors es, HttpServletRequest req) {
    try {
        if(es.hasError()){
             return Result.error(es);
        }
        if (menu != null && Strings.isEmpty(menu.getParentId())) {
            menu.setParentId("0");
        }
        if(Lang.isNotEmpty(menu)){
            menu.setUpdateBy(ShiroUtils.getSysUserId());
            menu.setUpdateTime(new Date());
            menuService.update(menu);
        }
        return Result.success("system.success");
    } catch (Exception e) {
        return Result.error(e instanceof ErrorException ? e.getMessage() : "system.error");
    }
}
 
Example 2
Source File: GlobalsSettingProcessor.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
@Override
    public void process(ActionContext ac) throws Throwable {

        boolean captcha = Boolean.valueOf(Globals.getConfig("login.captcha"));
        String path = ac.getServletContext().getContextPath();
        String projectName = path.length() > 0 ? path + "/" : "/";
        ac.getRequest().setAttribute("AppBase", projectName);
        ac.getRequest().setAttribute("captchaEnabled", captcha);
        ac.getRequest().setAttribute("pubkey", Globals.getPublicKey());
//      //允许跨越
//        ac.getResponse().addHeader("Access-Control-Allow-Origin", "*");
//        ac.getResponse().addHeader("Access-Control-Allow-Credentials", "true");
//        ac.getResponse().addHeader("Access-Control-Allow-Headers",
//                "Origin, X-Requested-With, Content-Type, Accept, Connection, User-Agent, Cookie");
        // 如果url中有语言属性则设置
        String lang = ac.getRequest().getParameter("lang");
        if (!Strings.isEmpty(lang)) {
            Mvcs.setLocalizationKey(lang);
        } else {
            // Mvcs.getLocalizationKey()  1.r.56 版本是null,所以要做两次判断, 1.r.57已修复为默认值 Nutz:Fix issue 1072
            lang = Strings.isBlank(Mvcs.getLocalizationKey()) ? Mvcs.getDefaultLocalizationKey() : Mvcs.getLocalizationKey();
        }
        ac.getRequest().setAttribute("lang", lang);
        doNext(ac);
    }
 
Example 3
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 4
Source File: BankCardUtils.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 获取银行 名称
 * @param cardId
 * @return
 */
public static String getNameOfBank(String cardId){
    // 获取银行卡的信息
    String name =  BankCardBin.getname(cardId);
    if(Strings.isEmpty(name)){
        CardInfoData cardInfoData = validateAndCacheCardInfo(cardId);
        if(cardInfoData.isValidated()){
            name = bankMap.get(cardInfoData.getBank());
        }
    }
    return name;
}
 
Example 5
Source File: PayUtil.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
/**
 * 支付宝订单创建
 * @param out_trade_no 商户订单号,商户网站订单系统中唯一订单号,必填
 * @param subject      订单名称,必填
 * @param total_amount 付款金额,必填
 * @param body         商品描述,可空
 */
public static String createOrder(String out_trade_no, String subject, String total_amount, String body) throws Exception {
    if (Strings.isEmpty(out_trade_no) || Strings.isEmpty(subject) || Strings.isEmpty(total_amount)) {
        throw new Exception("支付宝参数异常");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.URL, AlipayConfig.APPID, AlipayConfig.RSA_PRIVATE_KEY,
            AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, AlipayConfig.SIGNTYPE);
    //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
    AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
    //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
    AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
    model.setBody(body);
    model.setSubject(subject);
    model.setOutTradeNo(out_trade_no);
    model.setTimeoutExpress("30m");
    model.setTotalAmount(total_amount);
    model.setProductCode("QUICK_MSECURITY_PAY");
    request.setBizModel(model);
    request.setNotifyUrl(AlipayConfig.notify_url);
    try {
        //这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
        System.out.println(response.getBody());
        return response.getBody();
        //就是orderString 可以直接给客户端请求,无需再做处理。
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }
    return null;
}