Java Code Examples for jodd.util.StringUtil#isBlank()

The following examples show how to use jodd.util.StringUtil#isBlank() . 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: Variable.java    From maven-framework-project with MIT License 6 votes vote down vote up
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 2
Source File: TextUtils.java    From DAFramework with MIT License 5 votes vote down vote up
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 3
Source File: Constans.java    From DAFramework with MIT License 5 votes vote down vote up
public static String getLable(String type) {
	if(StringUtil.isBlank(type)){
		return "";
	}
	switch (type) {
	case Man: 
		return "男";
	case Woman: 
		return "女";
	default:
		return "";
	}
}
 
Example 4
Source File: TextUtils.java    From wES with MIT License 5 votes vote down vote up
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 5
Source File: HttpUtil.java    From ES-Fastloader with Apache License 2.0 4 votes vote down vote up
private static String doHttp(String url, JSONObject param, String body, HttpType httpType, boolean check) {
    String logInfo = "url:" + url + ", param:" + param + ", body:" + body + ", type:" + httpType.getType();

    if(param!=null) {
        StringBuilder sb = new StringBuilder();
        for (String key : param.keySet()) {
            sb.append(key).append("=").append(param.getString(key)).append("&");
        }

        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
        }

        url = url + "?" + sb.toString();
    }

    String result = "";
    try {
        switch (httpType) {
            case GET:
                result = HttpUtil.get(url);
                break;

            case PUT:
                result = HttpUtil.putJsonEntity(url, body);
                break;

            case POST:
                result = HttpUtil.postJsonEntity(url, body);
                break;
        }

        if (StringUtil.isBlank(result)) {
            LogUtils.error("do http fail, get blank result, " + logInfo);
            return null;
        }

        if (!check) {
            return result;
        }

        JSONObject jsonObject = JSONObject.parseObject(result);
        if (jsonObject.getIntValue("code") != 0) {
            LogUtils.error("do http fail, code is not 0, result:" + result + ", " + logInfo);
            return null;
        }


        String ret = jsonObject.getString("data");
        if(ret==null) {
            ret = "";
        }

        return ret;
    } catch (Throwable t) {
        LogUtils.error("do http get error, result:" + result + ", " + logInfo, t);
        return null;
    }
}
 
Example 6
Source File: XmlUtil.java    From DAFramework with MIT License 4 votes vote down vote up
public static boolean isBlank(Node node) {
	return node != null && ((node.getNodeType() == Node.TEXT_NODE && StringUtil.isBlank(node.getNodeValue())) || (node.getNodeType() == Node.COMMENT_NODE));
}
 
Example 7
Source File: TextUtils.java    From DAFramework with MIT License 4 votes vote down vote up
public static String prefix(String key) {
	return StringUtil.isBlank(key) ? "" : (key + ".");
}
 
Example 8
Source File: TextUtils.java    From DAFramework with MIT License 4 votes vote down vote up
public static String postfix(String key) {
	return StringUtil.isBlank(key) ? "" : ("." + key);
}
 
Example 9
Source File: FileController.java    From DAFramework with MIT License 4 votes vote down vote up
@RequestMapping(value="/upload")
public ActionResultObj upload(HttpServletRequest request, HttpServletResponse response){
	ActionResultObj result = new ActionResultObj();
	try{
		String grouping = request.getParameter("grouping");
		if(StringUtil.isBlank(grouping)||grouping.equalsIgnoreCase("null")){
			 grouping = IdGen.uuid();
		}
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		String newFilePath = filePath+"/"+grouping+"/";
		File file = new File(rootPath+ newFilePath);
		if (!file.exists()) {
			file.mkdirs();
		}
		String fileName = null;
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile mf = entity.getValue();
			fileName = mf.getOriginalFilename();
			String newFileName = FileUtil.generateFileName(fileName);// 构成新文件名。

			File uploadFile = new File(rootPath + newFilePath + newFileName);
			FileCopyUtils.copy(mf.getBytes(), uploadFile);
			
			EFile eFile = new EFile();
			eFile.setName(FileUtil.getFileNameNotSuffix(fileName)+FileUtil.getFileNameSuffix(fileName));
			eFile.setPath(newFilePath+newFileName);
			eFile.setGrouping(grouping);
			
			if(fileService.save(eFile) != null){
				WMap map = new WMap();
				map.put("data", eFile);
				result.ok(map);
				result.okMsg("上传成功!");
			}else{
				result.errorMsg("上传失败!");
			}
		}
	}catch(Exception e){
		LOG.error("上传失败,原因:"+e.getMessage());
		result.error(e);
	}
	return result;
}
 
