1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <xmloff/attrlist.hxx>
21 #include <comphelper/servicehelper.hxx>
22 #include "MutableAttrList.hxx"
25 using namespace ::com::sun::star::uno
;
26 using namespace ::com::sun::star::lang
;
27 using namespace ::com::sun::star::util
;
29 SvXMLAttributeList
*XMLMutableAttributeList::GetMutableAttrList()
31 if( !m_pMutableAttrList
)
33 m_pMutableAttrList
= new SvXMLAttributeList( m_xAttrList
);
34 m_xAttrList
= m_pMutableAttrList
;
37 return m_pMutableAttrList
;
40 XMLMutableAttributeList::XMLMutableAttributeList() :
41 m_pMutableAttrList( new SvXMLAttributeList
)
43 m_xAttrList
= m_pMutableAttrList
;
46 XMLMutableAttributeList::XMLMutableAttributeList( const Reference
<
47 XAttributeList
> & rAttrList
, bool bClone
) :
48 m_xAttrList( rAttrList
.is() ? rAttrList
: new SvXMLAttributeList
),
49 m_pMutableAttrList( nullptr )
56 XMLMutableAttributeList::~XMLMutableAttributeList()
58 m_xAttrList
= nullptr;
63 class theXMLMutableAttributeListUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theXMLMutableAttributeListUnoTunnelId
> {};
66 const css::uno::Sequence
<sal_Int8
>& XMLMutableAttributeList::getUnoTunnelId() throw()
68 return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
72 sal_Int64 SAL_CALL
XMLMutableAttributeList::getSomething(
73 const Sequence
< sal_Int8
>& rId
)
75 if( isUnoTunnelId
<XMLMutableAttributeList
>(rId
) )
77 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
82 sal_Int16 SAL_CALL
XMLMutableAttributeList::getLength()
84 return m_xAttrList
->getLength();
88 OUString SAL_CALL
XMLMutableAttributeList::getNameByIndex(sal_Int16 i
)
90 return m_xAttrList
->getNameByIndex( i
);
94 OUString SAL_CALL
XMLMutableAttributeList::getTypeByIndex(sal_Int16 i
)
96 return m_xAttrList
->getTypeByIndex( i
);
99 OUString SAL_CALL
XMLMutableAttributeList::getValueByIndex(sal_Int16 i
)
101 return m_xAttrList
->getValueByIndex( i
);
104 OUString SAL_CALL
XMLMutableAttributeList::getTypeByName(
105 const OUString
& rName
)
107 return m_xAttrList
->getTypeByName( rName
);
110 OUString SAL_CALL
XMLMutableAttributeList::getValueByName(
111 const OUString
& rName
)
113 return m_xAttrList
->getValueByName( rName
);
117 Reference
< XCloneable
> XMLMutableAttributeList::createClone()
119 // A cloned list will be a read only list!
120 Reference
< XCloneable
> r
= new SvXMLAttributeList( m_xAttrList
);
124 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i
,
125 const OUString
& rValue
)
127 GetMutableAttrList()->SetValueByIndex( i
, rValue
);
130 void XMLMutableAttributeList::AddAttribute( const OUString
&rName
,
131 const OUString
&rValue
)
133 GetMutableAttrList()->AddAttribute( rName
, rValue
);
136 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i
)
138 GetMutableAttrList()->RemoveAttributeByIndex( i
);
141 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i
,
142 const OUString
& rNewName
)
144 GetMutableAttrList()->RenameAttributeByIndex( i
, rNewName
);
147 void XMLMutableAttributeList::AppendAttributeList(
148 const Reference
< css::xml::sax::XAttributeList
>& r
)
150 GetMutableAttrList()->AppendAttributeList( r
);
153 sal_Int16
XMLMutableAttributeList::GetIndexByName( const OUString
& rName
) const
155 sal_Int16 nIndex
= -1;
156 if( m_pMutableAttrList
)
158 nIndex
= m_pMutableAttrList
->GetIndexByName( rName
);
162 sal_Int16 nCount
= m_xAttrList
->getLength();
163 for( sal_Int16 i
=0; nIndex
==-1 && i
<nCount
; ++i
)
165 if( m_xAttrList
->getNameByIndex(i
) == rName
)
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */