001package com.hfg.xml.msofficexml.xlsx.part;
002
003import com.hfg.util.FileUtil;
004import com.hfg.xml.XMLTag;
005import com.hfg.xml.msofficexml.OfficeXML;
006import com.hfg.xml.msofficexml.docx.RelationshipXML;
007import com.hfg.xml.msofficexml.part.OfficeXMLPart;
008import com.hfg.xml.msofficexml.xlsx.Xlsx;
009import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlTable;
010import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlWorksheet;
011import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXML;
012
013import java.io.File;
014
015//------------------------------------------------------------------------------
016/**
017 * Table Part of a OfficeOpenXML xlsx Excel document.
018 *
019 * @author J. Alex Taylor, hairyfatguy.com
020 */
021//------------------------------------------------------------------------------
022// com.hfg XML/HTML Coding Library
023//
024// This library is free software; you can redistribute it and/or
025// modify it under the terms of the GNU Lesser General Public
026// License as published by the Free Software Foundation; either
027// version 2.1 of the License, or (at your option) any later version.
028//
029// This library is distributed in the hope that it will be useful,
030// but WITHOUT ANY WARRANTY; without even the implied warranty of
031// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
032// Lesser General Public License for more details.
033//
034// You should have received a copy of the GNU Lesser General Public
035// License along with this library; if not, write to the Free Software
036// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
037//
038// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
039// jataylor@hairyfatguy.com
040//------------------------------------------------------------------------------
041
042public class TablePart extends OfficeXMLPart
043{
044   private WorksheetPart mParentWorksheetPart;
045   private int           mTableIndex;
046
047   //---------------------------------------------------------------------------
048   public TablePart(WorksheetPart inParentWorksheetPart)
049   {
050      super(inParentWorksheetPart.getParentDoc());
051//      setFile(WmlXML.WORKSHEET_FILE);
052
053      mParentWorksheetPart = inParentWorksheetPart;
054
055      XMLTag rootNode = new SsmlTable(this);
056      rootNode.addXMLNamespaceDeclaration(OfficeXML.OFFICE_NAMESPACE);
057      rootNode.addXMLNamespaceDeclaration(RelationshipXML.RELATIONSHIP_NAMESPACE);
058/*
059      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("ve", "http://schemas.openxmlformats.org/markup-compatibility/2006"));
060      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"));
061      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("v", "urn:schemas-microsoft-com:vml"));
062      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("w10", "urn:schemas-microsoft-com:office:word"));
063      rootNode.addXMLNamespaceDeclaration(XMLNamespace.getNamespace("wne", "http://schemas.microsoft.com/office/word/2006/wordml"));
064*/
065      setRootNode(rootNode);
066   }
067
068   //---------------------------------------------------------------------------
069   public WorksheetPart getParentWorksheetPart()
070   {
071      return mParentWorksheetPart;
072   }
073
074   //---------------------------------------------------------------------------
075   public TablePart setTableIndex(int inValue)
076   {
077      mTableIndex = inValue;
078
079      getRootNode().setId(mTableIndex);
080
081      return this;
082   }
083
084   //---------------------------------------------------------------------------
085   @Override
086   public File getFile()
087   {
088      File worksheetDir = new File(SsmlXML.WORKSHEETS_DIR, FileUtil.getNameMinusExtension(getParentWorksheetPart().getFile().getName()));
089      return new File(worksheetDir, "table" + mTableIndex + ".xml");
090   }
091
092   //---------------------------------------------------------------------------
093   @Override
094   public SsmlTable getRootNode()
095   {
096      return (SsmlTable) super.getRootNode();
097   }
098}