001package com.hfg.xml.msofficexml.docx.wordprocessingml.style; 002 003 004import com.hfg.util.StringBuilderPlus; 005import com.hfg.xml.msofficexml.OfficeXML; 006import com.hfg.xml.msofficexml.docx.Docx; 007import com.hfg.xml.msofficexml.docx.RelationshipXML; 008import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlXML; 009import com.hfg.xml.msofficexml.docx.wordprocessingml.WmlXMLTag; 010 011//------------------------------------------------------------------------------ 012/** 013 Root tag for Docx's Office Open XML document styles 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 WmlStyles extends WmlXMLTag 039{ 040 private int mIdSrc = 1; 041 042 //########################################################################## 043 // CONSTRUCTORS 044 //########################################################################## 045 046 //--------------------------------------------------------------------------- 047 public WmlStyles(Docx inDocx) 048 { 049 super(WmlXML.STYLES, inDocx); 050 051 addXMLNamespaceDeclaration(WmlXML.WORDPROCESSINGML_NAMESPACE); 052 addXMLNamespaceDeclaration(RelationshipXML.RELATIONSHIP_NAMESPACE); 053 addXMLNamespaceDeclaration(OfficeXML.MARKUP_CAPABILITY_NAMESPACE); 054 addXMLNamespaceDeclaration(WmlXML.WORDML_14_NAMESPACE); 055 addXMLNamespaceDeclaration(WmlXML.WORDML_15_NAMESPACE); 056 addXMLNamespaceDeclaration(WmlXML.WORDML_16_NAMESPACE); 057 addXMLNamespaceDeclaration(WmlXML.WORDML_16_COMMENTS_EXTENSIBLE_NAMESPACE); 058 addXMLNamespaceDeclaration(WmlXML.WORDML_16_COMMENTS_IDS_NAMESPACE); 059 addXMLNamespaceDeclaration(WmlXML.WORDML_16_SYMEX_NAMESPACE); 060 061 StringBuilderPlus ignorable = new StringBuilderPlus().setDelimiter(" ") 062 .delimitedAppend(WmlXML.WORDML_14_NAMESPACE.getPrefix()) 063 .delimitedAppend(WmlXML.WORDML_15_NAMESPACE.getPrefix()) 064 .delimitedAppend(WmlXML.WORDML_16_NAMESPACE.getPrefix()) 065 .delimitedAppend(WmlXML.WORDML_16_COMMENTS_EXTENSIBLE_NAMESPACE.getPrefix()) 066 .delimitedAppend(WmlXML.WORDML_16_COMMENTS_IDS_NAMESPACE.getPrefix()) 067 .delimitedAppend(WmlXML.WORDML_16_SYMEX_NAMESPACE.getPrefix()); 068 setAttribute(OfficeXML.IGNORABLE_ATT, ignorable); 069 070 } 071 072 //########################################################################## 073 // PUBLIC METHODS 074 //########################################################################## 075 076 //--------------------------------------------------------------------------- 077 public String addStyle(WmlStyle inStyle) 078 { 079 String id = inStyle.getId(); 080 if (null == id) 081 { 082 id = "" + mIdSrc++; 083 inStyle.setAttribute(WmlXML.ID_ATT, id); 084 } 085 086 if (null == inStyle.getName()) 087 { 088 inStyle.setName(id); 089 } 090 091 addSubtag(inStyle); 092 093 return id; 094 } 095}