cache vml drawing

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895388 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-11-28 09:43:28 +00:00
parent d9b0e2ebfa
commit a2fa746ee0
3 changed files with 42 additions and 35 deletions

View File

@ -52,6 +52,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
public static final int DEFAULT_AUTHOR_ID = 0;
private Sheet sheet;
private XSSFVMLDrawing vmlDrawing;
/**
* Underlying XML Beans CTComment list.
@ -337,11 +338,13 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
}
private XSSFVMLDrawing getVMLDrawing(Sheet sheet, boolean autocreate) {
if (sheet instanceof XSSFSheet) {
return ((XSSFSheet)sheet).getVMLDrawing(autocreate);
} else if (sheet instanceof SXSSFSheet) {
return ((SXSSFSheet)sheet).getVMLDrawing(autocreate);
if (vmlDrawing == null) {
if (sheet instanceof XSSFSheet) {
vmlDrawing = ((XSSFSheet)sheet).getVMLDrawing(autocreate);
} else if (sheet instanceof SXSSFSheet) {
vmlDrawing = ((SXSSFSheet)sheet).getVMLDrawing(autocreate);
}
}
return null;
return vmlDrawing;
}
}

View File

@ -104,6 +104,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
private SortedMap<String,XSSFTable> tables;
private List<CellRangeAddress> arrayFormulas;
private final XSSFDataValidationHelper dataValidationHelper;
private XSSFVMLDrawing xssfvmlDrawing;
/**
* Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch.
@ -568,41 +569,44 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
@Internal
public XSSFVMLDrawing getVMLDrawing(boolean autoCreate) {
XSSFVMLDrawing drawing = null;
CTLegacyDrawing ctDrawing = getCTLegacyDrawing();
if(ctDrawing == null) {
if(autoCreate) {
int drawingNumber = getNextPartNumber(XSSFRelation.VML_DRAWINGS,
getPackagePart().getPackage().getPartsByContentType(XSSFRelation.VML_DRAWINGS.getContentType()).size());
RelationPart rp = createRelationship(XSSFRelation.VML_DRAWINGS, getWorkbook().getXssfFactory(), drawingNumber, false);
drawing = rp.getDocumentPart();
String relId = rp.getRelationship().getId();
if (xssfvmlDrawing == null) {
XSSFVMLDrawing drawing = null;
CTLegacyDrawing ctDrawing = getCTLegacyDrawing();
if(ctDrawing == null) {
if(autoCreate) {
int drawingNumber = getNextPartNumber(XSSFRelation.VML_DRAWINGS,
getPackagePart().getPackage().getPartsByContentType(XSSFRelation.VML_DRAWINGS.getContentType()).size());
RelationPart rp = createRelationship(XSSFRelation.VML_DRAWINGS, getWorkbook().getXssfFactory(), drawingNumber, false);
drawing = rp.getDocumentPart();
String relId = rp.getRelationship().getId();
//add CTLegacyDrawing element which indicates that this sheet contains drawing components built on the drawingML platform.
//The relationship Id references the part containing the drawing definitions.
ctDrawing = worksheet.addNewLegacyDrawing();
ctDrawing.setId(relId);
}
} else {
//search the referenced drawing in the list of the sheet's relations
final String id = ctDrawing.getId();
for (RelationPart rp : getRelationParts()){
POIXMLDocumentPart p = rp.getDocumentPart();
if(p instanceof XSSFVMLDrawing) {
XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
String drId = rp.getRelationship().getId();
if (drId.equals(id)) {
drawing = dr;
break;
//add CTLegacyDrawing element which indicates that this sheet contains drawing components built on the drawingML platform.
//The relationship Id references the part containing the drawing definitions.
ctDrawing = worksheet.addNewLegacyDrawing();
ctDrawing.setId(relId);
}
} else {
//search the referenced drawing in the list of the sheet's relations
final String id = ctDrawing.getId();
for (RelationPart rp : getRelationParts()){
POIXMLDocumentPart p = rp.getDocumentPart();
if(p instanceof XSSFVMLDrawing) {
XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
String drId = rp.getRelationship().getId();
if (drId.equals(id)) {
drawing = dr;
break;
}
// do not break here since drawing has not been found yet (see bug 52425)
}
// do not break here since drawing has not been found yet (see bug 52425)
}
if(drawing == null){
LOG.atError().log("Can't find VML drawing with id={} in the list of the sheet's relationships", id);
}
}
if(drawing == null){
LOG.atError().log("Can't find VML drawing with id={} in the list of the sheet's relationships", id);
}
xssfvmlDrawing = drawing;
}
return drawing;
return xssfvmlDrawing;
}
protected CTDrawing getCTDrawing() {

Binary file not shown.