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 <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>
29 
30 #include <com/sun/star/container/XNameContainer.hpp>
31 
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;
39 
40 
42  SvXMLImport& rImport,
43  const OUString& rEntry,
44  XMLIndexTemplateContext& rTemplate,
45  sal_uInt16 nPrfx,
46  const OUString& rLocalName )
47 : SvXMLImportContext(rImport, nPrfx, rLocalName)
48 , m_rEntryType(rEntry)
49 , m_bCharStyleNameOK(false)
50 , m_rTemplateContext(rTemplate)
51 , m_nValues(1)
52 {
53 }
54 
56 {
57 }
58 
60  const Reference<XAttributeList> & xAttrList)
61 {
62  // we know only one attribute: style-name
63  sal_Int16 nLength = xAttrList->getLength();
64  for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
65  {
66  OUString sLocalName;
67  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
68  GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
69  &sLocalName );
70  if ( (XML_NAMESPACE_TEXT == nPrefix) &&
71  IsXMLToken(sLocalName, XML_STYLE_NAME) )
72  {
73  m_sCharStyleName = xAttrList->getValueByIndex(nAttr);
74  OUString sDisplayStyleName = GetImport().GetStyleDisplayName(
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;
81  else
82  m_bCharStyleNameOK = false;
83  }
84  }
85 
86  // if we have a style name, set it!
88  {
89  m_nValues++;
90  }
91 
92 }
93 
95 {
96  Sequence<PropertyValue> aValues(m_nValues);
97 
98  FillPropertyValues(aValues);
100 }
101 
103  css::uno::Sequence<css::beans::PropertyValue> & rValues)
104 {
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.
108 
109  Any aAny;
110 
111  // token type
112  rValues[0].Name = "TokenType";
113  rValues[0].Value <<= m_rEntryType;
114 
115  // char style
116  if (m_bCharStyleNameOK)
117  {
118  rValues[1].Name = "CharacterStyleName";
119  aAny <<= GetImport().GetStyleDisplayName(
122  rValues[1].Value = aAny;
123  }
124 
125 }
126 
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addTemplateEntry(const css::beans::PropertyValues &aValues)
add template; to be called by child template entry contexts
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
XMLIndexSimpleEntryContext(SvXMLImport &rImport, const OUString &rEntry, XMLIndexTemplateContext &rTemplate, sal_uInt16 nPrfx, const OUString &rLocalName)
virtual void EndElement() override
call FillPropertyValues and insert into template
virtual void FillPropertyValues(css::uno::Sequence< css::beans::PropertyValue > &rValues)
fill property values for this template entry
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:31
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
Definition: xmlimp.hxx:594
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
process parameters
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
XMLIndexTemplateContext & m_rTemplateContext
Import index entry templates.
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
Definition: xmlimp.cxx:1491
sal_Int32 nLength
Definition: xmltoken.cxx:36