Example 10
Source File: TextUtils.java    From wES with MIT License 4 votes vote down vote up
public static String prefix(String key) {
	return StringUtil.isBlank(key) ? "" : (key + ".");
}
 
Example 11
Source File: TextUtils.java    From wES with MIT License 4 votes vote down vote up
public static String postfix(String key) {
	return StringUtil.isBlank(key) ? "" : ("." + key);
}
 
Example 12
Source File: XmlUtil.java    From wES with MIT License 4 votes vote down vote up
public static boolean isBlank(Node node) {
	return node != null && ((node.getNodeType() == Node.TEXT_NODE && StringUtil.isBlank(node.getNodeValue())) || (node.getNodeType() == Node.COMMENT_NODE));
}
 
Example 13
Source File: HtmlFosterRules.java    From web-data-extractor with Apache License 2.0 4 votes vote down vote up
/**
 * Finds foster elements. Returns <code>true</code> if there was no change in
 * DOM tree of the parent element. Otherwise, returns <code>false</code>
 * meaning that parent will scan its childs again.
 */
protected boolean findFosterNodes(Node node) {
    boolean isTable = false;

    if (!lastTables.isEmpty()) {
        // if inside table
        if (node.getNodeType() == Node.NodeType.TEXT) {
            String value = node.getNodeValue();
            if (!StringUtil.isBlank(value)) {
                if (isParentNodeOneOfFosterTableElements(node.getParentNode())) {
                    fosterTexts.add((Text) node);
                }
            }
        }
    }

    if (node.getNodeType() == Node.NodeType.ELEMENT) {
        Element element = (Element) node;

        isTable = isTableElement(node);

        if (isTable) {
            // if node is a table, add it to the stack-of-last-tables
            lastTables.add(element);
        } else {
            // otherwise...

            // ...if inside the table
            if (!lastTables.isEmpty()) {
                // check this and parent
                Node parentNode = node.getParentNode();
                if (
                        isParentNodeOneOfFosterTableElements(parentNode) &&
                                !isOneOfTableElements(element)
                        ) {

                    String elementNodeName = element.getNodeName().toLowerCase();
                    if (elementNodeName.equals("form")) {
                        if (element.getChildNodesCount() > 0) {
                            // if form element, take all its child nodes
                            // and add after the from element
                            Node[] formChildNodes = element.getChildNodes();
                            parentNode.insertAfter(formChildNodes, element);
                            return false;
                        } else {
                            // empty form element, leave it where it is
                            return true;
                        }
                    }

                    if (elementNodeName.equals("input")) {
                        String inputType = element.getAttribute("type");

                        if (inputType.equals("hidden")) {
                            // input hidden elements remains as they are
                            return true;
                        }
                    }

                    // foster element found, remember it to process it later
                    fosterElements.add(element);
                }

            } else {
                // ...if not inside the table, just keep going
            }
        }
    }

    allchilds:
    while (true) {
        int childs = node.getChildNodesCount();
        for (int i = 0; i < childs; i++) {
            Node childNode = node.getChild(i);

            boolean done = findFosterNodes(childNode);
            if (!done) {
                continue allchilds;
            }
        }
        break;
    }

    if (isTable) {
        // remove last element
        int size = lastTables.size();
        if (size > 0) {
            lastTables.remove(size - 1);    // no array copy occurs when the last element is removed
        }
    }
    return true;
}