001package com.hfg.xml.msofficexml.part;
002
003import java.io.File;
004
005import com.hfg.util.FileUtil;
006import com.hfg.xml.XMLTag;
007import com.hfg.xml.msofficexml.OfficeOpenXmlDocument;
008import com.hfg.xml.msofficexml.OfficeXML;
009import com.hfg.xml.msofficexml.RelationshipType;
010
011//------------------------------------------------------------------------------
012/**
013 Represents an Office Open XML package relationship part.
014
015 @author J. Alex Taylor, hairyfatguy.com
016 */
017//------------------------------------------------------------------------------
018// com.hfg XML/HTML Coding Library
019//
020// This library is free software; you can redistribute it and/or
021// modify it under the terms of the GNU Lesser General Public
022// License as published by the Free Software Foundation; either
023// version 2.1 of the License, or (at your option) any later version.
024//
025// This library is distributed in the hope that it will be useful,
026// but WITHOUT ANY WARRANTY; without even the implied warranty of
027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
028// Lesser General Public License for more details.
029//
030// You should have received a copy of the GNU Lesser General Public
031// License along with this library; if not, write to the Free Software
032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
033//
034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
035// jataylor@hairyfatguy.com
036//------------------------------------------------------------------------------
037
038public class PackageRelationshipPart extends OfficeXMLPart
039{
040   private int mIndex = 1;
041
042   //---------------------------------------------------------------------------
043   public PackageRelationshipPart(OfficeOpenXmlDocument inOfficeDoc)
044   {
045      super(inOfficeDoc);
046
047      setFile(OfficeXML.PACKAGE_RELATIONSHIP_FILE);
048
049      setRootNode(new XMLTag(OfficeXML.RELATIONSHIPS));
050   }
051
052   //---------------------------------------------------------------------------
053   public String addRelationship(RelationshipType inType, File inTarget)
054   {
055      String id = "rId" + (mIndex++);
056      XMLTag relationshipTag = new XMLTag(OfficeXML.RELATIONSHIP);
057      relationshipTag.setAttribute(OfficeXML.ID_ATT, id);
058      relationshipTag.setAttribute(OfficeXML.TYPE_ATT, inType);
059      relationshipTag.setAttribute(OfficeXML.TARGET_ATT, FileUtil.convertSeparatorsToUnix(inTarget.getPath()));
060      getRootNode().addSubtag(relationshipTag);
061
062      return id;
063   }
064}