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"
22 #include <xmloff/xmlictxt.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <xmloff/txtimp.hxx>
25 #include <xmloff/namespacemap.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
30 #include <com/sun/star/container/XNameContainer.hpp>
32 using ::com::sun::star::beans::PropertyValue
;
33 using ::com::sun::star::uno::Reference
;
34 using ::com::sun::star::uno::Sequence
;
35 using ::com::sun::star::uno::Any
;
36 using ::com::sun::star::xml::sax::XAttributeList
;
37 using ::xmloff::token::IsXMLToken
;
38 using ::xmloff::token::XML_STYLE_NAME
;
41 XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
43 const OUString
& rEntry
,
44 XMLIndexTemplateContext
& rTemplate
,
46 const OUString
& rLocalName
)
47 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
48 , m_rEntryType(rEntry
)
49 , m_bCharStyleNameOK(false)
50 , m_rTemplateContext(rTemplate
)
55 XMLIndexSimpleEntryContext::~XMLIndexSimpleEntryContext()
59 void XMLIndexSimpleEntryContext::StartElement(
60 const Reference
<XAttributeList
> & xAttrList
)
62 // we know only one attribute: style-name
63 sal_Int16 nLength
= xAttrList
->getLength();
64 for(sal_Int16 nAttr
= 0; nAttr
< nLength
; nAttr
++)
67 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
68 GetKeyByAttrName( xAttrList
->getNameByIndex(nAttr
),
70 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
71 IsXMLToken(sLocalName
, XML_STYLE_NAME
) )
73 m_sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
74 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
75 XmlStyleFamily::TEXT_TEXT
, m_sCharStyleName
);
76 // #142494#: Check if style exists
77 const Reference
< css::container::XNameContainer
> & rStyles
=
78 GetImport().GetTextImport()->GetTextStyles();
79 if( rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
) )
80 m_bCharStyleNameOK
= true;
82 m_bCharStyleNameOK
= false;
86 // if we have a style name, set it!
87 if (m_bCharStyleNameOK
)
94 void XMLIndexSimpleEntryContext::endFastElement(sal_Int32
)
96 Sequence
<PropertyValue
> aValues(m_nValues
);
98 FillPropertyValues(aValues
);
99 m_rTemplateContext
.addTemplateEntry(aValues
);
102 void XMLIndexSimpleEntryContext::FillPropertyValues(
103 css::uno::Sequence
<css::beans::PropertyValue
> & rValues
)
105 // due to the limited number of subclasses, we fill the values
106 // directly into the slots. Subclasses will have to know they can
107 // only use slot so-and-so.
112 rValues
[0].Name
= "TokenType";
113 rValues
[0].Value
<<= m_rEntryType
;
116 if (m_bCharStyleNameOK
)
118 rValues
[1].Name
= "CharacterStyleName";
119 aAny
<<= GetImport().GetStyleDisplayName(
120 XmlStyleFamily::TEXT_TEXT
,
122 rValues
[1].Value
= aAny
;
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */