Bladeren bron

用阿里巴巴的代码规范插件,修复了一版

4.1.3.A
jueyue 7 jaren geleden
bovenliggende
commit
c7e80a9edf
33 gewijzigde bestanden met toevoegingen van 162 en 119 verwijderingen
  1. +1
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java
  2. +4
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/POICacheManager.java
  3. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java
  4. +10
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java
  5. +3
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/vo/BaseEntityTypeConstants.java
  6. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelBatchExportServer.java
  7. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportServer.java
  8. +12
    -14
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportServer.java
  9. +4
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java
  10. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/TemplateSumHanlder.java
  11. +7
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/builder/ExcelChartBuildService.java
  12. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphElementType.java
  13. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphType.java
  14. +11
    -6
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphDefined.java
  15. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphElement.java
  16. +9
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlServer.java
  17. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/CssParseServer.java
  18. +5
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/CellValueHelper.java
  19. +19
    -10
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/StylerHelper.java
  20. +8
    -7
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java
  21. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java
  22. +2
    -2
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java
  23. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java
  24. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/export/PdfExportServer.java
  25. +2
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java
  26. +8
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCssUtils.java
  27. +3
    -3
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiFunctionUtil.java
  28. +9
    -9
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java
  29. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java
  30. +10
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiSheetUtility.java
  31. +4
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java
  32. +6
    -6
      easypoi-base/src/main/java/cn/afterturn/easypoi/word/entity/MyXWPFDocument.java
  33. +1
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/word/parse/excel/ExcelEntityParse.java

+ 1
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.java Bestand weergeven

