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 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "XMLIndexTOCStylesContext.hxx" 29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 30cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 31cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 32cdf0e10cSrcweir #include <xmloff/xmlimp.hxx> 33cdf0e10cSrcweir #include <xmloff/txtimp.hxx> 34cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx" 35cdf0e10cSrcweir #include <xmloff/nmspmap.hxx> 36cdf0e10cSrcweir #include <xmloff/xmltoken.hxx> 37cdf0e10cSrcweir #include <xmloff/xmluconv.hxx> 38cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 39cdf0e10cSrcweir #include <tools/debug.hxx> 40cdf0e10cSrcweir #include <rtl/ustring.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::xmloff::token; 44cdf0e10cSrcweir 45cdf0e10cSrcweir using ::rtl::OUString; 46cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 47cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 48cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 49cdf0e10cSrcweir using ::com::sun::star::uno::Any; 50cdf0e10cSrcweir using ::com::sun::star::container::XIndexReplace; 51cdf0e10cSrcweir using ::com::sun::star::xml::sax::XAttributeList; 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles"; 55cdf0e10cSrcweir 56cdf0e10cSrcweir TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext ); 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir XMLIndexTOCStylesContext::XMLIndexTOCStylesContext( 60cdf0e10cSrcweir SvXMLImport& rImport, 61cdf0e10cSrcweir Reference<XPropertySet> & rPropSet, 62cdf0e10cSrcweir sal_uInt16 nPrfx, 63cdf0e10cSrcweir const OUString& rLocalName ) 64cdf0e10cSrcweir : SvXMLImportContext(rImport, nPrfx, rLocalName) 65cdf0e10cSrcweir , sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_LevelParagraphStyles)) 66cdf0e10cSrcweir , rTOCPropertySet(rPropSet) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir void XMLIndexTOCStylesContext::StartElement( 75cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir // find text:outline-level attribute 78cdf0e10cSrcweir sal_Int16 nCount = xAttrList->getLength(); 79cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir OUString sLocalName; 82cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 83cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 84cdf0e10cSrcweir &sLocalName ); 85cdf0e10cSrcweir if ( (XML_NAMESPACE_TEXT == nPrefix) && 86cdf0e10cSrcweir (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) ) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir sal_Int32 nTmp; 89cdf0e10cSrcweir if (SvXMLUnitConverter::convertNumber( 90cdf0e10cSrcweir nTmp, xAttrList->getValueByIndex(nAttr), 1, 91cdf0e10cSrcweir GetImport().GetTextImport()->GetChapterNumbering()-> 92cdf0e10cSrcweir getCount())) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir // API numbers 0..9, we number 1..10 95cdf0e10cSrcweir nOutlineLevel = nTmp-1; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir } 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir void XMLIndexTOCStylesContext::EndElement() 102cdf0e10cSrcweir { 103cdf0e10cSrcweir // if valid... 104cdf0e10cSrcweir if (nOutlineLevel >= 0) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir // copy vector into sequence 107cdf0e10cSrcweir const sal_Int32 nCount = aStyleNames.size(); 108cdf0e10cSrcweir Sequence<OUString> aStyleNamesSequence(nCount); 109cdf0e10cSrcweir for(sal_Int32 i = 0; i < nCount; i++) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir aStyleNamesSequence[i] = GetImport().GetStyleDisplayName( 112cdf0e10cSrcweir XML_STYLE_FAMILY_TEXT_PARAGRAPH, 113cdf0e10cSrcweir aStyleNames[i] ); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir // get index replace 117cdf0e10cSrcweir Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles); 118cdf0e10cSrcweir Reference<XIndexReplace> xIndexReplace; 119cdf0e10cSrcweir aAny >>= xIndexReplace; 120cdf0e10cSrcweir 121cdf0e10cSrcweir // set style names 122cdf0e10cSrcweir aAny <<= aStyleNamesSequence; 123cdf0e10cSrcweir xIndexReplace->replaceByIndex(nOutlineLevel, aAny); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext( 128cdf0e10cSrcweir sal_uInt16 p_nPrefix, 129cdf0e10cSrcweir const OUString& rLocalName, 130cdf0e10cSrcweir const Reference<XAttributeList> & xAttrList ) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // check for index-source-style 133cdf0e10cSrcweir if ( (XML_NAMESPACE_TEXT == p_nPrefix) && 134cdf0e10cSrcweir IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir // find text:style-name attribute and record in aStyleNames 137cdf0e10cSrcweir sal_Int16 nCount = xAttrList->getLength(); 138cdf0e10cSrcweir for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir OUString sLocalName; 141cdf0e10cSrcweir sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). 142cdf0e10cSrcweir GetKeyByAttrName( xAttrList->getNameByIndex(nAttr), 143cdf0e10cSrcweir &sLocalName ); 144cdf0e10cSrcweir if ( (XML_NAMESPACE_TEXT == nPrefix) && 145cdf0e10cSrcweir IsXMLToken( sLocalName, XML_STYLE_NAME ) ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir aStyleNames.push_back(xAttrList->getValueByIndex(nAttr)); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir } 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir // always return default context; we already got the interesting info 153cdf0e10cSrcweir return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName, 154cdf0e10cSrcweir xAttrList); 155cdf0e10cSrcweir } 156