xref: /trunk/main/xmloff/source/transform/MutableAttrList.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <osl/mutex.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <rtl/uuid.h>
29 #include <rtl/memory.h>
30 #include <xmloff/attrlist.hxx>
31 #include "MutableAttrList.hxx"
32 
33 using ::rtl::OUString;
34 
35 using namespace ::osl;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::util;
39 
GetMutableAttrList()40 SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
41 {
42     if( !m_pMutableAttrList )
43     {
44         m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
45         m_xAttrList = m_pMutableAttrList;
46     }
47 
48     return m_pMutableAttrList;
49 }
50 
XMLMutableAttributeList()51 XMLMutableAttributeList::XMLMutableAttributeList() :
52     m_pMutableAttrList( new SvXMLAttributeList )
53 {
54     m_xAttrList = m_pMutableAttrList;
55 }
56 
XMLMutableAttributeList(const Reference<XAttributeList> & rAttrList,sal_Bool bClone)57 XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
58         XAttributeList> & rAttrList, sal_Bool bClone ) :
59     m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
60     m_pMutableAttrList( 0 )
61 {
62     if( bClone )
63         GetMutableAttrList();
64 }
65 
66 
~XMLMutableAttributeList()67 XMLMutableAttributeList::~XMLMutableAttributeList()
68 {
69     m_xAttrList = 0;
70 }
71 
72 
73 // XUnoTunnel & co
getUnoTunnelId()74 const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw()
75 {
76     static Sequence< sal_Int8 > * pSeq = 0;
77     if( !pSeq )
78     {
79         Guard< Mutex > aGuard( Mutex::getGlobalMutex() );
80         if( !pSeq )
81         {
82             static Sequence< sal_Int8 > aSeq( 16 );
83             rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
84             pSeq = &aSeq;
85         }
86     }
87     return *pSeq;
88 }
89 
90 // XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)91 sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
92         const Sequence< sal_Int8 >& rId )
93 {
94     if( rId.getLength() == 16 &&
95         0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
96                                 rId.getConstArray(), 16 ) )
97     {
98         return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
99     }
100     return 0;
101 }
102 
getLength(void)103 sal_Int16 SAL_CALL XMLMutableAttributeList::getLength(void)
104 {
105     return m_xAttrList->getLength();
106 }
107 
108 
getNameByIndex(sal_Int16 i)109 OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
110 {
111     return m_xAttrList->getNameByIndex( i );
112 }
113 
114 
getTypeByIndex(sal_Int16 i)115 OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
116 {
117     return m_xAttrList->getTypeByIndex( i );
118 }
119 
getValueByIndex(sal_Int16 i)120 OUString SAL_CALL  XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
121 {
122     return m_xAttrList->getValueByIndex( i );
123 }
124 
getTypeByName(const OUString & rName)125 OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
126         const OUString& rName )
127 {
128     return m_xAttrList->getTypeByName( rName );
129 }
130 
getValueByName(const OUString & rName)131 OUString SAL_CALL XMLMutableAttributeList::getValueByName(
132         const OUString& rName)
133 {
134     return m_xAttrList->getValueByName( rName );
135 }
136 
137 
createClone()138 Reference< XCloneable > XMLMutableAttributeList::createClone()
139 {
140     // A cloned list will be a read only list!
141     Reference< XCloneable >  r = new SvXMLAttributeList( m_xAttrList );
142     return r;
143 }
144 
SetValueByIndex(sal_Int16 i,const::rtl::OUString & rValue)145 void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
146                                                const ::rtl::OUString& rValue )
147 {
148     GetMutableAttrList()->SetValueByIndex( i, rValue );
149 }
150 
AddAttribute(const OUString & rName,const OUString & rValue)151 void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
152                                             const OUString &rValue )
153 {
154     GetMutableAttrList()->AddAttribute( rName, rValue );
155 }
156 
RemoveAttributeByIndex(sal_Int16 i)157 void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
158 {
159     GetMutableAttrList()->RemoveAttributeByIndex( i );
160 }
161 
RenameAttributeByIndex(sal_Int16 i,const OUString & rNewName)162 void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
163                                                     const OUString& rNewName )
164 {
165     GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
166 }
167 
AppendAttributeList(const Reference<::com::sun::star::xml::sax::XAttributeList> & r)168 void XMLMutableAttributeList::AppendAttributeList(
169         const Reference< ::com::sun::star::xml::sax::XAttributeList >& r )
170 {
171     GetMutableAttrList()->AppendAttributeList( r );
172 }
173 
GetIndexByName(const OUString & rName) const174 sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
175 {
176     sal_Int16 nIndex = -1;
177     if( m_pMutableAttrList )
178     {
179         nIndex = m_pMutableAttrList->GetIndexByName( rName );
180     }
181     else
182     {
183         sal_Int16 nCount = m_xAttrList->getLength();
184         for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
185         {
186             if( m_xAttrList->getNameByIndex(i) == rName )
187                 nIndex = i;
188         }
189     }
190     return nIndex;
191 }
192