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;
38 }
39 
41  m_pMutableAttrList( new SvXMLAttributeList )
42 {
44 }
45 
47  XAttributeList> & rAttrList, bool bClone ) :
48  m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
49  m_pMutableAttrList( nullptr )
50 {
51  if( bClone )
53 }
54 
55 
57 {
58  m_xAttrList = nullptr;
59 }
60 
61 namespace
62 {
63  class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
64 }
65 
66 const css::uno::Sequence<sal_Int8>& XMLMutableAttributeList::getUnoTunnelId() throw()
67 {
68  return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
69 }
70 
71 // XUnoTunnel
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 
83 {
84  return m_xAttrList->getLength();
85 }
86 
87 
88 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
89 {
90  return m_xAttrList->getNameByIndex( i );
91 }
92 
93 
94 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
95 {
96  return m_xAttrList->getTypeByIndex( i );
97 }
98 
99 OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
100 {
101  return m_xAttrList->getValueByIndex( i );
102 }
103 
105  const OUString& rName )
106 {
107  return m_xAttrList->getTypeByName( rName );
108 }
109 
111  const OUString& rName)
112 {
113  return m_xAttrList->getValueByName( rName );
114 }
115 
116 
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 
125  const OUString& rValue )
126 {
127  GetMutableAttrList()->SetValueByIndex( i, rValue );
128 }
129 
130 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
131  const OUString &rValue )
132 {
133  GetMutableAttrList()->AddAttribute( rName, rValue );
134 }
135 
137 {
139 }
140 
142  const OUString& rNewName )
143 {
144  GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
145 }
146 
148  const Reference< css::xml::sax::XAttributeList >& r )
149 {
151 }
152 
153 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: */
void RenameAttributeByIndex(sal_Int16 i, const OUString &rNewName)
Definition: attrlist.cxx:203
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
sal_Int16 GetIndexByName(const OUString &rName) const
Definition: attrlist.cxx:213
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:167
int i
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
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:196
void AppendAttributeList(const css::uno::Reference< css::xml::sax::XAttributeList > &)
void SetValueByIndex(sal_Int16 i, const OUString &rValue)
Definition: attrlist.cxx:186
void AddAttribute(const OUString &sName, const OUString &sValue)
Definition: attrlist.cxx:143
virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override