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;
38using ::com::sun::star::xml::sax::XAttributeList;
41
42
44 SvXMLImport& rImport,
45 OUString aEntry,
46 XMLIndexTemplateContext& rTemplate )
47: SvXMLImportContext(rImport)
48, m_rEntryType(std::move(aEntry))
49, m_bCharStyleNameOK(false)
50, m_rTemplateContext(rTemplate)
51, m_nValues(1)
52{
53}
54
56{
57}
58
60 sal_Int32 /*nElement*/,
61 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
62{
63 // we know only one attribute: style-name
64 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
65 {
66 if(aIter.getToken() == XML_ELEMENT(TEXT, XML_STYLE_NAME))
67 {
68 m_sCharStyleName = aIter.toString();
69 OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
71 // #142494#: Check if style exists
72 const Reference < css::container::XNameContainer > & rStyles =
73 GetImport().GetTextImport()->GetTextStyles();
74 if( rStyles.is() && rStyles->hasByName( sDisplayStyleName ) )
75 m_bCharStyleNameOK = true;
76 else
77 m_bCharStyleNameOK = false;
78 }
79 else
80 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
81 }
82
83 // if we have a style name, set it!
85 {
86 m_nValues++;
87 }
88
89}
90
92{
93 Sequence<PropertyValue> aValues(m_nValues);
94
95 FillPropertyValues(aValues);
97}
98
100 css::uno::Sequence<css::beans::PropertyValue> & rValues)
101{
102 // due to the limited number of subclasses, we fill the values
103 // directly into the slots. Subclasses will have to know they can
104 // only use slot so-and-so.
105
106 Any aAny;
107 auto pValues = rValues.getArray();
108
109 // token type
110 pValues[0].Name = "TokenType";
111 pValues[0].Value <<= m_rEntryType;
112
113 // char style
115 {
116 pValues[1].Name = "CharacterStyleName";
117 aAny <<= GetImport().GetStyleDisplayName(
120 pValues[1].Value = aAny;
121 }
122
123}
124
125/* 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)
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3585
TEXT
#define XMLOFF_WARN_UNKNOWN(area, rIter)
Definition: xmlictxt.hxx:114
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97