@@ -37,6 +37,7 @@ public class FileLoaderImpl implements IFileLoader {

private static final Logger LOGGER = LoggerFactory.getLogger(FileLoaderImpl.class);

@Override
public byte[] getFile(String url) {
InputStream fileis = null;
ByteArrayOutputStream baos = null;


+ 4
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/POICacheManager.java Bestand weergeven

@@ -52,8 +52,9 @@ public final class POICacheManager {
.build(new CacheLoader<String, byte[]>() {
@Override
public byte[] load(String url) throws Exception {
if (LOCAL_FILELOADER.get() != null)
if (LOCAL_FILELOADER.get() != null) {
return LOCAL_FILELOADER.get().getFile(url);
}
return fileLoder.getFile(url);
}
});
@@ -81,8 +82,9 @@ public final class POICacheManager {
* @param fileLoder
*/
public static void setFileLoderOnce(IFileLoader fileLoder) {
if (fileLoder != null)
if (fileLoder != null) {
LOCAL_FILELOADER.set(fileLoder);
}
}
public static void setLoadingCache(LoadingCache<String, byte[]> loadingCache) {


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelBaseEntity.java Bestand weergeven

@@ -37,7 +37,7 @@ public class ExcelBaseEntity {
/**
* 对应type
*/
private int type = BaseEntityTypeConstants.StringType;
private int type = BaseEntityTypeConstants.STRING_TYPE;
/**
* 数据库格式
*/


+ 10
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java Bestand weergeven

@@ -212,18 +212,23 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
ExcelExportEntity other = (ExcelExportEntity) obj;
if (key == null) {
if (other.key != null)
if (other.key != null) {
return false;
} else if (!key.equals(other.key))
}
} else if (!key.equals(other.key)) {
return false;
}
return true;
}
}

+ 3
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/vo/BaseEntityTypeConstants.java Bestand weergeven

@@ -11,7 +11,7 @@ package cn.afterturn.easypoi.excel.entity.vo;
*
*/
public interface BaseEntityTypeConstants {
public final static Integer StringType = 1;
public final static Integer DoubleType = 10;
public final static Integer ImageType = 3;
public final static Integer STRING_TYPE = 1;
public final static Integer DOUBLE_TYPE = 10;
public final static Integer IMAGE_TYPE = 3;
}

+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelBatchExportServer.java Bestand weergeven

@@ -68,7 +68,7 @@ public class ExcelBatchExportServer extends ExcelExportServer {
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,
@@ -104,6 +104,7 @@ public class ExcelBatchExportServer extends ExcelExportServer {
return workbook;
}
@Override
protected void insertDataToSheet(Workbook workbook, ExportParams entity,
List<ExcelExportEntity> entityList, Collection<?> dataSet,
Sheet sheet) {


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportServer.java Bestand weergeven

@@ -34,7 +34,7 @@ import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.base.ExportBaseServer;
import cn.afterturn.easypoi.excel.export.base.BaseExportServer;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import cn.afterturn.easypoi.exception.excel.ExcelExportException;
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum;
@@ -46,10 +46,10 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
*
* @author JueYue 2014年6月17日 下午5:30:54
*/
public class ExcelExportServer extends ExportBaseServer {
public class ExcelExportServer extends BaseExportServer {
// 最大行数,超过自动多Sheet
private int MAX_NUM = 60000;
private static int MAX_NUM = 60000;
protected int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook,
List<ExcelExportEntity> excelParams) {
@@ -175,8 +175,9 @@ public class ExcelExportServer extends ExportBaseServer {
Object t = its.next();
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight);
tempList.add(t);
if (index >= MAX_NUM)
if (index >= MAX_NUM) {
break;
}
}
if (entity.getFreezeCol() != 0) {
sheet.createFreezePane(entity.getFreezeCol(), 0, entity.getFreezeCol(), 0);


easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportBaseServer.java → easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportServer.java Bestand weergeven

@@ -28,8 +28,6 @@ import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DecimalFormat;
import java.util.Collection;
@@ -56,7 +54,7 @@ import cn.afterturn.easypoi.util.PoiPublicUtil;
* @author JueYue 2014年6月17日 下午6:15:13
*/
@SuppressWarnings("unchecked")
public abstract class ExportBaseServer extends ExportCommonServer {
public abstract class BaseExportServer extends ExportCommonServer {

private int currentIndex = 0;

@@ -100,7 +98,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
} else {
Object value = getCellValue(entity, t);

if (entity.getType() == BaseEntityTypeConstants.StringType) {
if (entity.getType() == BaseEntityTypeConstants.STRING_TYPE) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity);
@@ -110,7 +108,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
row.getSheet().getWorkbook().getCreationHelper(), t,
entity.getName(), value));
}
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
} else if (entity.getType() == BaseEntityTypeConstants.DOUBLE_TYPE) {
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity);
@@ -193,7 +191,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
}

private int createIndexCell(Row row, int index, ExcelExportEntity excelExportEntity) {
if (excelExportEntity.getName() != null && excelExportEntity.getName().equals("序号") && excelExportEntity.getFormat() != null
if (excelExportEntity.getName() != null && "序号".equals(excelExportEntity.getName()) && excelExportEntity.getFormat() != null
&& excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) {
createStringCell(row, 0, currentIndex + "",
index % 2 == 0 ? getStyles(false, null) : getStyles(true, null), null);
@@ -221,7 +219,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) {
entity = excelParams.get(k);
Object value = getCellValue(entity, obj);
if (entity.getType() == BaseEntityTypeConstants.StringType) {
if (entity.getType() == BaseEntityTypeConstants.STRING_TYPE) {
createStringCell(row, cellNum++, value == null ? "" : value.toString(),
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity),
entity);
@@ -231,7 +229,7 @@ public abstract class ExportBaseServer extends ExportCommonServer {
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(),
value));
}
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) {
} else if (entity.getType() == BaseEntityTypeConstants.DOUBLE_TYPE) {
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(),
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity);
if (entity.isHyperlink()) {
@@ -257,13 +255,13 @@ public abstract class ExportBaseServer extends ExportCommonServer {
cell.setCellValue(Double.parseDouble(text));
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
} else {
RichTextString Rtext;
RichTextString rtext;
if (type.equals(ExcelType.HSSF)) {
Rtext = new HSSFRichTextString(text);
rtext = new HSSFRichTextString(text);
} else {
Rtext = new XSSFRichTextString(text);
rtext = new XSSFRichTextString(text);
}
cell.setCellValue(Rtext);
cell.setCellValue(rtext);
}
if (style != null) {
cell.setCellStyle(style);
@@ -330,9 +328,9 @@ public abstract class ExportBaseServer extends ExportCommonServer {
*/
public int getImageType(byte[] value) {
String type = PoiPublicUtil.getFileExtendName(value);
if (type.equalsIgnoreCase("JPG")) {
if ("JPG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_JPEG;
} else if (type.equalsIgnoreCase("PNG")) {
} else if ("PNG".equalsIgnoreCase(type)) {
return Workbook.PICTURE_TYPE_PNG;
}


+ 4
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java Bestand weergeven

@@ -47,7 +47,7 @@ import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.base.ExportBaseServer;
import cn.afterturn.easypoi.excel.export.base.BaseExportServer;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import cn.afterturn.easypoi.excel.export.template.TemplateSumHanlder.TemplateSumEntity;
import cn.afterturn.easypoi.excel.html.helper.MergedRegionHelper;
@@ -64,7 +64,7 @@ import cn.afterturn.easypoi.util.PoiSheetUtility;
* 2013-10-17
* @version 1.0
*/
public final class ExcelExportOfTemplateUtil extends ExportBaseServer {
public final class ExcelExportOfTemplateUtil extends BaseExportServer {
private static final Logger LOGGER = LoggerFactory
.getLogger(ExcelExportOfTemplateUtil.class);
@@ -517,8 +517,9 @@ public final class ExcelExportOfTemplateUtil extends ExportBaseServer {
: getStyles(true,
size >= j - columnIndex ? null : columns.get(j - columnIndex));
//返回的styler不为空时才使用,否则使用Excel设置的,更加推荐Excel设置的样式
if (style != null)
if (style != null) {
row.getCell(j).setCellStyle(style);
}
}
}


+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/TemplateSumHanlder.java Bestand weergeven

@@ -78,8 +78,9 @@ public class TemplateSumHanlder {
}
public void addValueOfKey(String key, String val) {
if (StringUtils.isNoneEmpty(key))
if (StringUtils.isNoneEmpty(key)) {
sumMap.get(key).setValue(sumMap.get(key).getValue() + Double.valueOf(val));
}
}
public List<TemplateSumEntity> getDataList() {


+ 7
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/builder/ExcelChartBuildService.java Bestand weergeven

@@ -88,7 +88,7 @@ public class ExcelChartBuildService
ExcelGraphElement categoryElement=graph.getCategory();
ChartDataSource categoryChart;
if(categoryElement!=null&&categoryElement.getElementType()==ExcelGraphElementType.StringType){
if(categoryElement!=null&& categoryElement.getElementType().equals(ExcelGraphElementType.STRING_TYPE)){
categoryChart=DataSources.fromStringCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum()));
}else{
categoryChart=DataSources.fromNumericCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum()));
@@ -103,7 +103,7 @@ public class ExcelChartBuildService
}
}
if(graph.getGraphType()==ExcelGraphType.LineChart){
if(graph.getGraphType().equals(ExcelGraphType.LINE_CHART)){
LineChartData data = chart.getChartDataFactory().createLineChartData();
buildLineChartData(data, categoryChart, chartValueList, graph.getTitle());
chart.plot(data, bottomAxis, leftAxis);
@@ -220,8 +220,8 @@ public class ExcelChartBuildService
{
int i=0;
for(ChartDataSource<Number> source:chartValueList){
String _title=title.get(i);
if(StringUtils.isNotBlank(_title)){
String temp_title=title.get(i);
if(StringUtils.isNotBlank(temp_title)){
//data.addSerie(categoryChart, source).setTitle(_title);
}else{
//data.addSerie(categoryChart, source);
@@ -249,9 +249,9 @@ public class ExcelChartBuildService
{
int i=0;
for(ChartDataSource<Number> source:chartValueList){
String _title=title.get(i);
if(StringUtils.isNotBlank(_title)){
data.addSerie(categoryChart, source).setTitle(_title);
String temp_title=title.get(i);
if(StringUtils.isNotBlank(temp_title)){
data.addSerie(categoryChart, source).setTitle(temp_title);
}else{
data.addSerie(categoryChart, source);
}


+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphElementType.java Bestand weergeven

@@ -11,6 +11,6 @@ package cn.afterturn.easypoi.excel.graph.constant;
*/
public interface ExcelGraphElementType
{
public static final Integer StringType=1;
public static final Integer NumericType=2;
public static final Integer STRING_TYPE =1;
public static final Integer NUMERIC_TYPE =2;
}

+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphType.java Bestand weergeven

@@ -11,7 +11,7 @@ package cn.afterturn.easypoi.excel.graph.constant;
*/
public interface ExcelGraphType
{
public static final Integer LineChart=1;
public static final Integer ScatterChart=2;
public static final Integer LINE_CHART =1;
public static final Integer SCATTER_CHART =2;
}

+ 11
- 6
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphDefined.java Bestand weergeven

@@ -20,10 +20,11 @@ public class ExcelGraphDefined implements ExcelGraph
private ExcelGraphElement category;
public List<ExcelGraphElement> valueList=Lists.newArrayList();
public List<ExcelTitleCell> titleCell=Lists.newArrayList();
private Integer graphType=ExcelGraphType.LineChart;
private Integer graphType=ExcelGraphType.LINE_CHART;
public List<String> title=Lists.newArrayList();
public ExcelGraphElement getCategory()
@Override
public ExcelGraphElement getCategory()
{
return category;
}
@@ -31,7 +32,8 @@ public class ExcelGraphDefined implements ExcelGraph
{
this.category = category;
}
public List<ExcelGraphElement> getValueList()
@Override
public List<ExcelGraphElement> getValueList()
{
return valueList;
}
@@ -40,7 +42,8 @@ public class ExcelGraphDefined implements ExcelGraph
this.valueList = valueList;
}

public Integer getGraphType()
@Override
public Integer getGraphType()
{
return graphType;
}
@@ -48,7 +51,8 @@ public class ExcelGraphDefined implements ExcelGraph
{
this.graphType = graphType;
}
public List<ExcelTitleCell> getTitleCell()
@Override
public List<ExcelTitleCell> getTitleCell()
{
return titleCell;
}
@@ -56,7 +60,8 @@ public class ExcelGraphDefined implements ExcelGraph
{
this.titleCell = titleCell;
}
public List<String> getTitle()
@Override
public List<String> getTitle()
{
return title;
}


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphElement.java Bestand weergeven

@@ -18,7 +18,7 @@ public class ExcelGraphElement
private Integer endRowNum;
private Integer startColNum;
private Integer endColNum;
private Integer elementType=ExcelGraphElementType.StringType;
private Integer elementType=ExcelGraphElementType.STRING_TYPE;
public Integer getStartRowNum()


+ 9
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/ExcelToHtmlServer.java Bestand weergeven

@@ -71,7 +71,7 @@ public class ExcelToHtmlServer {
this.sheetNum = params.getSheetNum();
cssRandom = (int) Math.ceil(Math.random() * 1000);
this.imageCachePath = params.getPath();
today = DATE_FORMAT.format(new Date());
today = new SimpleDateFormat("yyyy_MM_dd").format(new Date());
}
public String printPage() {
@@ -101,8 +101,9 @@ public class ExcelToHtmlServer {
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
} finally {
if (out != null)
if (out != null) {
out.close();
}
}
return null;
}
@@ -125,8 +126,9 @@ public class ExcelToHtmlServer {
}
private void ensureOut() {
if (out == null)
if (out == null) {
out = new Formatter(new StringBuilder());
}
}
private void printSheets() {
@@ -159,8 +161,9 @@ public class ExcelToHtmlServer {
}
private void ensureColumnBounds(Sheet sheet) {
if (gotBounds)
if (gotBounds) {
return;
}
Iterator<Row> iter = sheet.rowIterator();
firstColumn = (iter.hasNext() ? Integer.MAX_VALUE : 0);
@@ -301,8 +304,9 @@ public class ExcelToHtmlServer {
}
private String styleName(CellStyle style) {
if (style == null)
if (style == null) {
return "";
}
return String.format("style_%02x_%s font_%s_%s", style.getIndex(), cssRandom,
style.getFontIndex(), cssRandom);
}


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/CssParseServer.java Bestand weergeven

@@ -28,6 +28,9 @@ public class CssParseServer {
private static final Logger log = LoggerFactory.getLogger(CssParseServer.class);
private static final Pattern STYLE_PATTERN = Pattern.compile("(?:^|\\s+)(italic|oblique)(?:\\s+|$)");
private static final Pattern WEIGHT_PATTERN = Pattern.compile("(?:^|\\s+)(bold(?:er)?|[7-9]00)(?:\\s+|$)");
@SuppressWarnings("serial")
private final static Set<String> BORDER_STYLES = new HashSet<String>() {
{
@@ -193,8 +196,7 @@ public class CssParseServer {
font.replaceAll("^|\\s*" + StringUtils.join(ignoreStyles, "|") + "\\s+|$", " "));
log.debug("Font Attr [{}] After Process Ingore.", sbFont);
// style
Matcher m = Pattern.compile("(?:^|\\s+)(italic|oblique)(?:\\s+|$)")
.matcher(sbFont.toString());
Matcher m = STYLE_PATTERN.matcher(sbFont.toString());
if (m.find()) {
sbFont.setLength(0);
if (log.isDebugEnabled()) {
@@ -205,8 +207,7 @@ public class CssParseServer {
m.appendTail(sbFont);
}
// weight
m = Pattern.compile("(?:^|\\s+)(bold(?:er)?|[7-9]00)(?:\\s+|$)")
.matcher(sbFont.toString());
m = WEIGHT_PATTERN.matcher(sbFont.toString());
if (m.find()) {
sbFont.setLength(0);
if (log.isDebugEnabled()) {


+ 5
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/CellValueHelper.java Bestand weergeven

@@ -31,14 +31,15 @@ public class CellValueHelper {
public CellValueHelper(Workbook wb, int cssRandom) {
this.cssRandom = cssRandom;
if (wb instanceof HSSFWorkbook)
if (wb instanceof HSSFWorkbook) {
is07 = false;
else if (wb instanceof XSSFWorkbook) {
}else if (wb instanceof XSSFWorkbook) {
is07 = true;
cacheFontInfo(wb);
} else
} else {
throw new IllegalArgumentException(
"unknown workbook type: " + wb.getClass().getSimpleName());
"unknown workbook type: " + wb.getClass().getSimpleName());
}
}
/**


+ 19
- 10
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/helper/StylerHelper.java Bestand weergeven

@@ -69,13 +69,14 @@ public class StylerHelper {
this.out = out;
this.sheetNum = sheetNum;
this.cssRandom = cssRandom;
if (wb instanceof HSSFWorkbook)
if (wb instanceof HSSFWorkbook) {
helper = new HSSFHtmlHelper((HSSFWorkbook) wb);
else if (wb instanceof XSSFWorkbook)
} else if (wb instanceof XSSFWorkbook) {
helper = new XSSFHtmlHelper((XSSFWorkbook) wb);
else
} else {
throw new IllegalArgumentException(
"unknown workbook type: " + wb.getClass().getSimpleName());
"unknown workbook type: " + wb.getClass().getSimpleName());
}
printInlineStyle(wb);
}
@@ -157,10 +158,12 @@ public class StylerHelper {
}
private void fontStyle(Font font) {
if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD)
if (font.getBoldweight() >= Font.BOLDWEIGHT_BOLD) {
out.format(" font-weight: bold;%n");
if (font.getItalic())
}
if (font.getItalic()) {
out.format(" font-style: italic;%n");
}
out.format(" font-family: %s;%n", font.getFontName());
int fontheight = font.getFontHeightInPoints();
@@ -181,8 +184,9 @@ public class StylerHelper {
}
private String styleName(CellStyle style) {
if (style == null)
if (style == null) {
return "";
}
return String.format("style_%02x_%s", style.getIndex(), cssRandom);
}
@@ -209,13 +213,14 @@ public class StylerHelper {
private final HSSFWorkbook wb;
private final HSSFPalette colors;
private HSSFColor HSSF_AUTO = new HSSFColor.AUTOMATIC();
private HSSFColor hssfAuto = new HSSFColor.AUTOMATIC();
public HSSFHtmlHelper(HSSFWorkbook wb) {
this.wb = wb;
colors = wb.getCustomPalette();
}
@Override
public void colorStyles(CellStyle style, Formatter out) {
HSSFCellStyle cs = (HSSFCellStyle) style;
out.format(" /* fill pattern = %d */%n", cs.getFillPattern());
@@ -225,7 +230,7 @@ public class StylerHelper {
private void styleColor(Formatter out, String attr, short index) {
HSSFColor color = colors.getColor(index);
if (index == HSSF_AUTO.getIndex() || color == null) {
if (index == hssfAuto.getIndex() || color == null) {
out.format(" /* %s: index = %d */%n", attr, index);
} else {
short[] rgb = color.getTriplet();
@@ -234,6 +239,7 @@ public class StylerHelper {
}
}
@Override
public void styleColor(Formatter out, String attr, Color color) {
if (color == null) {
return;
@@ -254,16 +260,19 @@ public class StylerHelper {
public XSSFHtmlHelper(XSSFWorkbook wb) {
}
@Override
public void colorStyles(CellStyle style, Formatter out) {
XSSFCellStyle cs = (XSSFCellStyle) style;
styleColor(out, "background-color", cs.getFillForegroundXSSFColor());
styleColor(out, "color", cs.getFont().getXSSFColor());
}
@Override
public void styleColor(Formatter out, String attr, Color color) {
XSSFColor xSSFColor = (XSSFColor) color;
if (color == null || xSSFColor.isAuto())
if (color == null || xSSFColor.isAuto()) {
return;
}
byte[] rgb = xSSFColor.getRGB();
if (rgb == null) {


+ 8
- 7
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java Bestand weergeven

@@ -142,7 +142,7 @@ public class ExcelImportServer extends ImportBaseService {
*/
private String getSaveUrl(ExcelImportEntity excelImportEntity, Object object) throws Exception {
String url = "";
if (excelImportEntity.getSaveUrl().equals("upload")) {
if ("upload".equals(excelImportEntity.getSaveUrl())) {
if (excelImportEntity.getMethods() != null
&& excelImportEntity.getMethods().size() > 0) {
object = getFieldBySomeMethod(excelImportEntity.getMethods(), object);
@@ -162,7 +162,7 @@ public class ExcelImportServer extends ImportBaseService {
List<ExcelCollectionParams> excelCollection = new ArrayList<ExcelCollectionParams>();
String targetId = null;
if (!Map.class.equals(pojoClass)) {
Field fileds[] = PoiPublicUtil.getClassFields(pojoClass);
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass);
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class);
if (etarget != null) {
targetId = etarget.value();
@@ -267,8 +267,9 @@ public class ExcelImportServer extends ImportBaseService {
if (params.getVerifyHanlder() != null) {
ExcelVerifyHanlderResult result = params.getVerifyHanlder().verifyHandler(object);
if (!result.isSuccess()) {
if (cell == null)
if (cell == null) {
cell = row.createCell(row.getLastCellNum());
}
cell.setCellValue((StringUtils.isNoneBlank(cell.getStringCellValue())
? cell.getStringCellValue() + "," : "") + result.getMsg());
if (object instanceof IExcelModel) {
@@ -372,7 +373,7 @@ public class ExcelImportServer extends ImportBaseService {
for (int i = params.getStartSheetIndex(); i < params.getStartSheetIndex()
+ params.getSheetNum(); i++) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" start to read excel by is ,startTime is {}", new Date().getTime());
LOGGER.debug(" start to read excel by is ,startTime is {}", System.currentTimeMillis());
}
if (isXSSFWorkbook) {
pictures = PoiPublicUtil.getSheetPictrues07((XSSFSheet) book.getSheetAt(i),
@@ -382,16 +383,16 @@ public class ExcelImportServer extends ImportBaseService {
(HSSFWorkbook) book);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" end to read excel by is ,endTime is {}", new Date().getTime());
LOGGER.debug(" end to read excel by is ,endTime is {}", System.currentTimeMillis());
}
result.addAll(importExcel(result, book.getSheetAt(i), pojoClass, params, pictures));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" end to read excel list by pos ,endTime is {}", new Date().getTime());
LOGGER.debug(" end to read excel list by pos ,endTime is {}", System.currentTimeMillis());
}
if (params.isReadSingleCell()) {
readSingleCell(importResult, book.getSheetAt(i), params);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(" read Key-Value ,endTime is {}", new Date().getTime());
LOGGER.debug(" read Key-Value ,endTime is {}", System.currentTimeMillis());
}
}
}


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/base/ImportBaseService.java Bestand weergeven

@@ -222,7 +222,7 @@ public class ImportBaseService {
*/
public String getSaveExcelUrl(ImportParams params, Class<?> pojoClass) throws Exception {
String url = "";
if (params.getSaveUrl().equals("upload/excelUpload")) {
if ("upload/excelUpload".equals(params.getSaveUrl())) {
url = pojoClass.getName().split("\\.")[pojoClass.getName().split("\\.").length - 1];
return params.getSaveUrl() + "/" + url;
}


+ 2
- 2
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/SheetHandler.java Bestand weergeven

@@ -108,7 +108,7 @@ public class SheetHandler extends DefaultHandler {
// 将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符
} else if ("v".equals(name)) {
String value = lastContents.trim();
value = value.equals("") ? " " : value;
value = "".equals(value) ? " " : value;
if (CellValueType.Date.equals(type)) {
Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value));
rowlist.add(curCol, new SaxReadCellEntity(CellValueType.Date, date));
@@ -119,7 +119,7 @@ public class SheetHandler extends DefaultHandler {
rowlist.add(curCol, new SaxReadCellEntity(CellValueType.String, value));
}
curCol++;
} else if (name.equals("row")) {//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
} else if ("row".equals(name)) {//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法
read.parse(curRow, rowlist);
rowlist.clear();
curRow++;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/sax/parse/SaxRowRead.java Bestand weergeven

@@ -83,7 +83,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();


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/export/PdfExportServer.java Bestand weergeven

@@ -87,7 +87,7 @@ public class PdfExportServer extends ExportCommonServer {
//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,


+ 2
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCellUtil.java Bestand weergeven

@@ -100,8 +100,9 @@ public class PoiCellUtil {
* @return
*/
public static String getCellValue(Cell cell) {
if (cell == null)
if (cell == null) {
return "";
}

if (cell.getCellType() == Cell.CELL_TYPE_STRING) {



+ 8
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiCssUtils.java Bestand weergeven

@@ -27,6 +27,11 @@ public class PoiCssUtils {
private static final String COLOR_PATTERN_VALUE_LONG = "^(#(?:[a-f]|\\d{2}){3})$";
// matches #rgb(r, g, b)
private static final String COLOR_PATTERN_RGB = "^(rgb\\s*\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\))$";

private static final Pattern COLOR_PATTERN_VALUE_SHORT_PATTERN = Pattern.compile("([a-f]|\\d)");
private static final Pattern INT_PATTERN = Pattern.compile("^(\\d+)(?:\\w+|%)?$");
private static final Pattern INT_AND_PER_PATTERN = Pattern.compile("^(\\d*\\.?\\d+)\\s*(%)?$");

// color name -> POI Color
private static Map<String, HSSFColor> colors = new HashMap<String, HSSFColor>();
// static init
@@ -67,7 +72,7 @@ public class PoiCssUtils {
public static int getInt(String strValue) {
int value = 0;
if (StringUtils.isNotBlank(strValue)) {
Matcher m = Pattern.compile("^(\\d+)(?:\\w+|%)?$").matcher(strValue);
Matcher m = INT_PATTERN.matcher(strValue);
if (m.find()) {
value = Integer.parseInt(m.group(1));
}
@@ -98,7 +103,7 @@ public class PoiCssUtils {
if (color.matches(COLOR_PATTERN_VALUE_SHORT)) {
log.debug("Short Hex Color [{}] Found.", color);
StringBuffer sbColor = new StringBuffer();
Matcher m = Pattern.compile("([a-f]|\\d)").matcher(color);
Matcher m = COLOR_PATTERN_VALUE_SHORT_PATTERN.matcher(color);
while (m.find()) {
m.appendReplacement(sbColor, "$1$1");
}
@@ -180,7 +185,7 @@ public class PoiCssUtils {
public static int calcColorValue(String color) {
int rtn = 0;
// matches 64 or 64%
Matcher m = Pattern.compile("^(\\d*\\.?\\d+)\\s*(%)?$").matcher(color);
Matcher m = INT_AND_PER_PATTERN.matcher(color);
if (m.matches()) {
// % not found
if (m.group(2) == null) {


+ 3
- 3
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiFunctionUtil.java Bestand weergeven

@@ -103,11 +103,11 @@ public final class PoiFunctionUtil {
}
SimpleDateFormat dateFormat = null;
if (DAY_STR.equals(format)) {
dateFormat = DAY_FORMAT;
dateFormat = new SimpleDateFormat(DAY_STR);
} else if (TIME_STR.equals(format)) {
dateFormat = TIME_FORMAT;
dateFormat = new SimpleDateFormat(TIME_STR);
} else if (TIME__NO_S_STR.equals(format)) {
dateFormat = TIME__NO_S_FORMAT;
dateFormat = new SimpleDateFormat(TIME__NO_S_STR);
} else {
dateFormat = new SimpleDateFormat(format);
}


+ 9
- 9
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiPublicUtil.java Bestand weergeven

@@ -251,10 +251,10 @@ public final class PoiPublicUtil {
if (fieldType.isArray()) {
isBaseClass = false;
} else if (fieldType.isPrimitive() || fieldType.getPackage() == null
|| fieldType.getPackage().getName().equals("java.lang")
|| fieldType.getPackage().getName().equals("java.math")
|| fieldType.getPackage().getName().equals("java.sql")
|| fieldType.getPackage().getName().equals("java.util")) {
|| "java.lang".equals(fieldType.getPackage().getName())
|| "java.math".equals(fieldType.getPackage().getName())
|| "java.sql".equals(fieldType.getPackage().getName())
|| "java.util".equals(fieldType.getPackage().getName())) {
isBaseClass = true;
}
return isBaseClass;
@@ -300,21 +300,21 @@ public final class PoiPublicUtil {
* @return
*/
private static boolean isUseInThis(String exportName, String targetId) {
return targetId == null || exportName.equals("") || exportName.indexOf("_") < 0
return targetId == null || "".equals(exportName) || exportName.indexOf("_") < 0
|| exportName.indexOf(targetId) != -1;
}
private static Integer getImageType(String type) {
if (type.equalsIgnoreCase("JPG") || type.equalsIgnoreCase("JPEG")) {
if ("JPG".equalsIgnoreCase(type) || "JPEG".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_JPEG;
}
if (type.equalsIgnoreCase("GIF")) {
if ("GIF".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_GIF;
}
if (type.equalsIgnoreCase("BMP")) {
if ("BMP".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_GIF;
}
if (type.equalsIgnoreCase("PNG")) {
if ("PNG".equalsIgnoreCase(type)) {
return XWPFDocument.PICTURE_TYPE_PNG;
}
return XWPFDocument.PICTURE_TYPE_JPEG;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java Bestand weergeven

@@ -196,7 +196,7 @@ public final class PoiReflectorUtil {
// Ignored. This is only a final precaution, nothing we can do.
}
}
if (field.isAccessible() && !field.getName().equalsIgnoreCase("serialVersionUID")) {
if (field.isAccessible() && !"serialVersionUID".equalsIgnoreCase(field.getName())) {
this.fieldList.add(field);
}
}


+ 10
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiSheetUtility.java Bestand weergeven

@@ -40,21 +40,25 @@ public class PoiSheetUtility extends Object {
Row row = sheet.getRow(r);
// if no row exists here; then nothing to do; next!
if (row == null)
if (row == null) {
continue;
}
// if the row doesn't have this many columns then we are good; next!
int lastColumn = row.getLastCellNum();
if (lastColumn > maxColumn)
if (lastColumn > maxColumn) {
maxColumn = lastColumn;
}
if (lastColumn < columnToDelete)
if (lastColumn < columnToDelete) {
continue;
}
for (int x = columnToDelete + 1; x < lastColumn + 1; x++) {
Cell oldCell = row.getCell(x - 1);
if (oldCell != null)
if (oldCell != null) {
row.removeCell(oldCell);
}
Cell nextCell = row.getCell(x);
if (nextCell != null) {
@@ -99,6 +103,8 @@ public class PoiSheetUtility extends Object {
cNew.setCellFormula(cOld.getCellFormula());
break;
}
default:
cNew.setCellValue(cOld.getStringCellValue());
}
}

+ 4
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.java Bestand weergeven

@@ -29,19 +29,19 @@ import javax.validation.ValidatorFactory;
*/
public class PoiValidationUtil {
private final static Validator validator;
private final static Validator VALIDATOR;
static {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
VALIDATOR = factory.getValidator();
}
public static String validation(Object obj, Class[] verfiyGroup) {
Set<ConstraintViolation<Object>> set = null;
if(verfiyGroup != null){
set = validator.validate(obj,verfiyGroup);
set = VALIDATOR.validate(obj,verfiyGroup);
}else{
set = validator.validate(obj);
set = VALIDATOR.validate(obj);
}
if (set!= null && set.size() > 0) {
return getValidateErrMsg(set);


+ 6
- 6
easypoi-base/src/main/java/cn/afterturn/easypoi/word/entity/MyXWPFDocument.java Bestand weergeven

@@ -73,9 +73,9 @@ public class MyXWPFDocument extends XWPFDocument {
}
public void createPicture(String blipId, int id, int width, int height) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
final int emu = 9525;
width *= emu;
height *= emu;
CTInline inline = createParagraph().createRun().getCTR().addNewDrawing().addNewInline();
String picXml = String.format(PICXML, id, blipId, width, height);
XmlToken xmlToken = null;
@@ -102,9 +102,9 @@ public class MyXWPFDocument extends XWPFDocument {
}
public void createPicture(XWPFRun run, String blipId, int id, int width, int height) {
final int EMU = 9525;
width *= EMU;
height *= EMU;
final int emu = 9525;
width *= emu;
height *= emu;
CTInline inline = run.getCTR().addNewDrawing().addNewInline();
String picXml = String.format(PICXML, id, blipId, width, height);
XmlToken xmlToken = null;


+ 1
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/word/parse/excel/ExcelEntityParse.java Bestand weergeven

@@ -171,7 +171,7 @@ public class ExcelEntityParse extends ExportCommonServer {
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) {


Laden…
Annuleren
Opslaan