LibreOffice Module xmloff (master)  1
MutableAttrList.cxx
Go to the documentation of this file.
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>
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 
30 {
31  if( !m_pMutableAttrList )
32  {
35  }
36 
37  return m_pMutableAttrList.get();
38 }
39 
41  m_pMutableAttrList( new SvXMLAttributeList )
42 {
44 }
45 
47  XAttributeList> & rAttrList, bool bClone ) :
48  m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList )
49 {
50  if( bClone )
52 }
53 
54 
56 {
57  m_xAttrList = nullptr;
58 }
59 
60 namespace
61 {
62  class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
63 }
64 
65 const css::uno::Sequence<sal_Int8>& XMLMutableAttributeList::getUnoTunnelId() throw()
66 {
67  return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
68 }
69 
70 // XUnoTunnel
72  const Sequence< sal_Int8 >& rId )
73 {
74  if( isUnoTunnelId<XMLMutableAttributeList>(rId) )
75  {
76  return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
77  }
78  return 0;
79 }
80 
82 {
83  return m_xAttrList->getLength();
84 }
85 
86 
87 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
88 {
89  return m_xAttrList->getNameByIndex( i );
90 }
91 
92 
93 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
94 {
95  return m_xAttrList->getTypeByIndex( i );
96 }
97 
98 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
99 {
100  return m_xAttrList->getValueByIndex( i );
101 }
102 
104  const OUString& rName )
105 {
106  return m_xAttrList->getTypeByName( rName );
107 }
108 
110  const OUString& rName)
111 {
112  return m_xAttrList->getValueByName( rName );
113 }
114 
115 
116 Reference< XCloneable > XMLMutableAttributeList::createClone()
117 {
118  // A cloned list will be a read only list!
119  Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
120  return r;
121 }
122 
124  const OUString& rValue )
125 {
126  GetMutableAttrList()->SetValueByIndex( i, rValue );
127 }
128 
129 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
130  const OUString &rValue )
131 {
132  GetMutableAttrList()->AddAttribute( rName, rValue );
133 }
134 
136 {
138 }
139 
141  const OUString& rNewName )
142 {
143  GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
144 }
145 
147  const Reference< css::xml::sax::XAttributeList >& r )
148 {
150 }
151 
152 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
153 {
154  sal_Int16 nIndex = -1;
155  if( m_pMutableAttrList )
156  {
157  nIndex = m_pMutableAttrList->GetIndexByName( rName );
158  }
159  else
160  {
161  sal_Int16 nCount = m_xAttrList->getLength();
162  for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
163  {
164  if( m_xAttrList->getNameByIndex(i) == rName )
165  nIndex = i;
166  }
167  }
168  return nIndex;
169 }
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void RenameAttributeByIndex(sal_Int16 i, const OUString &rNewName)
Definition: attrlist.cxx:167
sal_Int32 nIndex
css::uno::Reference< css::xml::sax::XAttributeList > m_xAttrList
virtual OUString SAL_CALL getTypeByName(const OUString &aName) override
virtual ~XMLMutableAttributeList() override
sal_Int16 GetIndexByName(const OUString &rName) const
SvXMLAttributeList * GetMutableAttrList()
css::uno::Any const & rValue
Definition: ImageStyle.hxx:38
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
int nCount
virtual sal_Int16 SAL_CALL getLength() override
virtual OUString SAL_CALL getValueByName(const OUString &aName) override
virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override
void AppendAttributeList(const css::uno::Reference< css::xml::sax::XAttributeList > &)
Definition: attrlist.cxx:132
int i
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
rtl::Reference< SvXMLAttributeList > m_pMutableAttrList
void RemoveAttributeByIndex(sal_Int16 i)
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
void AddAttribute(const OUString &sName, const OUString &sValue)
void RenameAttributeByIndex(sal_Int16 i, const OUString &rNewName)
virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override
void RemoveAttributeByIndex(sal_Int16 i)
Definition: attrlist.cxx:160
void AppendAttributeList(const css::uno::Reference< css::xml::sax::XAttributeList > &)
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
Definition: attrlist.cxx:150
void AddAttribute(const OUString &sName, const OUString &sValue)
Definition: attrlist.cxx:110
virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override