/src/libreoffice/xmloff/source/text/XMLPropertyBackpatcher.cxx
Line | Count | Source (jump to first uncovered line) |
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 <memory> |
21 | | #include <com/sun/star/beans/XPropertySet.hpp> |
22 | | #include <com/sun/star/uno/Reference.h> |
23 | | |
24 | | #include <rtl/ustring.hxx> |
25 | | #include "XMLPropertyBackpatcher.hxx" |
26 | | #include <utility> |
27 | | #include <xmloff/txtimp.hxx> |
28 | | |
29 | | using ::std::map; |
30 | | using ::com::sun::star::uno::Reference; |
31 | | using ::com::sun::star::uno::Any; |
32 | | using ::com::sun::star::beans::XPropertySet; |
33 | | |
34 | | |
35 | | template<class A> |
36 | | XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher( |
37 | | OUString sPropName) |
38 | 604 | : sPropertyName(std::move(sPropName)) |
39 | 604 | { |
40 | 604 | } XMLPropertyBackpatcher<short>::XMLPropertyBackpatcher(rtl::OUString) Line | Count | Source | 38 | 604 | : sPropertyName(std::move(sPropName)) | 39 | 604 | { | 40 | 604 | } |
Unexecuted instantiation: XMLPropertyBackpatcher<rtl::OUString>::XMLPropertyBackpatcher(rtl::OUString) |
41 | | |
42 | | |
43 | | template<class A> |
44 | | XMLPropertyBackpatcher<A>::~XMLPropertyBackpatcher() |
45 | 604 | { |
46 | 604 | } XMLPropertyBackpatcher<short>::~XMLPropertyBackpatcher() Line | Count | Source | 45 | 604 | { | 46 | 604 | } |
Unexecuted instantiation: XMLPropertyBackpatcher<rtl::OUString>::~XMLPropertyBackpatcher() |
47 | | |
48 | | |
49 | | template<class A> |
50 | | void XMLPropertyBackpatcher<A>::ResolveId( |
51 | | const OUString& sName, |
52 | | A aValue) |
53 | 662 | { |
54 | | // insert ID into ID map |
55 | 662 | aIDMap[sName] = aValue; |
56 | | |
57 | | // backpatch old references, if backpatch list exists |
58 | 662 | auto it = aBackpatchListMap.find(sName); |
59 | 662 | if (it == aBackpatchListMap.end()) |
60 | 662 | return; |
61 | | |
62 | | // aah, we have a backpatch list! |
63 | 0 | std::unique_ptr<BackpatchListType> pList = std::move(it->second); |
64 | | |
65 | | // a) remove list from list map |
66 | 0 | aBackpatchListMap.erase(it); |
67 | | |
68 | | // b) for every item, set SequenceNumber |
69 | | // (and preserve Property, if appropriate) |
70 | 0 | Any aAny; |
71 | 0 | aAny <<= aValue; |
72 | 0 | for(const auto& rBackpatch : *pList) |
73 | 0 | { |
74 | 0 | rBackpatch->setPropertyValue(sPropertyName, aAny); |
75 | 0 | } |
76 | | // else: no backpatch list -> then we're finished |
77 | 0 | } XMLPropertyBackpatcher<short>::ResolveId(rtl::OUString const&, short) Line | Count | Source | 53 | 662 | { | 54 | | // insert ID into ID map | 55 | 662 | aIDMap[sName] = aValue; | 56 | | | 57 | | // backpatch old references, if backpatch list exists | 58 | 662 | auto it = aBackpatchListMap.find(sName); | 59 | 662 | if (it == aBackpatchListMap.end()) | 60 | 662 | return; | 61 | | | 62 | | // aah, we have a backpatch list! | 63 | 0 | std::unique_ptr<BackpatchListType> pList = std::move(it->second); | 64 | | | 65 | | // a) remove list from list map | 66 | 0 | aBackpatchListMap.erase(it); | 67 | | | 68 | | // b) for every item, set SequenceNumber | 69 | | // (and preserve Property, if appropriate) | 70 | 0 | Any aAny; | 71 | 0 | aAny <<= aValue; | 72 | 0 | for(const auto& rBackpatch : *pList) | 73 | 0 | { | 74 | 0 | rBackpatch->setPropertyValue(sPropertyName, aAny); | 75 | 0 | } | 76 | | // else: no backpatch list -> then we're finished | 77 | 0 | } |
Unexecuted instantiation: XMLPropertyBackpatcher<rtl::OUString>::ResolveId(rtl::OUString const&, rtl::OUString) |
78 | | |
79 | | template<class A> |
80 | | void XMLPropertyBackpatcher<A>::SetProperty( |
81 | | const Reference<XPropertySet> & xPropSet, |
82 | | const OUString& sName) |
83 | 0 | { |
84 | 0 | if (aIDMap.count(sName)) |
85 | 0 | { |
86 | | // we know this ID -> set property |
87 | 0 | xPropSet->setPropertyValue(sPropertyName, css::uno::Any(aIDMap[sName])); |
88 | 0 | } |
89 | 0 | else |
90 | 0 | { |
91 | | // ID unknown -> into backpatch list for later fixup |
92 | 0 | if (! aBackpatchListMap.count(sName)) |
93 | 0 | { |
94 | | // create backpatch list for this name |
95 | 0 | aBackpatchListMap.emplace(sName, new BackpatchListType); |
96 | 0 | } |
97 | | |
98 | | // insert footnote |
99 | 0 | aBackpatchListMap[sName]->push_back(xPropSet); |
100 | 0 | } |
101 | 0 | } Unexecuted instantiation: XMLPropertyBackpatcher<short>::SetProperty(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&) Unexecuted instantiation: XMLPropertyBackpatcher<rtl::OUString>::SetProperty(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> const&, rtl::OUString const&) |
102 | | |
103 | | // force instantiation of templates |
104 | | template class XMLPropertyBackpatcher<sal_Int16>; |
105 | | template class XMLPropertyBackpatcher<OUString>; |
106 | | |
107 | | struct XMLTextImportHelper::BackpatcherImpl |
108 | | { |
109 | | /// backpatcher for references to footnotes and endnotes |
110 | | ::std::unique_ptr< XMLPropertyBackpatcher<sal_Int16> > |
111 | | m_pFootnoteBackpatcher; |
112 | | |
113 | | /// backpatchers for references to sequences |
114 | | ::std::unique_ptr< XMLPropertyBackpatcher<sal_Int16> > |
115 | | m_pSequenceIdBackpatcher; |
116 | | |
117 | | ::std::unique_ptr< XMLPropertyBackpatcher< OUString> > |
118 | | m_pSequenceNameBackpatcher; |
119 | | }; |
120 | | |
121 | | std::shared_ptr<XMLTextImportHelper::BackpatcherImpl> |
122 | | XMLTextImportHelper::MakeBackpatcherImpl() |
123 | 48.8k | { |
124 | | // n.b.: the shared_ptr stores the dtor! |
125 | 48.8k | return std::make_shared<BackpatcherImpl>(); |
126 | 48.8k | } |
127 | | |
128 | | static OUString GetSequenceNumber() |
129 | 604 | { |
130 | 604 | return u"SequenceNumber"_ustr; |
131 | 604 | } |
132 | | |
133 | | |
134 | | // XMLTextImportHelper |
135 | | |
136 | | // Code from XMLTextImportHelper using the XMLPropertyBackpatcher is |
137 | | // implemented here. The reason is that in the unxsols2 environment, |
138 | | // all templates are instantiated as file local (switch |
139 | | // -instances=static), and thus are not accessible from the outside. |
140 | | |
141 | | // The previous solution was to force additional instantiation of |
142 | | // XMLPropertyBackpatcher in txtimp.cxx. This solution combines all |
143 | | // usage of the XMLPropertyBackpatcher in XMLPropertyBackpatcher.cxx |
144 | | // instead. |
145 | | |
146 | | |
147 | | XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetFootnoteBP() |
148 | 662 | { |
149 | 662 | if (!m_xBackpatcherImpl->m_pFootnoteBackpatcher) |
150 | 604 | { |
151 | 604 | m_xBackpatcherImpl->m_pFootnoteBackpatcher.reset( |
152 | 604 | new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber())); |
153 | 604 | } |
154 | 662 | return *m_xBackpatcherImpl->m_pFootnoteBackpatcher; |
155 | 662 | } |
156 | | |
157 | | XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetSequenceIdBP() |
158 | 0 | { |
159 | 0 | if (!m_xBackpatcherImpl->m_pSequenceIdBackpatcher) |
160 | 0 | { |
161 | 0 | m_xBackpatcherImpl->m_pSequenceIdBackpatcher.reset( |
162 | 0 | new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber())); |
163 | 0 | } |
164 | 0 | return *m_xBackpatcherImpl->m_pSequenceIdBackpatcher; |
165 | 0 | } |
166 | | |
167 | | XMLPropertyBackpatcher<OUString>& XMLTextImportHelper::GetSequenceNameBP() |
168 | 0 | { |
169 | 0 | if (!m_xBackpatcherImpl->m_pSequenceNameBackpatcher) |
170 | 0 | { |
171 | 0 | m_xBackpatcherImpl->m_pSequenceNameBackpatcher.reset( |
172 | 0 | new XMLPropertyBackpatcher<OUString>(u"SourceName"_ustr)); |
173 | 0 | } |
174 | 0 | return *m_xBackpatcherImpl->m_pSequenceNameBackpatcher; |
175 | 0 | } |
176 | | |
177 | | void XMLTextImportHelper::InsertFootnoteID( |
178 | | const OUString& sXMLId, |
179 | | sal_Int16 nAPIId) |
180 | 662 | { |
181 | 662 | GetFootnoteBP().ResolveId(sXMLId, nAPIId); |
182 | 662 | } |
183 | | |
184 | | void XMLTextImportHelper::ProcessFootnoteReference( |
185 | | const OUString& sXMLId, |
186 | | const Reference<XPropertySet> & xPropSet) |
187 | 0 | { |
188 | 0 | GetFootnoteBP().SetProperty(xPropSet, sXMLId); |
189 | 0 | } |
190 | | |
191 | | void XMLTextImportHelper::InsertSequenceID( |
192 | | const OUString& sXMLId, |
193 | | const OUString& sName, |
194 | | sal_Int16 nAPIId) |
195 | 0 | { |
196 | 0 | GetSequenceIdBP().ResolveId(sXMLId, nAPIId); |
197 | 0 | GetSequenceNameBP().ResolveId(sXMLId, sName); |
198 | 0 | } |
199 | | |
200 | | void XMLTextImportHelper::ProcessSequenceReference( |
201 | | const OUString& sXMLId, |
202 | | const Reference<XPropertySet> & xPropSet) |
203 | 0 | { |
204 | 0 | GetSequenceIdBP().SetProperty(xPropSet, sXMLId); |
205 | 0 | GetSequenceNameBP().SetProperty(xPropSet, sXMLId); |
206 | 0 | } |
207 | | |
208 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |