Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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/xmlnmspe.hxx"
27 : #include <xmloff/nmspmap.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>
32 :
33 :
34 : using namespace ::xmloff::token;
35 :
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;
42 :
43 :
44 : const sal_Char sAPI_LevelParagraphStyles[] = "LevelParagraphStyles";
45 :
46 0 : TYPEINIT1( XMLIndexTOCStylesContext, SvXMLImportContext );
47 :
48 :
49 0 : XMLIndexTOCStylesContext::XMLIndexTOCStylesContext(
50 : SvXMLImport& rImport,
51 : Reference<XPropertySet> & rPropSet,
52 : sal_uInt16 nPrfx,
53 : const OUString& rLocalName )
54 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
55 : , sLevelParagraphStyles(sAPI_LevelParagraphStyles)
56 0 : , rTOCPropertySet(rPropSet)
57 : {
58 0 : }
59 :
60 0 : XMLIndexTOCStylesContext::~XMLIndexTOCStylesContext()
61 : {
62 0 : }
63 :
64 0 : void XMLIndexTOCStylesContext::StartElement(
65 : const Reference<XAttributeList> & xAttrList )
66 : {
67 : // find text:outline-level attribute
68 0 : sal_Int16 nCount = xAttrList->getLength();
69 0 : for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
70 : {
71 0 : OUString sLocalName;
72 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
73 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
74 0 : &sLocalName );
75 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
76 0 : (IsXMLToken(sLocalName, XML_OUTLINE_LEVEL)) )
77 : {
78 : sal_Int32 nTmp;
79 0 : if (::sax::Converter::convertNumber(
80 0 : nTmp, xAttrList->getValueByIndex(nAttr), 1,
81 0 : GetImport().GetTextImport()->GetChapterNumbering()->
82 0 : getCount()))
83 : {
84 : // API numbers 0..9, we number 1..10
85 0 : nOutlineLevel = nTmp-1;
86 : }
87 : }
88 0 : }
89 0 : }
90 :
91 0 : void XMLIndexTOCStylesContext::EndElement()
92 : {
93 : // if valid...
94 0 : if (nOutlineLevel >= 0)
95 : {
96 : // copy vector into sequence
97 0 : const sal_Int32 nCount = aStyleNames.size();
98 0 : Sequence<OUString> aStyleNamesSequence(nCount);
99 0 : for(sal_Int32 i = 0; i < nCount; i++)
100 : {
101 0 : aStyleNamesSequence[i] = GetImport().GetStyleDisplayName(
102 : XML_STYLE_FAMILY_TEXT_PARAGRAPH,
103 0 : aStyleNames[i] );
104 : }
105 :
106 : // get index replace
107 0 : Any aAny = rTOCPropertySet->getPropertyValue(sLevelParagraphStyles);
108 0 : Reference<XIndexReplace> xIndexReplace;
109 0 : aAny >>= xIndexReplace;
110 :
111 : // set style names
112 0 : aAny <<= aStyleNamesSequence;
113 0 : xIndexReplace->replaceByIndex(nOutlineLevel, aAny);
114 : }
115 0 : }
116 :
117 0 : SvXMLImportContext *XMLIndexTOCStylesContext::CreateChildContext(
118 : sal_uInt16 p_nPrefix,
119 : const OUString& rLocalName,
120 : const Reference<XAttributeList> & xAttrList )
121 : {
122 : // check for index-source-style
123 0 : if ( (XML_NAMESPACE_TEXT == p_nPrefix) &&
124 0 : IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLE ) )
125 : {
126 : // find text:style-name attribute and record in aStyleNames
127 0 : sal_Int16 nCount = xAttrList->getLength();
128 0 : for(sal_Int16 nAttr = 0; nAttr < nCount; nAttr++)
129 : {
130 0 : OUString sLocalName;
131 0 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
132 0 : GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
133 0 : &sLocalName );
134 0 : if ( (XML_NAMESPACE_TEXT == nPrefix) &&
135 0 : IsXMLToken( sLocalName, XML_STYLE_NAME ) )
136 : {
137 0 : aStyleNames.push_back(xAttrList->getValueByIndex(nAttr));
138 : }
139 0 : }
140 : }
141 :
142 : // always return default context; we already got the interesting info
143 : return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
144 0 : xAttrList);
145 : }
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|