1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26
27 #include <memory>
28
29 #include <com/sun/star/xml/AttributeData.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
31 #include <xmloff/xmlcnimp.hxx>
32 #include <xmloff/unoatrcn.hxx>
33 #include <editeng/xmlcnitm.hxx>
34
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::xml;
39
40 // ------------------------------------------------------------------------
41
42 TYPEINIT1(SvXMLAttrContainerItem, SfxPoolItem);
43
SvXMLAttrContainerItem(sal_uInt16 _nWhich)44 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
45 SfxPoolItem( _nWhich )
46 {
47 pImpl = new SvXMLAttrContainerData;
48 }
49
SvXMLAttrContainerItem(const SvXMLAttrContainerItem & rItem)50 SvXMLAttrContainerItem::SvXMLAttrContainerItem(
51 const SvXMLAttrContainerItem& rItem ) :
52 SfxPoolItem( rItem )
53 {
54 pImpl = new SvXMLAttrContainerData( *rItem.pImpl );
55 }
56
~SvXMLAttrContainerItem()57 SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
58 {
59 delete pImpl;
60 }
61
operator ==(const SfxPoolItem & rItem) const62 int SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
63 {
64 DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem),
65 "SvXMLAttrContainerItem::operator ==(): Bad type");
66 return *pImpl == *((const SvXMLAttrContainerItem&)rItem).pImpl;
67 }
68
Compare(const SfxPoolItem &) const69 int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const
70 {
71 DBG_ASSERT( sal_False, "not yet implemented" );
72
73 return 0;
74 }
75
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString &,const IntlWrapper *) const76 SfxItemPresentation SvXMLAttrContainerItem::GetPresentation(
77 SfxItemPresentation /*ePresentation*/,
78 SfxMapUnit /*eCoreMetric*/,
79 SfxMapUnit /*ePresentationMetric*/,
80 XubString &/*rText*/,
81 const IntlWrapper * /*pIntlWrapper*/ ) const
82 {
83 return SFX_ITEM_PRESENTATION_NONE;
84 }
85
GetVersion(sal_uInt16) const86 sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
87 {
88 // This item should never be stored
89 return USHRT_MAX;
90 }
91
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const92 sal_Bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
93 {
94 Reference<XNameContainer> xContainer =
95 new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl ) );
96
97 rVal.setValue( &xContainer, ::getCppuType((Reference<XNameContainer>*)0) );
98 return sal_True;
99 }
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)100 sal_Bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
101 {
102 Reference<XInterface> xRef;
103 SvUnoAttributeContainer* pContainer = NULL;
104
105 if( rVal.getValue() != NULL && rVal.getValueType().getTypeClass() == TypeClass_INTERFACE )
106 {
107 xRef = *(Reference<XInterface>*)rVal.getValue();
108 Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY);
109 if( xTunnel.is() )
110 pContainer = (SvUnoAttributeContainer*)(sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
111 }
112
113 if( pContainer )
114 {
115 delete pImpl;
116 pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() );
117 }
118 else
119 {
120 ::std::auto_ptr<SvXMLAttrContainerData> pNewImpl(
121 new SvXMLAttrContainerData);
122
123 try
124 {
125 Reference<XNameContainer> xContainer( xRef, UNO_QUERY );
126 if( !xContainer.is() )
127 return sal_False;
128
129 const Sequence< ::rtl::OUString > aNameSequence( xContainer->getElementNames() );
130 const ::rtl::OUString* pNames = aNameSequence.getConstArray();
131 const sal_Int32 nCount = aNameSequence.getLength();
132 Any aAny;
133 AttributeData* pData;
134 sal_Int32 nAttr;
135
136 for( nAttr = 0; nAttr < nCount; nAttr++ )
137 {
138 const ::rtl::OUString aName( *pNames++ );
139
140 aAny = xContainer->getByName( aName );
141 if( aAny.getValue() == NULL || aAny.getValueType() != ::getCppuType((AttributeData*)0) )
142 return sal_False;
143
144 pData = (AttributeData*)aAny.getValue();
145 sal_Int32 pos = aName.indexOf( sal_Unicode(':') );
146 if( pos != -1 )
147 {
148 const ::rtl::OUString aPrefix( aName.copy( 0, pos ));
149 const ::rtl::OUString aLName( aName.copy( pos+1 ));
150
151 if( pData->Namespace.getLength() == 0 )
152 {
153 if( !pNewImpl->AddAttr( aPrefix, aLName, pData->Value ) )
154 break;
155 }
156 else
157 {
158 if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
159 break;
160 }
161 }
162 else
163 {
164 if( !pNewImpl->AddAttr( aName, pData->Value ) )
165 break;
166 }
167 }
168
169 if( nAttr == nCount )
170 {
171 delete pImpl;
172 pImpl = pNewImpl.release();
173 }
174 else
175 {
176 return sal_False;
177 }
178 }
179 catch(...)
180 {
181 return sal_False;
182 }
183 }
184 return sal_True;
185 }
186
187
AddAttr(const::rtl::OUString & rLName,const::rtl::OUString & rValue)188 sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rLName,
189 const ::rtl::OUString& rValue )
190 {
191 return pImpl->AddAttr( rLName, rValue );
192 }
193
AddAttr(const::rtl::OUString & rPrefix,const::rtl::OUString & rNamespace,const::rtl::OUString & rLName,const::rtl::OUString & rValue)194 sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rPrefix,
195 const ::rtl::OUString& rNamespace, const ::rtl::OUString& rLName,
196 const ::rtl::OUString& rValue )
197 {
198 return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue );
199 }
200
GetAttrCount() const201 sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
202 {
203 return (sal_uInt16)pImpl->GetAttrCount();
204 }
205
GetAttrNamespace(sal_uInt16 i) const206 ::rtl::OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
207 {
208 return pImpl->GetAttrNamespace( i );
209 }
210
GetAttrPrefix(sal_uInt16 i) const211 ::rtl::OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
212 {
213 return pImpl->GetAttrPrefix( i );
214 }
215
GetAttrLName(sal_uInt16 i) const216 const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
217 {
218 return pImpl->GetAttrLName( i );
219 }
220
GetAttrValue(sal_uInt16 i) const221 const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
222 {
223 return pImpl->GetAttrValue( i );
224 }
225
226
GetFirstNamespaceIndex() const227 sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
228 {
229 return pImpl->GetFirstNamespaceIndex();
230 }
231
GetNextNamespaceIndex(sal_uInt16 nIdx) const232 sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
233 {
234 return pImpl->GetNextNamespaceIndex( nIdx );
235 }
236
GetNamespace(sal_uInt16 i) const237 const ::rtl::OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
238 {
239 return pImpl->GetNamespace( i );
240 }
241
GetPrefix(sal_uInt16 i) const242 const ::rtl::OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
243 {
244 return pImpl->GetPrefix( i );
245 }
246
247