fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / text / XMLPropertyBackpatcher.cxx
blob7807dc73b82e24c87bdaab8f2d24b777ffd63c60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/uno/Reference.h>
23 #include <rtl/ustring.hxx>
24 #include <tools/debug.hxx>
25 #include "XMLPropertyBackpatcher.hxx"
26 #include <xmloff/txtimp.hxx> // XMLTextImportHelper partially implemented here
29 using ::std::vector;
30 using ::std::map;
31 using ::com::sun::star::uno::Reference;
32 using ::com::sun::star::uno::Any;
33 using ::com::sun::star::beans::XPropertySet;
36 template<class A>
37 XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher(
38 const OUString& sPropName)
39 : sPropertyName(sPropName)
40 , bDefaultHandling(sal_False)
41 , bPreserveProperty(sal_False)
42 , sPreservePropertyName()
47 template<class A>
48 XMLPropertyBackpatcher<A>::~XMLPropertyBackpatcher()
50 SetDefault();
54 template<class A>
55 void XMLPropertyBackpatcher<A>::ResolveId(
56 const OUString& sName,
57 A aValue)
59 // insert ID into ID map
60 aIDMap[sName] = aValue;
62 // backpatch old references, if backpatch list exists
63 if (aBackpatchListMap.count(sName))
65 // aah, we have a backpatch list!
66 BackpatchListType* pList =
67 (BackpatchListType*)aBackpatchListMap[sName];
69 // a) remove list from list map
70 aBackpatchListMap.erase(sName);
72 // b) for every item, set SequenceNumber
73 // (and preserve Property, if appropriate)
74 Any aAny;
75 aAny <<= aValue;
76 if (bPreserveProperty)
78 // preserve version
79 for(BackpatchListType::iterator aIter = pList->begin();
80 aIter != pList->end();
81 ++aIter)
83 Reference<XPropertySet> xProp = (*aIter);
84 Any aPres = xProp->getPropertyValue(sPreservePropertyName);
85 xProp->setPropertyValue(sPropertyName, aAny);
86 xProp->setPropertyValue(sPreservePropertyName, aPres);
89 else
91 // without preserve
92 for(BackpatchListType::iterator aIter = pList->begin();
93 aIter != pList->end();
94 ++aIter)
96 (*aIter)->setPropertyValue(sPropertyName, aAny);
100 // c) delete list
101 delete pList;
103 // else: no backpatch list -> then we're finished
106 template<class A>
107 void XMLPropertyBackpatcher<A>::SetProperty(
108 const Reference<XPropertySet> & xPropSet,
109 const OUString& sName)
111 Reference<XPropertySet> xNonConstPropSet(xPropSet);
112 SetProperty(xNonConstPropSet, sName);
115 template<class A>
116 void XMLPropertyBackpatcher<A>::SetProperty(
117 Reference<XPropertySet> & xPropSet,
118 const OUString& sName)
120 if (aIDMap.count(sName))
122 // we know this ID -> set property
123 Any aAny;
124 aAny <<= aIDMap[sName];
125 xPropSet->setPropertyValue(sPropertyName, aAny);
127 else
129 // ID unknown -> into backpatch list for later fixup
130 if (! aBackpatchListMap.count(sName))
132 // create backpatch list for this name
133 BackpatchListType* pTmp = new BackpatchListType() ;
134 aBackpatchListMap[sName] = (void*)pTmp;
137 // insert footnote
138 ((BackpatchListType*)aBackpatchListMap[sName])->push_back(xPropSet);
142 template<class A>
143 void XMLPropertyBackpatcher<A>::SetDefault()
145 if (bDefaultHandling)
147 // not implemented yet
151 // force instantiation of templates
152 template class XMLPropertyBackpatcher<sal_Int16>;
153 template class XMLPropertyBackpatcher<OUString>;
155 struct SAL_DLLPRIVATE XMLTextImportHelper::BackpatcherImpl
157 SAL_WNODEPRECATED_DECLARATIONS_PUSH
158 /// backpatcher for references to footnotes and endnotes
159 ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> >
160 m_pFootnoteBackpatcher;
162 /// backpatchers for references to sequences
163 ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> >
164 m_pSequenceIdBackpatcher;
166 ::std::auto_ptr< XMLPropertyBackpatcher< OUString> >
167 m_pSequenceNameBackpatcher;
168 SAL_WNODEPRECATED_DECLARATIONS_POP
171 ::boost::shared_ptr<XMLTextImportHelper::BackpatcherImpl>
172 XMLTextImportHelper::MakeBackpatcherImpl()
174 // n.b.: the shared_ptr stores the dtor!
175 return ::boost::shared_ptr<BackpatcherImpl>(new BackpatcherImpl);
178 static OUString const& GetSequenceNumber()
180 static OUString s_SequenceNumber("SequenceNumber");
181 return s_SequenceNumber;
185 // XMLTextImportHelper
187 // Code from XMLTextImportHelper using the XMLPropertyBackpatcher is
188 // implemented here. The reason is that in the unxsols2 environment,
189 // all templates are instatiated as file local (switch
190 // -instances=static), and thus are not accessible from the outside.
192 // The previous solution was to force additional instantiation of
193 // XMLPropertyBackpatcher in txtimp.cxx. This solution combines all
194 // usage of the XMLPropertyBackpatcher in XMLPropertyBackpatcher.cxx
195 // instead.
198 XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetFootnoteBP()
200 if (!m_pBackpatcherImpl->m_pFootnoteBackpatcher.get())
202 m_pBackpatcherImpl->m_pFootnoteBackpatcher.reset(
203 new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber()));
205 return *m_pBackpatcherImpl->m_pFootnoteBackpatcher;
208 XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetSequenceIdBP()
210 if (!m_pBackpatcherImpl->m_pSequenceIdBackpatcher.get())
212 m_pBackpatcherImpl->m_pSequenceIdBackpatcher.reset(
213 new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber()));
215 return *m_pBackpatcherImpl->m_pSequenceIdBackpatcher;
218 XMLPropertyBackpatcher<OUString>& XMLTextImportHelper::GetSequenceNameBP()
220 static OUString s_SourceName("SourceName");
221 if (!m_pBackpatcherImpl->m_pSequenceNameBackpatcher.get())
223 m_pBackpatcherImpl->m_pSequenceNameBackpatcher.reset(
224 new XMLPropertyBackpatcher<OUString>(s_SourceName));
226 return *m_pBackpatcherImpl->m_pSequenceNameBackpatcher;
229 void XMLTextImportHelper::InsertFootnoteID(
230 const OUString& sXMLId,
231 sal_Int16 nAPIId)
233 GetFootnoteBP().ResolveId(sXMLId, nAPIId);
236 void XMLTextImportHelper::ProcessFootnoteReference(
237 const OUString& sXMLId,
238 const Reference<XPropertySet> & xPropSet)
240 GetFootnoteBP().SetProperty(xPropSet, sXMLId);
243 void XMLTextImportHelper::InsertSequenceID(
244 const OUString& sXMLId,
245 const OUString& sName,
246 sal_Int16 nAPIId)
248 GetSequenceIdBP().ResolveId(sXMLId, nAPIId);
249 GetSequenceNameBP().ResolveId(sXMLId, sName);
252 void XMLTextImportHelper::ProcessSequenceReference(
253 const OUString& sXMLId,
254 const Reference<XPropertySet> & xPropSet)
256 GetSequenceIdBP().SetProperty(xPropSet, sXMLId);
257 GetSequenceNameBP().SetProperty(xPropSet, sXMLId);
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */