LibreOffice Module editeng (master) 1
xmlcnitm.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
20#include <memory>
21
23#include <com/sun/star/xml/AttributeData.hpp>
24#include <com/sun/star/lang/XUnoTunnel.hpp>
25#include <o3tl/any.hxx>
26#include <xmloff/xmlcnimp.hxx>
27#include <xmloff/unoatrcn.hxx>
28#include <editeng/xmlcnitm.hxx>
29
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::container;
32using namespace ::com::sun::star::lang;
33using namespace ::com::sun::star::xml;
34
35
37 SfxPoolItem( _nWhich )
38{
39}
40
42 const SvXMLAttrContainerItem& rItem ) :
43 SfxPoolItem( rItem ),
44 maContainerData( rItem.maContainerData )
45{
46}
47
49{
50}
51
53{
54 return SfxPoolItem::operator==(rItem) &&
55 maContainerData == static_cast<const SvXMLAttrContainerItem&>(rItem).maContainerData;
56}
57
59 SfxItemPresentation /*ePresentation*/,
60 MapUnit /*eCoreMetric*/,
61 MapUnit /*ePresentationMetric*/,
62 OUString & /*rText*/,
63 const IntlWrapper& /*rIntlWrapper*/ ) const
64{
65 return false;
66}
67
68bool SvXMLAttrContainerItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
69{
70 Reference<XNameContainer> xContainer
71 = new SvUnoAttributeContainer(std::make_unique<SvXMLAttrContainerData>(maContainerData));
72
73 rVal <<= xContainer;
74 return true;
75}
76
77bool SvXMLAttrContainerItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
78{
79 Reference<XInterface> xTunnel(rVal, UNO_QUERY);
80 if (auto pContainer = dynamic_cast<SvUnoAttributeContainer*>(xTunnel.get()))
81 {
82 maContainerData = *pContainer->GetContainerImpl();
83 }
84 else
85 {
87
88 try
89 {
90 Reference<XNameContainer> xContainer( rVal, UNO_QUERY );
91 if( !xContainer.is() )
92 return false;
93
94 const Sequence< OUString > aNameSequence( xContainer->getElementNames() );
95 const OUString* pNames = aNameSequence.getConstArray();
96 const sal_Int32 nCount = aNameSequence.getLength();
97 Any aAny;
98 sal_Int32 nAttr;
99
100 for( nAttr = 0; nAttr < nCount; nAttr++ )
101 {
102 const OUString aName( *pNames++ );
103
104 aAny = xContainer->getByName( aName );
105 auto pData = o3tl::tryAccess<AttributeData>(aAny);
106 if( !pData )
107 return false;
108
109 sal_Int32 pos = aName.indexOf( ':' );
110 if( pos != -1 )
111 {
112 const OUString aPrefix( aName.copy( 0, pos ));
113 const OUString aLName( aName.copy( pos+1 ));
114
115 if( pData->Namespace.isEmpty() )
116 {
117 if( !aNewImpl.AddAttr( aPrefix, aLName, pData->Value ) )
118 break;
119 }
120 else
121 {
122 if( !aNewImpl.AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
123 break;
124 }
125 }
126 else
127 {
128 if( !aNewImpl.AddAttr( aName, pData->Value ) )
129 break;
130 }
131 }
132
133 if( nAttr == nCount )
134 maContainerData = std::move(aNewImpl);
135 else
136 return false;
137 }
138 catch(...)
139 {
140 return false;
141 }
142 }
143 return true;
144}
145
146
147bool SvXMLAttrContainerItem::AddAttr( const OUString& rLName,
148 const OUString& rValue )
149{
150 return maContainerData.AddAttr( rLName, rValue );
151}
152
153bool SvXMLAttrContainerItem::AddAttr( const OUString& rPrefix,
154 const OUString& rNamespace, const OUString& rLName,
155 const OUString& rValue )
156{
157 return maContainerData.AddAttr( rPrefix, rNamespace, rLName, rValue );
158}
159
161{
162 return static_cast<sal_uInt16>(maContainerData.GetAttrCount());
163}
164
165OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
166{
168}
169
170OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
171{
173}
174
175const OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
176{
178}
179
180const OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
181{
183}
184
185
187{
189}
190
191sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
192{
194}
195
196const OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
197{
199}
200
201const OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
202{
203 return maContainerData.GetPrefix( i );
204}
205
206/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool operator==(const SfxPoolItem &) const=0
size_t GetAttrCount() const
OUString GetAttrPrefix(size_t i) const
OUString GetAttrNamespace(size_t i) const
const OUString & GetAttrValue(size_t i) const
sal_uInt16 GetNextNamespaceIndex(sal_uInt16 nIdx) const
const OUString & GetPrefix(sal_uInt16 i) const
const OUString & GetNamespace(sal_uInt16 i) const
const OUString & GetAttrLName(size_t i) const
sal_uInt16 GetFirstNamespaceIndex() const
bool AddAttr(const OUString &rLName, const OUString &rValue)
OUString GetAttrPrefix(sal_uInt16 i) const
Definition: xmlcnitm.cxx:170
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: xmlcnitm.cxx:68
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: xmlcnitm.cxx:77
const OUString & GetPrefix(sal_uInt16 i) const
Definition: xmlcnitm.cxx:201
virtual ~SvXMLAttrContainerItem() override
Definition: xmlcnitm.cxx:48
const OUString & GetAttrValue(sal_uInt16 i) const
Definition: xmlcnitm.cxx:180
sal_uInt16 GetNextNamespaceIndex(sal_uInt16 nIdx) const
Definition: xmlcnitm.cxx:191
OUString GetAttrNamespace(sal_uInt16 i) const
Definition: xmlcnitm.cxx:165
bool AddAttr(const OUString &rLName, const OUString &rValue)
Definition: xmlcnitm.cxx:147
sal_uInt16 GetAttrCount() const
Definition: xmlcnitm.cxx:160
sal_uInt16 GetFirstNamespaceIndex() const
Definition: xmlcnitm.cxx:186
SvXMLAttrContainerData maContainerData
Definition: xmlcnitm.hxx:30
const OUString & GetNamespace(sal_uInt16 i) const
Definition: xmlcnitm.cxx:196
SvXMLAttrContainerItem(sal_uInt16 nWhich=0)
Definition: xmlcnitm.cxx:36
virtual bool GetPresentation(SfxItemPresentation ePresentation, MapUnit eCoreMetric, MapUnit ePresentationMetric, OUString &rText, const IntlWrapper &rIntlWrapper) const override
Definition: xmlcnitm.cxx:58
virtual bool operator==(const SfxPoolItem &) const override
Definition: xmlcnitm.cxx:52
const OUString & GetAttrLName(sal_uInt16 i) const
Definition: xmlcnitm.cxx:175
int nCount
OUString aName
MapUnit
std::unique_ptr< sal_Int32[]> pData
int i
SfxItemPresentation
unsigned char sal_uInt8
size_t pos