1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <xmloff/attrlist.hxx>
21 #include <comphelper/servicehelper.hxx>
22 #include "MutableAttrList.hxx"
23
24
25 using namespace ::com::sun::star::uno;
26 using namespace ::com::sun::star::lang;
27 using namespace ::com::sun::star::util;
28
GetMutableAttrList()29 SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
30 {
31 if( !m_pMutableAttrList )
32 {
33 m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
34 m_xAttrList = m_pMutableAttrList;
35 }
36
37 return m_pMutableAttrList.get();
38 }
39
XMLMutableAttributeList()40 XMLMutableAttributeList::XMLMutableAttributeList() :
41 m_pMutableAttrList( new SvXMLAttributeList )
42 {
43 m_xAttrList = m_pMutableAttrList;
44 }
45
XMLMutableAttributeList(const Reference<XAttributeList> & rAttrList,bool bClone)46 XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
47 XAttributeList> & rAttrList, bool bClone ) :
48 m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList )
49 {
50 if( bClone )
51 GetMutableAttrList();
52 }
53
54
~XMLMutableAttributeList()55 XMLMutableAttributeList::~XMLMutableAttributeList()
56 {
57 m_xAttrList = nullptr;
58 }
59
getUnoTunnelId()60 const css::uno::Sequence<sal_Int8>& XMLMutableAttributeList::getUnoTunnelId() noexcept
61 {
62 static const UnoTunnelIdInit theXMLMutableAttributeListUnoTunnelId;
63 return theXMLMutableAttributeListUnoTunnelId.getSeq();
64 }
65
66 // XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)67 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
68 const Sequence< sal_Int8 >& rId )
69 {
70 if( isUnoTunnelId<XMLMutableAttributeList>(rId) )
71 {
72 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
73 }
74 return 0;
75 }
76
getLength()77 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
78 {
79 return m_xAttrList->getLength();
80 }
81
82
getNameByIndex(sal_Int16 i)83 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
84 {
85 return m_xAttrList->getNameByIndex( i );
86 }
87
88
getTypeByIndex(sal_Int16 i)89 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
90 {
91 return m_xAttrList->getTypeByIndex( i );
92 }
93
getValueByIndex(sal_Int16 i)94 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
95 {
96 return m_xAttrList->getValueByIndex( i );
97 }
98
getTypeByName(const OUString & rName)99 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
100 const OUString& rName )
101 {
102 return m_xAttrList->getTypeByName( rName );
103 }
104
getValueByName(const OUString & rName)105 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
106 const OUString& rName)
107 {
108 return m_xAttrList->getValueByName( rName );
109 }
110
111
createClone()112 Reference< XCloneable > XMLMutableAttributeList::createClone()
113 {
114 // A cloned list will be a read only list!
115 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
116 return r;
117 }
118
SetValueByIndex(sal_Int16 i,const OUString & rValue)119 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
120 const OUString& rValue )
121 {
122 GetMutableAttrList()->SetValueByIndex( i, rValue );
123 }
124
AddAttribute(const OUString & rName,const OUString & rValue)125 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
126 const OUString &rValue )
127 {
128 GetMutableAttrList()->AddAttribute( rName, rValue );
129 }
130
RemoveAttributeByIndex(sal_Int16 i)131 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
132 {
133 GetMutableAttrList()->RemoveAttributeByIndex( i );
134 }
135
RenameAttributeByIndex(sal_Int16 i,const OUString & rNewName)136 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
137 const OUString& rNewName )
138 {
139 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
140 }
141
AppendAttributeList(const Reference<css::xml::sax::XAttributeList> & r)142 void XMLMutableAttributeList::AppendAttributeList(
143 const Reference< css::xml::sax::XAttributeList >& r )
144 {
145 GetMutableAttrList()->AppendAttributeList( r );
146 }
147
GetIndexByName(const OUString & rName) const148 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
149 {
150 sal_Int16 nIndex = -1;
151 if( m_pMutableAttrList )
152 {
153 nIndex = m_pMutableAttrList->GetIndexByName( rName );
154 }
155 else
156 {
157 sal_Int16 nCount = m_xAttrList->getLength();
158 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
159 {
160 if( m_xAttrList->getNameByIndex(i) == rName )
161 nIndex = i;
162 }
163 }
164 return nIndex;
165 }
166
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
168