poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r707839 [1/2] - in /poi/branches/ooxml/src: examples/src/org/apache/poi/xssf/usermodel/examples/ java/org/apache/poi/ss/util/ ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/xssf/mode...
Date Sat, 25 Oct 2008 11:48:51 GMT
Author: yegor
Date: Sat Oct 25 04:48:50 2008
New Revision: 707839

URL: http://svn.apache.org/viewvc?rev=707839&view=rev
Log:
more cleanup and refactoring of the ooxml code:1. removed deprecated methods from xssf and interfaces 
2. minimized the accessibility of internal constructors
3. more javadocs

Modified:
    poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
    poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellRangeAddress.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShapeGroup.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextBox.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java

Modified: poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java (original)
+++ poi/branches/ooxml/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java Sat Oct 25 04:48:50 2008
@@ -20,6 +20,7 @@
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 import org.apache.poi.hssf.util.Region;
@@ -38,7 +39,7 @@
         Cell cell = row.createCell((short) 1);
         cell.setCellValue(new XSSFRichTextString("This is a test of merging"));
 
-        sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));
+        sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
 
         // Write the output to a file
         FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");

Modified: poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellRangeAddress.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellRangeAddress.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellRangeAddress.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellRangeAddress.java Sat Oct 25 04:48:50 2008
@@ -50,4 +50,21 @@
 	public static int getEncodedSize(int numberOfItems) {
 		return numberOfItems * ENCODED_SIZE;
 	}
