Version 24.2.2.2, tag libreoffice-24.2.2.2
[LibreOffice.git] / xmloff / source / transform / MutableAttrList.cxx
blob6798721b4cdcea9d6e6be3aed3aae9723dbcf4ac
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 <sal/config.h>
22 #include <comphelper/attributelist.hxx>
23 #include <comphelper/servicehelper.hxx>
24 #include "MutableAttrList.hxx"
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::lang;
29 using namespace ::com::sun::star::util;
31 comphelper::AttributeList* XMLMutableAttributeList::GetMutableAttrList()
33 if( !m_pMutableAttrList )
35 m_pMutableAttrList = new comphelper::AttributeList( m_xAttrList );
36 m_xAttrList = m_pMutableAttrList;
39 return m_pMutableAttrList.get();
42 XMLMutableAttributeList::XMLMutableAttributeList() :
43 m_pMutableAttrList( new comphelper::AttributeList )
45 m_xAttrList = m_pMutableAttrList;
48 XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
49 XAttributeList> & rAttrList, bool bClone ) :
50 m_xAttrList( rAttrList.is() ? rAttrList : new comphelper::AttributeList )
52 if( bClone )
53 GetMutableAttrList();
57 XMLMutableAttributeList::~XMLMutableAttributeList()
59 m_xAttrList = nullptr;
62 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
64 return m_xAttrList->getLength();
68 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
70 return m_xAttrList->getNameByIndex( i );
74 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
76 return m_xAttrList->getTypeByIndex( i );
79 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
81 return m_xAttrList->getValueByIndex( i );
84 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
85 const OUString& rName )
87 return m_xAttrList->getTypeByName( rName );
90 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
91 const OUString& rName)
93 return m_xAttrList->getValueByName( rName );
97 Reference< XCloneable > XMLMutableAttributeList::createClone()
99 // A cloned list will be a read only list!
100 Reference< XCloneable > r = new comphelper::AttributeList( m_xAttrList );
101 return r;
104 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
105 const OUString& rValue )
107 GetMutableAttrList()->SetValueByIndex( i, rValue );
110 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
111 const OUString &rValue )
113 GetMutableAttrList()->AddAttribute( rName, rValue );
116 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
118 GetMutableAttrList()->RemoveAttributeByIndex( i );
121 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
122 const OUString& rNewName )
124 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
127 void XMLMutableAttributeList::AppendAttributeList(
128 const Reference< css::xml::sax::XAttributeList >& r )
130 GetMutableAttrList()->AppendAttributeList( r );
133 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
135 sal_Int16 nIndex = -1;
136 if( m_pMutableAttrList )
138 nIndex = m_pMutableAttrList->GetIndexByName( rName );
140 else
142 sal_Int16 nCount = m_xAttrList->getLength();
143 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
145 if( m_xAttrList->getNameByIndex(i) == rName )
146 nIndex = i;
149 return nIndex;
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */