From 94f0b157f5a743b8e36a1032f26b290f8696f5c1 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Wed, 13 Nov 2019 00:29:57 +0800 Subject: [PATCH] init --- src/main/java/com/wb/excel/api/WCell.java | 27 +- src/main/java/com/wb/excel/api/WSheet.java | 31 ++- .../wb/excel/api/annotation/ColumnName.java | 4 +- .../excel/api/annotation/ExcelCollection.java | 39 --- .../api/entity/ExcelCollectionEntity.java | 61 ----- .../excel/api/entity/ExcelImportEntity.java | 37 --- .../excel/api/entity/ExcelImportResult.java | 2 +- .../excel/api/entity/ExcelVerifyEntity.java | 141 ----------- .../wb/excel/api/interfaces/EnumSupport.java | 6 +- .../api/interfaces/IExcelVerifyHandler.java | 2 +- .../java/com/wb/excel/api/util/ClassUtil.java | 37 +-- .../java/com/wb/excel/api/util/ExcelUtil.java | 40 --- .../com/wb/excel/api/util/ValidationUtil.java | 237 ------------------ .../com/wb/excel/api/util/VerifyDataUtil.java | 64 ----- 14 files changed, 53 insertions(+), 675 deletions(-) delete mode 100644 src/main/java/com/wb/excel/api/annotation/ExcelCollection.java delete mode 100644 src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java delete mode 100644 src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java delete mode 100644 src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java delete mode 100644 src/main/java/com/wb/excel/api/util/ExcelUtil.java delete mode 100644 src/main/java/com/wb/excel/api/util/ValidationUtil.java delete mode 100644 src/main/java/com/wb/excel/api/util/VerifyDataUtil.java diff --git a/src/main/java/com/wb/excel/api/WCell.java b/src/main/java/com/wb/excel/api/WCell.java index db5b1ad..e7b584e 100644 --- a/src/main/java/com/wb/excel/api/WCell.java +++ b/src/main/java/com/wb/excel/api/WCell.java @@ -1,28 +1,21 @@ package com.wb.excel.api; +import com.wb.excel.api.entity.DataVerifyResult; import com.wb.excel.api.enumeration.Status; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; -/** - * 单元格. - * Created on 2014/9/23. - * - * @author - * @since 0.1.0 - */ public class WCell implements Serializable { - /** - * 单元格的状态 - */ + private Status status; - /** - * 单元格的值 - */ private String value; + private List verifyResultList = new ArrayList<>(); + /** * 默认无参构造方法.会将单元格的状态设为通过. */ @@ -56,4 +49,12 @@ public class WCell implements Serializable { public void setValue(String value) { this.value = value; } + + public void addVerifyResult(DataVerifyResult verifyResult) { + verifyResultList.add(verifyResult); + } + + public boolean hasVerifyResult(DataVerifyResult verifyResult) { + return verifyResultList.size() > 0; + } } diff --git a/src/main/java/com/wb/excel/api/WSheet.java b/src/main/java/com/wb/excel/api/WSheet.java index d668631..68439ba 100644 --- a/src/main/java/com/wb/excel/api/WSheet.java +++ b/src/main/java/com/wb/excel/api/WSheet.java @@ -8,8 +8,8 @@ import com.wb.excel.api.exception.IllegalParameterException; import com.wb.excel.api.exception.TemplateNotMatchException; import com.wb.excel.api.style.*; import com.wb.excel.api.util.ClassUtil; -import com.wb.excel.api.util.ExcelUtil; import com.wb.excel.api.util.StringUtil; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; @@ -19,6 +19,7 @@ import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.text.SimpleDateFormat; import java.util.*; /** @@ -241,7 +242,7 @@ public class WSheet implements Serializable, Cloneable { for (int i = 0; i < list.size(); i++) { WColumn wColumn = list.get(i); Cell cell = headRow.getCell(i); - String headValue = ExcelUtil.getValue(cell); + String headValue = getValue(cell); headValue = headValue.replace("*", ""); headValue = headValue.replace(" ", ""); @@ -269,7 +270,7 @@ public class WSheet implements Serializable, Cloneable { String value = ""; if (null != excelCell) { - value = ExcelUtil.getValue(excelCell); + value = getValue(excelCell); } value = value.trim(); @@ -633,4 +634,28 @@ public class WSheet implements Serializable, Cloneable { } return workbook; } + + /** + * 获取单元格的值 + * + * @param cell 要获取值的单元格 + * @return 单元格的值 + */ + public static String getValue(Cell cell) { + switch (cell.getCellType()) { + case Cell.CELL_TYPE_STRING: + return cell.getStringCellValue(); + case Cell.CELL_TYPE_BOOLEAN: + return String.valueOf(cell.getBooleanCellValue()); + case Cell.CELL_TYPE_NUMERIC: + if (HSSFDateUtil.isCellDateFormatted(cell)) { + Date value = cell.getDateCellValue(); + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value); + } else { + return String.valueOf(cell.getNumericCellValue()); + } + default: + return cell.getStringCellValue(); + } + } } diff --git a/src/main/java/com/wb/excel/api/annotation/ColumnName.java b/src/main/java/com/wb/excel/api/annotation/ColumnName.java index abdc4fb..a082685 100644 --- a/src/main/java/com/wb/excel/api/annotation/ColumnName.java +++ b/src/main/java/com/wb/excel/api/annotation/ColumnName.java @@ -20,12 +20,12 @@ public @interface ColumnName { * * @return */ - public String orderNum() default "0"; + String orderNum() default "0"; /** * 日期格式化 * * @return */ - public String dateFormat() default "yyyy-MM-dd"; + String dateFormat() default "yyyy-MM-dd"; } diff --git a/src/main/java/com/wb/excel/api/annotation/ExcelCollection.java b/src/main/java/com/wb/excel/api/annotation/ExcelCollection.java deleted file mode 100644 index 4aa697b..0000000 --- a/src/main/java/com/wb/excel/api/annotation/ExcelCollection.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.wb.excel.api.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.ArrayList; - -/** - * *************************************************************** - *

- *

- * Copyright (c) 2014 –
- *  ColumnDescription: 导入导出接合
- * ***************************************************************
- * 
- */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface ExcelCollection { - /** - * 名称 - * - * @return - */ - public String value(); - - /** - * 所属的排序 - * - * @return - */ - public String orderNum() default "0"; - - /** - * 创建时创建的类型 默认值是 arrayList - */ - public Class type() default ArrayList.class; -} diff --git a/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java deleted file mode 100644 index 42cd014..0000000 --- a/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.wb.excel.api.entity; - -import java.util.Map; - -/** - * *************************************************************** - *

- *

- * Copyright (c) 2014 –
- *  ColumnDescription:WExcel 集合对象
- * ***************************************************************
- * 
- */ -public class ExcelCollectionEntity { - /** - * 集合对应的名称 - */ - private String name; - /** - * WExcel 列名称 - */ - private String excelName; - /** - * 实体对象 - */ - private Class type; - - private Map excelParams; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getExcelName() { - return excelName; - } - - public void setExcelName(String excelName) { - this.excelName = excelName; - } - - public Class getType() { - return type; - } - - public void setType(Class type) { - this.type = type; - } - - public Map getExcelParams() { - return excelParams; - } - - public void setExcelParams(Map excelParams) { - this.excelParams = excelParams; - } -} diff --git a/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java deleted file mode 100644 index d61d44e..0000000 --- a/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wb.excel.api.entity; - -/** - * *************************************************************** - *

- *

- * Copyright (c) 2014 –
- *  ColumnDescription:导入的实体信息
- * ***************************************************************
- * 
- */ -public class ExcelImportEntity extends ExcelEntity { - /** - * 校驗參數 - */ - private ExcelVerifyEntity verify; - - /** - * 校验参数名称 - */ -// private String verifyFieldName ; - public ExcelVerifyEntity getVerify() { - return verify; - } - - public void setVerify(ExcelVerifyEntity verify) { - this.verify = verify; - } - -// public String getVerifyFieldName() { -// return verifyFieldName; -// } -// -// public void setVerifyFieldName(String verifyFieldName) { -// this.verifyFieldName = verifyFieldName; -// } -} diff --git a/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java b/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java index e436a91..56be87f 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java @@ -108,7 +108,7 @@ public class ExcelImportResult { for (int i = row.getFirstCellNum(), le = row.getLastCellNum(); i < le; i++) { row.createCell(i + 1).setCellValue(temptitle.get(i)); } - Boolean result = (dataVerifyResult == null || dataVerifyResult.isSuccess()) ? true : false; + Boolean result = dataVerifyResult == null || dataVerifyResult.isSuccess(); Cell statusCell = row.createCell(0); if (!result) { statusCell.setCellStyle(errorCellStyle.getStyle()); diff --git a/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java deleted file mode 100644 index aa064c2..0000000 --- a/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.wb.excel.api.entity; - -/** - * WExcel 校验对象 - */ -public class ExcelVerifyEntity { - - /** - * 接口校验 - * - * @return - */ - private boolean interHandler; - - /** - * 不允许空 - * - * @return - */ - private boolean notNull; - - /** - * 是13位移动电话 - * - * @return - */ - private boolean isMobile; - /** - * 是座机号码 - * - * @return - */ - private boolean isTel; - - /** - * 是电子邮件 - * - * @return - */ - private boolean isEmail; - - /** - * 最小长度 - * - * @return - */ - private int minLength; - - /** - * 最大长度 - * - * @return - */ - private int maxLength; - - /** - * 正在表达式 - * - * @return - */ - private String regex; - /** - * 正在表达式,错误提示信息 - * - * @return - */ - private String regexTip; - - public int getMaxLength() { - return maxLength; - } - - public int getMinLength() { - return minLength; - } - - public String getRegex() { - return regex; - } - - public String getRegexTip() { - return regexTip; - } - - public boolean isEmail() { - return isEmail; - } - - public boolean isInterHandler() { - return interHandler; - } - - public boolean isMobile() { - return isMobile; - } - - public boolean isNotNull() { - return notNull; - } - - public boolean isTel() { - return isTel; - } - - public void setEmail(boolean isEmail) { - this.isEmail = isEmail; - } - - public void setInterHandler(boolean interHandler) { - this.interHandler = interHandler; - } - - public void setMaxLength(int maxLength) { - this.maxLength = maxLength; - } - - public void setMinLength(int minLength) { - this.minLength = minLength; - } - - public void setMobile(boolean isMobile) { - this.isMobile = isMobile; - } - - public void setNotNull(boolean notNull) { - this.notNull = notNull; - } - - public void setRegex(String regex) { - this.regex = regex; - } - - public void setRegexTip(String regexTip) { - this.regexTip = regexTip; - } - - public void setTel(boolean isTel) { - this.isTel = isTel; - } - -} diff --git a/src/main/java/com/wb/excel/api/interfaces/EnumSupport.java b/src/main/java/com/wb/excel/api/interfaces/EnumSupport.java index 97421b0..125fa06 100644 --- a/src/main/java/com/wb/excel/api/interfaces/EnumSupport.java +++ b/src/main/java/com/wb/excel/api/interfaces/EnumSupport.java @@ -16,7 +16,7 @@ public interface EnumSupport { * @param str 要判断的值 * @return true || false / 符合||不符合 */ - public Boolean check(String str); + Boolean check(String str); /** * 通过Value来获取Key。
@@ -25,7 +25,7 @@ public interface EnumSupport { * @param value * @return Key。最终存储至数据库中的值。 */ - public Object getKey(String value); + Object getKey(String value); /** * 通过Key来获取Value
@@ -34,5 +34,5 @@ public interface EnumSupport { * @param key * @return Value。最终要展现给用户看的值。 */ - public String getValue(Object key); + String getValue(Object key); } diff --git a/src/main/java/com/wb/excel/api/interfaces/IExcelVerifyHandler.java b/src/main/java/com/wb/excel/api/interfaces/IExcelVerifyHandler.java index 2cbf4ad..8e89396 100644 --- a/src/main/java/com/wb/excel/api/interfaces/IExcelVerifyHandler.java +++ b/src/main/java/com/wb/excel/api/interfaces/IExcelVerifyHandler.java @@ -29,6 +29,6 @@ public interface IExcelVerifyHandler { * @param value 当前值 * @return */ - public DataVerifyResult verifyHandler(Object obj, String name, Object value); + DataVerifyResult verifyHandler(Object obj, String name, Object value); } diff --git a/src/main/java/com/wb/excel/api/util/ClassUtil.java b/src/main/java/com/wb/excel/api/util/ClassUtil.java index 61b9e51..990fb71 100644 --- a/src/main/java/com/wb/excel/api/util/ClassUtil.java +++ b/src/main/java/com/wb/excel/api/util/ClassUtil.java @@ -1,8 +1,6 @@ package com.wb.excel.api.util; -import com.wb.excel.api.annotation.ExcelCollection; - import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.*; @@ -93,11 +91,11 @@ public class ClassUtil { getMethodName.append(name.substring(1)); Method method = null; try { - method = pojoClass.getMethod(getMethodName.toString(), new Class[]{}); + method = pojoClass.getMethod(getMethodName.toString()); } catch (Exception e) { method = pojoClass.getMethod( - getMethodName.toString().replace("get", "is"), - new Class[]{}); + getMethodName.toString().replace("get", "is") + ); } return method; } @@ -115,7 +113,7 @@ public class ClassUtil { StringBuffer getMethodName = new StringBuffer("set"); getMethodName.append(name.substring(0, 1).toUpperCase()); getMethodName.append(name.substring(1)); - return pojoClass.getMethod(getMethodName.toString(), new Class[]{type}); + return pojoClass.getMethod(getMethodName.toString(), type); } /** @@ -172,31 +170,4 @@ public class ClassUtil { } return fieldList; } - - public static Object createObject(Class clazz) { - Object obj = null; - Method setMethod; - try { - if (clazz.equals(Map.class)) { - return new HashMap(); - } - obj = clazz.newInstance(); - Field[] fields = getClassFields(clazz); - for (Field field : fields) { - if (isCollection(field.getType())) { - ExcelCollection collection = field.getAnnotation(ExcelCollection.class); - setMethod = getMethod(field.getName(), clazz, field.getType()); - setMethod.invoke(obj, collection.type().newInstance()); - } else if (!isJavaClass(field)) { - setMethod = getMethod(field.getName(), clazz, field.getType()); - setMethod.invoke(obj, createObject(field.getType())); - } - } - - } catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException("创建对象异常"); - } - return obj; - } } diff --git a/src/main/java/com/wb/excel/api/util/ExcelUtil.java b/src/main/java/com/wb/excel/api/util/ExcelUtil.java deleted file mode 100644 index 48c5fae..0000000 --- a/src/main/java/com/wb/excel/api/util/ExcelUtil.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.wb.excel.api.util; - -import org.apache.poi.hssf.usermodel.HSSFDateUtil; -import org.apache.poi.ss.usermodel.Cell; - -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * Excel工具类. - * Created on 2014/9/1. - * - * @author - * @since 0.1.0 - */ -public class ExcelUtil { - - /** - * 获取单元格的值 - * - * @param cell 要获取值的单元格 - * @return 单元格的值 - */ - public static String getValue(Cell cell) { - if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { - // 返回布尔类型的值 - return String.valueOf(cell.getBooleanCellValue()); - } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC && !HSSFDateUtil.isCellDateFormatted(cell)) { - // 返回数值类型的值 - return String.valueOf(cell.getNumericCellValue()); - } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC && HSSFDateUtil.isCellDateFormatted(cell)) { - // 返回数值类型的值 - Date value = cell.getDateCellValue(); - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(value); - } else { - // 返回字符串类型的值 - return String.valueOf(cell.getStringCellValue()); - } - } -} diff --git a/src/main/java/com/wb/excel/api/util/ValidationUtil.java b/src/main/java/com/wb/excel/api/util/ValidationUtil.java deleted file mode 100644 index a06ef20..0000000 --- a/src/main/java/com/wb/excel/api/util/ValidationUtil.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.wb.excel.api.util; - - -import javax.validation.Validator; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * 验证工具类。提供一些通用简单的数据验证功能。 - * Created by DEV001 on 2014/8/1. - */ -public class ValidationUtil { - - private static Validator validator; - - /** - * 检查ID是否合法 - * - * @param id 要检查的ID - * @return true, ID合法 - */ - public static Boolean checkId(Long id) { - return !(null == id || id < 1); - } - - public static Boolean checkDate(String value) { - try { - Double.valueOf(value); - } catch (Exception e) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - try { - sdf.parse(value); - return true; - } catch (ParseException e1) { - e1.printStackTrace(); - } - return false; - } - return true; - } - - public static Boolean checkDatetime(String value) { - try { - Double.valueOf(value); - } catch (Exception e) { - List sdfList = new ArrayList<>(); - sdfList.add("yyyy-MM-dd HH:mm:ss"); - sdfList.add("yyyy-MM-dd hh:mm:ss"); - sdfList.add("yyyy/MM/dd HH:mm:ss"); - sdfList.add("yyyy/MM/dd hh:mm:ss"); - - for (int i = 0; i < sdfList.size(); i++) { - String sdfValue = sdfList.get(i); - SimpleDateFormat sdf = new SimpleDateFormat(sdfValue); - try { - sdf.parse(value); - return true; - } catch (ParseException ignored) { - } - } - return false; - } - return true; - } - - public static Boolean checkDouble(String value) { - try { - Double.parseDouble(value); - } catch (Exception e) { - return false; - } - return true; - } - - /** - * 检查一个字符串是否可以转为整数。 - * - * @param value 要检查的字符串 - * @return true || false - */ - public static Boolean checkInteger(String value) { - try { - Double d = Double.parseDouble(value); - int i = d.intValue(); - return d == i; - } catch (Exception e) { - return false; - } - } - - /** - * 检查一个字符串是否可以转为长整数。 - * - * @param value 要检查的字符串 - * @return true || false - */ - public static boolean checkLong(String value) { - try { - Double d = Double.parseDouble(value); - long l = d.longValue(); - return d == l; - } catch (Exception e) { - return false; - } - } - - /** - * 检查用户ID的列表是否合法 - * - * @param ids 要检查的ID列表 - * @return true, 输入的ID列表合法 - */ - public static Boolean checkIdList(List ids) { - return !(null == ids || ids.size() == 0); - } - - /** - * 检查字符串。不为空返回true;为空返回false。
- * 内容为空也认为是空 - * - * @param str 要检查的字符串 - * @return 检查的结果。true,检查通过;false,检查不通过。 - */ - public static Boolean checkString(String str) { - return !(null == str || 0 == str.trim().length()); - } - - /** - * 检查字符串的长度是否符合要求。
该方法不会删除字符串前后的空格 - * - * @param str 要进行判断的字符串 - * @param minLength 字符串限制的最小长度(包含) - * @param maxLength 字符串限制的最大长度(包含) - * @return 例如:限制长度 2,50。字符串为"aa"返回true,字符串为"a"返回false - */ - public static Boolean checkStringLength(String str, int minLength, int maxLength) { - if (null == str) { - return false; - } else { - if (str.length() >= minLength && str.length() <= maxLength) { - return true; - } - } - return false; - } - - /** - * 检查邮箱格式是否正确
- * - * @param email 要检查的邮箱地址 - * @return true, 格式正确;false,格式不正确
- * 例如:
- * 0123-abcd_ABCD@0123-abcd_ABCD.00aaBB--__.cc true
- * a@a.a true
- * tony@sina@qq.com false - */ - public static Boolean checkEmail(String email) { - //验证邮箱地址的正则表达式 - Pattern p; - p = Pattern.compile( - "^([a-zA-Z0-9]+[_|_|-|-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|-|-|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$"); - Matcher m = p.matcher(email); - return m.matches(); - } - - - /** - * 检查文件路径格式是否正确
- * - * @param filePath 要检查的文件路径 - * @return true, 格式正确;false,格式不正确
- * 例如:
- * C:\b.txt true
- * C:\abc\a.txt true
- * C:\windows\sys<\mfc.dll false - */ - public static Boolean checkFilePath(String filePath) { - //验证文件路径格式的正则表达式 - Pattern p = Pattern.compile("^(?(?:[a-zA-Z]:)?\\\\(?:[^\\\\\\?\\/\\*\\|<>:\"]+\\\\)+)(?(?[^\\\\\\?\\/\\*\\|<>:\"]+?)\\.(?[^.\\\\\\?\\/\\*\\|<>:\"]+))$"); - Matcher m = p.matcher(filePath); - return m.matches(); - } - - /** - * 检查电话号码格式是否正确。 - * - * @param phone 要检查的电话号码 - * @return true, 格式正确;false,格式不正确
- * 例如:
- * 13345661234 true
- * 16812341234 false
- * 0512-123456 false
- * 0512-2345678 true
- * 12345678 false
- * 22345678 true - */ - public static Boolean checkPhone(String phone) { - List list = new LinkedList<>(); - list.add(Pattern.compile("^[1][3,4,5,8][0-9]{9}$")); //验证手机号 - list.add(Pattern.compile("^[0][1-9]{1,2}[0-9]-[2-9][0-9]{6,7}$")); //验证带区号固定电话,区号后加“-” - list.add(Pattern.compile("^[2-9][0-9]{6,7}$")); //验证不带区号的固定电话 - list.add(Pattern.compile("([0][1-9]{1,2}[0-9])[2-9][0-9]{6,7}$")); - - Matcher matcher; - Boolean result = false; - for (Pattern pattern : list) { - matcher = pattern.matcher(phone); //遍历匹配 - result |= matcher.matches(); //对所有的匹配结果做或运算。 - } - return result; - } - - /** - * 检查URL是否正确 - * - * @param url - * @return - */ - public static Boolean checkUrl(String url) { - List list = new LinkedList<>(); - list.add(Pattern.compile("^(http|www|ftp|)?(://)?(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*((:\\d+)?)(/(\\w+(-\\w+)*))*(\\.?(\\w)*)(\\?)?(((\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*(\\w*%)*(\\w*\\?)*(\\w*:)*(\\w*\\+)*(\\w*\\.)*(\\w*&)*(\\w*-)*(\\w*=)*)*(\\w*)*)$")); - - Matcher matcher; - Boolean result = false; - for (Pattern pattern : list) { - matcher = pattern.matcher(url); //遍历匹配 - result |= matcher.matches(); //对所有的匹配结果做或运算。 - } - return result; - } - -} diff --git a/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java b/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java deleted file mode 100644 index e46319f..0000000 --- a/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.wb.excel.api.util; - -import com.wb.excel.api.entity.DataVerifyResult; -import com.wb.excel.api.entity.ExcelVerifyEntity; -import com.wb.excel.api.interfaces.IExcelVerifyHandler; - -/** - * *************************************************************** - *

- *

- * Copyright (c) 2014 –
- *  ColumnDescription:
- * ***************************************************************
- * 
- */ -public class VerifyDataUtil { - private final static DataVerifyResult DEFAULT_RESULT = new DataVerifyResult( - true); - - private void addVerifyResult(DataVerifyResult hanlderResult, - DataVerifyResult result) { - if (!hanlderResult.isSuccess()) { - result.setSuccess(false); - result.setMsg((StringUtils.isEmpty(result.getMsg()) ? "" : result.getMsg() + " , ") - + hanlderResult.getMsg()); - } - } - - public DataVerifyResult verifyData(Object object, Object value, String name, String showName, - ExcelVerifyEntity verify, IExcelVerifyHandler excelVerifyHandler) { - if (verify == null) { - return DEFAULT_RESULT; - } - DataVerifyResult result = new DataVerifyResult(true, ""); - if (verify.isNotNull()) { - addVerifyResult(BaseVerifyUtil.notNull(showName, value), result); - } - if (verify.isEmail()) { - addVerifyResult(BaseVerifyUtil.isEmail(showName, value), result); - } - if (verify.isMobile()) { - addVerifyResult(BaseVerifyUtil.isMobile(showName, value), result); - } - if (verify.isTel()) { - addVerifyResult(BaseVerifyUtil.isTel(showName, value), result); - } - if (verify.getMaxLength() != -1) { - addVerifyResult(BaseVerifyUtil.maxLength(showName, value, verify.getMaxLength()), result); - } - if (verify.getMinLength() != -1) { - addVerifyResult(BaseVerifyUtil.minLength(showName, value, verify.getMinLength()), result); - } - if (StringUtils.isNotEmpty(verify.getRegex())) { - addVerifyResult( - BaseVerifyUtil.regex(showName, value, verify.getRegex(), verify.getRegexTip()), - result); - } - if (verify.isInterHandler()) { - addVerifyResult(excelVerifyHandler.verifyHandler(object, name, value), result); - } - return result; - - } -}