bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / MutableAttrList.cxx
blob7839fead2c705809cdb7c2dad1ab7b3ffbb1e5de
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <string.h>
22 #include <osl/mutex.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/attrlist.hxx>
25 #include <comphelper/servicehelper.hxx>
26 #include "MutableAttrList.hxx"
29 using namespace ::osl;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::util;
34 SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
36 if( !m_pMutableAttrList )
38 m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
39 m_xAttrList = m_pMutableAttrList;
42 return m_pMutableAttrList;
45 XMLMutableAttributeList::XMLMutableAttributeList() :
46 m_pMutableAttrList( new SvXMLAttributeList )
48 m_xAttrList = m_pMutableAttrList;
51 XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
52 XAttributeList> & rAttrList, bool bClone ) :
53 m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
54 m_pMutableAttrList( 0 )
56 if( bClone )
57 GetMutableAttrList();
61 XMLMutableAttributeList::~XMLMutableAttributeList()
63 m_xAttrList = 0;
66 namespace
68 class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
71 // XUnoTunnel & co
72 const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw()
74 return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
77 // XUnoTunnel
78 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
79 const Sequence< sal_Int8 >& rId )
80 throw( RuntimeException, std::exception )
82 if( rId.getLength() == 16 &&
83 0 == memcmp( getUnoTunnelId().getConstArray(),
84 rId.getConstArray(), 16 ) )
86 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
88 return 0;
91 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
92 throw( RuntimeException, std::exception )
94 return m_xAttrList->getLength();
98 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
99 throw( RuntimeException, std::exception )
101 return m_xAttrList->getNameByIndex( i );
105 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
106 throw( RuntimeException, std::exception )
108 return m_xAttrList->getTypeByIndex( i );
111 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
112 throw( RuntimeException, std::exception )
114 return m_xAttrList->getValueByIndex( i );
117 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
118 const OUString& rName )
119 throw( RuntimeException, std::exception )
121 return m_xAttrList->getTypeByName( rName );
124 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
125 const OUString& rName)
126 throw( RuntimeException, std::exception )
128 return m_xAttrList->getValueByName( rName );
132 Reference< XCloneable > XMLMutableAttributeList::createClone()
133 throw( RuntimeException, std::exception )
135 // A cloned list will be a read only list!
136 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
137 return r;
140 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
141 const OUString& rValue )
143 GetMutableAttrList()->SetValueByIndex( i, rValue );
146 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
147 const OUString &rValue )
149 GetMutableAttrList()->AddAttribute( rName, rValue );
152 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
154 GetMutableAttrList()->RemoveAttributeByIndex( i );
157 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
158 const OUString& rNewName )
160 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
163 void XMLMutableAttributeList::AppendAttributeList(
164 const Reference< ::com::sun::star::xml::sax::XAttributeList >& r )
166 GetMutableAttrList()->AppendAttributeList( r );
169 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
171 sal_Int16 nIndex = -1;
172 if( m_pMutableAttrList )
174 nIndex = m_pMutableAttrList->GetIndexByName( rName );
176 else
178 sal_Int16 nCount = m_xAttrList->getLength();
179 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
181 if( m_xAttrList->getNameByIndex(i) == rName )
182 nIndex = i;
185 return nIndex;
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */