poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1652876 - /poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
Date Sun, 18 Jan 2015 23:45:04 GMT
Author: nick
Date: Sun Jan 18 23:45:04 2015
New Revision: 1652876

URL: http://svn.apache.org/r1652876
Log:
For XSSFSheet, add a getDrawingPatriarch() method alongside the existing createDrawingPatriarch()
one

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1652876&r1=1652875&r2=1652876&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sun Jan 18 23:45:04
2015
@@ -407,43 +407,56 @@ public class XSSFSheet extends POIXMLDoc
             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;
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message