Skip to content

Commit

Permalink
修改cglib
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangjiaju committed Dec 6, 2023
1 parent 4f4a2e6 commit 7929e36
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
Expand All @@ -31,6 +32,7 @@
import com.alibaba.excel.util.StringUtils;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
Expand Down Expand Up @@ -79,6 +81,9 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor {
*/
private final Map<Integer, CommentsTable> commentsTableMap;

private final Map<Integer, PackagePart> drawingMap;
private final Map<Integer, PackagePart> drawingResMap;

public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStream) throws Exception {
this.xlsxReadContext = xlsxReadContext;
// Initialize cache
Expand Down Expand Up @@ -106,6 +111,20 @@ public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStr
sheetList = new ArrayList<>();
sheetMap = new HashMap<>();
commentsTableMap = new HashMap<>();
drawingMap = MapUtils.newHashMap();
drawingResMap = MapUtils.newHashMap();

// Reading images
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.IMAGE)) {
List<PackagePart> drawingsPackagePartList = pkg.getPartsByName(
Pattern.compile("xl/drawings/drawing[0-9]+.xml"));
if (CollectionUtils.isNotEmpty(drawingsPackagePartList)) {
for (PackagePart drawingPackagePart : drawingsPackagePartList) {
log.info("xx{}", drawingPackagePart);
}
}
}

Map<Integer, PackageRelationshipCollection> packageRelationshipCollectionMap = MapUtils.newHashMap();
xlsxReadWorkbookHolder.setPackageRelationshipCollectionMap(packageRelationshipCollectionMap);

Expand All @@ -121,7 +140,7 @@ public XlsxSaxAnalyser(XlsxReadContext xlsxReadContext, InputStream decryptedStr
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
Comments comments = ite.getSheetComments();
if (comments instanceof CommentsTable) {
commentsTableMap.put(index, (CommentsTable) comments);
commentsTableMap.put(index, (CommentsTable)comments);
}
}
if (xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.HYPERLINK)) {
Expand Down Expand Up @@ -258,12 +277,36 @@ public void execute() {
parseXmlSource(sheetMap.get(readSheet.getSheetNo()), new XlsxRowHandler(xlsxReadContext));
// Read comments
readComments(readSheet);
// Read image
readImages(readSheet);
// The last sheet is read
xlsxReadContext.analysisEventProcessor().endSheet(xlsxReadContext);
}
}
}

private void readImages(ReadSheet readSheet) {
if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.IMAGE)) {
return;
}

//xlsxReadContext.xlsxReadWorkbookHolder().getOpcPackage().getPart();
//
//CommentsTable commentsTable = commentsTableMap.get(readSheet.getSheetNo());
//if (commentsTable == null) {
// return;
//}
//Iterator<CellAddress> cellAddresses = commentsTable.getCellAddresses();
//while (cellAddresses.hasNext()) {
// CellAddress cellAddress = cellAddresses.next();
// XSSFComment cellComment = commentsTable.findCellComment(cellAddress);
// CellExtra cellExtra = new CellExtra(CellExtraTypeEnum.COMMENT, cellComment.getString().toString(),
// cellAddress.getRow(), cellAddress.getColumn());
// xlsxReadContext.readSheetHolder().setCellExtra(cellExtra);
// xlsxReadContext.analysisEventProcessor().extra(xlsxReadContext);
//}
}

private void readComments(ReadSheet readSheet) {
if (!xlsxReadContext.readWorkbookHolder().getExtraReadSet().contains(CellExtraTypeEnum.COMMENT)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ public enum CellExtraTypeEnum {
/**
* Merge
*/
MERGE,;
MERGE,

/**
* Image
*/
IMAGE,

;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.time.LocalDateTime;
import java.util.Map;

import javax.print.DocFlavor.STRING;

import com.alibaba.excel.constant.EasyExcelConstants;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.enums.HeadKindEnum;
Expand All @@ -17,15 +14,13 @@
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
import com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.DateUtils;
import com.alibaba.excel.util.MapUtils;
import com.alibaba.excel.util.StringUtils;

import org.springframework.cglib.beans.BeanMap;

/**
* Convert to the object the user needs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.alibaba.excel.util;

import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DefaultNamingPolicy;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.core.DefaultNamingPolicy;

/**
* bean utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.alibaba.excel.metadata.property.FontProperty;
import com.alibaba.excel.metadata.property.NumberFormatProperty;
import com.alibaba.excel.metadata.property.StyleProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.write.metadata.holder.WriteHolder;

import lombok.AllArgsConstructor;
Expand All @@ -41,7 +42,6 @@
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.cglib.beans.BeanMap;

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import java.util.Map;

import com.alibaba.excel.metadata.NullObject;

import org.springframework.cglib.beans.BeanMap;
import com.alibaba.excel.support.cglib.beans.BeanMap;

/**
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.alibaba.excel.write.executor;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.alibaba.excel.context.WriteContext;
import com.alibaba.excel.enums.HeadKindEnum;
import com.alibaba.excel.metadata.FieldCache;
import com.alibaba.excel.metadata.FieldWrapper;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.ClassUtils;
import com.alibaba.excel.util.FieldUtils;
Expand All @@ -30,7 +29,6 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.cglib.beans.BeanMap;

/**
* Add the data into excel
Expand Down
2 changes: 1 addition & 1 deletion easyexcel-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.27</version>
<version>5.3.31</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import java.util.List;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.fastjson2.JSON;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.cglib.core.DebuggingClassWriter;

/**
* 临时测试
Expand All @@ -32,8 +31,8 @@ public void test() {
@Test
public void test2() {
System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");
System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
"/Users/zhuangjiaju/IdeaProjects/easyexcel/target");
//System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY,
// "/Users/zhuangjiaju/IdeaProjects/easyexcel/target");

CamlData camlData = new CamlData();
//camlData.setTest("test2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.alibaba.easyexcel.test.demo.read.CustomStringStringConverter;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.cglib.beans.BeanMap;
import com.alibaba.excel.util.BeanMapUtils;
import com.alibaba.excel.util.FileUtils;
import com.alibaba.excel.util.ListUtils;
Expand All @@ -24,7 +25,6 @@
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.springframework.cglib.beans.BeanMap;

@Slf4j
public class TempWriteTest {
Expand Down
33 changes: 7 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@
<version>${revision}</version>
</dependency>

<!-- Using the latest version of support simultaneously requires global use of the shade plugin, which is prone to errors, so changing to support will be lower than the overall -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-support</artifactId>
<version>${revision}</version>
<version>3.3.2</version>
</dependency>

<dependency>
Expand All @@ -103,6 +104,11 @@
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
Expand Down Expand Up @@ -313,31 +319,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.springframework</pattern>
<shadedPattern>com.alibaba.excel.support</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down

0 comments on commit 7929e36

Please sign in to comment.