+
+    public String formatAsString() {
+        StringBuffer sb = new StringBuffer();
+        CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn());
+        CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn());
+        sb.append(cellRefFrom.formatAsString());
+        sb.append(':');
+        sb.append(cellRefTo.formatAsString());
+        return sb.toString();
+    }
+
+    public static CellRangeAddress valueOf(String ref) {
+        int sep = ref.indexOf(":");
+        CellReference cellFrom = new CellReference(ref.substring(0, sep));
+        CellReference cellTo = new CellReference(ref.substring(sep + 1));
+        return new CellRangeAddress(cellFrom.getRow(), cellTo.getRow(), cellFrom.getCol(), cellTo.getCol());
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java Sat Oct 25 04:48:50 2008
@@ -21,7 +21,6 @@
 
 import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.Region;
 
 public interface Sheet extends Iterable<Row> {
 
@@ -198,11 +197,6 @@
     int addMergedRegion(CellRangeAddress region);
 
     /**
-     * @deprecated (Aug-2008) use {@link #addMergedRegion(CellRangeAddress)}
-     */
-    int addMergedRegion(Region region);
-
-    /**
      * determines whether the output is vertically centered on the page.
      * @param value true to vertically center, false otherwise.
      */
@@ -237,14 +231,6 @@
     int getNumMergedRegions();
 
     /**
-     * gets the region at a particular index
-     * @param index of the region to fetch
-     * @return the merged region (simple eh?)
-     */
-
-    Region getMergedRegionAt(int index);
-
-    /**
      * @return an iterator of the PHYSICAL rows.  Meaning the 3rd element may not
      * be the third row if say for instance the second row is undefined.
      */
@@ -301,20 +287,6 @@
     void setRowSumsRight(boolean b);
 
     /**
-     * whether alternate expression evaluation is on
-     * @return alternative expression evaluation or not
-     */
-
-    boolean getAlternateExpression();
-
-    /**
-     * whether alternative formula entry is on
-     * @return alternative formulas or not
-     */
-
-    boolean getAlternateFormula();
-
-    /**
      * show automatic page breaks or not
      * @return whether to show auto page breaks
      */
@@ -412,29 +384,12 @@
     boolean getProtect();
 
     /**
-     * @return hashed password
-     */
-    short getPassword();
-
-    /**
-     * Answer whether object protection is enabled or disabled
-     * @return true => protection enabled; false => protection disabled
-     */
-    boolean getObjectProtect();
-
-    /**
      * Answer whether scenario protection is enabled or disabled
      * @return true => protection enabled; false => protection disabled
      */
     boolean getScenarioProtect();
 
     /**
-     * Sets the protection enabled as well as the password
-     * @param password to set for protection
-     */
-    void protectSheet(String password);
-
-    /**
      * Sets the zoom magnication for the sheet.  The zoom is expressed as a
      * fraction.  For example to express a zoom of 75% use 3 for the numerator
      * and 4 for the denominator.

Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Workbook.java Sat Oct 25 04:48:50 2008
@@ -376,13 +376,6 @@
     List getAllPictures();
 
     /**
-     * Gets all embedded OLE2 objects from the Workbook.
-     *
-     * @return the list of embedded objects
-     */
-    List getAllEmbeddedObjects();
-
-    /**
      * Returns an object that handles instantiating concrete
      *  classes of the various instances one needs for 
      *  HSSF and XSSF.

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java Sat Oct 25 04:48:50 2008
@@ -17,7 +17,6 @@
 package org.apache.poi;
 
 import java.io.*;
-import java.util.LinkedList;
 import java.util.List;
 
 import org.apache.poi.poifs.common.POIFSConstants;
@@ -48,19 +47,9 @@
      */
     private POIXMLProperties properties;
 
-    protected POIXMLDocument() {
-        super(null, null);
-        try {
-            Package pkg = newPackage();
-            initialize(pkg);
-        } catch (IOException e){
-            throw new POIXMLException(e);
-        }
-    }
-
-    protected POIXMLDocument(Package pkg) throws IOException {
-        super(null, null);
-        initialize(pkg);
+    protected POIXMLDocument(Package pkg) {
+        super(pkg);
+        this.pkg = pkg;
     }
 
     /**
@@ -76,36 +65,12 @@
         }
     }
 
-    private void initialize(Package pkg) throws IOException {
-        try {
-            this.pkg = pkg;
-
-            PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
-                    PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
-
-            // Get core part
-            this.packagePart = this.pkg.getPart(coreDocRelationship);
-            this.packageRel = coreDocRelationship;
-
-            // Verify it's there
-            if(this.packagePart == null) {
-                throw new IllegalArgumentException("No core part found for this document! Nothing with " + coreDocRelationship.getRelationshipType() + " present as a relation.");
-            }
-        } catch (OpenXML4JException e) {
-            throw new IOException(e.toString());
-        }
-    }
-
-    protected Package newPackage() throws IOException {
-        throw new POIXMLException("Must be overridden");
-    }
-
     public Package getPackage() {
         return this.pkg;
     }
 
     protected PackagePart getCorePart() {
-        return this.packagePart;
+        return getPackagePart();
     }
 
     /**

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Sat Oct 25 04:48:50 2008
@@ -25,6 +25,7 @@
 import org.apache.poi.util.POILogFactory;
 import org.openxml4j.exceptions.OpenXML4JException;
 import org.openxml4j.opc.*;
+import org.openxml4j.opc.Package;
 
 /**
  * Represents an entry of a OOXML package.
@@ -38,7 +39,7 @@
 public class POIXMLDocumentPart {
     private static POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class);
 
-    public static XmlOptions DEFAULT_XML_OPTIONS;
+    public static final XmlOptions DEFAULT_XML_OPTIONS;
     static {
         DEFAULT_XML_OPTIONS = new XmlOptions();
         DEFAULT_XML_OPTIONS.setSaveOuter();
@@ -46,14 +47,46 @@
         DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
     }
 
-    protected PackagePart packagePart;
-    protected PackageRelationship packageRel;
-    protected POIXMLDocumentPart parent;
+    private PackagePart packagePart;
+    private PackageRelationship packageRel;
+    private POIXMLDocumentPart parent;
+    private List<POIXMLDocumentPart> relations;
 
-    protected List<POIXMLDocumentPart> relations;
+    /**
+     * Construct POIXMLDocumentPart representing a "core document" package part.
+     */
+    public POIXMLDocumentPart(Package pkg) {
+        try {
+            PackageRelationship coreRel = pkg.getRelationshipsByType(
+                    PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
 
+            this.relations = new LinkedList<POIXMLDocumentPart>();
+            this.packagePart = pkg.getPart(coreRel);
+            this.packageRel = coreRel;
+        } catch (OpenXML4JException e){
+            throw new POIXMLException(e);
+        }
+    }
+
+    /**
+     * Creates new POIXMLDocumentPart   - called by client code to create new parts from scratch.
+     *
+     * @see #createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)
+     */
+    public POIXMLDocumentPart(){
+        this.relations = new LinkedList<POIXMLDocumentPart>();
+    }
+
+    /**
+     * Creates an POIXMLDocumentPart representing the given package part and relationship.
+     * Called by {@link #read(POIXMLFactory)} when reading in an exisiting file.
+     *
+     * @param part - The package part that holds xml data represenring this sheet.
+     * @param rel - the relationship of the given package part
+     * @see #read(POIXMLFactory)
+     */
     public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
-        relations = new LinkedList<POIXMLDocumentPart>();
+        this.relations = new LinkedList<POIXMLDocumentPart>();
         this.packagePart = part;
         this.packageRel = rel;
     }
@@ -63,7 +96,7 @@
      *
      * @return the underlying PackagePart
      */
-    public PackagePart getPackagePart(){
+    public final PackagePart getPackagePart(){
         return packagePart;
     }
 
@@ -72,7 +105,7 @@
      *
      * @return the PackageRelationship that identifies this POIXMLDocumentPart
      */
-    public PackageRelationship getPackageRelationship(){
+    public final PackageRelationship getPackageRelationship(){
         return packageRel;
     }
 
@@ -81,7 +114,7 @@
      *
      * @return child relations
      */
-    public List<POIXMLDocumentPart> getRelations(){
+    public final List<POIXMLDocumentPart> getRelations(){
         return relations;
     }
 
@@ -90,7 +123,7 @@
      *
      * @param part the child to add
      */
-    protected void addRelation(POIXMLDocumentPart part){
+    protected final void addRelation(POIXMLDocumentPart part){
         relations.add(part);
     }
 
@@ -99,7 +132,7 @@
      *
      * @return the parent POIXMLDocumentPart or <code>null</code> for the root element.
      */
-    public POIXMLDocumentPart getParent(){
+    public final POIXMLDocumentPart getParent(){
         return parent;
     }
 
@@ -132,11 +165,12 @@
 
     /**
      * Save changes in the underlying OOXML package.
+     * Recursively fires {@link #commit()} for each package part
      */
-    protected void save() throws IOException{
+    protected final void onSave() throws IOException{
         commit();
         for(POIXMLDocumentPart p : relations){
-            p.save();
+            p.onSave();
         }
     }
 
@@ -147,11 +181,11 @@
      * @param factory the factory that will create an instance of the requested relation
      * @return the created child POIXMLDocumentPart
      */
-    protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){
+    protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){
         return createRelationship(descriptor, factory, -1, false);
     }
 
-    protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){
+    protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){
         return createRelationship(descriptor, factory, idx, false);
     }
 
@@ -164,7 +198,7 @@
      * @param noRelation if true, then no relationship is added.
      * @return the created child POIXMLDocumentPart
      */
-    protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
+    protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
         try {
 
             PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
@@ -176,7 +210,6 @@
             doc.packageRel = rel;
             doc.packagePart = part;
             doc.parent = this;
-            doc.onDocumentCreate();
             addRelation(doc);
             return doc;
         } catch (Exception e){
@@ -190,7 +223,7 @@
      *
      * @param factory   the factory object that creates POIXMLFactory instances
      */
-    protected void read(POIXMLFactory factory) throws OpenXML4JException {
+    protected final void read(POIXMLFactory factory) throws OpenXML4JException {
         PackageRelationshipCollection rels = packagePart.getRelationships();
         for (PackageRelationship rel : rels) {
             if(rel.getTargetMode() == TargetMode.INTERNAL){
@@ -202,7 +235,6 @@
                 }
                 POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
                 childPart.parent = this;
-                childPart.onDocumentRead();
                 addRelation(childPart);
 
                 if(p.hasRelationships()) childPart.read(factory);
@@ -210,17 +242,19 @@
         }
     }
 
+
     /**
      * Fired when a new package part is created
      */
-    protected void onDocumentCreate(){
+    protected void onDocumentCreate() throws IOException {
 
     }
 
     /**
      * Fired when a package part is read
      */
-    protected void onDocumentRead(){
+    protected void onDocumentRead() throws IOException{
 
     }
+
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java Sat Oct 25 04:48:50 2008
@@ -34,11 +34,11 @@
 import org.openxml4j.opc.PackagePart;
 import org.openxml4j.opc.PackageRelationship;
 
-public class CommentsTable extends POIXMLDocumentPart implements CommentsSource {
+public class CommentsTable extends POIXMLDocumentPart {
     protected CTComments comments;
 
     public CommentsTable() {
-        super(null, null);
+        super();
         comments = CTComments.Factory.newInstance();
     }
 
@@ -56,16 +56,9 @@
         }
     }
     public void writeTo(OutputStream out) throws IOException {
-        XmlOptions options = new XmlOptions();
-        options.setSaveOuter();
-        options.setUseDefaultNamespace();
-
-        // Requests use of whitespace for easier reading
-        //options.setSavePrettyPrint();
-
-        CommentsDocument doc = CommentsDocument.Factory.newInstance(options);
+        CommentsDocument doc = CommentsDocument.Factory.newInstance();
         doc.setComments(comments);
-        doc.save(out, options);
+        doc.save(out, DEFAULT_XML_OPTIONS);
     }
 
     @Override

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Sat Oct 25 04:48:50 2008
@@ -86,7 +86,7 @@
     private int uniqueCount;
 
     public SharedStringsTable() {
-        super(null, null);
+        super();
     }
 
     public SharedStringsTable(PackagePart part, PackageRelationship rel) throws IOException {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Sat Oct 25 04:48:50 2008
@@ -64,8 +64,8 @@
  *
  * @author ugo
  */
-public class StylesTable extends POIXMLDocumentPart implements StylesSource {
-	private final Hashtable<Long,String> numberFormats = new Hashtable<Long,String>();
+public class StylesTable extends POIXMLDocumentPart {
+	private final Hashtable<Integer, String> numberFormats = new Hashtable<Integer,String>();
 	private final List<XSSFFont> fonts = new ArrayList<XSSFFont>();
 	private final List<XSSFCellFill> fills = new ArrayList<XSSFCellFill>();
 	private final List<XSSFCellBorder> borders = new ArrayList<XSSFCellBorder>();
@@ -77,7 +77,7 @@
 	/**
 	 * The first style id available for use as a custom style
 	 */
-	public static final long FIRST_CUSTOM_STYLE_ID = 165;
+	public static final int FIRST_CUSTOM_STYLE_ID = 165;
 
 	private StyleSheetDocument doc;
 
@@ -85,7 +85,7 @@
 	 * Create a new, empty StylesTable
 	 */
 	public StylesTable() {
-        super(null, null);
+        super();
 		doc = StyleSheetDocument.Factory.newInstance();
 		doc.addNewStyleSheet();
 		// Initialization required in order to make the document readable by MSExcel
@@ -109,7 +109,7 @@
 			// Grab all the different bits we care about
 			if(doc.getStyleSheet().getNumFmts() != null)
 			for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtArray()) {
-				numberFormats.put(nfmt.getNumFmtId(), nfmt.getFormatCode());
+				numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode());
 			}
 			if(doc.getStyleSheet().getFonts() != null){
                 int idx = 0;
@@ -150,14 +150,14 @@
 	//  Start of style related getters and setters
 	// ===========================================================
 
-	public String getNumberFormatAt(long idx) {
+	public String getNumberFormatAt(int idx) {
 		return numberFormats.get(idx);
 	}
-	public synchronized long putNumberFormat(String fmt) {
+	public synchronized int putNumberFormat(String fmt) {
 		if (numberFormats.containsValue(fmt)) {
 			// Find the key, and return that
-			for(Enumeration<Long> keys = numberFormats.keys(); keys.hasMoreElements();) {
-				Long key = keys.nextElement();
+			for(Enumeration<Integer> keys = numberFormats.keys(); keys.hasMoreElements();) {
+				int key = keys.nextElement();
 				if(numberFormats.get(key).equals(fmt)) {
 					return key;
 				}
@@ -166,7 +166,7 @@
 		}
 
 		// Find a spare key, and add that
-		long newKey = FIRST_CUSTOM_STYLE_ID;
+		int newKey = FIRST_CUSTOM_STYLE_ID;
 		while(numberFormats.containsKey(newKey)) {
 			newKey++;
 		}
@@ -174,11 +174,11 @@
 		return newKey;
 	}
 
-	public XSSFFont getFontAt(long idx) {
+	public XSSFFont getFontAt(int idx) {
 		return fonts.get((int)idx);
 	}
 
-	public long putFont(Font font) {
+	public int putFont(Font font) {
         int idx = fonts.indexOf(font);
         if (idx != -1) {
             return idx;
@@ -187,7 +187,7 @@
         return fonts.size() - 1;
 	}
 
-	public XSSFCellStyle getStyleAt(long idx) {
+	public XSSFCellStyle getStyleAt(int idx) {
 		int styleXfId = 0;
 
 		// 0 is the empty default
@@ -197,7 +197,7 @@
 
 		return new XSSFCellStyle((int) idx, styleXfId, this);
 	}
-	public synchronized long putStyle(CellStyle style) {
+	public synchronized int putStyle(CellStyle style) {
 		XSSFCellStyle xStyle = (XSSFCellStyle)style;
 		CTXf mainXF = xStyle.getCoreXf();
 
@@ -241,7 +241,7 @@
         return fills.size() - 1;
 	}
 
-	public CTXf getCellXfAt(long idx) {
+	public CTXf getCellXfAt(int idx) {
 		return xfs.get((int) idx);
 	}
 	public int putCellXf(CTXf cellXf) {
@@ -249,7 +249,7 @@
 		return xfs.size();
 	}
 
-	public CTXf getCellStyleXfAt(long idx) {
+	public CTXf getCellStyleXfAt(int idx) {
 		return styleXfs.get((int) idx);
 	}
 	public int putCellStyleXf(CTXf cellStyleXf) {
@@ -328,7 +328,7 @@
 		// Formats
 		CTNumFmts formats = CTNumFmts.Factory.newInstance();
 		formats.setCount(numberFormats.size());
-		for (Entry<Long, String> fmt : numberFormats.entrySet()) {
+		for (Entry<Integer, String> fmt : numberFormats.entrySet()) {
 			CTNumFmt ctFmt = formats.addNewNumFmt();
 			ctFmt.setNumFmtId(fmt.getKey());
 			ctFmt.setFormatCode(fmt.getValue());
@@ -460,14 +460,14 @@
 		return xssfFont;
 	}
 
-	public CTDxf getDxf(long idx) {
+	public CTDxf getDxf(int idx) {
 		if(dxfs.size()==0)
 		return CTDxf.Factory.newInstance();
 		else
 		return dxfs.get((int) idx);
 	}
 
-	public long putDxf(CTDxf dxf) {
+	public int putDxf(CTDxf dxf) {
 		this.dxfs.add(dxf);
 		return this.dxfs.size();
 	}

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sat Oct 25 04:48:50 2008
@@ -383,7 +383,7 @@
      */
     public XSSFCellStyle getCellStyle() {
         long idx = cell.isSetS() ? cell.getS() : 0;
-        return stylesSource.getStyleAt(idx);
+        return stylesSource.getStyleAt((int)idx);
     }
 
     /**

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java Sat Oct 25 04:48:50 2008
@@ -77,7 +77,7 @@
     /**
      * Creates an empty Cell Style
      */
-    public XSSFCellStyle(StylesSource stylesSource) {
+    public XSSFCellStyle(StylesTable stylesSource) {
         this.stylesSource = (StylesTable)stylesSource;
         // We need a new CTXf for the main styles
         // TODO decide on a style ctxf
@@ -94,7 +94,7 @@
      *  workbook (if they're not, it won't work)
      * @throws IllegalArgumentException if there's a workbook mis-match
      */
-    public void verifyBelongsToStylesSource(StylesSource src) {
+    public void verifyBelongsToStylesSource(StylesTable src) {
         if(this.stylesSource != src) {
             throw new IllegalArgumentException("This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?");
         }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Sat Oct 25 04:48:50 2008
@@ -20,6 +20,7 @@
 import org.apache.poi.ss.usermodel.CommentsSource;
 import org.apache.poi.ss.usermodel.RichTextString;
 import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
+import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.ss.util.CellReference;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
@@ -27,7 +28,7 @@
 public class XSSFComment implements Comment {
 	
 	private CTComment comment;
-	private CommentsSource comments;
+	private CommentsTable comments;
 
 	/**
 	 * Creates a new XSSFComment, associated with a given
@@ -35,13 +36,13 @@
 	 * If, as an end user, you want a new XSSFComment
 	 *  object, the please ask your sheet for one.
 	 */
-	public XSSFComment(CommentsSource comments, CTComment comment) {
+	public XSSFComment(CommentsTable comments, CTComment comment) {
 		this.comment = comment;
 		this.comments = comments;
 	}
 
 	public String getAuthor() {
-		return comments.getAuthor(comment.getAuthorId());
+		return comments.getAuthor((int)comment.getAuthorId());
 	}
 
 	public int getColumn() {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataFormat.java Sat Oct 25 04:48:50 2008
@@ -18,22 +18,24 @@
 
 import org.apache.poi.ss.usermodel.DataFormat;
 import org.apache.poi.ss.usermodel.StylesSource;
+import org.apache.poi.xssf.model.StylesTable;
 
 /**
  * Handles data formats for XSSF.
  * TODO Figure out if there are build in formats too 
  */
 public class XSSFDataFormat implements DataFormat {
-	private StylesSource stylesSource;
-	public XSSFDataFormat(StylesSource stylesSource) {
-		this.stylesSource = stylesSource;
-	}
-	
-	public short getFormat(String format) {
-		return (short)stylesSource.putNumberFormat(format);
-	}
+    private StylesTable stylesSource;
 
-	public String getFormat(short index) {
-		return stylesSource.getNumberFormatAt((long)index);
-	}
+    protected XSSFDataFormat(StylesTable stylesSource) {
+        this.stylesSource = stylesSource;
+    }
+
+    public short getFormat(String format) {
+        return (short)stylesSource.putNumberFormat(format);
+    }
+
+    public String getFormat(short index) {
+        return stylesSource.getNumberFormatAt(index);
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java Sat Oct 25 04:48:50 2008
@@ -19,6 +19,7 @@
 
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.POIXMLException;
 import org.apache.xmlbeans.XmlException;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 import org.openxml4j.opc.PackagePart;
@@ -26,13 +27,14 @@
 
 import java.io.IOException;
 
+//YK: TODO: this is only a prototype
 public class XSSFDialogsheet extends XSSFSheet implements Sheet{
     protected CTDialogsheet dialogsheet;
 
-    public XSSFDialogsheet(XSSFSheet sheet) {
-        this.packagePart = sheet.getPackagePart();
-        this.packageRel = sheet.getPackageRelationship();
+    protected XSSFDialogsheet(XSSFSheet sheet) {
+        super(sheet.getPackagePart(), sheet.getPackageRelationship());
         this.dialogsheet = CTDialogsheet.Factory.newInstance();
+        this.worksheet = CTWorksheet.Factory.newInstance();
     }
 
     public XSSFRow createRow(int rowNum) {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Sat Oct 25 04:48:50 2008
@@ -19,7 +19,6 @@
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.XmlObject;
 import org.openxml4j.opc.*;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
 import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
@@ -29,8 +28,6 @@
 import java.io.OutputStream;
 import java.util.Map;
 import java.util.HashMap;
-import java.util.List;
-import java.util.LinkedList;
 
 /**
  * Represents a SpreadsheetML drawing
@@ -48,8 +45,8 @@
      *
      * @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
      */
-    public XSSFDrawing() {
-        super(null, null);
+    protected XSSFDrawing() {
+        super();
         drawing = newDrawing();
     }
 
@@ -61,7 +58,7 @@
      * @param rel  the package relationship holding this drawing,
      * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
      */
-    public XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
+    protected XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
         super(part, rel);
         drawing = CTDrawing.Factory.parse(part.getInputStream());
     }
@@ -157,7 +154,7 @@
         XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
         XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
         PackagePartName ppName = data.getPackagePart().getPartName();
-        PackageRelationship rel = packagePart.addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
+        PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
         addRelation(new XSSFPictureData(data.getPackagePart(), rel));
         return rel;
     }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java Sat Oct 25 04:48:50 2008
@@ -39,8 +39,10 @@
 
     }
 
+    private static final XSSFFactory inst = new XSSFFactory();
+
     public static XSSFFactory getInstance(){
-        return new XSSFFactory();
+        return inst;
     }
 
     public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){
@@ -52,7 +54,7 @@
 
         try {
             Class cls = descriptor.getRelationClass();
-            Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor(PackagePart.class, PackageRelationship.class);
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
             return constructor.newInstance(part, rel);
         } catch (Exception e){
             throw new POIXMLException(e);
@@ -62,7 +64,7 @@
     public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
         try {
             Class cls = descriptor.getRelationClass();
-            Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor();
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
             return constructor.newInstance();
         } catch (Exception e){
             throw new POIXMLException(e);

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstFooter.java Sat Oct 25 04:48:50 2008
@@ -23,7 +23,7 @@
 
 public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
 
-    public XSSFFirstFooter(CTHeaderFooter headerFooter) {
+    protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
         super(headerFooter);
     }
     

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFirstHeader.java Sat Oct 25 04:48:50 2008
@@ -23,7 +23,7 @@
 
 public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
 
-    public XSSFFirstHeader(CTHeaderFooter headerFooter) {
+    protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
         super(headerFooter);
     }
     

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFOddHeader.java Sat Oct 25 04:48:50 2008
@@ -23,7 +23,7 @@
 
 public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
 
-    public XSSFOddHeader(CTHeaderFooter headerFooter) {
+    protected XSSFOddHeader(CTHeaderFooter headerFooter) {
         super(headerFooter);
     }
     

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPictureData.java Sat Oct 25 04:48:50 2008
@@ -52,8 +52,8 @@
      *
      * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#addPicture(byte[], int)
      */
-    public XSSFPictureData() {
-        super(null, null);
+    protected XSSFPictureData() {
+        super();
     }
 
     /**
@@ -63,7 +63,7 @@
      * @param rel  the package relationship holding this drawing,
      * the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
      */
-    public XSSFPictureData(PackagePart part, PackageRelationship rel) {
+    protected XSSFPictureData(PackagePart part, PackageRelationship rel) {
         super(part, rel);
     }
 

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java Sat Oct 25 04:48:50 2008
@@ -31,7 +31,7 @@
     private CTPageMargins pageMargins;
 
 
-    public XSSFPrintSetup(CTWorksheet worksheet) {
+    protected XSSFPrintSetup(CTWorksheet worksheet) {
         this.ctWorksheet = worksheet;
         this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
         this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShape.java Sat Oct 25 04:48:50 2008
@@ -16,11 +16,6 @@
 ==================================================================== */
 package org.apache.poi.xssf.usermodel;
 
-import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTAbsoluteAnchor;
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor;
-import org.openxmlformats.schemas.drawingml.x2006.chartDrawing.CTGroupShape;
 import org.openxmlformats.schemas.drawingml.x2006.main.*;
 
 /**

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShapeGroup.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShapeGroup.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShapeGroup.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFShapeGroup.java Sat Oct 25 04:48:50 2008
@@ -18,11 +18,7 @@
 
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
 import org.openxmlformats.schemas.drawingml.x2006.main.*;
-import org.openxml4j.opc.PackagePartName;
 import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.TargetMode;
-
-import java.util.List;
 
 /**
  * This object specifies a group shape that represents many shapes grouped together. This shape is to be treated
@@ -43,7 +39,7 @@
      * @param drawing the XSSFDrawing that owns this shape
      * @param ctGroup the XML bean that stores this group content
      */
-    public XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {
+    protected XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {
         this.drawing = drawing;
         this.ctGroup = ctGroup;
     }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sat Oct 25 04:48:50 2008
@@ -24,16 +24,13 @@
 
 import org.apache.poi.hssf.util.PaneInformation;
 import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CommentsSource;
 import org.apache.poi.ss.usermodel.Footer;
 import org.apache.poi.ss.usermodel.Header;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.Region;
 import org.apache.poi.xssf.model.CommentsTable;
-import org.apache.poi.xssf.model.Control;
 import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
 import org.apache.poi.POIXMLDocumentPart;
 import org.apache.poi.POIXMLException;
@@ -44,6 +41,7 @@
 import org.openxml4j.opc.PackagePart;
 import org.openxml4j.opc.PackageRelationship;
 import org.openxml4j.opc.PackageRelationshipCollection;
+import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
 
@@ -71,20 +69,30 @@
 
     protected CTSheet sheet;
     protected CTWorksheet worksheet;
-    protected TreeMap<Integer, Row> rows;
-    protected List<XSSFHyperlink> hyperlinks;
-    protected ColumnHelper columnHelper;
-    private CommentsSource sheetComments;
-
-    public XSSFSheet() {
-        super(null, null);
-        this.worksheet = newSheet();
-        initialize();
+    private TreeMap<Integer, Row> rows;
+    private List<XSSFHyperlink> hyperlinks;
+    private ColumnHelper columnHelper;
+    private CommentsTable sheetComments;
+
+    /**
+     * Creates new XSSFSheet   - called by XSSFWorkbook to create a sheet from scratch.
+     *
+     * @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createSheet()
+     */
+    protected XSSFSheet() {
+        super();
+        onDocumentCreate();
     }
 
-    public XSSFSheet(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
+    /**
+     * Creates an XSSFSheet representing the given package part and relationship.
+     * Should only be called by XSSFWorkbook when reading in an exisiting file.
+     *
+     * @param part - The package part that holds xml data represenring this sheet.
+     * @param rel - the relationship of the given package part in the underlying OPC package
+     */
+    protected XSSFSheet(PackagePart part, PackageRelationship rel) {
         super(part, rel);
-        worksheet = WorksheetDocument.Factory.parse(part.getInputStream()).getWorksheet();
     }
 
     /**
@@ -96,25 +104,81 @@
         return (XSSFWorkbook)getParent();
     }
 
-    protected void initialize(){
-        if (this.worksheet.getSheetData() == null) {
-            this.worksheet.addNewSheetData();
+    /**
+     * Initialize worksheet data when reading in an exisiting file.
+     */
+    @Override
+    protected void onDocumentRead() {
+        try {
+            worksheet = WorksheetDocument.Factory.parse(getPackagePart().getInputStream()).getWorksheet();
+        } catch (XmlException e){
+            throw new POIXMLException(e);
+        } catch (IOException e){
+            throw new POIXMLException(e);
         }
-        initRows(this.worksheet);
-        initColumns(this.worksheet);
+
+        initRows(worksheet);
+        columnHelper = new ColumnHelper(worksheet);
 
         for(POIXMLDocumentPart p : getRelations()){
             if(p instanceof CommentsTable) sheetComments = (CommentsTable)p;
         }
+        // Process external hyperlinks for the sheet, if there are any
+        initHyperlinks();
+    }
+
+    /**
+     * Initialize worksheet data when creating a new sheet.
+     */
+    @Override
+    protected void onDocumentCreate(){
+        worksheet = newSheet();
+        initRows(worksheet);
+        columnHelper = new ColumnHelper(worksheet);
+        hyperlinks = new ArrayList<XSSFHyperlink>();
+    }
+
+    private void initRows(CTWorksheet worksheet) {
+        rows = new TreeMap<Integer, Row>();
+        for (CTRow row : worksheet.getSheetData().getRowArray()) {
+            XSSFRow r = new XSSFRow(row, this);
+            rows.put(r.getRowNum(), r);
+        }
+    }
+
+    /**
+     * Read hyperlink relations, link them with CTHyperlink beans in this worksheet
+     * and initialize the internal array of XSSFHyperlink objects
+     */
+    private void initHyperlinks() {
         hyperlinks = new ArrayList<XSSFHyperlink>();
+
+        if(!worksheet.isSetHyperlinks()) return;
+
+        try {
+            PackageRelationshipCollection hyperRels =
+                getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
+
+            // Turn each one into a XSSFHyperlink
+            for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
+                PackageRelationship hyperRel = null;
+                if(hyperlink.getId() != null) {
+                    hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
+                }
+
+                hyperlinks.add( new XSSFHyperlink(hyperlink, hyperRel) );
+            }
+        } catch (InvalidFormatException e){
+            throw new POIXMLException(e);
+        }
     }
 
     /**
-     * Create a new CTWorksheet instance and setup default values
+     * Create a new CTWorksheet instance with all values set to defaults
      *
      * @return a new instance
      */
-    protected static CTWorksheet newSheet(){
+    private static CTWorksheet newSheet(){
         CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
         CTSheetFormatPr ctFormat = worksheet.addNewSheetFormatPr();
         ctFormat.setDefaultRowHeight(15.0);
@@ -137,17 +201,12 @@
         return worksheet;
     }
 
-    public List<Control> getControls()
-    {
-        return null;
-    }
-
     /**
-     * Provide access to the underlying XML bean
+     * Provide access to the CTWorksheet bean holding this sheet's data
      *
-     * @return the underlying CTWorksheet bean
+     * @return the CTWorksheet bean holding this sheet's data
      */
-    public CTWorksheet getWorksheet() {
+    public CTWorksheet getCTWorksheet() {
         return this.worksheet;
     }
 
@@ -155,48 +214,16 @@
         return columnHelper;
     }
 
-    protected void initRows(CTWorksheet worksheet) {
-        this.rows = new TreeMap<Integer, Row>();
-        for (CTRow row : worksheet.getSheetData().getRowArray()) {
-            XSSFRow r = new XSSFRow(row, this);
-            this.rows.put(r.getRowNum(), r);
-        }
-    }
-
-    protected void initColumns(CTWorksheet worksheet) {
-        columnHelper = new ColumnHelper(worksheet);
-    }
-
-    protected void initHyperlinks(PackageRelationshipCollection hyperRels) {
-        if(worksheet.getHyperlinks() == null) return;
-
-        // Turn each one into a XSSFHyperlink
-        for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
-            PackageRelationship hyperRel = null;
-            if(hyperlink.getId() != null) {
-                hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
-            }
-
-            hyperlinks.add(
-                    new XSSFHyperlink(hyperlink, hyperRel)
-            );
-        }
-    }
-
-    protected CTSheet getSheet() {
-        return this.sheet;
-    }
+    /**
+     * Sdds a merged region of cells (hence those cells form one)
+     *
+     * @param cra (rowfrom/colfrom-rowto/colto) to merge
+     * @return index of this region
+     */
     public int addMergedRegion(CellRangeAddress cra) {
-        Region r = new Region(cra.getFirstRow(), (short)cra.getFirstColumn(),
-                cra.getLastRow(), (short)cra.getLastColumn());
-        return addMergedRegion(r);
-    }
-
-
-    public int addMergedRegion(Region region) {
         CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();
         CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
-        ctMergeCell.setRef(region.getRegionRef());
+        ctMergeCell.setRef(cra.formatAsString());
         return ctMergeCells.sizeOfMergeCellArray();
     }
 
@@ -215,11 +242,11 @@
 
     /**
      * Adjusts the column width to fit the contents.
-     *
+     * <p>
      * This process can be relatively slow on large sheets, so this should
      *  normally only be called once per column, at the end of your
      *  processing.
-     *
+     * </p>
      * You can specify whether the content of merged cells should be considered or ignored.
      *  Default is to ignore merged cells.
      *
@@ -305,7 +332,7 @@
         if (sheetComments == null) {
             sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
         }
-        return (XSSFComment)sheetComments.addComment();
+        return sheetComments.addComment();
     }
 
     /**
@@ -341,19 +368,9 @@
         getPane().setActivePane(STPane.Enum.forInt(activePane));
     }
 
-    public boolean getAlternateExpression() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-    public boolean getAlternateFormula() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     public XSSFComment getCellComment(int row, int column) {
         if (sheetComments == null) return null;
-        else return (XSSFComment)sheetComments.findCellComment(row, column);
+        else return sheetComments.findCellComment(row, column);
     }
 
     public XSSFHyperlink getHyperlink(int row, int column) {
@@ -480,13 +497,7 @@
      * @return the number of the first logical row on the sheet, zero based
      */
     public int getFirstRowNum() {
-        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
-            Row row = it.next();
-            if (row != null) {
-                return row.getRowNum();
-            }
-        }
-        return -1;
+        return rows.size() == 0 ? -1 : rows.firstKey();
     }
 
     /**
@@ -602,14 +613,7 @@
     }
 
     public int getLastRowNum() {
-        int lastRowNum = -1;
-        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
-            Row row = it.next();
-            if (row != null) {
-                lastRowNum = row.getRowNum();
-            }
-        }
-        return lastRowNum;
+        return rows.size() == 0 ? -1 : rows.lastKey();
     }
 
     public short getLeftCol() {
@@ -618,43 +622,74 @@
         return cellReference.getCol();
     }
 
+    /**
+     * Gets the size of the margin in inches.
+     *
+     * @param margin which margin to get
+     * @return the size of the margin
+     * @see Sheet#LeftMargin
+     * @see Sheet#RightMargin
+     * @see Sheet#TopMargin
+     * @see Sheet#BottomMargin
+     * @see Sheet#HeaderMargin
+     * @see Sheet#FooterMargin
+     */
     public double getMargin(short margin) {
-        CTPageMargins pageMargins = getSheetTypePageMargins();
+        if (!worksheet.isSetPageMargins()) return 0;
+
+        CTPageMargins pageMargins = worksheet.getPageMargins();
         switch (margin) {
-        case LeftMargin:
-            return pageMargins.getLeft();
-        case RightMargin:
-            return pageMargins.getRight();
-        case TopMargin:
-            return pageMargins.getTop();
-        case BottomMargin:
-            return pageMargins.getBottom();
-        case HeaderMargin:
-            return pageMargins.getHeader();
-        case FooterMargin:
-            return pageMargins.getFooter();
-        default :
-            throw new POIXMLException( "Unknown margin constant:  " + margin );
+            case LeftMargin:
+                return pageMargins.getLeft();
+            case RightMargin:
+                return pageMargins.getRight();
+            case TopMargin:
+                return pageMargins.getTop();
+            case BottomMargin:
+                return pageMargins.getBottom();
+            case HeaderMargin:
+                return pageMargins.getHeader();
+            case FooterMargin:
+                return pageMargins.getFooter();
+            default :
+                throw new POIXMLException("Unknown margin constant:  " + margin);
         }
     }
 
-    protected CTPageMargins getSheetTypePageMargins() {
-        if (worksheet.getPageMargins() == null) {
-            worksheet.setPageMargins(CTPageMargins.Factory.newInstance());
+    /**
+     * Sets the size of the margin in inches.
+     *
+     * @param margin which margin to get
+     * @param size the size of the margin
+     * @see Sheet#LeftMargin
+     * @see Sheet#RightMargin
+     * @see Sheet#TopMargin
+     * @see Sheet#BottomMargin
+     * @see Sheet#HeaderMargin
+     * @see Sheet#FooterMargin
+     */
+    public void setMargin(short margin, double size) {
+        CTPageMargins pageMargins = worksheet.isSetPageMargins() ?
+                worksheet.getPageMargins() : worksheet.addNewPageMargins();
+        switch (margin) {
+            case LeftMargin:
+                pageMargins.setLeft(size);
+            case RightMargin:
+                pageMargins.setRight(size);
+            case TopMargin:
+                pageMargins.setTop(size);
+            case BottomMargin:
+                pageMargins.setBottom(size);
+            case HeaderMargin:
+                pageMargins.setHeader(size);
+            case FooterMargin:
+                pageMargins.setFooter(size);
         }
-        return worksheet.getPageMargins();
-    }
-
-    public Region getMergedRegionAt(int index) {
-        CTMergeCells ctMergeCells = worksheet.getMergeCells();
-        if(ctMergeCells == null) throw new IllegalStateException("This worksheet does not contain merged regions");
-
-        CTMergeCell ctMergeCell = ctMergeCells.getMergeCellArray(index);
-        return new Region(ctMergeCell.getRef());
     }
 
     /**
      * @return the merged region at the specified index
+     * @throws IllegalStateException if this worksheet does not contain merged regions
      */
     public CellRangeAddress getMergedRegion(int index) {
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
@@ -667,6 +702,11 @@
         return new CellRangeAddress(cell1.getRow(), cell2.getRow(), cell1.getCol(), cell2.getCol());
     }
 
+    /**
+     * Returns the number of merged regions defined in this worksheet
+     *
+     * @return number of merged regions in this worksheet
+     */
     public int getNumMergedRegions() {
         CTMergeCells ctMergeCells = worksheet.getMergeCells();
         return ctMergeCells == null ? 0 : ctMergeCells.sizeOfMergeCellArray();
@@ -676,38 +716,36 @@
         return hyperlinks.size();
     }
 
-    public boolean getObjectProtect() {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     public PaneInformation getPaneInformation() {
         // TODO Auto-generated method stub
         return null;
     }
 
-    public short getPassword() {
-        // TODO Auto-generated method stub
-        return 0;
-    }
-
+    /**
+     * Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
+     *
+     * @return the number of phsyically defined rows
+     */
     public int getPhysicalNumberOfRows() {
-        int counter = 0;
-        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
-            if (it.next() != null) {
-                counter++;
-            }
-        }
-        return counter;
+        return rows.size();
     }
 
+    /**
+     * Gets the print setup object.
+     *
+     * @return The user model for the print setup object.
+     */
     public XSSFPrintSetup getPrintSetup() {
-        return new XSSFPrintSetup(getWorksheet());
+        return new XSSFPrintSetup(worksheet);
     }
 
+    /**
+     * Answer whether protection is enabled or disabled
+     *
+     * @return true => protection enabled; false => protection disabled
+     */
     public boolean getProtect() {
-        // TODO Auto-generated method stub
-        return false;
+        return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getSheet();
     }
 
     /**
@@ -757,8 +795,8 @@
     public boolean getRowSumsBelow() {
         CTSheetPr sheetPr = worksheet.getSheetPr();
         CTOutlinePr outlinePr = (sheetPr != null && sheetPr.isSetOutlinePr())
-                ? sheetPr.getOutlinePr() : CTOutlinePr.Factory.newInstance();
-        return outlinePr.getSummaryBelow();
+                ? sheetPr.getOutlinePr() : null;
+        return outlinePr == null || outlinePr.getSummaryBelow();
     }
 
     /**
@@ -821,8 +859,7 @@
      */
     private CTOutlinePr ensureOutlinePr(){
         CTSheetPr sheetPr = worksheet.isSetSheetPr() ? worksheet.getSheetPr() : worksheet.addNewSheetPr();
-        CTOutlinePr outlinePr = sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
-        return outlinePr;
+        return sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
     }
 
     /**
@@ -831,14 +868,7 @@
      * @return true => protection enabled; false => protection disabled
      */
     public boolean getScenarioProtect() {
-        return getSheetTypeProtection().getScenarios();
-    }
-
-    protected CTSheetProtection getSheetTypeProtection() {
-        if (worksheet.getSheetProtection() == null) {
-            worksheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
-        }
-        return worksheet.getSheetProtection();
+        return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getScenarios();
     }
 
     /**
@@ -1015,11 +1045,6 @@
         }
     }
 
-    public void protectSheet(String password) {
-        // TODO Auto-generated method stub
-
-    }
-
     /**
      * Removes a merged region of cells (hence letting them free)
      *
@@ -1040,8 +1065,12 @@
         ctMergeCells.setMergeCellArray(mergeCellsArray);
     }
 
+    /**
+     * Remove a row from this sheet.  All cells contained in the row are removed as well
+     *
+     * @param row  the row to remove.
+     */
     public void removeRow(Row row) {
-
         rows.remove(row.getRowNum());
     }
 
@@ -1227,24 +1256,6 @@
         getSheetTypePrintOptions().setHorizontalCentered(value);
     }
 
-    public void setMargin(short margin, double size) {
-        CTPageMargins pageMargins = getSheetTypePageMargins();
-        switch (margin) {
-        case LeftMargin:
-            pageMargins.setLeft(size);
-        case RightMargin:
-            pageMargins.setRight(size);
-        case TopMargin:
-            pageMargins.setTop(size);
-        case BottomMargin:
-            pageMargins.setBottom(size);
-        case HeaderMargin:
-            pageMargins.setHeader(size);
-        case FooterMargin:
-            pageMargins.setFooter(size);
-        }
-    }
-
     public void setPrintGridlines(boolean newPrintGridlines) {
         getSheetTypePrintOptions().setGridLines(newPrintGridlines);
     }
@@ -1474,7 +1485,7 @@
         getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol);
     }
 
-    protected CTSheetViews getSheetTypeSheetViews() {
+    private CTSheetViews getSheetTypeSheetViews() {
         if (worksheet.getSheetViews() == null) {
             worksheet.setSheetViews(CTSheetViews.Factory.newInstance());
             worksheet.getSheetViews().addNewSheetView();
@@ -1560,6 +1571,7 @@
         if(sheetComments == null) { return false; }
         return (sheetComments.getNumberOfComments() > 0);
     }
+
     protected int getNumberOfComments() {
         if(sheetComments == null) { return 0; }
         return sheetComments.getNumberOfComments();
@@ -1593,7 +1605,7 @@
      * Returns the sheet's comments object if there is one,
      *  or null if not
      */
-    protected CommentsSource getCommentsSourceIfExists() {
+    protected CommentsTable getCommentsSourceIfExists() {
         return sheetComments;
     }
 

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextBox.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextBox.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextBox.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTextBox.java Sat Oct 25 04:48:50 2008
@@ -17,7 +17,6 @@
 package org.apache.poi.xssf.usermodel;
 
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
-import org.openxmlformats.schemas.drawingml.x2006.main.*;
 
 /**
  * Represents a text box in a SpreadsheetML drawing.

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sat Oct 25 04:48:50 2008
@@ -37,8 +37,8 @@
 import org.apache.poi.POIXMLException;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.opc.*;
 import org.openxml4j.opc.Package;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
@@ -105,25 +105,11 @@
     private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
 
     /**
-     * The embedded OLE2 files in the OPC package
-     */
-    private List<PackagePart> embedds;
-
-    /**
      * Create a new SpreadsheetML workbook.
      */
     public XSSFWorkbook() {
-        super();
-        onDocumentCreate();
-    }
-
-    /**
-     * Constructs a XSSFWorkbook object given a file name.
-     *
-     * @param      path   the file name.
-     */
-    public XSSFWorkbook(String path) throws IOException {
-        this(openPackage(path));
+        super(newPackage());
+        onWorkbookCreate();
     }
 
     /**
@@ -134,10 +120,26 @@
      */
     public XSSFWorkbook(Package pkg) throws IOException {
         super(ensureWriteAccess(pkg));
+
+        //build a tree of POIXMLDocumentParts, this workbook being the root
+        try {
+            read(XSSFFactory.getInstance());
+        } catch (OpenXML4JException e){
+            throw new POIXMLException(e);
+        }
         onDocumentRead();
     }
 
     /**
+     * Constructs a XSSFWorkbook object given a file name.
+     *
+     * @param      path   the file name.
+     */
+    public XSSFWorkbook(String path) throws IOException {
+        this(openPackage(path));
+    }
+
+    /**
      * YK: current implementation of OpenXML4J is funny.
      * Packages opened by Package.open(InputStream is) are read-only,
      * there is no way to change or even save such an instance in a OutputStream.
@@ -154,19 +156,13 @@
         return pkg;
     }
 
-    /**
-     * Initialize this workbook from the specified Package
-     */
     @Override
-    protected void onDocumentRead() {
+    protected void onDocumentRead() throws IOException {
         try {
-            //build the POIXMLDocumentPart tree, this workbook is the root
-            read(XSSFFactory.getInstance());
-
             WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
             this.workbook = doc.getWorkbook();
 
-            HashMap<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
+            Map<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
             for(POIXMLDocumentPart p : getRelations()){
                 if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
                 else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
@@ -175,34 +171,16 @@
                 }
             }
 
-            // Load individual sheets
-            sheets = new LinkedList<XSSFSheet>();
-            embedds = new LinkedList<PackagePart>();
+            // Load individual sheets. The order of sheets is defined by the order of CTSheet beans in the workbook
+            sheets = new ArrayList<XSSFSheet>(shIdMap.size());
             for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
-                String id = ctSheet.getId();
-                XSSFSheet sh = shIdMap.get(id);
-                sh.sheet = ctSheet;
+                XSSFSheet sh = shIdMap.get(ctSheet.getId());
                 if(sh == null) {
                     log.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
                     continue;
                 }
-                //initialize internal arrays of rows and columns
-                sh.initialize();
-
-                PackagePart sheetPart = sh.getPackagePart();
-                // Process external hyperlinks for the sheet,
-                //  if there are any
-                PackageRelationshipCollection hyperlinkRels =
-                    sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
-                sh.initHyperlinks(hyperlinkRels);
-
-                // Get the embeddings for the workbook
-                for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
-                    embedds.add(getTargetPart(rel)); // TODO: Add this reference to each sheet as well
-
-                for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
-                    embedds.add(getTargetPart(rel));
-
+                sh.sheet = ctSheet;
+                sh.onDocumentRead();
                 sheets.add(sh);
             }
 
@@ -212,20 +190,22 @@
             }
 
             // Process the named ranges
-            namedRanges = new LinkedList<XSSFName>();
+            namedRanges = new ArrayList<XSSFName>();
             if(workbook.getDefinedNames() != null) {
                 for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
                     namedRanges.add(new XSSFName(ctName, this));
                 }
             }
 
-        } catch (Exception e) {
+        } catch (XmlException e) {
             throw new POIXMLException(e);
         }
     }
 
-    @Override
-    protected void onDocumentCreate() {
+    /**
+     * Create a new CTWorkbook with all values set to default
+     */
+    private void onWorkbookCreate() {
         workbook = CTWorkbook.Factory.newInstance();
         CTBookViews bvs = workbook.addNewBookViews();
         CTBookView bv = bvs.addNewWorkbookView();
@@ -235,15 +215,14 @@
         sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
         stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
 
-        namedRanges = new LinkedList<XSSFName>();
-        sheets = new LinkedList<XSSFSheet>();
-        embedds = new LinkedList<PackagePart>();
+        namedRanges = new ArrayList<XSSFName>();
+        sheets = new ArrayList<XSSFSheet>();
     }
 
     /**
      * Create a new SpreadsheetML package and setup the default minimal content
      */
-    protected Package newPackage() throws IOException {
+    protected static Package newPackage() {
         try {
             Package pkg = Package.create(PackageHelper.createTempFile());
             // Main part
@@ -256,7 +235,7 @@
             pkg.getPackageProperties().setCreatorProperty("Apache POI");
 
             return pkg;
-        } catch (InvalidFormatException e){
+        } catch (Exception e){
             throw new POIXMLException(e);
         }
     }
@@ -266,7 +245,7 @@
      *
      * @return the underlying CTWorkbook bean
      */
-    public CTWorkbook getWorkbook() {
+    public CTWorkbook getCTWorkbook() {
         return this.workbook;
     }
 
@@ -345,7 +324,7 @@
         }
 
         XSSFSheet clonedSheet = createSheet(name);
-        clonedSheet.worksheet.set(srcSheet.worksheet);
+        clonedSheet.getCTWorksheet().set(srcSheet.getCTWorksheet());
         return clonedSheet;
     }
 
@@ -380,7 +359,7 @@
     }
 
     /**
-     * create a new Font and add it to the workbook's font table
+     * Create a new Font and add it to the workbook's font table
      *
      * @return new font object
      */
@@ -391,7 +370,7 @@
     }
 
     /**
-     * Creates a new named range and add it to the model
+     * Create a new named range and add it to the workbook's names table
      *
      * @return named range high level
      */
@@ -402,7 +381,7 @@
     }
 
     /**
-     * create an XSSFSheet for this workbook, adds it to the sheets and returns
+     * Create an XSSFSheet for this workbook, adds it to the sheets and returns
      * the high level representation.  Use this to create new sheets.
      *
      * @return XSSFSheet representing the new sheet.
@@ -413,25 +392,26 @@
     }
 
     /**
-     * create an XSSFSheet for this workbook, adds it to the sheets and returns
+     * Create an XSSFSheet for this workbook, adds it to the sheets and returns
      * the high level representation.  Use this to create new sheets.
      *
      * @param sheetname  sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
      * @return XSSFSheet representing the new sheet.
+     * @throws IllegalArgumentException if the sheetname is invalid or the workbook already contains a sheet of this name
      */
     public XSSFSheet createSheet(String sheetname) {
         if (containsSheet( sheetname, sheets.size() ))
                throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
 
+        CTSheet sheet = addSheet(sheetname);
+
         int sheetNumber = getNumberOfSheets() + 1;
         XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber);
-
-        CTSheet sheet = addSheet(sheetname);
         wrapper.sheet = sheet;
         sheet.setId(wrapper.getPackageRelationship().getId());
         sheet.setSheetId(sheetNumber);
         if(sheets.size() == 0) wrapper.setSelected(true);
-        this.sheets.add(wrapper);
+        sheets.add(wrapper);
         return wrapper;
     }
 
@@ -479,23 +459,14 @@
     public int getActiveSheetIndex() {
         //activeTab (Active Sheet Index) Specifies an unsignedInt
         //that contains the index to the active sheet in this book view.
-        Long index = workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
-        return index.intValue();
-    }
-
-    /**
-     * Gets all embedded OLE2 objects from the Workbook.
-     *
-     * @return the list of embedded objects (a list of {@link org.openxml4j.opc.PackagePart} objects.)
-     */
-    public List getAllEmbeddedObjects() {
-        return embedds;
+        return (int)workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
     }
 
     /**
      * Gets all pictures from the Workbook.
      *
      * @return the list of pictures (a list of {@link XSSFPictureData} objects.)
+     * @see #addPicture(byte[], int)
      */
     public List<XSSFPictureData> getAllPictures() {
         if(pictures == null) {
@@ -642,10 +613,10 @@
      * @return XSSFSheet with the name provided or <code>null</code> if it does not exist
      */
     public XSSFSheet getSheet(String name) {
-        CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
-        for (int i = 0 ; i < sheets.length ; ++i) {
-            if (name.equals(sheets[i].getName())) {
-                return this.sheets.get(i);
+        CTSheet[] ctSheets = this.workbook.getSheets().getSheetArray();
+        for (int i = 0 ; i < ctSheets.length ; ++i) {
+            if (name.equalsIgnoreCase(ctSheets[i].getName())) {
+                return sheets.get(i);
             }
         }
         return null;
@@ -656,22 +627,24 @@
      *
      * @param index of the sheet number (0-based physical & logical)
      * @return XSSFSheet at the provided index
+     * @throws IllegalArgumentException if the index is out of range (index
+     *            &lt; 0 || index &gt;= getNumberOfSheets()).
      */
     public XSSFSheet getSheetAt(int index) {
         validateSheetIndex(index);
-        return this.sheets.get(index);
+        return sheets.get(index);
     }
 
     /**
-     * Returns the index of the sheet by his name
+     * Returns the index of the sheet by his name (case insensitive match)
      *
      * @param name the sheet name
-     * @return index of the sheet (0 based)
+     * @return index of the sheet (0 based) or <tt>-1</tt if not found
      */
     public int getSheetIndex(String name) {
         CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
         for (int i = 0 ; i < sheets.length ; ++i) {
-            if (name.equals(sheets[i].getName())) {
+            if (name.equalsIgnoreCase(sheets[i].getName())) {
                 return i;
             }
         }
@@ -1034,7 +1007,7 @@
      */
     public void write(OutputStream stream) throws IOException {
         //force all children to commit their changes into the underlying OOXML Package
-        save();
+        onSave();
 
         getPackage().save(stream);
     }
@@ -1147,6 +1120,17 @@
      * Get the document's embedded files.
      */
     public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+        List<PackagePart> embedds = new LinkedList<PackagePart>();
+
+        for(XSSFSheet sheet : sheets){
+            // Get the embeddings for the workbook
+            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
+                embedds.add(getTargetPart(rel));
+
+            for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
+                embedds.add(getTargetPart(rel));
+
+        }
         return embedds;
     }
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestStylesTable.java Sat Oct 25 04:48:50 2008
@@ -118,8 +118,8 @@
 		assertEquals(1, st._getStyleXfsSize());
 		assertEquals(0, st._getNumberFormatSize());
 		
-		long nf1 = st.putNumberFormat("yyyy-mm-dd");
-		long nf2 = st.putNumberFormat("yyyy-mm-DD");
+		int nf1 = st.putNumberFormat("yyyy-mm-dd");
+		int nf2 = st.putNumberFormat("yyyy-mm-DD");
 		assertEquals(nf1, st.putNumberFormat("yyyy-mm-dd"));
 		
 		st.putStyle(new XSSFCellStyle(st));
@@ -146,8 +146,8 @@
 		assertEquals(1, st._getStyleXfsSize());
 		assertEquals(8, st._getNumberFormatSize());
 		
-		long nf1 = st.putNumberFormat("YYYY-mm-dd");
-		long nf2 = st.putNumberFormat("YYYY-mm-DD");
+		int nf1 = st.putNumberFormat("YYYY-mm-dd");
+		int nf2 = st.putNumberFormat("YYYY-mm-DD");
 		assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
 		
         st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java Sat Oct 25 04:48:50 2008
@@ -369,7 +369,7 @@
     	Cell cell = sheet.createRow(0).createCell((short)0);
     	cell.setAsActiveCell();
     	
-    	assertEquals("A1", sheet.getWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
+    	assertEquals("A1", sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
     }
     
     

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java?rev=707839&r1=707838&r2=707839&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDialogSheet.java Sat Oct 25 04:48:50 2008
@@ -22,7 +22,6 @@
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
 
 
 public class TestXSSFDialogSheet extends TestCase {
@@ -51,7 +50,7 @@
     
     public void testGetSetAutoBreaks() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertTrue(sheet.getAutobreaks());
         sheet.setAutobreaks(false);
         assertFalse(sheet.getAutobreaks());
@@ -59,7 +58,7 @@
     
     public void testIsSetFitToPage() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.getFitToPage());
         sheet.setFitToPage(true);
         assertTrue(sheet.getFitToPage());
@@ -69,7 +68,7 @@
     
     public void testGetSetMargin() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertEquals((double) 0, sheet.getMargin((short) 0));
         sheet.setMargin((short) 0, 10);
         assertEquals((double) 10, sheet.getMargin((short) 0));
@@ -111,7 +110,7 @@
     
     public void testGetFooter() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertNotNull(sheet.getFooter());
         sheet.getFooter().setCenter("test center footer");
         assertEquals("test center footer", sheet.getFooter().getCenter());
@@ -119,7 +118,7 @@
     
     public void testGetAllHeadersFooters() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertNotNull(sheet);
         assertNotNull(sheet.getOddFooter());
         assertNotNull(sheet.getEvenFooter());
@@ -156,7 +155,7 @@
     
     public void testGetSetHorizontallyCentered() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.getHorizontallyCenter());
         sheet.setHorizontallyCenter(true);
         assertTrue(sheet.getHorizontallyCenter());
@@ -166,7 +165,7 @@
     
     public void testGetSetVerticallyCentered() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.getVerticallyCenter());
         sheet.setVerticallyCenter(true);
         assertTrue(sheet.getVerticallyCenter());
@@ -176,7 +175,7 @@
     
     public void testIsSetPrintGridlines() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.isPrintGridlines());
         sheet.setPrintGridlines(true);
         assertTrue(sheet.isPrintGridlines());
@@ -184,7 +183,7 @@
     
     public void testIsSetDisplayFormulas() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.isDisplayFormulas());
         sheet.setDisplayFormulas(true);
         assertTrue(sheet.isDisplayFormulas());
@@ -192,7 +191,7 @@
     
     public void testIsSetDisplayGridLines() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertTrue(sheet.isDisplayGridlines());
         sheet.setDisplayGridlines(false);
         assertFalse(sheet.isDisplayGridlines());
@@ -200,7 +199,7 @@
     
     public void testIsSetDisplayRowColHeadings() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertTrue(sheet.isDisplayRowColHeadings());
         sheet.setDisplayRowColHeadings(false);
         assertFalse(sheet.isDisplayRowColHeadings());
@@ -208,7 +207,7 @@
     
     public void testGetScenarioProtect() {
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+        XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
         assertFalse(sheet.getScenarioProtect());
     }
 	



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


Mime
View raw message