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/nmspmap.hxx>
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
30 using ::com::sun::star::beans::PropertyValue
;
31 using ::com::sun::star::beans::PropertyValues
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Any
;
35 using ::com::sun::star::xml::sax::XAttributeList
;
36 using ::xmloff::token::IsXMLToken
;
37 using ::xmloff::token::XML_STYLE_NAME
;
39 TYPEINIT1( XMLIndexSimpleEntryContext
, SvXMLImportContext
);
41 XMLIndexSimpleEntryContext::XMLIndexSimpleEntryContext(
43 const OUString
& rEntry
,
44 XMLIndexTemplateContext
& rTemplate
,
46 const OUString
& rLocalName
)
47 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
49 , bCharStyleNameOK(false)
50 , 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 sCharStyleName
= xAttrList
->getValueByIndex(nAttr
);
74 OUString sDisplayStyleName
= GetImport().GetStyleDisplayName(
75 XML_STYLE_FAMILY_TEXT_TEXT
, sCharStyleName
);
76 // #142494#: Check if style exists
77 const Reference
< ::com::sun::star::container::XNameContainer
> & rStyles
=
78 GetImport().GetTextImport()->GetTextStyles();
79 if( rStyles
.is() && rStyles
->hasByName( sDisplayStyleName
) )
80 bCharStyleNameOK
= true;
82 bCharStyleNameOK
= false;
86 // if we have a style name, set it!
94 void XMLIndexSimpleEntryContext::EndElement()
96 Sequence
<PropertyValue
> aValues(nValues
);
98 FillPropertyValues(aValues
);
99 rTemplateContext
.addTemplateEntry(aValues
);
102 void XMLIndexSimpleEntryContext::FillPropertyValues(
103 ::com::sun::star::uno::Sequence
<
104 ::com::sun::star::beans::PropertyValue
> & rValues
)
106 // due to the limited number of subclasses, we fill the values
107 // directly into the slots. Subclasses will have to know they can
108 // only use slot so-and-so.
113 rValues
[0].Name
= rTemplateContext
.sTokenType
;
115 rValues
[0].Value
= aAny
;
118 if (bCharStyleNameOK
)
120 rValues
[1].Name
= rTemplateContext
.sCharacterStyleName
;
121 aAny
<<= GetImport().GetStyleDisplayName(
122 XML_STYLE_FAMILY_TEXT_TEXT
,
124 rValues
[1].Value
= aAny
;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */