LibreOffice Module xmloff (master) 1
XMLIndexSimpleEntryContext.cxx
Go to the documentation of this file.
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
22#include <utility>
23#include <xmloff/xmlictxt.hxx>
24#include <xmloff/xmlimp.hxx>
25#include <xmloff/txtimp.hxx>
28#include <xmloff/xmltoken.hxx>
29#include <xmloff/xmluconv.hxx>
30#include <sal/log.hxx>
31
32#include <com/sun/star/container/XNameContainer.hpp>
33
34using ::com::sun::star::beans::PropertyValue;
35using ::com::sun::star::uno::Reference;
36using ::com::sun::star::uno::Sequence;
37using ::com::sun::star::uno::Any;
39
40
42 SvXMLImport& rImport,
43 OUString aEntry,
44 XMLIndexTemplateContext& rTemplate )
45: SvXMLImportContext(rImport)
46, m_rEntryType(std::move(aEntry))
47, m_bCharStyleNameOK(false)
48, m_rTemplateContext(rTemplate)
49, m_nValues(1)
50{
51}
52
54{
55}
56
58 sal_Int32 /*nElement*/,
59 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
60{
61 // we know only one attribute: style-name
62 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
63 {
64 if(aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
65 {
66 m_sCharStyleName = aIter.toString();
67 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
69 // #142494#: Check if style exists
70 const Reference < css::container::XNameContainer > & rStyles =
71 GetImport().GetTextImport()->GetTextStyles();
72 if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
73 m_bCharStyleNameOK = true;
74 else
75 m_bCharStyleNameOK = false;
76 }
77 else
78 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
79 }
80
81 // if we have a style name, set it!
83 {
84 m_nValues++;
85 }
86
87}
88
90{
91 Sequence<PropertyValue> aValues(m_nValues);
92
93 FillPropertyValues(aValues);
95}
96
98 css::uno::Sequence<css::beans::PropertyValue> & rValues)
99{
100 // due to the limited number of subclasses, we fill the values
101 // directly into the slots. Subclasses will have to know they can
102 // only use slot so-and-so.
103
104 Any aAny;
105 auto pValues = rValues.getArray();
106
107 // token type
108 pValues[0].Name = "TokenType";
109 pValues[0].Value <<= m_rEntryType;
110
111 // char style
113 {
114 pValues[1].Name = "CharacterStyleName";
115 aAny <<= GetImport().GetStyleDisplayName(
118 pValues[1].Value = aAny;
119 }
120
121}
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
process parameters
XMLIndexTemplateContext & m_rTemplateContext
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
call FillPropertyValues and insert into template
XMLIndexSimpleEntryContext(SvXMLImport &rImport, OUString aEntry, XMLIndexTemplateContext &rTemplate)
Import index entry templates.
void addTemplateEntry(const css::beans::PropertyValues &aValues)
add template; to be called by child template entry contexts
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
TEXT
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97