cURL: follow redirects
[LibreOffice.git] / xmloff / source / transform / MutableAttrList.cxx
bloba020147ddd057b7cf9c4744f69e3aa7e36cc2847
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( nullptr )
56 if( bClone )
57 GetMutableAttrList();
61 XMLMutableAttributeList::~XMLMutableAttributeList()
63 m_xAttrList = nullptr;
66 namespace
68 class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
71 // XUnoTunnel
72 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
73 const Sequence< sal_Int8 >& rId )
74 throw( RuntimeException, std::exception )
76 if( rId.getLength() == 16 &&
77 0 == memcmp( theXMLMutableAttributeListUnoTunnelId::get().getSeq().getConstArray(),
78 rId.getConstArray(), 16 ) )
80 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
82 return 0;
85 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
86 throw( RuntimeException, std::exception )
88 return m_xAttrList->getLength();
92 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
93 throw( RuntimeException, std::exception )
95 return m_xAttrList->getNameByIndex( i );
99 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
100 throw( RuntimeException, std::exception )
102 return m_xAttrList->getTypeByIndex( i );
105 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
106 throw( RuntimeException, std::exception )
108 return m_xAttrList->getValueByIndex( i );
111 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
112 const OUString& rName )
113 throw( RuntimeException, std::exception )
115 return m_xAttrList->getTypeByName( rName );
118 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
119 const OUString& rName)
120 throw( RuntimeException, std::exception )
122 return m_xAttrList->getValueByName( rName );
126 Reference< XCloneable > XMLMutableAttributeList::createClone()
127 throw( RuntimeException, std::exception )
129 // A cloned list will be a read only list!
130 Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
131 return r;
134 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
135 const OUString& rValue )
137 GetMutableAttrList()->SetValueByIndex( i, rValue );
140 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
141 const OUString &rValue )
143 GetMutableAttrList()->AddAttribute( rName, rValue );
146 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
148 GetMutableAttrList()->RemoveAttributeByIndex( i );
151 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
152 const OUString& rNewName )
154 GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
157 void XMLMutableAttributeList::AppendAttributeList(
158 const Reference< css::xml::sax::XAttributeList >& r )
160 GetMutableAttrList()->AppendAttributeList( r );
163 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
165 sal_Int16 nIndex = -1;
166 if( m_pMutableAttrList )
168 nIndex = m_pMutableAttrList->GetIndexByName( rName );
170 else
172 sal_Int16 nCount = m_xAttrList->getLength();
173 for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
175 if( m_xAttrList->getNameByIndex(i) == rName )
176 nIndex = i;
179 return nIndex;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */