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;
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 m_pMutableAttrList( nullptr )
50 {
51 if( bClone )
52 GetMutableAttrList();
53 }
54
55
~XMLMutableAttributeList()56 XMLMutableAttributeList::~XMLMutableAttributeList()
57 {
58 m_xAttrList = nullptr;
59 }
60
61 namespace
62 {
63 class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
64 }
65
getUnoTunnelId()66 const css::uno::Sequence<sal_Int8>& XMLMutableAttributeList::getUnoTunnelId() throw()
67 {
68 return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
69 }
70
71 // XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)72 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
73 const Sequence< sal_Int8 >& rId )
74 {
75 if( isUnoTunnelId<XMLMutableAttributeList>(rId) )
76 {
77 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
78 }
79 return 0;
80 }
81
getLength()82 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
83 {
84 return m_xAttrList->getLength();
85 }
86
87
getNameByIndex(sal_Int16 i)88 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
89 {
90 return m_xAttrList->getNameByIndex( i );
91 }
92
93
getTypeByIndex(sal_Int16 i)94 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
95 {
96 return m_xAttrList->getTypeByIndex( i );
97 }
98
getValueByIndex(sal_Int16 i)99 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
100 {
101 return m_xAttrList->getValueByIndex( i );
102 }
103
getTypeByName(const OUString & rName)104 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
105 const OUString& rName )
106 {
107 return m_xAttrList->getTypeByName( rName );
108 }
109
getValueByName(const OUString & rName)110 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
111 const OUString& rName)
112 {
113 return m_xAttrList->getValueByName( rName );
114 }
115
116
createClone()117 Reference< XCloneable > XMLMutableAttributeList::createClone()
118 {
119 // A cloned list will be a read only list!
120 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
121 return r;
122 }
123
SetValueByIndex(sal_Int16 i,const OUString & rValue)124 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
125 const OUString& rValue )
126 {
127 GetMutableAttrList()->SetValueByIndex( i, rValue );
128 }
129
AddAttribute(const OUString & rName,const OUString & rValue)130 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
131 const OUString &rValue )
132 {
133 GetMutableAttrList()->AddAttribute( rName, rValue );
134 }
135
RemoveAttributeByIndex(sal_Int16 i)136 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
137 {
138 GetMutableAttrList()->RemoveAttributeByIndex( i );
139 }
140
RenameAttributeByIndex(sal_Int16 i,const OUString & rNewName)141 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
142 const OUString& rNewName )
143 {
144 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
145 }
146
AppendAttributeList(const Reference<css::xml::sax::XAttributeList> & r)147 void XMLMutableAttributeList::AppendAttributeList(
148 const Reference< css::xml::sax::XAttributeList >& r )
149 {
150 GetMutableAttrList()->AppendAttributeList( r );
151 }
152
GetIndexByName(const OUString & rName) const153 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
154 {
155 sal_Int16 nIndex = -1;
156 if( m_pMutableAttrList )
157 {
158 nIndex = m_pMutableAttrList->GetIndexByName( rName );
159 }
160 else
161 {
162 sal_Int16 nCount = m_xAttrList->getLength();
163 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
164 {
165 if( m_xAttrList->getNameByIndex(i) == rName )
166 nIndex = i;
167 }
168 }
169 return nIndex;
170 }
171
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
173