All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlExtension Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.xlsx.spreadsheetml;


import com.hfg.exception.ProgrammingException;
import com.hfg.xml.XMLNamespace;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.xlsx.CellRange;

//------------------------------------------------------------------------------
/**
 Represents an Office Open XML extension (<ssml:ext>) tag.

 @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class SsmlExtension extends SsmlXMLTag
{
   private SsmlWorksheet mParentWorksheet;
   private XMLTag        mConditionalFormattings;

   // Specifies the URI to use for the extension when they contain the following child element types.
   // These are constant values defined by Microsoft
   // See https://docs.microsoft.com/en-us/openspecs/office_standards/ms-xlsx/07d607af-5618-4ca2-b683-6a78dc0d9627
   public enum URI_Type
   {
      conditionalFormattings("{78C0D931-6437-407d-A8EE-F0AAD7539E65}"), // This value has a mistaken uppercase 'D' in the reference!
      dataValidations("{CCE6A557-97BC-4B89-ADB6-D9C93CAAB3DF}"),
      sparklineGroups("{05C60535-1F16-4FD2-B633-F4F36F0B64E0}"),
      slicerList("{A8765BA9-456A-4DAB-B4F3-ACF838C121DE}"),
      protectedRanges("{FC87AEE6-9EDD-4A0A-B7FB-166176984837}"),
      ignoredErrors("{01252117-D84E-4E92-8308-4BE1C098FCBB}"),
      webExtensions("{F7C9EE02-42E1-4005-9D12-6889AFFD525C}"),
      timelineRefs("{7E03D99C-DC04-49d9-9315-930204A7B6E9}"),

      id("{B025F937-C7B1-47D3-B67F-A62EFF666E3E}");

      private String mURI;

      private URI_Type(String inURI)
      {
         mURI = inURI;
      }

      public String getURI()
      {
         return mURI;
      }
   }

   //###########################################################################
   // CONSTRUCTORS
   //###########################################################################

   //---------------------------------------------------------------------------
   public SsmlExtension(SsmlWorksheet inParentWorksheet, XMLNamespace inNamespace, URI_Type inURI_Type)
   {
      super(SsmlXML.EXTENSION, inParentWorksheet.getParentDoc());
      mParentWorksheet = inParentWorksheet;
      setAttribute(SsmlXML.URI_ATT, inURI_Type.getURI());

      addXMLNamespaceDeclaration(inNamespace);
   }

   //###########################################################################
   // PUBLIC METHODS
   //###########################################################################

   //---------------------------------------------------------------------------
   public SsmlConditionalFormatting addConditionalFormatting(CellRange inCellRange)
   {
      // Consistency check
      uriConsistencyCheck(URI_Type.conditionalFormattings);

      // Extensions are collected under an extLst tag
      if (null == mConditionalFormattings)
      {
         // Check it it has been added via addSubtag()...
         mConditionalFormattings = getOptionalSubtagByName(SsmlXML.X14_CONDITIONAL_FORMATTINGS);
         if (null == mConditionalFormattings)
         {
            mConditionalFormattings = new XMLTag(SsmlXML.X14_CONDITIONAL_FORMATTINGS);
            addSubtag(mConditionalFormattings);
         }
      }

      SsmlConditionalFormatting conditionalFormatting = new SsmlConditionalFormatting(mParentWorksheet, inCellRange, SsmlXML.SPREADSHEETML_2009_NAMESPACE);
      mConditionalFormattings.addSubtag(conditionalFormatting);

      return conditionalFormatting;
   }

   //###########################################################################
   // PRIVATE METHODS
   //###########################################################################

   //---------------------------------------------------------------------------
   private void uriConsistencyCheck(URI_Type inExpectedURI_Type)
   {
      String uri = getAttributeValue(SsmlXML.URI_ATT);
      if (null == uri)
      {
         throw new ProgrammingException("No uri value specified for extension!");
      }
      else if (! uri.equals(inExpectedURI_Type.getURI()))
      {
         throw new ProgrammingException("Mismatched extension uri value for content!");
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy