1*63bba73cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*63bba73cSAndrew Rist * distributed with this work for additional information 6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance 9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*63bba73cSAndrew Rist * software distributed under the License is distributed on an 15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the 17*63bba73cSAndrew Rist * specific language governing permissions and limitations 18*63bba73cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*63bba73cSAndrew Rist *************************************************************/ 21*63bba73cSAndrew Rist 22*63bba73cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_xmloff.hxx" 26cdf0e10cSrcweir #include "XMLSectionFootnoteConfigImport.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #ifndef _RTL_USTRING 29cdf0e10cSrcweir #include <rtl/ustring.hxx> 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 32cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp> 33cdf0e10cSrcweir #include <com/sun/star/style/NumberingType.hpp> 34cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 35cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 36cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 37cdf0e10cSrcweir #include <xmloff/xmlprmap.hxx> 38cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 39cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 40cdf0e10cSrcweir #include <xmloff/maptype.hxx> 41cdf0e10cSrcweir #include <xmloff/xmlnumi.hxx> 42cdf0e10cSrcweir #include <xmloff/txtprmap.hxx> 43cdf0e10cSrcweir #include <tools/debug.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include <vector> 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir using namespace ::xmloff::token; 49cdf0e10cSrcweir using namespace ::com::sun::star::style; 50cdf0e10cSrcweir 51cdf0e10cSrcweir using ::rtl::OUString; 52cdf0e10cSrcweir using ::std::vector; 53cdf0e10cSrcweir using ::com::sun::star::uno::Any; 54cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 55cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList; 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir TYPEINIT1(XMLSectionFootnoteConfigImport, SvXMLImportContext); 59cdf0e10cSrcweir 60cdf0e10cSrcweir 61cdf0e10cSrcweir XMLSectionFootnoteConfigImport::XMLSectionFootnoteConfigImport( 62cdf0e10cSrcweir SvXMLImport& rImport, 63cdf0e10cSrcweir sal_uInt16 nPrefix, 64cdf0e10cSrcweir const OUString& rLocalName, 65cdf0e10cSrcweir vector<XMLPropertyState> & rProps, 66cdf0e10cSrcweir const UniReference<XMLPropertySetMapper> & rMapperRef) : 67cdf0e10cSrcweir SvXMLImportContext(rImport, nPrefix, rLocalName), 68cdf0e10cSrcweir rProperties(rProps), 69cdf0e10cSrcweir rMapper(rMapperRef) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir XMLSectionFootnoteConfigImport::~XMLSectionFootnoteConfigImport() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir void XMLSectionFootnoteConfigImport::StartElement( 78cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir sal_Bool bEnd = sal_True; // we're inside the element, so this is true 81cdf0e10cSrcweir sal_Bool bNumOwn = sal_False; 82cdf0e10cSrcweir sal_Bool bNumRestart = sal_False; 83cdf0e10cSrcweir sal_Bool bEndnote = sal_False; 84cdf0e10cSrcweir sal_Int16 nNumRestartAt = 0; 85cdf0e10cSrcweir OUString sNumPrefix; 86cdf0e10cSrcweir OUString sNumSuffix; 87cdf0e10cSrcweir OUString sNumFormat; 88cdf0e10cSrcweir OUString sNumLetterSync; 89cdf0e10cSrcweir 90cdf0e10cSrcweir // iterate over xattribute list and fill values 91cdf0e10cSrcweir sal_Int16 nLength = xAttrList->getLength(); 92cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir OUString sLocalName; 95cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 96cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 97cdf0e10cSrcweir &sLocalName ); 98cdf0e10cSrcweir OUString sAttrValue = xAttrList->getValueByIndex(nAttr); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if (XML_NAMESPACE_TEXT == nPrefix) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if (IsXMLToken(sLocalName, XML_START_VALUE)) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir sal_Int32 nTmp; 105cdf0e10cSrcweir if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue)) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir nNumRestartAt = static_cast< sal_Int16 >( nTmp ) - 1; 108cdf0e10cSrcweir bNumRestart = sal_True; 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir else if( IsXMLToken( sLocalName, XML_NOTE_CLASS ) ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir if( IsXMLToken( sAttrValue, XML_ENDNOTE ) ) 114cdf0e10cSrcweir bEndnote = sal_True; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir else if (XML_NAMESPACE_STYLE == nPrefix) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir if (IsXMLToken(sLocalName, XML_NUM_PREFIX)) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir sNumPrefix = sAttrValue; 122cdf0e10cSrcweir bNumOwn = sal_True; 123cdf0e10cSrcweir } 124cdf0e10cSrcweir else if (IsXMLToken(sLocalName, XML_NUM_SUFFIX)) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir sNumSuffix = sAttrValue; 127cdf0e10cSrcweir bNumOwn = sal_True; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir else if (IsXMLToken(sLocalName, XML_NUM_FORMAT)) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir sNumFormat = sAttrValue; 132cdf0e10cSrcweir bNumOwn = sal_True; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else if (IsXMLToken(sLocalName, XML_NUM_LETTER_SYNC)) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir sNumLetterSync = sAttrValue; 137cdf0e10cSrcweir bNumOwn = sal_True; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir // OK, now we have all values and can fill the XMLPropertyState vector 143cdf0e10cSrcweir Any aAny; 144cdf0e10cSrcweir 145cdf0e10cSrcweir aAny.setValue( &bNumOwn, ::getBooleanCppuType() ); 146cdf0e10cSrcweir sal_Int32 nIndex = rMapper->FindEntryIndex( bEndnote ? 147cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_OWN : CTF_SECTION_FOOTNOTE_NUM_OWN ); 148cdf0e10cSrcweir XMLPropertyState aNumOwn( nIndex, aAny ); 149cdf0e10cSrcweir rProperties.push_back( aNumOwn ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir aAny.setValue( &bNumRestart, ::getBooleanCppuType() ); 152cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 153cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_RESTART : CTF_SECTION_FOOTNOTE_NUM_RESTART ); 154cdf0e10cSrcweir XMLPropertyState aNumRestart( nIndex, aAny ); 155cdf0e10cSrcweir rProperties.push_back( aNumRestart ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir aAny <<= nNumRestartAt; 158cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 159cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_RESTART_AT : 160cdf0e10cSrcweir CTF_SECTION_FOOTNOTE_NUM_RESTART_AT ); 161cdf0e10cSrcweir XMLPropertyState aNumRestartAtState( nIndex, aAny ); 162cdf0e10cSrcweir rProperties.push_back( aNumRestartAtState ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir sal_Int16 nNumType = NumberingType::ARABIC; 165cdf0e10cSrcweir GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, 166cdf0e10cSrcweir sNumFormat, 167cdf0e10cSrcweir sNumLetterSync ); 168cdf0e10cSrcweir aAny <<= nNumType; 169cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 170cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_TYPE : CTF_SECTION_FOOTNOTE_NUM_TYPE ); 171cdf0e10cSrcweir XMLPropertyState aNumFormatState( nIndex, aAny ); 172cdf0e10cSrcweir rProperties.push_back( aNumFormatState ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir aAny <<= sNumPrefix; 175cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 176cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_PREFIX : CTF_SECTION_FOOTNOTE_NUM_PREFIX ); 177cdf0e10cSrcweir XMLPropertyState aPrefixState( nIndex, aAny ); 178cdf0e10cSrcweir rProperties.push_back( aPrefixState ); 179cdf0e10cSrcweir 180cdf0e10cSrcweir aAny <<= sNumSuffix; 181cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 182cdf0e10cSrcweir CTF_SECTION_ENDNOTE_NUM_SUFFIX : CTF_SECTION_FOOTNOTE_NUM_SUFFIX ); 183cdf0e10cSrcweir XMLPropertyState aSuffixState( nIndex, aAny ); 184cdf0e10cSrcweir rProperties.push_back( aSuffixState ); 185cdf0e10cSrcweir 186cdf0e10cSrcweir aAny.setValue( &bEnd, ::getBooleanCppuType() ); 187cdf0e10cSrcweir nIndex = rMapper->FindEntryIndex( bEndnote ? 188cdf0e10cSrcweir CTF_SECTION_ENDNOTE_END : CTF_SECTION_FOOTNOTE_END ); 189cdf0e10cSrcweir XMLPropertyState aEndState( nIndex, aAny ); 190cdf0e10cSrcweir rProperties.push_back( aEndState ); 191cdf0e10cSrcweir } 192