aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2015-01-18 23:45:04 +0000
committerNick Burch <nick@apache.org>2015-01-18 23:45:04 +0000
commitbcb02aa4bcef5a9ed161e0c8c6795f13e5a461ad (patch)
tree4192fce51f659dd0cf994fa1c722ad628bd39ae3 /src/ooxml
parent631fc8f9bca1bad6f4135628f7d39d74f34c1f8e (diff)
downloadpoi-bcb02aa4bcef5a9ed161e0c8c6795f13e5a461ad.tar.gz
poi-bcb02aa4bcef5a9ed161e0c8c6795f13e5a461ad.zip
For XSSFSheet, add a getDrawingPatriarch() method alongside the existing createDrawingPatriarch() one
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1652876 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml')
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java63
1 files changed, 38 insertions, 25 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 2c49ed2595..6a48bf0005 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -407,43 +407,56 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
columnHelper.setColBestFit(column, true);
}
}
-
+
/**
- * Create a new SpreadsheetML drawing. If this sheet already contains a drawing - return that.
+ * Return the sheet's existing drawing, or null if there isn't yet one.
+ *
+ * Use {@link #createDrawingPatriarch()} to get or create
*
* @return a SpreadsheetML drawing
*/
- @Override
- public XSSFDrawing createDrawingPatriarch() {
- XSSFDrawing drawing = null;
+ public XSSFDrawing getDrawingPatriarch() {
CTDrawing ctDrawing = getCTDrawing();
- if(ctDrawing == null) {
- //drawingNumber = #drawings.size() + 1
- int drawingNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size() + 1;
- drawing = (XSSFDrawing)createRelationship(XSSFRelation.DRAWINGS, XSSFFactory.getInstance(), drawingNumber);
- String relId = drawing.getPackageRelationship().getId();
-
- //add CT_Drawing element which indicates that this sheet contains drawing components built on the drawingML platform.
- //The relationship Id references the part containing the drawingML definitions.
- ctDrawing = worksheet.addNewDrawing();
- ctDrawing.setId(relId);
- } else {
- //search the referenced drawing in the list of the sheet's relations
- for(POIXMLDocumentPart p : getRelations()){
- if(p instanceof XSSFDrawing) {
+ if (ctDrawing != null) {
+ // Search the referenced drawing in the list of the sheet's relations
+ for (POIXMLDocumentPart p : getRelations()){
+ if (p instanceof XSSFDrawing) {
XSSFDrawing dr = (XSSFDrawing)p;
String drId = dr.getPackageRelationship().getId();
- if(drId.equals(ctDrawing.getId())){
- drawing = dr;
- break;
+ if (drId.equals(ctDrawing.getId())){
+ return dr;
}
break;
}
}
- if(drawing == null){
- logger.log(POILogger.ERROR, "Can't find drawing with id=" + ctDrawing.getId() + " in the list of the sheet's relationships");
- }
+ logger.log(POILogger.ERROR, "Can't find drawing with id=" + ctDrawing.getId() + " in the list of the sheet's relationships");
}
+ return null;
+ }
+
+ /**
+ * Create a new SpreadsheetML drawing. If this sheet already contains a drawing - return that.
+ *
+ * @return a SpreadsheetML drawing
+ */
+ @Override
+ public XSSFDrawing createDrawingPatriarch() {
+ CTDrawing ctDrawing = getCTDrawing();
+ if (ctDrawing != null) {
+ return getDrawingPatriarch();
+ }
+
+ //drawingNumber = #drawings.size() + 1
+ int drawingNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size() + 1;
+ XSSFDrawing drawing = (XSSFDrawing)createRelationship(XSSFRelation.DRAWINGS, XSSFFactory.getInstance(), drawingNumber);
+ String relId = drawing.getPackageRelationship().getId();
+
+ //add CT_Drawing element which indicates that this sheet contains drawing components built on the drawingML platform.
+ //The relationship Id references the part containing the drawingML definitions.
+ ctDrawing = worksheet.addNewDrawing();
+ ctDrawing.setId(relId);
+
+ // Return the newly created drawing
return drawing;
}