nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / text / XMLIndexTOCStylesContext.cxx
blob3eda66f4b9184e8ab3c4f93a2670d6113146e07c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "XMLIndexTOCStylesContext.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XIndexReplace.hpp>
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/txtimp.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/namespacemap.hxx>
28 #include <xmloff/xmltoken.hxx>
29 #include <sax/tools/converter.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <rtl/ustring.hxx>
34 using namespace ::xmloff::token;
36 using ::com::sun::star::beans::XPropertySet;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::container::XIndexReplace;
41 using ::com::sun::star::xml::sax::XAttributeList;
45 XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
46 SvXMLImport& rImport, Reference<XPropertySet> & rPropSet,
47 sal_uInt16 nPrfx, const OUString& rLocalName)
48 : SvXMLImportContext(rImport, nPrfx, rLocalName)
49 , rTOCPropertySet(rPropSet)
50 , nOutlineLevel(0)
54 XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
58 void XMLIndexTOCStylesContext::StartElement(
59 const Reference<XAttributeList> & xAttrList )
61 // find text:outline-level attribute
62 sal_Int16 nCount = xAttrList->getLength();
63 for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
65 OUString sLocalName;
66 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
67 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
68 &sLocalName );
69 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
70 (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
72 sal_Int32 nTmp;
73 if (::sax::Converter::convertNumber(
74 nTmp, xAttrList->getValueByIndex(nAttr), 1,
75 GetImport().GetTextImport()->GetChapterNumbering()->
76 getCount()))
78 // API numbers 0..9, we number 1..10
79 nOutlineLevel = nTmp-1;
85 void XMLIndexTOCStylesContext::endFastElement(sal_Int32 )
87 // if valid...
88 if (nOutlineLevel < 0)
89 return;
91 // copy vector into sequence
92 const sal_Int32 nCount = aStyleNames.size();
93 Sequence<OUString> aStyleNamesSequence(nCount);
94 for(sal_Int32 i = 0; i < nCount; i++)
96 aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
97 XmlStyleFamily::TEXT_PARAGRAPH,
98 aStyleNames[i] );
101 // get index replace
102 Any aAny = rTOCPropertySet->getPropertyValue("LevelParagraphStyles");
103 Reference<XIndexReplace> xIndexReplace;
104 aAny >>= xIndexReplace;
106 // set style names
107 xIndexReplace->replaceByIndex(nOutlineLevel, Any(aStyleNamesSequence));
110 SvXMLImportContextRef XMLIndexTOCStylesContext::CreateChildContext(
111 sal_uInt16 p_nPrefix,
112 const OUString& rLocalName,
113 const Reference<XAttributeList> & xAttrList )
115 // check for index-source-style
116 if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
117 IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
119 // find text:style-name attribute and record in aStyleNames
120 sal_Int16 nCount = xAttrList->getLength();
121 for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
123 OUString sLocalName;
124 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
125 GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
126 &sLocalName );
127 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
128 IsXMLToken( sLocalName, XML_STYLE_NAME ) )
130 aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
135 // always return default context; we already got the interesting info
136 return new SvXMLImportContext(GetImport());
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */