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