001package com.hfg.xml.msofficexml.xlsx.spreadsheetml; 002 003 004import com.hfg.exception.ProgrammingException; 005import com.hfg.xml.XMLNamespace; 006import com.hfg.xml.XMLTag; 007import com.hfg.xml.msofficexml.xlsx.CellRange; 008 009//------------------------------------------------------------------------------ 010/** 011 Represents an Office Open XML extension (<ssml:ext>) tag. 012 013 @author J. Alex Taylor, hairyfatguy.com 014 */ 015//------------------------------------------------------------------------------ 016// com.hfg XML/HTML Coding Library 017// 018// This library is free software; you can redistribute it and/or 019// modify it under the terms of the GNU Lesser General Public 020// License as published by the Free Software Foundation; either 021// version 2.1 of the License, or (at your option) any later version. 022// 023// This library is distributed in the hope that it will be useful, 024// but WITHOUT ANY WARRANTY; without even the implied warranty of 025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 026// Lesser General Public License for more details. 027// 028// You should have received a copy of the GNU Lesser General Public 029// License along with this library; if not, write to the Free Software 030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 031// 032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 033// jataylor@hairyfatguy.com 034//------------------------------------------------------------------------------ 035 036public class SsmlExtension extends SsmlXMLTag 037{ 038 private SsmlWorksheet mParentWorksheet; 039 private XMLTag mConditionalFormattings; 040 041 // Specifies the URI to use for the extension when they contain the following child element types. 042 // These are constant values defined by Microsoft 043 // See https://docs.microsoft.com/en-us/openspecs/office_standards/ms-xlsx/07d607af-5618-4ca2-b683-6a78dc0d9627 044 public enum URI_Type 045 { 046 conditionalFormattings("{78C0D931-6437-407d-A8EE-F0AAD7539E65}"), // This value has a mistaken uppercase 'D' in the reference! 047 dataValidations("{CCE6A557-97BC-4B89-ADB6-D9C93CAAB3DF}"), 048 sparklineGroups("{05C60535-1F16-4FD2-B633-F4F36F0B64E0}"), 049 slicerList("{A8765BA9-456A-4DAB-B4F3-ACF838C121DE}"), 050 protectedRanges("{FC87AEE6-9EDD-4A0A-B7FB-166176984837}"), 051 ignoredErrors("{01252117-D84E-4E92-8308-4BE1C098FCBB}"), 052 webExtensions("{F7C9EE02-42E1-4005-9D12-6889AFFD525C}"), 053 timelineRefs("{7E03D99C-DC04-49d9-9315-930204A7B6E9}"), 054 055 id("{B025F937-C7B1-47D3-B67F-A62EFF666E3E}"); 056 057 private String mURI; 058 059 private URI_Type(String inURI) 060 { 061 mURI = inURI; 062 } 063 064 public String getURI() 065 { 066 return mURI; 067 } 068 } 069 070 //########################################################################### 071 // CONSTRUCTORS 072 //########################################################################### 073 074 //--------------------------------------------------------------------------- 075 public SsmlExtension(SsmlWorksheet inParentWorksheet, XMLNamespace inNamespace, URI_Type inURI_Type) 076 { 077 super(SsmlXML.EXTENSION, inParentWorksheet.getParentDoc()); 078 mParentWorksheet = inParentWorksheet; 079 setAttribute(SsmlXML.URI_ATT, inURI_Type.getURI()); 080 081 addXMLNamespaceDeclaration(inNamespace); 082 } 083 084 //########################################################################### 085 // PUBLIC METHODS 086 //########################################################################### 087 088 //--------------------------------------------------------------------------- 089 public SsmlConditionalFormatting addConditionalFormatting(CellRange inCellRange) 090 { 091 // Consistency check 092 uriConsistencyCheck(URI_Type.conditionalFormattings); 093 094 // Extensions are collected under an extLst tag 095 if (null == mConditionalFormattings) 096 { 097 // Check it it has been added via addSubtag()... 098 mConditionalFormattings = getOptionalSubtagByName(SsmlXML.X14_CONDITIONAL_FORMATTINGS); 099 if (null == mConditionalFormattings) 100 { 101 mConditionalFormattings = new XMLTag(SsmlXML.X14_CONDITIONAL_FORMATTINGS); 102 addSubtag(mConditionalFormattings); 103 } 104 } 105 106 SsmlConditionalFormatting conditionalFormatting = new SsmlConditionalFormatting(mParentWorksheet, inCellRange, SsmlXML.SPREADSHEETML_2009_NAMESPACE); 107 mConditionalFormattings.addSubtag(conditionalFormatting); 108 109 return conditionalFormatting; 110 } 111 112 //########################################################################### 113 // PRIVATE METHODS 114 //########################################################################### 115 116 //--------------------------------------------------------------------------- 117 private void uriConsistencyCheck(URI_Type inExpectedURI_Type) 118 { 119 String uri = getAttributeValue(SsmlXML.URI_ATT); 120 if (null == uri) 121 { 122 throw new ProgrammingException("No uri value specified for extension!"); 123 } 124 else if (! uri.equals(inExpectedURI_Type.getURI())) 125 { 126 throw new ProgrammingException("Mismatched extension uri value for content!"); 127 } 128 } 129}