1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <osl/mutex.hxx>
30 #include <xmloff/xmltoken.hxx>
31 #include <rtl/memory.h>
32 #include <xmloff/attrlist.hxx>
33 #include <comphelper/servicehelper.hxx>
34 #include "MutableAttrList.hxx"
36 using ::rtl::OUString
;
38 using namespace ::osl
;
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::util
;
43 SvXMLAttributeList
*XMLMutableAttributeList::GetMutableAttrList()
45 if( !m_pMutableAttrList
)
47 m_pMutableAttrList
= new SvXMLAttributeList( m_xAttrList
);
48 m_xAttrList
= m_pMutableAttrList
;
51 return m_pMutableAttrList
;
54 XMLMutableAttributeList::XMLMutableAttributeList() :
55 m_pMutableAttrList( new SvXMLAttributeList
)
57 m_xAttrList
= m_pMutableAttrList
;
60 XMLMutableAttributeList::XMLMutableAttributeList( const Reference
<
61 XAttributeList
> & rAttrList
, sal_Bool bClone
) :
62 m_xAttrList( rAttrList
.is() ? rAttrList
: new SvXMLAttributeList
),
63 m_pMutableAttrList( 0 )
70 XMLMutableAttributeList::~XMLMutableAttributeList()
77 class theXMLMutableAttributeListUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theXMLMutableAttributeListUnoTunnelId
> {};
81 const Sequence
< sal_Int8
> & XMLMutableAttributeList::getUnoTunnelId() throw()
83 return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
87 sal_Int64 SAL_CALL
XMLMutableAttributeList::getSomething(
88 const Sequence
< sal_Int8
>& rId
)
89 throw( RuntimeException
)
91 if( rId
.getLength() == 16 &&
92 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
93 rId
.getConstArray(), 16 ) )
95 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_uIntPtr
>(this));
100 sal_Int16 SAL_CALL
XMLMutableAttributeList::getLength(void)
101 throw( RuntimeException
)
103 return m_xAttrList
->getLength();
107 OUString SAL_CALL
XMLMutableAttributeList::getNameByIndex(sal_Int16 i
)
108 throw( RuntimeException
)
110 return m_xAttrList
->getNameByIndex( i
);
114 OUString SAL_CALL
XMLMutableAttributeList::getTypeByIndex(sal_Int16 i
)
115 throw( RuntimeException
)
117 return m_xAttrList
->getTypeByIndex( i
);
120 OUString SAL_CALL
XMLMutableAttributeList::getValueByIndex(sal_Int16 i
)
121 throw( RuntimeException
)
123 return m_xAttrList
->getValueByIndex( i
);
126 OUString SAL_CALL
XMLMutableAttributeList::getTypeByName(
127 const OUString
& rName
)
128 throw( RuntimeException
)
130 return m_xAttrList
->getTypeByName( rName
);
133 OUString SAL_CALL
XMLMutableAttributeList::getValueByName(
134 const OUString
& rName
)
135 throw( RuntimeException
)
137 return m_xAttrList
->getValueByName( rName
);
141 Reference
< XCloneable
> XMLMutableAttributeList::createClone()
142 throw( RuntimeException
)
144 // A cloned list will be a read only list!
145 Reference
< XCloneable
> r
= new SvXMLAttributeList( m_xAttrList
);
149 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i
,
150 const ::rtl::OUString
& rValue
)
152 GetMutableAttrList()->SetValueByIndex( i
, rValue
);
155 void XMLMutableAttributeList::AddAttribute( const OUString
&rName
,
156 const OUString
&rValue
)
158 GetMutableAttrList()->AddAttribute( rName
, rValue
);
161 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i
)
163 GetMutableAttrList()->RemoveAttributeByIndex( i
);
166 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i
,
167 const OUString
& rNewName
)
169 GetMutableAttrList()->RenameAttributeByIndex( i
, rNewName
);
172 void XMLMutableAttributeList::AppendAttributeList(
173 const Reference
< ::com::sun::star::xml::sax::XAttributeList
>& r
)
175 GetMutableAttrList()->AppendAttributeList( r
);
178 sal_Int16
XMLMutableAttributeList::GetIndexByName( const OUString
& rName
) const
180 sal_Int16 nIndex
= -1;
181 if( m_pMutableAttrList
)
183 nIndex
= m_pMutableAttrList
->GetIndexByName( rName
);
187 sal_Int16 nCount
= m_xAttrList
->getLength();
188 for( sal_Int16 i
=0; nIndex
==-1 && i
<nCount
; ++i
)
190 if( m_xAttrList
->getNameByIndex(i
) == rName
)
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */