You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2018/01/27 13:30:52 UTC

svn commit: r1822404 - in /poi/trunk/src/ooxml/java/org/apache/poi/xssf: model/SharedStringsTable.java usermodel/XSSFFactory.java usermodel/XSSFWorkbook.java

Author: fanningpj
Date: Sat Jan 27 13:30:52 2018
New Revision: 1822404

URL: http://svn.apache.org/viewvc?rev=1822404&view=rev
Log:
some changes to allow shared string table to be subclassed

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=1822404&r1=1822403&r2=1822404&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Sat Jan 27 13:30:52 2018
@@ -20,6 +20,7 @@ package org.apache.poi.xssf.model;
 import static org.apache.poi.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
 import static org.apache.poi.xssf.usermodel.XSSFRelation.NS_SPREADSHEETML;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -61,7 +62,7 @@ import org.openxmlformats.schemas.spread
  * properties, and phonetic properties (for East Asian languages).
  * </p>
  */
-public class SharedStringsTable extends POIXMLDocumentPart {
+public class SharedStringsTable extends POIXMLDocumentPart implements Closeable {
 
     /**
      *  Array of individual string items in the Shared String table.
@@ -77,22 +78,22 @@ public class SharedStringsTable extends
      * An integer representing the total count of strings in the workbook. This count does not
      * include any numbers, it counts only the total of text strings in the workbook.
      */
-    private int count;
+    protected int count;
 
     /**
      * An integer representing the total count of unique strings in the Shared String Table.
      * A string is unique even if it is a copy of another string, but has different formatting applied
      * at the character level.
      */
-    private int uniqueCount;
+    protected int uniqueCount;
 
     private SstDocument _sstDoc;
 
     private static final XmlOptions options = new XmlOptions();
     static {
         options.put( XmlOptions.SAVE_INNER );
-     	options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
-     	options.put( XmlOptions.SAVE_USE_DEFAULT_NAMESPACE );
+        options.put( XmlOptions.SAVE_AGGRESSIVE_NAMESPACES );
+        options.put( XmlOptions.SAVE_USE_DEFAULT_NAMESPACE );
         options.setSaveImplicitNamespaces(Collections.singletonMap("", NS_SPREADSHEETML));
     }
 
@@ -108,11 +109,11 @@ public class SharedStringsTable extends
     public SharedStringsTable(PackagePart part) throws IOException {
         super(part);
         readFrom(part.getInputStream());
-    }    
-    
+    }
+
     /**
      * Read this shared strings table from an XML file.
-     * 
+     *
      * @param is The input stream containing the XML document.
      * @throws IOException if an error occurs while reading.
      */
@@ -125,7 +126,7 @@ public class SharedStringsTable extends
             uniqueCount = (int)sst.getUniqueCount();
             //noinspection deprecation
             for (CTRst st : sst.getSiArray()) {
-                stmap.put(getKey(st), cnt);
+                stmap.put(xmlText(st), cnt);
                 strings.add(st);
                 cnt++;
             }
@@ -134,7 +135,7 @@ public class SharedStringsTable extends
         }
     }
 
