Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
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 [ + + ][ - + ]: 206724 : TYPEINIT1(SvXMLAttrContainerItem, SfxPoolItem);
42 : :
43 : 4880 : SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) :
44 : 4880 : SfxPoolItem( _nWhich )
45 : : {
46 [ + - ][ + - ]: 4880 : pImpl = new SvXMLAttrContainerData;
47 : 4880 : }
48 : :
49 : 3613 : SvXMLAttrContainerItem::SvXMLAttrContainerItem(
50 : : const SvXMLAttrContainerItem& rItem ) :
51 : 3613 : SfxPoolItem( rItem )
52 : : {
53 [ + - ][ + - ]: 3613 : pImpl = new SvXMLAttrContainerData( *rItem.pImpl );
54 : 3613 : }
55 : :
56 : 8102 : SvXMLAttrContainerItem::~SvXMLAttrContainerItem()
57 : : {
58 [ + - ][ + - ]: 8102 : delete pImpl;
59 [ - + ]: 16156 : }
60 : :
61 : 6969 : int SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const
62 : : {
63 : : DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem),
64 : : "SvXMLAttrContainerItem::operator ==(): Bad type");
65 : 6969 : return *pImpl == *((const SvXMLAttrContainerItem&)rItem).pImpl;
66 : : }
67 : :
68 : 0 : int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const
69 : : {
70 : : DBG_ASSERT( !this, "not yet implemented" );
71 : :
72 : 0 : return 0;
73 : : }
74 : :
75 : 0 : SfxItemPresentation SvXMLAttrContainerItem::GetPresentation(
76 : : SfxItemPresentation /*ePresentation*/,
77 : : SfxMapUnit /*eCoreMetric*/,
78 : : SfxMapUnit /*ePresentationMetric*/,
79 : : XubString &/*rText*/,
80 : : const IntlWrapper * /*pIntlWrapper*/ ) const
81 : : {
82 : 0 : return SFX_ITEM_PRESENTATION_NONE;
83 : : }
84 : :
85 : 14232 : sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const
86 : : {
87 : : // This item should never be stored
88 : 14232 : return USHRT_MAX;
89 : : }
90 : :
91 : 489 : bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
92 : : {
93 : : Reference<XNameContainer> xContainer =
94 [ + - ][ + - ]: 489 : new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl ) );
[ + - ][ + - ]
[ + - ]
95 : :
96 [ + - ]: 489 : rVal.setValue( &xContainer, ::getCppuType((Reference<XNameContainer>*)0) );
97 : 489 : return true;
98 : : }
99 : :
100 : 20 : bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
101 : : {
102 : 20 : Reference<XInterface> xRef;
103 : 20 : SvUnoAttributeContainer* pContainer = NULL;
104 : :
105 [ + - ][ + - ]: 20 : if( rVal.getValue() != NULL && rVal.getValueType().getTypeClass() == TypeClass_INTERFACE )
[ + - ]
106 : : {
107 [ + - ]: 20 : xRef = *(Reference<XInterface>*)rVal.getValue();
108 [ + - ]: 20 : Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY);
109 [ + - ]: 20 : if( xTunnel.is() )
110 [ + - ][ + - ]: 20 : pContainer = (SvUnoAttributeContainer*)(sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId());
111 : : }
112 : :
113 [ + - ]: 20 : if( pContainer )
114 : : {
115 [ + - ][ + - ]: 20 : delete pImpl;
116 [ + - ][ + - ]: 20 : pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() );
117 : : }
118 : : else
119 : : {
120 [ # # ][ # # ]: 0 : std::auto_ptr<SvXMLAttrContainerData> pNewImpl(new SvXMLAttrContainerData);
121 : :
122 : : try
123 : : {
124 [ # # ]: 0 : Reference<XNameContainer> xContainer( xRef, UNO_QUERY );
125 [ # # ]: 0 : if( !xContainer.is() )
126 : 0 : return sal_False;
127 : :
128 [ # # ][ # # ]: 0 : const Sequence< ::rtl::OUString > aNameSequence( xContainer->getElementNames() );
129 : 0 : const ::rtl::OUString* pNames = aNameSequence.getConstArray();
130 : 0 : const sal_Int32 nCount = aNameSequence.getLength();
131 : 0 : Any aAny;
132 : : AttributeData* pData;
133 : : sal_Int32 nAttr;
134 : :
135 [ # # ]: 0 : for( nAttr = 0; nAttr < nCount; nAttr++ )
136 : : {
137 : 0 : const ::rtl::OUString aName( *pNames++ );
138 : :
139 [ # # ][ # # ]: 0 : aAny = xContainer->getByName( aName );
140 [ # # ][ # # ]: 0 : if( aAny.getValue() == NULL || aAny.getValueType() != ::getCppuType((AttributeData*)0) )
[ # # ][ # # ]
141 : 0 : return sal_False;
142 : :
143 : 0 : pData = (AttributeData*)aAny.getValue();
144 : 0 : sal_Int32 pos = aName.indexOf( sal_Unicode(':') );
145 [ # # ]: 0 : if( pos != -1 )
146 : : {
147 : 0 : const ::rtl::OUString aPrefix( aName.copy( 0, pos ));
148 : 0 : const ::rtl::OUString aLName( aName.copy( pos+1 ));
149 : :
150 [ # # ]: 0 : if( pData->Namespace.isEmpty() )
151 : : {
152 [ # # ][ # # ]: 0 : if( !pNewImpl->AddAttr( aPrefix, aLName, pData->Value ) )
153 : : break;
154 : : }
155 : : else
156 : : {
157 [ # # ][ # # ]: 0 : if( !pNewImpl->AddAttr( aPrefix, pData->Namespace, aLName, pData->Value ) )
158 : : break;
159 [ # # ][ # # ]: 0 : }
160 : : }
161 : : else
162 : : {
163 [ # # ][ # # ]: 0 : if( !pNewImpl->AddAttr( aName, pData->Value ) )
164 : : break;
165 : : }
166 [ # # # ]: 0 : }
167 : :
168 [ # # ]: 0 : if( nAttr == nCount )
169 : 0 : pImpl = pNewImpl.release();
170 : : else
171 [ # # ][ # # ]: 0 : return false;
[ # # ][ # # ]
172 : : }
173 [ # # ]: 0 : catch(...)
174 : : {
175 : 0 : return false;
176 [ # # ][ # # ]: 0 : }
177 : : }
178 : 20 : return true;
179 : : }
180 : :
181 : :
182 : 0 : sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rLName,
183 : : const ::rtl::OUString& rValue )
184 : : {
185 : 0 : return pImpl->AddAttr( rLName, rValue );
186 : : }
187 : :
188 : 0 : sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rPrefix,
189 : : const ::rtl::OUString& rNamespace, const ::rtl::OUString& rLName,
190 : : const ::rtl::OUString& rValue )
191 : : {
192 : 0 : return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue );
193 : : }
194 : :
195 : 34 : sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const
196 : : {
197 : 34 : return (sal_uInt16)pImpl->GetAttrCount();
198 : : }
199 : :
200 : 0 : ::rtl::OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const
201 : : {
202 : 0 : return pImpl->GetAttrNamespace( i );
203 : : }
204 : :
205 : 0 : ::rtl::OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const
206 : : {
207 : 0 : return pImpl->GetAttrPrefix( i );
208 : : }
209 : :
210 : 0 : const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const
211 : : {
212 : 0 : return pImpl->GetAttrLName( i );
213 : : }
214 : :
215 : 0 : const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const
216 : : {
217 : 0 : return pImpl->GetAttrValue( i );
218 : : }
219 : :
220 : :
221 : 0 : sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const
222 : : {
223 : 0 : return pImpl->GetFirstNamespaceIndex();
224 : : }
225 : :
226 : 0 : sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const
227 : : {
228 : 0 : return pImpl->GetNextNamespaceIndex( nIdx );
229 : : }
230 : :
231 : 0 : const ::rtl::OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const
232 : : {
233 : 0 : return pImpl->GetNamespace( i );
234 : : }
235 : :
236 : 0 : const ::rtl::OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const
237 : : {
238 : 0 : return pImpl->GetPrefix( i );
239 : : }
240 : :
241 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|