001package com.hfg.xml.msofficexml.part;
002
003import java.io.File;
004
005import com.hfg.util.FileUtil;
006import com.hfg.xml.XMLDoc;
007import com.hfg.xml.XMLName;
008import com.hfg.xml.XMLTag;
009import com.hfg.xml.msofficexml.OfficeOpenXmlDocument;
010
011
012//------------------------------------------------------------------------------
013/**
014 * Base class for OfficeOpenXml document parts.
015 *
016 * @author J. Alex Taylor, hairyfatguy.com
017 */
018//------------------------------------------------------------------------------
019// com.hfg XML/HTML Coding Library
020//
021// This library is free software; you can redistribute it and/or
022// modify it under the terms of the GNU Lesser General Public
023// License as published by the Free Software Foundation; either
024// version 2.1 of the License, or (at your option) any later version.
025//
026// This library is distributed in the hope that it will be useful,
027// but WITHOUT ANY WARRANTY; without even the implied warranty of
028// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
029// Lesser General Public License for more details.
030//
031// You should have received a copy of the GNU Lesser General Public
032// License along with this library; if not, write to the Free Software
033// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
034//
035// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
036// jataylor@hairyfatguy.com
037//------------------------------------------------------------------------------
038
039public class OfficeXMLPart extends XMLDoc
040{
041   private File mFile;
042   private OfficeOpenXmlDocument mParentDoc;
043
044   //---------------------------------------------------------------------------
045   public OfficeXMLPart(OfficeOpenXmlDocument inOfficeDoc)
046   {
047      mParentDoc = inOfficeDoc;
048      mParentDoc.addPart(this);
049   }
050
051   //---------------------------------------------------------------------------
052   public OfficeXMLPart setFile(File inValue)
053   {
054      mFile = inValue;
055
056      return this;
057   }
058
059   //---------------------------------------------------------------------------
060   public File getFile()
061   {
062      return mFile;
063   }
064
065   //---------------------------------------------------------------------------
066   public OfficeXMLPart setParentDoc(OfficeOpenXmlDocument inValue)
067   {
068      mParentDoc = inValue;
069      return this;
070   }
071
072   //---------------------------------------------------------------------------
073   public OfficeOpenXmlDocument getParentDoc()
074   {
075      return mParentDoc;
076   }
077
078   //---------------------------------------------------------------------------
079   @Override
080   public OfficeXMLPart clone()
081   {
082      return (OfficeXMLPart) super.clone();
083   }
084
085   //---------------------------------------------------------------------------
086   @Override
087   public String toString()
088   {
089      return (getFile() != null ? FileUtil.convertSeparatorsToUnix(getFile().getPath()) : super.toString());
090   }
091
092   //###########################################################################
093   // PROTECTED METHODS
094   //###########################################################################
095
096   //---------------------------------------------------------------------------
097   protected XMLTag getOrCreateSubtag(XMLName inTagName)
098   {
099      XMLTag subtag = getRootNode().getOptionalSubtagByName(inTagName.getLocalName());
100      if (null == subtag)
101      {
102         subtag = new XMLTag(inTagName);
103         getRootNode().addSubtag(subtag);
104      }
105
106      return subtag;
107   }
108
109}