-    private String getKey(CTRst st) {
+    protected String xmlText(CTRst st) {
         return st.xmlText(options);
     }
 
@@ -195,7 +196,7 @@ public class SharedStringsTable extends
      */
     @Removal(version = "4.2") //make private in 4.2
     public int addEntry(CTRst st) {
-        String s = getKey(st);
+        String s = xmlText(st);
         count++;
         if (stmap.containsKey(s)) {
             return stmap.get(s);
@@ -256,7 +257,7 @@ public class SharedStringsTable extends
 
     /**
      * Write this table out as XML.
-     * 
+     *
      * @param out The stream to write to.
      * @throws IOException if an error occurs while writing.
      */
@@ -282,4 +283,16 @@ public class SharedStringsTable extends
             writeTo(out);
         }
     }
+
+    /**
+     * Close any open resources, like temp files. This method is called by <code>XSSFWorkbook#close()</code>.
+     * <p>
+     *     This implementation is empty but subclasses may need to implement some logic.
+     * </p>
+     *
+     * @since 4.0.0
+     * @throws IOException if an error occurs while closing.
+     */
+    @Override
+    public void close() throws IOException {}
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java?rev=1822404&r1=1822403&r2=1822404&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java Sat Jan 27 13:30:52 2018
@@ -27,8 +27,8 @@ import org.apache.poi.POIXMLRelation;
 /**
  * Instantiates sub-classes of POIXMLDocumentPart depending on their relationship type
  */
-public final class XSSFFactory extends POIXMLFactory  {
-    private XSSFFactory() {
+public class XSSFFactory extends POIXMLFactory {
+    protected XSSFFactory() {
     }
 
     private static final XSSFFactory inst = new XSSFFactory();
@@ -50,8 +50,8 @@ public final class XSSFFactory extends P
      */
     @Override
     protected POIXMLDocumentPart createDocumentPart
-        (Class<? extends POIXMLDocumentPart> cls, Class<?>[] classes, Object[] values)
-    throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
+    (Class<? extends POIXMLDocumentPart> cls, Class<?>[] classes, Object[] values)
+            throws SecurityException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
         Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(classes);
         return constructor.newInstance(values);
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1822404&r1=1822403&r2=1822404&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sat Jan 27 13:30:52 2018
@@ -127,7 +127,7 @@ public class XSSFWorkbook extends POIXML
      * @deprecated POI 3.17 beta 1
      * @see Units#DEFAULT_CHARACTER_WIDTH
      */
-    @Removal(version="3.19")
+    @Removal(version="4.1")
     public static final float DEFAULT_CHARACTER_WIDTH = Units.DEFAULT_CHARACTER_WIDTH;
 
     /**
@@ -186,7 +186,7 @@ public class XSSFWorkbook extends POIXML
      * TODO
      */
     private CalculationChain calcChain;
-    
+
     /**
      * External Links, for referencing names or cells in other workbooks.
      */
@@ -236,6 +236,7 @@ public class XSSFWorkbook extends POIXML
     private List<XSSFPivotTable> pivotTables;
     private List<CTPivotCache> pivotCaches;
 
+    private final XSSFFactory xssfFactory;
 
     /**
      * Create a new SpreadsheetML workbook.
@@ -244,23 +245,33 @@ public class XSSFWorkbook extends POIXML
         this(XSSFWorkbookType.XLSX);
     }
 
+    @Internal
+    public XSSFWorkbook(XSSFFactory factory) {
+        this(XSSFWorkbookType.XLSX, factory);
+    }
+
     /**
      * Create a new SpreadsheetML workbook.
      * @param workbookType The type of workbook to make (.xlsx or .xlsm).
      */
     public XSSFWorkbook(XSSFWorkbookType workbookType) {
+        this(workbookType, null);
+    }
+
+    private XSSFWorkbook(XSSFWorkbookType workbookType, XSSFFactory factory) {
         super(newPackage(workbookType));
+        this.xssfFactory = (factory == null) ? XSSFFactory.getInstance() : factory;
         onWorkbookCreate();
     }
 
     /**
      * Constructs a XSSFWorkbook object given a OpenXML4J <code>Package</code> object,
      *  see <a href="http://poi.apache.org/oxml4j/">http://poi.apache.org/oxml4j/</a>.
-     * 
+     *
      * <p>Once you have finished working with the Workbook, you should close the package
-     * by calling either {@link #close()} or {@link OPCPackage#close()}, to avoid 
+     * by calling either {@link #close()} or {@link OPCPackage#close()}, to avoid
      * leaving file handles open.
-     * 
+     *
      * <p>Creating a XSSFWorkbook from a file-backed OPC Package has a lower memory
      *  footprint than an InputStream backed one.
      *
@@ -268,12 +279,13 @@ public class XSSFWorkbook extends POIXML
      */
     public XSSFWorkbook(OPCPackage pkg) throws IOException {
         super(pkg);
-        
+        this.xssfFactory = XSSFFactory.getInstance();
+
         beforeDocumentRead();
-        
+
         // Build a tree of POIXMLDocumentParts, this workbook being the root
-        load(XSSFFactory.getInstance());
-        
+        load(this.xssfFactory);
+
         // some broken Workbooks miss this...
         setBookViewsIfMissing();
     }
@@ -281,7 +293,7 @@ public class XSSFWorkbook extends POIXML
     /**
      * Constructs a XSSFWorkbook object, by buffering the whole stream into memory
      *  and then opening an {@link OPCPackage} object for it.
-     * 
+     *
      * <p>Using an {@link InputStream} requires more memory than using a File, so
      *  if a {@link File} is available then you should instead do something like
      *   <pre><code>
@@ -298,29 +310,29 @@ public class XSSFWorkbook extends POIXML
 
     /**
      * Constructs a XSSFWorkbook object from a given file.
-     * 
-     * <p>Once you have finished working with the Workbook, you should close 
-     * the package by calling  {@link #close()}, to avoid leaving file 
+     *
+     * <p>Once you have finished working with the Workbook, you should close
+     * the package by calling  {@link #close()}, to avoid leaving file
      * handles open.
-     * 
-     * <p>Opening a XSSFWorkbook from a file has a lower memory footprint 
+     *
+     * <p>Opening a XSSFWorkbook from a file has a lower memory footprint
      *  than opening from an InputStream
-     *  
+     *
      * @param file   the file to open
      */
     public XSSFWorkbook(File file) throws IOException, InvalidFormatException {
         this(OPCPackage.open(file));
     }
-    
+
     /**
      * Constructs a XSSFWorkbook object given a file name.
      *
-     * 
-     * <p>Once you have finished working with the Workbook, you should close 
-     * the package by calling  {@link #close()}, to avoid leaving file 
+     *
+     * <p>Once you have finished working with the Workbook, you should close
+     * the package by calling  {@link #close()}, to avoid leaving file
      * handles open.
-     * 
-     * <p>Opening a XSSFWorkbook from a file has a lower memory footprint 
+     *
+     * <p>Opening a XSSFWorkbook from a file has a lower memory footprint
      *  than opening from an InputStream
      *
      * @param path   the file name.
@@ -328,7 +340,7 @@ public class XSSFWorkbook extends POIXML
     public XSSFWorkbook(String path) throws IOException {
         this(openPackage(path));
     }
-    
+
     /**
      * Constructs a XSSFWorkbook object using Package Part.
      * @param part  package part
@@ -337,7 +349,7 @@ public class XSSFWorkbook extends POIXML
     public XSSFWorkbook(PackagePart part) throws IOException {
         this(part.getInputStream());
     }
-    
+
     protected void beforeDocumentRead() {
         // Ensure it isn't a XLSB file, which we don't support
         if (getCorePart().getContentType().equals(XSSFRelation.XLSB_BINARY_WORKBOOK.getContentType())) {
@@ -377,13 +389,13 @@ public class XSSFWorkbook extends POIXML
                 }
             }
             boolean packageReadOnly = (getPackage().getPackageAccess() == PackageAccess.READ);
-            
+
             if (stylesSource == null) {
                 // Create Styles if it is missing
                 if (packageReadOnly) {
                     stylesSource = new StylesTable();
                 } else {
-                    stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
+                    stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, this.xssfFactory);
                 }
             }
             stylesSource.setWorkbook(this);
@@ -394,10 +406,10 @@ public class XSSFWorkbook extends POIXML
                 if (packageReadOnly) {
                     sharedStringSource = new SharedStringsTable();
                 } else {
-                    sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
+                    sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
                 }
             }
-            
+
             // Load individual sheets. The order of sheets is defined by the order
             //  of CTSheet elements in the workbook
             sheets = new ArrayList<>(shIdMap.size());
@@ -405,8 +417,8 @@ public class XSSFWorkbook extends POIXML
             for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
                 parseSheet(shIdMap, ctSheet);
             }
-            
-            // Load the external links tables. Their order is defined by the order 
+
+            // Load the external links tables. Their order is defined by the order
             //  of CTExternalReference elements in the workbook
             externalLinks = new ArrayList<>(elIdMap.size());
             if (this.workbook.isSetExternalReferences()) {
@@ -419,7 +431,7 @@ public class XSSFWorkbook extends POIXML
                     externalLinks.add(el);
                 }
             }
-            
+
             // Process the named ranges
             reprocessNamedRanges();
         } catch (XmlException e) {
@@ -458,8 +470,8 @@ public class XSSFWorkbook extends POIXML
         POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
         expProps.getUnderlyingProperties().setApplication(DOCUMENT_CREATOR);
 
-        sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
-        stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
+        sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
+        stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, this.xssfFactory);
         stylesSource.setWorkbook(this);
 
         namedRanges = new ArrayList<>();
@@ -467,7 +479,7 @@ public class XSSFWorkbook extends POIXML
         sheets = new ArrayList<>();
         pivotTables = new ArrayList<>();
     }
-    
+
     private void setBookViewsIfMissing() {
         if(!workbook.isSetBookViews()) {
             CTBookViews bvs = workbook.addNewBookViews();
@@ -525,7 +537,7 @@ public class XSSFWorkbook extends POIXML
     @Override
     public int addPicture(byte[] pictureData, int format) {
         int imageNumber = getAllPictures().size() + 1;
-        XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], XSSFFactory.getInstance(), imageNumber, true).getDocumentPart();
+        XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], this.xssfFactory, imageNumber, true).getDocumentPart();
         try (OutputStream out = img.getPackagePart().getOutputStream()) {
             out.write(pictureData);
         } catch (IOException e){
@@ -552,7 +564,7 @@ public class XSSFWorkbook extends POIXML
      */
     public int addPicture(InputStream is, int format) throws IOException {
         int imageNumber = getAllPictures().size() + 1;
-        XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], XSSFFactory.getInstance(), imageNumber, true).getDocumentPart();
+        XSSFPictureData img = createRelationship(XSSFPictureData.RELATIONS[format], this.xssfFactory, imageNumber, true).getDocumentPart();
         try (OutputStream out = img.getPackagePart().getOutputStream()) {
             IOUtils.copy(is, out);
         }
@@ -574,6 +586,12 @@ public class XSSFWorkbook extends POIXML
         return cloneSheet(sheetNum, null);
     }
 
+    @Override
+    public void close() throws IOException {
+        super.close();
+        sharedStringSource.close();
+    }
+
     /**
      * Create an XSSFSheet from an existing sheet in the XSSFWorkbook.
      *  The cloned sheet is a deep copy of the original but with a new given
@@ -618,14 +636,14 @@ public class XSSFWorkbook extends POIXML
             for(PackageRelationship pr : srcSheet.getPackagePart().getRelationships()) {
                 if (pr.getTargetMode() == TargetMode.EXTERNAL) {
                     clonedSheet.getPackagePart().addExternalRelationship
-                        (pr.getTargetURI().toASCIIString(), pr.getRelationshipType(), pr.getId());
+                            (pr.getTargetURI().toASCIIString(), pr.getRelationshipType(), pr.getId());
                 }
             }
         } catch (InvalidFormatException e) {
             throw new POIXMLException("Failed to clone sheet", e);
         }
-        
-        
+
+
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
             srcSheet.write(out);
             try (ByteArrayInputStream bis = new ByteArrayInputStream(out.toByteArray())) {
@@ -658,7 +676,7 @@ public class XSSFWorkbook extends POIXML
             clonedDg.getCTDrawing().set(dg.getCTDrawing());
 
             clonedDg = clonedSheet.createDrawingPatriarch();
-            
+
             // Clone drawing relations
             List<RelationPart> srcRels = srcSheet.createDrawingPatriarch().getRelationParts();
             for (RelationPart rp : srcRels) {
@@ -667,7 +685,7 @@ public class XSSFWorkbook extends POIXML
         }
         return clonedSheet;
     }
-    
+
     /**
      * @since 3.14-Beta1
      */
@@ -675,8 +693,8 @@ public class XSSFWorkbook extends POIXML
         PackageRelationship rel = rp.getRelationship();
         if (rel.getTargetMode() == TargetMode.EXTERNAL) {
             target.getPackagePart().addRelationship(
-                rel.getTargetURI(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
-        } else {        
+                    rel.getTargetURI(), rel.getTargetMode(), rel.getRelationshipType(), rel.getId());
+        } else {
             XSSFRelation xssfRel = XSSFRelation.getInstance(rel.getRelationshipType());
             if (xssfRel == null) {
                 // Don't copy all relations blindly, but only the ones we know about
@@ -859,12 +877,12 @@ public class XSSFWorkbook extends POIXML
             for(XSSFSheet sh : sheets) {
                 sheetNumber = (int)Math.max(sh.sheet.getSheetId() + 1, sheetNumber);
             }
-            
+
             // Bug 57165: We also need to check that the resulting file name is not already taken
             // this can happen when moving/cloning sheets
             String sheetName = XSSFRelation.WORKSHEET.getFileName(sheetNumber);
             for(POIXMLDocumentPart relation : getRelations()) {
-                if(relation.getPackagePart() != null && 
+                if(relation.getPackagePart() != null &&
                         sheetName.equals(relation.getPackagePart().getPartName().getName())) {
                     // name is taken => try next one
                     sheetNumber++;
@@ -876,7 +894,7 @@ public class XSSFWorkbook extends POIXML
             break;
         }
 
-        RelationPart rp = createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber, false);
+        RelationPart rp = createRelationship(XSSFRelation.WORKSHEET, this.xssfFactory, sheetNumber, false);
         XSSFSheet wrapper = rp.getDocumentPart();
         wrapper.sheet = sheet;
         sheet.setId(rp.getRelationship().getId());
@@ -904,7 +922,7 @@ public class XSSFWorkbook extends POIXML
         sheet.setName(sheetname);
         return sheet;
     }
-    
+
     /**
      * Finds a font that matches the one with the supplied attributes
      */
@@ -1194,21 +1212,21 @@ public class XSSFWorkbook extends POIXML
     public Iterator<Sheet> sheetIterator() {
         return new SheetIterator<>();
     }
-    
+
     /**
      * Alias for {@link #sheetIterator()} to allow
      * foreach loops
-     * 
+     *
      * Note: remove() is not supported on this iterator.
      * Use {@link #removeSheetAt(int)} to remove sheets instead.
-     * 
+     *
      * @return an iterator of the sheets.
      */
     @Override
     public Iterator<Sheet> iterator() {
         return sheetIterator();
     }
-    
+
     private final class SheetIterator<T extends Sheet> implements Iterator<T> {
         final private Iterator<T> it;
         @SuppressWarnings("unchecked")
@@ -1234,7 +1252,7 @@ public class XSSFWorkbook extends POIXML
                     "Use Sheet.removeSheetAt(int) instead.");
         }
     }
-    
+
     /**
      * Are we a normal workbook (.xlsx), or a
      *  macro enabled workbook (.xlsm)?
@@ -1258,11 +1276,11 @@ public class XSSFWorkbook extends POIXML
 
     /**
      * Remove the first named range found with the given name.
-     * 
+     *
      * Note: names of named ranges are not unique (name + sheet
      * index is unique), so {@link #removeName(Name)} should
      * be used if possible.
-     * 
+     *
      * @param name the named range name to remove
      *
      * @throws IllegalArgumentException if no named range could be found
@@ -1373,7 +1391,7 @@ public class XSSFWorkbook extends POIXML
         final XSSFSheet sheet = getSheetAt(index);
 
         sheet.onSheetDelete();
-        
+
         //delete the CTSheet reference from workbook.xml
         workbook.getSheets().removeSheet(index);
 
@@ -1445,7 +1463,7 @@ public class XSSFWorkbook extends POIXML
      * @param index the index to validate
      * @throws IllegalArgumentException if the index is out of range (index
      *            &lt; 0 || index &gt;= getNumberOfSheets()).
-    */
+     */
     private void validateSheetIndex(int index) {
         int lastSheetIx = sheets.size() - 1;
         if (index < 0 || index > lastSheetIx) {
@@ -1592,7 +1610,7 @@ public class XSSFWorkbook extends POIXML
         if (sheetname == null) {
             throw new IllegalArgumentException( "sheetName must not be null" );
         }
-        
+
         validateSheetIndex(sheetIndex);
         String oldSheetName = getSheetName(sheetIndex);
 
@@ -1606,7 +1624,7 @@ public class XSSFWorkbook extends POIXML
         if (sheetname.equals(oldSheetName)) {
             return;
         }
-        
+
         // Check it isn't already taken
         if (containsSheet(sheetname, sheetIndex )) {
             throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
@@ -1643,11 +1661,11 @@ public class XSSFWorkbook extends POIXML
         for(int i=0; i < sheetArray.length; i++) {
             sheets.get(i).sheet = sheetArray[i];
         }
-        
+
         updateNamedRangesAfterSheetReorder(idx, pos);
         updateActiveSheetAfterSheetReorder(idx, pos);
     }
-    
+
     /**
      * update sheet-scoped named ranges in this workbook after changing the sheet order
      * of a sheet at oldIndex to newIndex.
@@ -1677,7 +1695,7 @@ public class XSSFWorkbook extends POIXML
             }
         }
     }
-    
+
     private void updateActiveSheetAfterSheetReorder(int oldIndex, int newIndex) {
         // adjust active sheet if necessary
         int active = getActiveSheetIndex();
@@ -1714,7 +1732,7 @@ public class XSSFWorkbook extends POIXML
                 workbook.unsetDefinedNames();
             }
             workbook.setDefinedNames(names);
-                        
+
             // Re-process the named ranges
             reprocessNamedRanges();
         } else {
@@ -1723,7 +1741,7 @@ public class XSSFWorkbook extends POIXML
             }
         }
     }
-    
+
     private void reprocessNamedRanges() {
         namedRangesByName = new ArrayListValuedHashMap<>();
         namedRanges = new ArrayList<>();
@@ -1757,7 +1775,7 @@ public class XSSFWorkbook extends POIXML
             workbook.save(out, xmlOptions);
         }
     }
-    
+
     /**
      * Returns SharedStringsTable - tha cache of string for this workbook
      *
@@ -1855,7 +1873,7 @@ public class XSSFWorkbook extends POIXML
             }
 
             for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation())) {
-               embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
+                embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
             }
         }
         return embedds;
@@ -1886,7 +1904,7 @@ public class XSSFWorkbook extends POIXML
         CTSheet ctSheet = sheets.get(sheetIx).sheet;
         return ctSheet.getState() == STSheetState.VERY_HIDDEN;
     }
-    
+
     @Override
     public SheetVisibility getSheetVisibility(int sheetIx) {
         validateSheetIndex(sheetIx);
@@ -1912,7 +1930,7 @@ public class XSSFWorkbook extends POIXML
     @Override
     public void setSheetVisibility(int sheetIx, SheetVisibility visibility) {
         validateSheetIndex(sheetIx);
-        
+
         final CTSheet ctSheet = sheets.get(sheetIx).sheet;
         switch (visibility) {
             case VISIBLE:
@@ -1928,9 +1946,9 @@ public class XSSFWorkbook extends POIXML
                 throw new IllegalArgumentException("This should never happen");
         }
     }
-    
-    
-    
+
+
+
 
     /**
      * Fired when a formula is deleted from this workbook,
@@ -1957,10 +1975,10 @@ public class XSSFWorkbook extends POIXML
     public CalculationChain getCalculationChain() {
         return calcChain;
     }
-    
+
     /**
      * Returns the list of {@link ExternalLinksTable} object for this workbook
-     * 
+     *
      * <p>The external links table specifies details of named ranges etc
      *  that are referenced from other workbooks, along with the last seen
      *  values of what they point to.</p>
@@ -1994,9 +2012,9 @@ public class XSSFWorkbook extends POIXML
     }
 
     /**
-     * Adds the External Link Table part and relations required to allow formulas 
+     * Adds the External Link Table part and relations required to allow formulas
      *  referencing the specified external workbook to be added to this one. Allows
-     *  formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the 
+     *  formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the
      *  file, for workbooks not already linked / referenced.
      *
      *  Note: this is not implemented and thus currently throws an Exception stating this.
@@ -2088,8 +2106,8 @@ public class XSSFWorkbook extends POIXML
     }
 
     /**
-     * Sets the workbook password. 
-     * 
+     * Sets the workbook password.
+     *
      * @param password if null, the password will be removed
      * @param hashAlgo if null, the password will be set as XOR password (Excel 2010 and earlier)
      *  otherwise the given algorithm is used for calculating the hash password (Excel 2013)
@@ -2115,7 +2133,7 @@ public class XSSFWorkbook extends POIXML
 
     /**
      * Sets the revisions password.
-     * 
+     *
      * @param password if null, the password will be removed
      * @param hashAlgo if null, the password will be set as XOR password (Excel 2010 and earlier)
      *  otherwise the given algorithm is used for calculating the hash password (Excel 2013)
@@ -2138,7 +2156,7 @@ public class XSSFWorkbook extends POIXML
         }
         return validatePassword(safeGetWorkbookProtection(), password, "revisions");
     }
-    
+
     /**
      * Removes the workbook protection settings
      */
@@ -2147,7 +2165,7 @@ public class XSSFWorkbook extends POIXML
             workbook.unsetWorkbookProtection();
         }
     }
-    
+
     private boolean workbookProtectionPresent() {
         return workbook.isSetWorkbookProtection();
     }
@@ -2158,7 +2176,7 @@ public class XSSFWorkbook extends POIXML
         }
         return workbook.getWorkbookProtection();
     }
-    
+
     /**
      *
      * Returns the locator of user-defined functions.
@@ -2298,7 +2316,7 @@ public class XSSFWorkbook extends POIXML
         OPCPackage opc = getPackage();
         OutputStream outputStream;
         if (!opc.containPart(ppName)) {
-            POIXMLDocumentPart relationship = createRelationship(XSSFRelation.VBA_MACROS, XSSFFactory.getInstance());
+            POIXMLDocumentPart relationship = createRelationship(XSSFRelation.VBA_MACROS, this.xssfFactory);
             outputStream = relationship.getPackagePart().getOutputStream();
         } else {
             PackagePart part = opc.getPart(ppName);
@@ -2328,7 +2346,7 @@ public class XSSFWorkbook extends POIXML
 
     /**
      * Returns the spreadsheet version (EXCLE2007) of this workbook
-     * 
+     *
      * @return EXCEL2007 SpreadsheetVersion enum
      * @since 3.14 beta 2
      */
@@ -2336,10 +2354,10 @@ public class XSSFWorkbook extends POIXML
     public SpreadsheetVersion getSpreadsheetVersion() {
         return SpreadsheetVersion.EXCEL2007;
     }
-    
+
     /**
      * Returns the data table with the given name (case insensitive).
-     * 
+     *
      * @param name the data table name (case-insensitive)
      * @return The Data table in the workbook named <tt>name</tt>, or <tt>null</tt> if no table is named <tt>name</tt>.
      * @since 3.15 beta 2
@@ -2359,7 +2377,7 @@ public class XSSFWorkbook extends POIXML
 
     @Override
     public int addOlePackage(byte[] oleData, String label, String fileName, String command)
-                throws IOException {
+            throws IOException {
         // find an unused part name
         OPCPackage opc = getPackage();
         PackagePartName pnOLE;
@@ -2373,7 +2391,7 @@ public class XSSFWorkbook extends POIXML
         } while (opc.containPart(pnOLE));
 
         PackagePart pp = opc.createPart( pnOLE, "application/vnd.openxmlformats-officedocument.oleObject" );
-        
+
         Ole10Native ole10 = new Ole10Native(label, fileName, command, oleData);
 
         try (ByteArrayOutputStream bos = new ByteArrayOutputStream(oleData.length+500)) {



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