1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "XMLIndexSimpleEntryContext.hxx"
21 #include "XMLIndexTemplateContext.hxx"
23 #include <xmloff/xmlictxt.hxx>
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/txtimp.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <sal/log.hxx>
31 #include <com/sun/star/container/XNameContainer.hpp>
33 using ::com::sun::star::beans::PropertyValue
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Sequence
;
36 using ::com::sun::star::uno::Any
;
37 using ::xmloff::token::XML_STYLE_NAME
;
40 XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
43 XMLIndexTemplateContext
& rTemplate
)
44 : SvXMLImportContext(rImport
)
45 , m_rEntryType(std::move(aEntry
))
46 , m_bCharStyleNameOK(false)
47 , m_rTemplateContext(rTemplate
)
52 XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
56 void XMLIndexSimpleEntryContext::startFastElement(
57 sal_Int32
/*nElement*/,
58 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
60 // we know only one attribute: style-name
61 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
63 if(aIter
.getToken() == XML_ELEMENT(TEXT
, XML_STYLE_NAME
))
65 m_sCharStyleName
= aIter
.toString();
66 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
67 XmlStyleFamily::TEXT_TEXT
, m_sCharStyleName
);
68 // #142494#: Check if style exists
69 const Reference
< css::container::XNameContainer
> & rStyles
=
70 GetImport().GetTextImport()->GetTextStyles();
71 if( rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
) )
72 m_bCharStyleNameOK
= true;
74 m_bCharStyleNameOK
= false;
77 XMLOFF_INFO_UNKNOWN("xmloff", aIter
);
80 // if we have a style name, set it!
81 if (m_bCharStyleNameOK
)
88 void XMLIndexSimpleEntryContext::endFastElement(sal_Int32
)
90 Sequence
<PropertyValue
> aValues(m_nValues
);
92 FillPropertyValues(aValues
);
93 m_rTemplateContext
.addTemplateEntry(aValues
);
96 void XMLIndexSimpleEntryContext::FillPropertyValues(
97 css::uno::Sequence
<css::beans::PropertyValue
> & rValues
)
99 // due to the limited number of subclasses, we fill the values
100 // directly into the slots. Subclasses will have to know they can
101 // only use slot so-and-so.
103 auto pValues
= rValues
.getArray();
106 pValues
[0].Name
= "TokenType";
107 pValues
[0].Value
<<= m_rEntryType
;
110 if (m_bCharStyleNameOK
)
112 pValues
[1].Name
= "CharacterStyleName";
113 pValues
[1].Value
<<= GetImport().GetStyleDisplayName(
114 XmlStyleFamily::TEXT_TEXT
,
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */