001package com.hfg.xml.msofficexml;
002
003
004//------------------------------------------------------------------------------
005
006import com.hfg.util.StringUtil;
007import com.hfg.xml.XMLTag;
008
009/**
010 Content types specific to OfficeOpenXML.
011
012 @author J. Alex Taylor, hairyfatguy.com
013 */
014//------------------------------------------------------------------------------
015// com.hfg XML/HTML Coding Library
016//
017// This library is free software; you can redistribute it and/or
018// modify it under the terms of the GNU Lesser General Public
019// License as published by the Free Software Foundation; either
020// version 2.1 of the License, or (at your option) any later version.
021//
022// This library is distributed in the hope that it will be useful,
023// but WITHOUT ANY WARRANTY; without even the implied warranty of
024// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
025// Lesser General Public License for more details.
026//
027// You should have received a copy of the GNU Lesser General Public
028// License along with this library; if not, write to the Free Software
029// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030//
031// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
032// jataylor@hairyfatguy.com
033//------------------------------------------------------------------------------
034
035public class OfficeOpenXMLContentType
036{
037   public static final OfficeOpenXMLContentType IMAGE_JPEG          = new OfficeOpenXMLContentType("image/jpeg").setExtension("jpeg");
038   public static final OfficeOpenXMLContentType IMAGE_JPG           = new OfficeOpenXMLContentType("image/jpeg").setExtension("jpg");
039   public static final OfficeOpenXMLContentType IMAGE_PNG           = new OfficeOpenXMLContentType("image/png").setExtension("png");
040
041   public static final OfficeOpenXMLContentType APPLICATION         = new OfficeOpenXMLContentType("application/xml").setExtension("xml");
042   public static final OfficeOpenXMLContentType CORE_PROPERTIES     = new OfficeOpenXMLContentType("application/vnd.openxmlformats-package.core-properties+xml");
043   public static final OfficeOpenXMLContentType DRAWING             = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.drawing+xml");
044   public static final OfficeOpenXMLContentType EXTENDED_PROPERTIES = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.extended-properties+xml");
045   public static final OfficeOpenXMLContentType RELATIONSHIPS       = new OfficeOpenXMLContentType("application/vnd.openxmlformats-package.relationships+xml").setExtension("rels");
046   public static final OfficeOpenXMLContentType THEME               = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.theme+xml");
047   public static final OfficeOpenXMLContentType HEADER              = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml");
048   public static final OfficeOpenXMLContentType FOOTER              = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml");
049   public static final OfficeOpenXMLContentType FOOTNOTES           = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.footnotes+xml");
050   public static final OfficeOpenXMLContentType COMMENTS            = new OfficeOpenXMLContentType("application/vnd.openxmlformats-officedocument.comments+xml");
051
052   private String mTypeString;
053   private String mExtension;
054
055   //---------------------------------------------------------------------------
056   protected OfficeOpenXMLContentType(String inTypeString)
057   {
058      mTypeString = inTypeString;
059   }
060
061   //---------------------------------------------------------------------------
062   protected OfficeOpenXMLContentType setExtension(String inValue)
063   {
064      mExtension = inValue;
065      return this;
066   }
067
068   //---------------------------------------------------------------------------
069   public String getTypeString()
070   {
071      return mTypeString;
072   }
073
074   //---------------------------------------------------------------------------
075   public String getExtension()
076   {
077      return mExtension;
078   }
079
080   //---------------------------------------------------------------------------
081   public XMLTag toXMLTag()
082   {
083      XMLTag tag = new XMLTag(StringUtil.isSet(getExtension()) ? OfficeXML.DEFAULT : OfficeXML.OVERRIDE);
084      tag.setAttribute(OfficeXML.CONTENT_TYPE_ATT, getTypeString());
085
086      if (StringUtil.isSet(getExtension()))
087      {
088         tag.setAttribute(OfficeXML.EXTENSION_ATT, getExtension());
089      }
090
091      return tag;
092   }
093
094   //---------------------------------------------------------------------------
095   @Override
096   public String toString()
097   {
098      return getTypeString();
099   }
100}