update dev300-m58
[ooovba.git] / xmloff / source / text / XMLIndexTOCStylesContext.cxx
blobae43e705fbde80925ac76d0e1a3da1e55158bf32
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexTOCStylesContext.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexTOCStylesContext.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include <xmloff/xmlictxt.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include "xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
46 #include <tools/debug.hxx>
47 #include <rtl/ustring.hxx>
50 using namespace ::xmloff::token;
52 using ::rtl::OUString;
53 using ::com::sun::star::beans::XPropertySet;
54 using ::com::sun::star::uno::Reference;
55 using ::com::sun::star::uno::Sequence;
56 using ::com::sun::star::uno::Any;
57 using ::com::sun::star::container::XIndexReplace;
58 using ::com::sun::star::xml::sax::XAttributeList;
61 const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles";
63 TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext );
66 XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
67 SvXMLImport& rImport,
68 Reference<XPropertySet> & rPropSet,
69 sal_uInt16 nPrfx,
70 const OUString& rLocalName )
71 : SvXMLImportContext(rImport, nPrfx, rLocalName)
72 , sLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(sAPI_LevelParagraphStyles))
73 , rTOCPropertySet(rPropSet)
77 XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
81 void XMLIndexTOCStylesContext::StartElement(
82 const Reference<XAttributeList> & xAttrList )
84 // find text:outline-level attribute
85 sal_Int16 nCount = xAttrList->getLength();
86 for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
88 OUString sLocalName;
89 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
90 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
91 &sLocalName );
92 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
93 (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
95 sal_Int32 nTmp;
96 if (SvXMLUnitConverter::convertNumber(
97 nTmp, xAttrList->getValueByIndex(nAttr), 1,
98 GetImport().GetTextImport()->GetChapterNumbering()->
99 getCount()))
101 // API numbers 0..9, we number 1..10
102 nOutlineLevel = nTmp-1;
108 void XMLIndexTOCStylesContext::EndElement()
110 // if valid...
111 if (nOutlineLevel >= 0)
113 // copy vector into sequence
114 const sal_Int32 nCount = aStyleNames.size();
115 Sequence<OUString> aStyleNamesSequence(nCount);
116 for(sal_Int32 i = 0; i < nCount; i++)
118 aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
119 XML_STYLE_FAMILY_TEXT_PARAGRAPH,
120 aStyleNames[i] );
123 // get index replace
124 Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles);
125 Reference<XIndexReplace> xIndexReplace;
126 aAny >>= xIndexReplace;
128 // set style names
129 aAny <<= aStyleNamesSequence;
130 xIndexReplace->replaceByIndex(nOutlineLevel, aAny);
134 SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext(
135 sal_uInt16 p_nPrefix,
136 const OUString& rLocalName,
137 const Reference<XAttributeList> & xAttrList )
139 // check for index-source-style
140 if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
141 IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
143 // find text:style-name attribute and record in aStyleNames
144 sal_Int16 nCount = xAttrList->getLength();
145 for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
147 OUString sLocalName;
148 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
149 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
150 &sLocalName );
151 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
152 IsXMLToken( sLocalName, XML_STYLE_NAME ) )
154 aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
159 // always return default context; we already got the interesting info
160 return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
161 xAttrList);