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