1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 #include <com/sun/star/xml/AttributeData.hpp> 31 #include <com/sun/star/lang/XUnoTunnel.hpp> 32 #include <xmloff/xmlcnimp.hxx> 33 #include <xmloff/unoatrcn.hxx> 34 #include <editeng/xmlcnitm.hxx> 35 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::container; 38 using namespace ::com::sun::star::lang; 39 using namespace ::com::sun::star::xml; 40 41 // ------------------------------------------------------------------------ 42 43 TYPEINIT1(SvXMLAttrContainerItem, SfxPoolItem); 44 45 SvXMLAttrContainerItem::SvXMLAttrContainerItem( sal_uInt16 _nWhich ) : 46 SfxPoolItem( _nWhich ) 47 { 48 pImpl = new SvXMLAttrContainerData; 49 } 50 51 SvXMLAttrContainerItem::SvXMLAttrContainerItem( 52 const SvXMLAttrContainerItem& rItem ) : 53 SfxPoolItem( rItem ) 54 { 55 pImpl = new SvXMLAttrContainerData( *rItem.pImpl ); 56 } 57 58 SvXMLAttrContainerItem::~SvXMLAttrContainerItem() 59 { 60 delete pImpl; 61 } 62 63 int SvXMLAttrContainerItem::operator==( const SfxPoolItem& rItem ) const 64 { 65 DBG_ASSERT( rItem.ISA(SvXMLAttrContainerItem), 66 "SvXMLAttrContainerItem::operator ==(): Bad type"); 67 return *pImpl == *((const SvXMLAttrContainerItem&)rItem).pImpl; 68 } 69 70 int SvXMLAttrContainerItem::Compare( const SfxPoolItem &/*rWith*/ ) const 71 { 72 DBG_ASSERT( !this, "not yet implemented" ); 73 74 return 0; 75 } 76 77 SfxItemPresentation SvXMLAttrContainerItem::GetPresentation( 78 SfxItemPresentation /*ePresentation*/, 79 SfxMapUnit /*eCoreMetric*/, 80 SfxMapUnit /*ePresentationMetric*/, 81 XubString &/*rText*/, 82 const IntlWrapper * /*pIntlWrapper*/ ) const 83 { 84 return SFX_ITEM_PRESENTATION_NONE; 85 } 86 87 sal_uInt16 SvXMLAttrContainerItem::GetVersion( sal_uInt16 /*nFileFormatVersion*/ ) const 88 { 89 // This item should never be stored 90 return USHRT_MAX; 91 } 92 93 sal_Bool SvXMLAttrContainerItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const 94 { 95 Reference<XNameContainer> xContainer = 96 new SvUnoAttributeContainer( new SvXMLAttrContainerData( *pImpl ) ); 97 98 rVal.setValue( &xContainer, ::getCppuType((Reference<XNameContainer>*)0) ); 99 return sal_True; 100 } 101 sal_Bool SvXMLAttrContainerItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) 102 { 103 Reference<XInterface> xRef; 104 SvUnoAttributeContainer* pContainer = NULL; 105 106 if( rVal.getValue() != NULL && rVal.getValueType().getTypeClass() == TypeClass_INTERFACE ) 107 { 108 xRef = *(Reference<XInterface>*)rVal.getValue(); 109 Reference<XUnoTunnel> xTunnel(xRef, UNO_QUERY); 110 if( xTunnel.is() ) 111 pContainer = (SvUnoAttributeContainer*)(sal_uLong)xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId()); 112 } 113 114 if( pContainer ) 115 { 116 delete pImpl; 117 pImpl = new SvXMLAttrContainerData( * pContainer->GetContainerImpl() ); 118 } 119 else 120 { 121 SvXMLAttrContainerData* pNewImpl = 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; 173 } 174 else 175 { 176 delete pNewImpl; 177 return sal_False; 178 } 179 } 180 catch(...) 181 { 182 delete pNewImpl; 183 return sal_False; 184 } 185 } 186 return sal_True; 187 } 188 189 190 sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rLName, 191 const ::rtl::OUString& rValue ) 192 { 193 return pImpl->AddAttr( rLName, rValue ); 194 } 195 196 sal_Bool SvXMLAttrContainerItem::AddAttr( const ::rtl::OUString& rPrefix, 197 const ::rtl::OUString& rNamespace, const ::rtl::OUString& rLName, 198 const ::rtl::OUString& rValue ) 199 { 200 return pImpl->AddAttr( rPrefix, rNamespace, rLName, rValue ); 201 } 202 203 sal_uInt16 SvXMLAttrContainerItem::GetAttrCount() const 204 { 205 return (sal_uInt16)pImpl->GetAttrCount(); 206 } 207 208 ::rtl::OUString SvXMLAttrContainerItem::GetAttrNamespace( sal_uInt16 i ) const 209 { 210 return pImpl->GetAttrNamespace( i ); 211 } 212 213 ::rtl::OUString SvXMLAttrContainerItem::GetAttrPrefix( sal_uInt16 i ) const 214 { 215 return pImpl->GetAttrPrefix( i ); 216 } 217 218 const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrLName( sal_uInt16 i ) const 219 { 220 return pImpl->GetAttrLName( i ); 221 } 222 223 const ::rtl::OUString& SvXMLAttrContainerItem::GetAttrValue( sal_uInt16 i ) const 224 { 225 return pImpl->GetAttrValue( i ); 226 } 227 228 229 sal_uInt16 SvXMLAttrContainerItem::GetFirstNamespaceIndex() const 230 { 231 return pImpl->GetFirstNamespaceIndex(); 232 } 233 234 sal_uInt16 SvXMLAttrContainerItem::GetNextNamespaceIndex( sal_uInt16 nIdx ) const 235 { 236 return pImpl->GetNextNamespaceIndex( nIdx ); 237 } 238 239 const ::rtl::OUString& SvXMLAttrContainerItem::GetNamespace( sal_uInt16 i ) const 240 { 241 return pImpl->GetNamespace( i ); 242 } 243 244 const ::rtl::OUString& SvXMLAttrContainerItem::GetPrefix( sal_uInt16 i ) const 245 { 246 return pImpl->GetPrefix( i ); 247 } 248 249