| @@ -5,7 +5,7 @@ import java.io.FileInputStream; | |||
| import java.io.FileNotFoundException; | |||
| import java.io.IOException; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -23,8 +23,13 @@ class FileLoade { | |||
| FileInputStream fileis = null; | |||
| ByteArrayOutputStream baos = null; | |||
| try { | |||
| String path = POIPublicUtil.getWebRootPath(url); | |||
| fileis = new FileInputStream(path); | |||
| //先用绝对路径查询,再查询相对路径 | |||
| try { | |||
| fileis = new FileInputStream(url); | |||
| } catch (FileNotFoundException e) { | |||
| String path = PoiPublicUtil.getWebRootPath(url); | |||
| fileis = new FileInputStream(path); | |||
| } | |||
| baos = new ByteArrayOutputStream(); | |||
| byte[] buffer = new byte[1024]; | |||
| int len; | |||
| @@ -34,9 +39,9 @@ class FileLoade { | |||
| baos.flush(); | |||
| return baos.toByteArray(); | |||
| } catch (FileNotFoundException e) { | |||
| LOGGER.error(e.getMessage(),e); | |||
| LOGGER.error(e.getMessage(), e); | |||
| } catch (IOException e) { | |||
| LOGGER.error(e.getMessage(),e); | |||
| LOGGER.error(e.getMessage(), e); | |||
| } finally { | |||
| try { | |||
| if (fileis != null) | |||
| @@ -44,7 +49,7 @@ class FileLoade { | |||
| if (fileis != null) | |||
| baos.close(); | |||
| } catch (IOException e) { | |||
| LOGGER.error(e.getMessage(),e); | |||
| LOGGER.error(e.getMessage(), e); | |||
| } | |||
| } | |||
| LOGGER.error(fileis + "这个路径文件没有找到,请查询"); | |||
| @@ -24,6 +24,9 @@ import org.jeecgframework.poi.excel.export.template.ExcelExportOfTemplateUtil; | |||
| */ | |||
| public final class ExcelExportUtil { | |||
| private ExcelExportUtil() { | |||
| } | |||
| /** | |||
| * @param entity | |||
| * 表格标题属性 | |||
| @@ -23,7 +23,10 @@ import org.slf4j.LoggerFactory; | |||
| * @version 1.0 | |||
| */ | |||
| @SuppressWarnings({ "unchecked" }) | |||
| public class ExcelImportUtil { | |||
| public final class ExcelImportUtil { | |||
| private ExcelImportUtil() { | |||
| } | |||
| private static final Logger LOGGER = LoggerFactory.getLogger(ExcelImportUtil.class); | |||
| @@ -23,7 +23,7 @@ import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | |||
| import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||
| import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||
| import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -120,7 +120,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| excelParams.add(indexExcelEntity(entity)); | |||
| } | |||
| // 得到所有字段 | |||
| Field fileds[] = POIPublicUtil.getClassFields(pojoClass); | |||
| Field fileds[] = PoiPublicUtil.getClassFields(pojoClass); | |||
| ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
| String targetId = etarget == null ? null : etarget.value(); | |||
| getAllExcelField(entity.getExclusions(), targetId, fileds, excelParams, pojoClass, null); | |||
| @@ -33,7 +33,7 @@ import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.entity.params.MergeEntity; | |||
| import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | |||
| import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| /** | |||
| * 提供POI基础操作服务 | |||
| @@ -164,7 +164,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); | |||
| BufferedImage bufferImg; | |||
| try { | |||
| String path = POIPublicUtil.getWebRootPath(imagePath); | |||
| String path = PoiPublicUtil.getWebRootPath(imagePath); | |||
| path = path.replace("WEB-INF/classes/", ""); | |||
| path = path.replace("file:/", ""); | |||
| bufferImg = ImageIO.read(new File(path)); | |||
| @@ -346,7 +346,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| * @date 2013年11月25日 | |||
| */ | |||
| public int getImageType(byte[] value) { | |||
| String type = POIPublicUtil.getFileExtendName(value); | |||
| String type = PoiPublicUtil.getFileExtendName(value); | |||
| if (type.equalsIgnoreCase("JPG")) { | |||
| return Workbook.PICTURE_TYPE_JPEG; | |||
| } else if (type.equalsIgnoreCase("PNG")) { | |||
| @@ -18,7 +18,7 @@ import org.jeecgframework.poi.excel.annotation.ExcelCollection; | |||
| import org.jeecgframework.poi.excel.annotation.ExcelEntity; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.handler.inter.IExcelDataHandler; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| /** | |||
| * 导出基础处理,不设计POI,只设计对象,保证复用性 | |||
| @@ -91,23 +91,23 @@ public class ExportBase { | |||
| for (int i = 0; i < fields.length; i++) { | |||
| Field field = fields[i]; | |||
| // 先判断是不是collection,在判断是不是java自带对象,之后就是我们自己的对象了 | |||
| if (POIPublicUtil.isNotUserExcelUserThis(exclusionsList, field, targetId)) { | |||
| if (PoiPublicUtil.isNotUserExcelUserThis(exclusionsList, field, targetId)) { | |||
| continue; | |||
| } | |||
| // 首先判断Excel 可能一下特殊数据用户回自定义处理 | |||
| if (field.getAnnotation(Excel.class) != null) { | |||
| excelParams.add(createExcelExportEntity(field, targetId, pojoClass, getMethods)); | |||
| } else if (POIPublicUtil.isCollection(field.getType())) { | |||
| } else if (PoiPublicUtil.isCollection(field.getType())) { | |||
| ExcelCollection excel = field.getAnnotation(ExcelCollection.class); | |||
| ParameterizedType pt = (ParameterizedType) field.getGenericType(); | |||
| Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0]; | |||
| List<ExcelExportEntity> list = new ArrayList<ExcelExportEntity>(); | |||
| getAllExcelField(exclusions, StringUtils.isNotEmpty(excel.id()) ? excel.id() | |||
| : targetId, POIPublicUtil.getClassFields(clz), list, clz, null); | |||
| : targetId, PoiPublicUtil.getClassFields(clz), list, clz, null); | |||
| excelEntity = new ExcelExportEntity(); | |||
| excelEntity.setName(getExcelName(excel.name(), targetId)); | |||
| excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId)); | |||
| excelEntity.setMethod(POIPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| excelEntity.setMethod(PoiPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| excelEntity.setList(list); | |||
| excelParams.add(excelEntity); | |||
| } else { | |||
| @@ -115,10 +115,10 @@ public class ExportBase { | |||
| if (getMethods != null) { | |||
| newMethods.addAll(getMethods); | |||
| } | |||
| newMethods.add(POIPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| ExcelEntity excel = field.getAnnotation(ExcelEntity.class); | |||
| getAllExcelField(exclusions, StringUtils.isNotEmpty(excel.id()) ? excel.id() | |||
| : targetId, POIPublicUtil.getClassFields(field.getType()), excelParams, | |||
| : targetId, PoiPublicUtil.getClassFields(field.getType()), excelParams, | |||
| field.getType(), newMethods); | |||
| } | |||
| } | |||
| @@ -222,7 +222,7 @@ public class ExportBase { | |||
| : excel.format()); | |||
| excelEntity.setStatistics(excel.isStatistics()); | |||
| String fieldname = field.getName(); | |||
| excelEntity.setMethod(POIPublicUtil.getMethod(fieldname, pojoClass)); | |||
| excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass)); | |||
| } | |||
| /** | |||
| @@ -27,7 +27,7 @@ import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | |||
| import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||
| import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||
| import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -70,7 +70,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| Map<String, Integer> titlemap = getTitleMap(params, sheet); | |||
| Drawing patriarch = sheet.createDrawingPatriarch(); | |||
| // 得到所有字段 | |||
| Field[] fileds = POIPublicUtil.getClassFields(pojoClass); | |||
| Field[] fileds = PoiPublicUtil.getClassFields(pojoClass); | |||
| ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
| String targetId = null; | |||
| if (etarget != null) { | |||
| @@ -201,7 +201,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| if (params.indexOf(".") != -1) { | |||
| String[] paramsArr = params.split("\\."); | |||
| return String | |||
| .valueOf(POIPublicUtil.getValueDoWhile(map.get(paramsArr[0]), paramsArr, 1)); | |||
| .valueOf(PoiPublicUtil.getValueDoWhile(map.get(paramsArr[0]), paramsArr, 1)); | |||
| } | |||
| return map.containsKey(params) ? map.get(params).toString() : ""; | |||
| } | |||
| @@ -257,7 +257,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| */ | |||
| private void setValueForCellByMap(Cell cell, Map<String, Object> map) throws Exception { | |||
| int cellType = cell.getCellType(); | |||
| if (cellType != Cell.CELL_TYPE_STRING && cellType == Cell.CELL_TYPE_NUMERIC) { | |||
| if (cellType != Cell.CELL_TYPE_STRING && cellType != Cell.CELL_TYPE_NUMERIC) { | |||
| return; | |||
| } | |||
| String oldString; | |||
| @@ -340,7 +340,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| row.createCell(i); | |||
| } | |||
| for (int i = 0, max = columns.size(); i < max; i++) { | |||
| String val = String.valueOf(POIPublicUtil.getValueDoWhile(t, columns.get(i) | |||
| String val = String.valueOf(PoiPublicUtil.getValueDoWhile(t, columns.get(i) | |||
| .split("\\."), 0)); | |||
| row.getCell(i + columnIndex).setCellValue(val); | |||
| tempCreateCellSet.add(row.getRowNum() + "_" + (i + columnIndex)); | |||
| @@ -153,6 +153,9 @@ public class CellValueServer { | |||
| if (xclass.equals("class java.lang.Long") || xclass.equals("long")) { | |||
| return Long.valueOf(String.valueOf(result)); | |||
| } | |||
| if (xclass.equals("class java.lang.Float") || xclass.equals("float")) { | |||
| return Float.valueOf(String.valueOf(result)); | |||
| } | |||
| if (xclass.equals("class java.lang.Integer") || xclass.equals("int")) { | |||
| return Integer.valueOf(String.valueOf(result)); | |||
| } | |||
| @@ -39,7 +39,7 @@ import org.jeecgframework.poi.excel.imports.base.ImportBaseService; | |||
| import org.jeecgframework.poi.excel.imports.verifys.VerifyHandlerServer; | |||
| import org.jeecgframework.poi.exception.excel.ExcelImportException; | |||
| import org.jeecgframework.poi.exception.excel.enums.ExcelImportEnum; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -85,9 +85,9 @@ public class ExcelImportServer extends ImportBaseService { | |||
| Map<Integer, String> titlemap, String targetId, | |||
| Map<String, PictureData> pictures, ImportParams params) | |||
| throws Exception { | |||
| Collection collection = (Collection) POIPublicUtil.getMethod(param.getName(), | |||
| Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), | |||
| object.getClass()).invoke(object, new Object[] {}); | |||
| Object entity = POIPublicUtil.createObject(param.getType(), targetId); | |||
| Object entity = PoiPublicUtil.createObject(param.getType(), targetId); | |||
| String picId; | |||
| boolean isUsed = false;// 是否需要加上这个对象 | |||
| for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++) { | |||
| @@ -159,7 +159,7 @@ public class ExcelImportServer extends ImportBaseService { | |||
| List collection = new ArrayList(); | |||
| Map<String, ExcelImportEntity> excelParams = new HashMap<String, ExcelImportEntity>(); | |||
| List<ExcelCollectionParams> excelCollection = new ArrayList<ExcelCollectionParams>(); | |||
| Field fileds[] = POIPublicUtil.getClassFields(pojoClass); | |||
| Field fileds[] = PoiPublicUtil.getClassFields(pojoClass); | |||
| ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
| String targetId = null; | |||
| if (etarget != null) { | |||
| @@ -197,7 +197,7 @@ public class ExcelImportServer extends ImportBaseService { | |||
| addListContinue(object, param, row, titlemap, targetId, pictures, params); | |||
| } | |||
| } else { | |||
| object = POIPublicUtil.createObject(pojoClass, targetId); | |||
| object = PoiPublicUtil.createObject(pojoClass, targetId); | |||
| try { | |||
| for (int i = row.getFirstCellNum(), le = row.getLastCellNum(); i < le; i++) { | |||
| Cell cell = row.getCell(i); | |||
| @@ -259,10 +259,10 @@ public class ExcelImportServer extends ImportBaseService { | |||
| LOGGER.debug(" start to read excel by is ,startTime is {}", new Date().getTime()); | |||
| } | |||
| if (isXSSFWorkbook) { | |||
| pictures = POIPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i), | |||
| pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i), | |||
| (XSSFWorkbook) book); | |||
| } else { | |||
| pictures = POIPublicUtil.getSheetPictrues03((HSSFSheet) book.getSheetAt(i), | |||
| pictures = PoiPublicUtil.getSheetPictrues03((HSSFSheet) book.getSheetAt(i), | |||
| (HSSFWorkbook) book); | |||
| } | |||
| if (LOGGER.isDebugEnabled()) { | |||
| @@ -328,9 +328,9 @@ public class ExcelImportServer extends ImportBaseService { | |||
| PictureData image = pictures.get(picId); | |||
| byte[] data = image.getData(); | |||
| String fileName = "pic" + Math.round(Math.random() * 100000000000L); | |||
| fileName += "." + POIPublicUtil.getFileExtendName(data); | |||
| fileName += "." + PoiPublicUtil.getFileExtendName(data); | |||
| if (excelParams.get(titleString).getSaveType() == 1) { | |||
| String path = POIPublicUtil.getWebRootPath(getSaveUrl(excelParams.get(titleString), | |||
| String path = PoiPublicUtil.getWebRootPath(getSaveUrl(excelParams.get(titleString), | |||
| object)); | |||
| File savefile = new File(path); | |||
| if (!savefile.exists()) { | |||
| @@ -20,7 +20,7 @@ import org.jeecgframework.poi.excel.entity.ImportParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelCollectionParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelImportEntity; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelVerifyEntity; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| /** | |||
| * 导入基础和,普通方法和Sax共用 | |||
| @@ -104,10 +104,10 @@ public class ImportBaseService { | |||
| ExcelImportEntity excelEntity = null; | |||
| for (int i = 0; i < fields.length; i++) { | |||
| Field field = fields[i]; | |||
| if (POIPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { | |||
| if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { | |||
| continue; | |||
| } | |||
| if (POIPublicUtil.isCollection(field.getType())) { | |||
| if (PoiPublicUtil.isCollection(field.getType())) { | |||
| // 集合对象设置属性 | |||
| ExcelCollectionParams collection = new ExcelCollectionParams(); | |||
| collection.setName(field.getName()); | |||
| @@ -115,18 +115,18 @@ public class ImportBaseService { | |||
| ParameterizedType pt = (ParameterizedType) field.getGenericType(); | |||
| Class<?> clz = (Class<?>) pt.getActualTypeArguments()[0]; | |||
| collection.setType(clz); | |||
| getExcelFieldList(targetId, POIPublicUtil.getClassFields(clz), clz, temp, null); | |||
| getExcelFieldList(targetId, PoiPublicUtil.getClassFields(clz), clz, temp, null); | |||
| collection.setExcelParams(temp); | |||
| excelCollection.add(collection); | |||
| } else if (POIPublicUtil.isJavaClass(field)) { | |||
| } else if (PoiPublicUtil.isJavaClass(field)) { | |||
| addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, excelParams); | |||
| } else { | |||
| List<Method> newMethods = new ArrayList<Method>(); | |||
| if (getMethods != null) { | |||
| newMethods.addAll(getMethods); | |||
| } | |||
| newMethods.add(POIPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| getAllExcelField(targetId, POIPublicUtil.getClassFields(field.getType()), | |||
| newMethods.add(PoiPublicUtil.getMethod(field.getName(), pojoClass)); | |||
| getAllExcelField(targetId, PoiPublicUtil.getClassFields(field.getType()), | |||
| excelParams, excelCollection, field.getType(), newMethods); | |||
| } | |||
| } | |||
| @@ -136,7 +136,7 @@ public class ImportBaseService { | |||
| Excel excel, Class<?> pojoClass) throws Exception { | |||
| excelEntity.setName(getExcelName(excel.name(), targetId)); | |||
| String fieldname = field.getName(); | |||
| excelEntity.setMethod(POIPublicUtil.getMethod(fieldname, pojoClass, field.getType())); | |||
| excelEntity.setMethod(PoiPublicUtil.getMethod(fieldname, pojoClass, field.getType())); | |||
| if (StringUtils.isEmpty(excel.importFormat())) { | |||
| excelEntity.setFormat(excel.format()); | |||
| } else { | |||
| @@ -150,10 +150,10 @@ public class ImportBaseService { | |||
| ExcelImportEntity excelEntity = null; | |||
| for (int i = 0; i < fields.length; i++) { | |||
| Field field = fields[i]; | |||
| if (POIPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { | |||
| if (PoiPublicUtil.isNotUserExcelUserThis(null, field, targetId)) { | |||
| continue; | |||
| } | |||
| if (POIPublicUtil.isJavaClass(field)) { | |||
| if (PoiPublicUtil.isJavaClass(field)) { | |||
| addEntityToMap(targetId, field, excelEntity, pojoClass, getMethods, temp); | |||
| } else { | |||
| List<Method> newMethods = new ArrayList<Method>(); | |||
| @@ -161,8 +161,8 @@ public class ImportBaseService { | |||
| newMethods.addAll(getMethods); | |||
| } | |||
| newMethods | |||
| .add(POIPublicUtil.getMethod(field.getName(), pojoClass, field.getType())); | |||
| getExcelFieldList(targetId, POIPublicUtil.getClassFields(field.getType()), | |||
| .add(PoiPublicUtil.getMethod(field.getName(), pojoClass, field.getType())); | |||
| getExcelFieldList(targetId, PoiPublicUtil.getClassFields(field.getType()), | |||
| field.getType(), temp, newMethods); | |||
| } | |||
| } | |||
| @@ -199,7 +199,7 @@ public class ImportBaseService { | |||
| public void saveThisExcel(ImportParams params, Class<?> pojoClass, boolean isXSSFWorkbook, | |||
| Workbook book) throws Exception { | |||
| String path = POIPublicUtil.getWebRootPath(getSaveExcelUrl(params, pojoClass)); | |||
| String path = PoiPublicUtil.getWebRootPath(getSaveExcelUrl(params, pojoClass)); | |||
| File savefile = new File(path); | |||
| if (!savefile.exists()) { | |||
| savefile.mkdirs(); | |||
| @@ -17,7 +17,7 @@ import org.jeecgframework.poi.excel.imports.CellValueServer; | |||
| import org.jeecgframework.poi.excel.imports.base.ImportBaseService; | |||
| import org.jeecgframework.poi.exception.excel.ExcelImportException; | |||
| import org.jeecgframework.poi.handler.inter.IExcelReadRowHanlder; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -67,7 +67,7 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| private void initParams(Class<?> pojoClass, ImportParams params) { | |||
| try { | |||
| Field fileds[] = POIPublicUtil.getClassFields(pojoClass); | |||
| Field fileds[] = PoiPublicUtil.getClassFields(pojoClass); | |||
| ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
| if (etarget != null) { | |||
| targetId = etarget.value(); | |||
| @@ -122,7 +122,7 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| if (object != null && hanlder != null) { | |||
| hanlder.hanlder(object); | |||
| } | |||
| object = POIPublicUtil.createObject(pojoClass, targetId); | |||
| object = PoiPublicUtil.createObject(pojoClass, targetId); | |||
| SaxReadCellEntity entity; | |||
| for (int i = 0, le = datas.size(); i < le; i++) { | |||
| entity = datas.get(i); | |||
| @@ -155,9 +155,9 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| private void addListContinue(Object object, ExcelCollectionParams param, | |||
| List<SaxReadCellEntity> datas, Map<Integer, String> titlemap, | |||
| String targetId, ImportParams params) throws Exception { | |||
| Collection collection = (Collection) POIPublicUtil.getMethod(param.getName(), | |||
| Collection collection = (Collection) PoiPublicUtil.getMethod(param.getName(), | |||
| object.getClass()).invoke(object, new Object[] {}); | |||
| Object entity = POIPublicUtil.createObject(param.getType(), targetId); | |||
| Object entity = PoiPublicUtil.createObject(param.getType(), targetId); | |||
| boolean isUsed = false;// 是否需要加上这个对象 | |||
| for (int i = 0; i < datas.size(); i++) { | |||
| String titleString = (String) titlemap.get(i); | |||
| @@ -0,0 +1,218 @@ | |||
| package org.jeecgframework.poi.util; | |||
| import java.util.Map; | |||
| import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||
| /** | |||
| * EasyPoi的el 表达式支持工具类 | |||
| * @author JueYue | |||
| * @date 2015年4月25日 下午12:13:21 | |||
| */ | |||
| public final class PoiElUtil { | |||
| private static final String LENGTH = "le:"; | |||
| private static final String FORMAT_DATE = "fd:"; | |||
| private static final String FORMAT_NUMBER = "fn:"; | |||
| private static final String IF_DELETE = "!if:"; | |||
| private static final String EMPTY = ""; | |||
| private static final String LEFT_BRACKET = "("; | |||
| private static final String RIGHT_BRACKET = ")"; | |||
| private PoiElUtil() { | |||
| } | |||
| /** | |||
| * 解析字符串,支持 le,fd,fn,!if,三目 | |||
| * @param obj | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public static Object eval(String text, Map<String, Object> map) throws Exception { | |||
| String tempText = new String(text); | |||
| Object obj = innerEval(text, map); | |||
| //如果没有被处理而且这个值找map中存在就处理这个值 | |||
| if (tempText.equals(obj.toString()) && map.containsKey(tempText.split("\\.")[0])) { | |||
| return PoiPublicUtil.getParamsValue(tempText, map); | |||
| } | |||
| return obj; | |||
| } | |||
| /** | |||
| * 解析字符串,支持 le,fd,fn,!if,三目 | |||
| * @param obj | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| public static Object innerEval(String text, Map<String, Object> map) throws Exception { | |||
| if (text.indexOf("?") != -1 && text.indexOf(":") != -1) { | |||
| return trinocular(text, map); | |||
| } | |||
| if (text.indexOf(LENGTH) != -1) { | |||
| return length(text, map); | |||
| } | |||
| if (text.indexOf(FORMAT_DATE) != -1) { | |||
| return formatDate(text, map); | |||
| } | |||
| if (text.indexOf(FORMAT_NUMBER) != -1) { | |||
| return formatNumber(text, map); | |||
| } | |||
| if (text.indexOf(IF_DELETE) != -1) { | |||
| return ifDelete(text, map); | |||
| } | |||
| if (text.startsWith("'")) { | |||
| return text.replace("'", ""); | |||
| } | |||
| return text; | |||
| } | |||
| /** | |||
| * 是不是删除列 | |||
| * @param text | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| private static Object ifDelete(String text, Map<String, Object> map) throws Exception { | |||
| //把多个空格变成一个空格 | |||
| text = text.replaceAll("\\s{1,}", " ").trim(); | |||
| String[] keys = getKey(IF_DELETE, text).split(" "); | |||
| text = text.replace(IF_DELETE, EMPTY); | |||
| return isTrue(keys, map); | |||
| } | |||
| /** | |||
| * 是不是真 | |||
| * @param keys | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| private static Boolean isTrue(String[] keys, Map<String, Object> map) throws Exception { | |||
| if (keys.length == 0) { | |||
| String constant = null; | |||
| if ((constant = isConstant(keys[0])) != null) { | |||
| return Boolean.valueOf(constant); | |||
| } | |||
| return Boolean.valueOf(PoiPublicUtil.getParamsValue(keys[0], map).toString()); | |||
| } | |||
| if (keys.length == 3) { | |||
| Object first = eval(keys[0], map); | |||
| Object second = eval(keys[2], map); | |||
| return PoiFunctionUtil.isTrue(first, keys[1], second); | |||
| } | |||
| throw new ExcelExportException("判断参数不对"); | |||
| } | |||
| /** | |||
| * 判断是不是常量 | |||
| * @param string | |||
| * @return | |||
| */ | |||
| private static String isConstant(String param) { | |||
| if (param.indexOf("'") != -1) { | |||
| return param.replace("'", ""); | |||
| } | |||
| return null; | |||
| } | |||
| /** | |||
| * 格式化数字 | |||
| * @param text | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| private static Object formatNumber(String text, Map<String, Object> map) throws Exception { | |||
| String[] key = getKey(FORMAT_NUMBER, text).split(";"); | |||
| text = text.replace(FORMAT_NUMBER, EMPTY); | |||
| return innerEval( | |||
| replacinnerEvalue(text, | |||
| PoiFunctionUtil.formatNumber(PoiPublicUtil.getParamsValue(key[0], map), key[1])), | |||
| map); | |||
| } | |||
| /** | |||
| * 格式化时间 | |||
| * @param text | |||
| * @param map | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| private static Object formatDate(String text, Map<String, Object> map) throws Exception { | |||
| String[] key = getKey(FORMAT_DATE, text).split(";"); | |||
| text = text.replace(FORMAT_DATE, EMPTY); | |||
| return innerEval( | |||
| replacinnerEvalue(text, | |||
| PoiFunctionUtil.formatDate(PoiPublicUtil.getParamsValue(key[0], map), key[1])), map); | |||
| } | |||
| /** | |||
| * 计算这个的长度 | |||
| * @param text | |||
| * @param map | |||
| * @throws Exception | |||
| */ | |||
| private static Object length(String text, Map<String, Object> map) throws Exception { | |||
| String key = getKey(LENGTH, text); | |||
| text = text.replace(LENGTH, EMPTY); | |||
| Object val = PoiPublicUtil.getParamsValue(key, map); | |||
| return innerEval(replacinnerEvalue(text, PoiFunctionUtil.length(val)), map); | |||
| } | |||
| private static String replacinnerEvalue(String text, Object val) { | |||
| StringBuilder sb = new StringBuilder(); | |||
| sb.append(text.substring(0, text.indexOf(LEFT_BRACKET))); | |||
| sb.append(" "); | |||
| sb.append(val); | |||
| sb.append(" "); | |||
| sb.append(text.substring(text.indexOf(RIGHT_BRACKET) + 1, text.length())); | |||
| return sb.toString().trim(); | |||
| } | |||
| private static String getKey(String prefix, String text) { | |||
| int leftBracket = 1, rigthBracket = 0, position = 0; | |||
| int index = text.indexOf(prefix) + prefix.length(); | |||
| while (text.charAt(index) == " ".charAt(0)) { | |||
| text = text.substring(0, index) + text.substring(index + 1, text.length()); | |||
| } | |||
| for (int i = text.indexOf(prefix + LEFT_BRACKET) + prefix.length() + 1; i < text.length(); i++) { | |||
| if (text.charAt(i) == LEFT_BRACKET.charAt(0)) { | |||
| leftBracket++; | |||
| } | |||
| if (text.charAt(i) == RIGHT_BRACKET.charAt(0)) { | |||
| rigthBracket++; | |||
| } | |||
| if (leftBracket == rigthBracket) { | |||
| position = i; | |||
| break; | |||
| } | |||
| } | |||
| return text.substring(text.indexOf(prefix + LEFT_BRACKET) + 1 + prefix.length(), position) | |||
| .trim(); | |||
| } | |||
| public static void main(String[] args) { | |||
| System.out.println(getKey(IF_DELETE, "测试 " + IF_DELETE + " (小明)")); | |||
| } | |||
| /** | |||
| * 三目运算 | |||
| * @return | |||
| * @throws Exception | |||
| */ | |||
| private static Object trinocular(String text, Map<String, Object> map) throws Exception { | |||
| //把多个空格变成一个空格 | |||
| text = text.replaceAll("\\s{1,}", " ").trim(); | |||
| String testText = text.substring(0, text.indexOf("?")); | |||
| text = text.substring(text.indexOf("?") + 1, text.length()).trim(); | |||
| text = innerEval(text, map).toString(); | |||
| String[] keys = text.split(":"); | |||
| Object first = eval(keys[0].trim(), map); | |||
| Object second = eval(keys[1].trim(), map); | |||
| return isTrue(testText.split(" "), map) ? first : second; | |||
| } | |||
| } | |||
| @@ -0,0 +1,147 @@ | |||
| package org.jeecgframework.poi.util; | |||
| import java.lang.reflect.Array; | |||
| import java.text.DecimalFormat; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.Collection; | |||
| import java.util.Map; | |||
| import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||
| /** | |||
| * if else,length,for each,fromatNumber,formatDate | |||
| * 满足模板的 el 表达式支持 | |||
| * @author JueYue | |||
| * @date 2015年4月24日 下午8:04:02 | |||
| */ | |||
| public final class PoiFunctionUtil { | |||
| private static final String TWO_DECIMAL_STR = "###.00"; | |||
| private static final String THREE_DECIMAL_STR = "###.000"; | |||
| private static final DecimalFormat TWO_DECIMAL = new DecimalFormat(TWO_DECIMAL_STR); | |||
| private static final DecimalFormat THREE_DECIMAL = new DecimalFormat(THREE_DECIMAL_STR); | |||
| private static final String DAY_STR = "yyyy-MM-dd"; | |||
| private static final String TIME_STR = "yyyy-MM-dd HH:mm:ss"; | |||
| private static final String TIME__NO_S_STR = "yyyy-MM-dd HH:mm"; | |||
| private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat(DAY_STR); | |||
| private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat(TIME_STR); | |||
| private static final SimpleDateFormat TIME__NO_S_FORMAT = new SimpleDateFormat(TIME__NO_S_STR); | |||
| private PoiFunctionUtil() { | |||
| } | |||
| /** | |||
| * 获取对象的长度 | |||
| * @param obj | |||
| * @return | |||
| */ | |||
| @SuppressWarnings("rawtypes") | |||
| public static int length(Object obj) { | |||
| if (obj == null) { | |||
| return 0; | |||
| } | |||
| if (obj instanceof Map) { | |||
| return ((Map) obj).size(); | |||
| } | |||
| if (obj instanceof Collection) { | |||
| return ((Collection) obj).size(); | |||
| } | |||
| if (obj.getClass().isArray()) { | |||
| return Array.getLength(obj); | |||
| } | |||
| return String.valueOf(obj).length(); | |||
| } | |||
| /** | |||
| * 格式化数字 | |||
| * @param obj | |||
| * @throws NumberFormatException | |||
| * @return | |||
| */ | |||
| public static String formatNumber(Object obj, String format) { | |||
| if (obj == null) { | |||
| return ""; | |||
| } | |||
| double number = Double.valueOf(obj.toString()); | |||
| DecimalFormat decimalFormat = null; | |||
| if (TWO_DECIMAL.equals(format)) { | |||
| decimalFormat = TWO_DECIMAL; | |||
| } else if (THREE_DECIMAL_STR.equals(format)) { | |||
| decimalFormat = THREE_DECIMAL; | |||
| } else { | |||
| decimalFormat = new DecimalFormat(format); | |||
| } | |||
| return decimalFormat.format(number); | |||
| } | |||
| /** | |||
| * 格式化时间 | |||
| * @param obj | |||
| * @return | |||
| */ | |||
| public static String formatDate(Object obj, String format) { | |||
| if (obj == null) { | |||
| return ""; | |||
| } | |||
| SimpleDateFormat dateFormat = null; | |||
| if (DAY_STR.equals(format)) { | |||
| dateFormat = DAY_FORMAT; | |||
| } else if (TIME_STR.equals(format)) { | |||
| dateFormat = TIME_FORMAT; | |||
| } else if (TIME__NO_S_STR.equals(format)) { | |||
| dateFormat = TIME__NO_S_FORMAT; | |||
| } else { | |||
| dateFormat = new SimpleDateFormat(format); | |||
| } | |||
| return dateFormat.format(obj); | |||
| } | |||
| /** | |||
| * 判断是不是成功 | |||
| * @param first | |||
| * @param operator | |||
| * @param second | |||
| * @return | |||
| */ | |||
| public static boolean isTrue(Object first, String operator, Object second) { | |||
| if (">".endsWith(operator)) { | |||
| return isGt(first, second); | |||
| } else if ("<".endsWith(operator)) { | |||
| return isGt(second, first); | |||
| } else if ("==".endsWith(operator)) { | |||
| if (first != null && second != null) { | |||
| return first.equals(second); | |||
| } | |||
| return first == second; | |||
| } else if ("!=".endsWith(operator)) { | |||
| if (first != null && second != null) { | |||
| return !first.equals(second); | |||
| } | |||
| return first != second; | |||
| } else { | |||
| throw new ExcelExportException("占不支持改操作符"); | |||
| } | |||
| } | |||
| /** | |||
| * 前者是不是大于后者 | |||
| * @param first | |||
| * @param second | |||
| * @return | |||
| */ | |||
| private static boolean isGt(Object first, Object second) { | |||
| if (first == null) { | |||
| return false; | |||
| } | |||
| if (second == null) { | |||
| return false; | |||
| } | |||
| double one = Double.valueOf(first.toString()); | |||
| double two = Double.valueOf(second.toString()); | |||
| return one > two; | |||
| } | |||
| } | |||
| @@ -42,9 +42,9 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; | |||
| * @author JueYue | |||
| * @date 2015年4月5日 上午12:59:22 | |||
| */ | |||
| public final class POIPublicUtil { | |||
| public final class PoiPublicUtil { | |||
| private POIPublicUtil() { | |||
| private PoiPublicUtil() { | |||
| } | |||
| @@ -219,7 +219,7 @@ public final class POIPublicUtil { | |||
| public static String getWebRootPath(String filePath) { | |||
| try { | |||
| String path = POIPublicUtil.class.getClassLoader().getResource("").toURI().getPath(); | |||
| String path = PoiPublicUtil.class.getClassLoader().getResource("").toURI().getPath(); | |||
| path = path.replace("WEB-INF/classes/", ""); | |||
| path = path.replace("file:/", ""); | |||
| return path + filePath; | |||
| @@ -349,7 +349,7 @@ public final class POIPublicUtil { | |||
| type = entity.getUrl().split("/.")[entity.getUrl().split("/.").length - 1]; | |||
| } else { | |||
| result[0] = entity.getData(); | |||
| type = POIPublicUtil.getFileExtendName(entity.getData()); | |||
| type = PoiPublicUtil.getFileExtendName(entity.getData()); | |||
| } | |||
| result[1] = getImageType(type); | |||
| return result; | |||
| @@ -362,7 +362,7 @@ public final class POIPublicUtil { | |||
| * @param map | |||
| * @return | |||
| */ | |||
| private static Object getParamsValue(String params, Map<String, Object> map) throws Exception { | |||
| public static Object getParamsValue(String params, Map<String, Object> map) throws Exception { | |||
| if (params.indexOf(".") != -1) { | |||
| String[] paramsArr = params.split("\\."); | |||
| return getValueDoWhile(map.get(paramsArr[0]), paramsArr, 1); | |||
| @@ -12,10 +12,10 @@ import org.jeecgframework.poi.word.parse.ParseWord07; | |||
| * @date 2013-11-16 | |||
| * @version 1.0 | |||
| */ | |||
| public class WordExportUtil { | |||
| private WordExportUtil(){ | |||
| public final class WordExportUtil { | |||
| private WordExportUtil() { | |||
| } | |||
| /** | |||
| @@ -14,7 +14,7 @@ import org.apache.poi.xwpf.usermodel.XWPFTable; | |||
| import org.apache.poi.xwpf.usermodel.XWPFTableCell; | |||
| import org.apache.poi.xwpf.usermodel.XWPFTableRow; | |||
| import org.jeecgframework.poi.cache.WordCache; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.jeecgframework.poi.word.entity.MyXWPFDocument; | |||
| import org.jeecgframework.poi.word.entity.WordImageEntity; | |||
| import org.jeecgframework.poi.word.entity.params.ExcelListEntity; | |||
| @@ -45,7 +45,7 @@ public class ParseWord07 { | |||
| * @throws Exception | |||
| */ | |||
| private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { | |||
| Object[] isAndType = POIPublicUtil.getIsAndType(obj); | |||
| Object[] isAndType = PoiPublicUtil.getIsAndType(obj); | |||
| String picId; | |||
| try { | |||
| picId = currentRun.getParagraph().getDocument() | |||
| @@ -70,7 +70,7 @@ public class ParseWord07 { | |||
| */ | |||
| private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText, | |||
| List<Integer> runIndex, Map<String, Object> map) throws Exception { | |||
| Object obj = POIPublicUtil.getRealValue(currentText, map); | |||
| Object obj = PoiPublicUtil.getRealValue(currentText, map); | |||
| if (obj instanceof WordImageEntity) {// 如果是图片就设置为图片 | |||
| currentRun.setText("", 0); | |||
| addAnImage((WordImageEntity) obj, currentRun); | |||
| @@ -97,7 +97,7 @@ public class ParseWord07 { | |||
| String text = cell.getText().trim(); | |||
| // 判断是不是迭代输出 | |||
| if (text.startsWith("{{") && text.endsWith("}}") && text.indexOf("in ") != -1) { | |||
| return POIPublicUtil.getRealValue(text.replace("in ", "").trim(), map); | |||
| return PoiPublicUtil.getRealValue(text.replace("in ", "").trim(), map); | |||
| } | |||
| return null; | |||
| } | |||
| @@ -17,7 +17,7 @@ import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.export.base.ExportBase; | |||
| import org.jeecgframework.poi.exception.word.WordExportException; | |||
| import org.jeecgframework.poi.exception.word.enmus.WordExportEnum; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| import org.jeecgframework.poi.word.entity.params.ExcelListEntity; | |||
| /** | |||
| @@ -139,7 +139,7 @@ public class ExcelEntityParse extends ExportBase { | |||
| Map<String, Integer> titlemap = getTitleMap(table, index, entity.getHeadRows()); | |||
| try { | |||
| // 得到所有字段 | |||
| Field fileds[] = POIPublicUtil.getClassFields(entity.getClazz()); | |||
| Field fileds[] = PoiPublicUtil.getClassFields(entity.getClazz()); | |||
| ExcelTarget etarget = entity.getClazz().getAnnotation(ExcelTarget.class); | |||
| String targetId = null; | |||
| if (etarget != null) { | |||
| @@ -5,7 +5,7 @@ import java.util.List; | |||
| import org.apache.poi.xwpf.usermodel.XWPFTable; | |||
| import org.apache.poi.xwpf.usermodel.XWPFTableCell; | |||
| import org.apache.poi.xwpf.usermodel.XWPFTableRow; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| import org.jeecgframework.poi.util.PoiPublicUtil; | |||
| /** | |||
| * 处理和生成Map 类型的数据变成表格 | |||
| @@ -54,12 +54,12 @@ public final class ExcelMapParse { | |||
| .getTableCells() | |||
| .get(cellIndex) | |||
| .setText( | |||
| POIPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) | |||
| PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) | |||
| .toString()); | |||
| } | |||
| for (; cellIndex < params.length; cellIndex++) { | |||
| currentRow.createCell().setText( | |||
| POIPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) | |||
| PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) | |||
| .toString()); | |||
| } | |||
| } | |||
| @@ -7,6 +7,9 @@ public class UtilTest { | |||
| text = text.replace("{{", "").replace("}}", "").replaceAll("\\s{1,}", " ").trim(); | |||
| System.out.println(text); | |||
| System.out.println(text.length()); | |||
| } | |||
| } | |||
| @@ -0,0 +1,103 @@ | |||
| package org.jeecgframework.poi.util; | |||
| import static org.junit.Assert.*; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import junit.framework.Assert; | |||
| import org.junit.Test; | |||
| public class PoiElUtilTest { | |||
| @Test | |||
| public void testEval() throws Exception { | |||
| Map<String, Object> map = new HashMap<String, Object>(); | |||
| map.put("jueyue", "jueyue"); | |||
| //length 测试 | |||
| Object obj = PoiElUtil.eval("le:(jueyue)", map); | |||
| Assert.assertEquals("6", obj); | |||
| //format date 测试 | |||
| map.put("date", new Date()); | |||
| obj = PoiElUtil.eval("fd:(date;yyyy-MM-dd)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date;yyyy-MM-dd HH:mm:ss)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date;yyyy-MM-dd HH:mm)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date;yyyy/MM/dd HH:mm:ss)", map); | |||
| System.out.println(obj); | |||
| map.put("date2", new Date().getTime()); | |||
| obj = PoiElUtil.eval("fd:(date2;yyyy-MM-dd)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date2;yyyy-MM-dd HH:mm:ss)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date2;yyyy-MM-dd HH:mm)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fd:(date2;yyyy/MM/dd HH:mm:ss)", map); | |||
| System.out.println(obj); | |||
| //format number 测试 | |||
| map.put("number", 213123123123.34234234); | |||
| obj = PoiElUtil.eval("fn:(number;###.00)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fn:(number;###.0)", map); | |||
| System.out.println(obj); | |||
| obj = PoiElUtil.eval("fn:(number;#,###.0)", map); | |||
| System.out.println(obj); | |||
| // !if 测试 | |||
| obj = PoiElUtil.eval("!if:(le:(jueyue) == '6')", map); | |||
| Assert.assertEquals(obj, true); | |||
| obj = PoiElUtil.eval("!if:(fd:(date2;yyyy-MM-dd) == '2015-04-25')", map); | |||
| Assert.assertEquals(obj, true); | |||
| obj = PoiElUtil.eval("!if:(fn:(number;###.0) > '3')", map); | |||
| Assert.assertEquals(obj, true); | |||
| map.put("key1", "测试1"); | |||
| //三目运算 | |||
| obj = PoiElUtil.eval("'6' == '6' ? 'jueyue' : '小明'", map); | |||
| Assert.assertEquals(obj, "jueyue"); | |||
| obj = PoiElUtil.eval("le:(jueyue) == '6' ? 'jueyue' : '小明'", map); | |||
| Assert.assertEquals(obj, "jueyue"); | |||
| obj = PoiElUtil.eval("'6' == le:(jueyue) ? 'jueyue' : '小明'", map); | |||
| Assert.assertEquals(obj, "jueyue"); | |||
| obj = PoiElUtil.eval("'6' == le:(jueyue) ? fd:(date;yyyy-MM-dd) : '小明'", map); | |||
| Assert.assertEquals(obj, "2015-04-25"); | |||
| obj = PoiElUtil.eval("'6' != le:(jueyue) ? '小明' : fd:(date;yyyy-MM-dd)", map); | |||
| Assert.assertEquals(obj, "2015-04-25"); | |||
| obj = PoiElUtil.eval("jueyue == 'jueyue' ? key1 : '小明'", map); | |||
| Assert.assertEquals(obj, "测试1"); | |||
| map.put("key1", "100"); | |||
| map.put("key2", "200"); | |||
| obj = PoiElUtil.eval("key1 == key2 ? key1 : '小明'", map); | |||
| Assert.assertEquals(obj, "小明"); | |||
| obj = PoiElUtil.eval("key1 < key2 ? key1 : '小明'", map); | |||
| Assert.assertEquals(obj, "100"); | |||
| obj = PoiElUtil.eval("key2 > key1 ? key1 : '小明'", map); | |||
| Assert.assertEquals(obj, "100"); | |||
| map.put("key1", "你好"); | |||
| obj = PoiElUtil.eval("key1 == '你好' ? '不好' : '小明'", map); | |||
| Assert.assertEquals(obj, "不好"); | |||
| } | |||
| } | |||