Line data Source code
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 <string.h>
21 :
22 : #include <osl/mutex.hxx>
23 : #include <xmloff/xmltoken.hxx>
24 : #include <xmloff/attrlist.hxx>
25 : #include <comphelper/servicehelper.hxx>
26 : #include "MutableAttrList.hxx"
27 :
28 :
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;
33 :
34 6482 : SvXMLAttributeList *XMLMutableAttributeList::GetMutableAttrList()
35 : {
36 6482 : if( !m_pMutableAttrList )
37 : {
38 1327 : m_pMutableAttrList = new SvXMLAttributeList( m_xAttrList );
39 1327 : m_xAttrList = m_pMutableAttrList;
40 : }
41 :
42 6482 : return m_pMutableAttrList;
43 : }
44 :
45 793 : XMLMutableAttributeList::XMLMutableAttributeList() :
46 793 : m_pMutableAttrList( new SvXMLAttributeList )
47 : {
48 793 : m_xAttrList = m_pMutableAttrList;
49 793 : }
50 :
51 2920 : XMLMutableAttributeList::XMLMutableAttributeList( const Reference<
52 : XAttributeList> & rAttrList, bool bClone ) :
53 2920 : m_xAttrList( rAttrList.is() ? rAttrList : new SvXMLAttributeList ),
54 5840 : m_pMutableAttrList( 0 )
55 : {
56 2920 : if( bClone )
57 336 : GetMutableAttrList();
58 2920 : }
59 :
60 :
61 11139 : XMLMutableAttributeList::~XMLMutableAttributeList()
62 : {
63 3713 : m_xAttrList = 0;
64 7426 : }
65 :
66 : namespace
67 : {
68 : class theXMLMutableAttributeListUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theXMLMutableAttributeListUnoTunnelId> {};
69 : }
70 :
71 : // XUnoTunnel & co
72 101 : const Sequence< sal_Int8 > & XMLMutableAttributeList::getUnoTunnelId() throw()
73 : {
74 101 : return theXMLMutableAttributeListUnoTunnelId::get().getSeq();
75 : }
76 :
77 : // XUnoTunnel
78 101 : sal_Int64 SAL_CALL XMLMutableAttributeList::getSomething(
79 : const Sequence< sal_Int8 >& rId )
80 : throw( RuntimeException, std::exception )
81 : {
82 202 : if( rId.getLength() == 16 &&
83 101 : 0 == memcmp( getUnoTunnelId().getConstArray(),
84 202 : rId.getConstArray(), 16 ) )
85 : {
86 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
87 : }
88 101 : return 0;
89 : }
90 :
91 6352 : sal_Int16 SAL_CALL XMLMutableAttributeList::getLength()
92 : throw( RuntimeException, std::exception )
93 : {
94 6352 : return m_xAttrList->getLength();
95 : }
96 :
97 :
98 20941 : OUString SAL_CALL XMLMutableAttributeList::getNameByIndex(sal_Int16 i)
99 : throw( RuntimeException, std::exception )
100 : {
101 20941 : return m_xAttrList->getNameByIndex( i );
102 : }
103 :
104 :
105 726 : OUString SAL_CALL XMLMutableAttributeList::getTypeByIndex(sal_Int16 i)
106 : throw( RuntimeException, std::exception )
107 : {
108 726 : return m_xAttrList->getTypeByIndex( i );
109 : }
110 :
111 16385 : OUString SAL_CALL XMLMutableAttributeList::getValueByIndex(sal_Int16 i)
112 : throw( RuntimeException, std::exception )
113 : {
114 16385 : return m_xAttrList->getValueByIndex( i );
115 : }
116 :
117 0 : OUString SAL_CALL XMLMutableAttributeList::getTypeByName(
118 : const OUString& rName )
119 : throw( RuntimeException, std::exception )
120 : {
121 0 : return m_xAttrList->getTypeByName( rName );
122 : }
123 :
124 29 : OUString SAL_CALL XMLMutableAttributeList::getValueByName(
125 : const OUString& rName)
126 : throw( RuntimeException, std::exception )
127 : {
128 29 : return m_xAttrList->getValueByName( rName );
129 : }
130 :
131 :
132 5 : Reference< XCloneable > XMLMutableAttributeList::createClone()
133 : throw( RuntimeException, std::exception )
134 : {
135 : // A cloned list will be a read only list!
136 5 : Reference< XCloneable > r = new SvXMLAttributeList( m_xAttrList );
137 5 : return r;
138 : }
139 :
140 1057 : void XMLMutableAttributeList::SetValueByIndex( sal_Int16 i,
141 : const OUString& rValue )
142 : {
143 1057 : GetMutableAttrList()->SetValueByIndex( i, rValue );
144 1057 : }
145 :
146 4301 : void XMLMutableAttributeList::AddAttribute( const OUString &rName ,
147 : const OUString &rValue )
148 : {
149 4301 : GetMutableAttrList()->AddAttribute( rName, rValue );
150 4301 : }
151 :
152 212 : void XMLMutableAttributeList::RemoveAttributeByIndex( sal_Int16 i )
153 : {
154 212 : GetMutableAttrList()->RemoveAttributeByIndex( i );
155 212 : }
156 :
157 551 : void XMLMutableAttributeList::RenameAttributeByIndex( sal_Int16 i,
158 : const OUString& rNewName )
159 : {
160 551 : GetMutableAttrList()->RenameAttributeByIndex( i, rNewName );
161 551 : }
162 :
163 25 : void XMLMutableAttributeList::AppendAttributeList(
164 : const Reference< ::com::sun::star::xml::sax::XAttributeList >& r )
165 : {
166 25 : GetMutableAttrList()->AppendAttributeList( r );
167 25 : }
168 :
169 0 : sal_Int16 XMLMutableAttributeList::GetIndexByName( const OUString& rName ) const
170 : {
171 0 : sal_Int16 nIndex = -1;
172 0 : if( m_pMutableAttrList )
173 : {
174 0 : nIndex = m_pMutableAttrList->GetIndexByName( rName );
175 : }
176 : else
177 : {
178 0 : sal_Int16 nCount = m_xAttrList->getLength();
179 0 : for( sal_Int16 i=0; nIndex==-1 && i<nCount ; ++i )
180 : {
181 0 : if( m_xAttrList->getNameByIndex(i) == rName )
182 0 : nIndex = i;
183 : }
184 : }
185 0 : return nIndex;
186 : }
187 :
188 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|