LibreOffice Module xmloff (master) 1
XMLPropertyBackpatcher.cxx
Go to the documentation of this file.
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>
26#include <utility>
27#include <xmloff/txtimp.hxx>
28
29using ::std::map;
30using ::com::sun::star::uno::Reference;
31using ::com::sun::star::uno::Any;
32using ::com::sun::star::beans::XPropertySet;
33
34
35template<class A>
37 OUString sPropName)
38: sPropertyName(std::move(sPropName))
39{
40}
41
42
43template<class A>
45{
46}
47
48
49template<class A>
51 const OUString& sName,
52 A aValue)
53{
54 // insert ID into ID map
55 aIDMap[sName] = aValue;
56
57 // backpatch old references, if backpatch list exists
58 auto it = aBackpatchListMap.find(sName);
59 if (it == aBackpatchListMap.end())
60 return;
61
62 // aah, we have a backpatch list!
63 std::unique_ptr<BackpatchListType> pList = std::move(it->second);
64
65 // a) remove list from list map
66 aBackpatchListMap.erase(it);
67
68 // b) for every item, set SequenceNumber
69 // (and preserve Property, if appropriate)
70 Any aAny;
71 aAny <<= aValue;
72 for(const auto& rBackpatch : *pList)
73 {
74 rBackpatch->setPropertyValue(sPropertyName, aAny);
75 }
76 // else: no backpatch list -> then we're finished
77}
78
79template<class A>
81 const Reference<XPropertySet> & xPropSet,
82 const OUString& sName)
83{
84 if (aIDMap.count(sName))
85 {
86 // we know this ID -> set property
87 xPropSet->setPropertyValue(sPropertyName, css::uno::Any(aIDMap[sName]));
88 }
89 else
90 {
91 // ID unknown -> into backpatch list for later fixup
92 if (! aBackpatchListMap.count(sName))
93 {
94 // create backpatch list for this name
95 aBackpatchListMap.emplace(sName, new BackpatchListType);
96 }
97
98 // insert footnote
99 aBackpatchListMap[sName]->push_back(xPropSet);
100 }
101}
102
103// force instantiation of templates
106
108{
110 ::std::unique_ptr< XMLPropertyBackpatcher<sal_Int16> >
112
114 ::std::unique_ptr< XMLPropertyBackpatcher<sal_Int16> >
116
117 ::std::unique_ptr< XMLPropertyBackpatcher< OUString> >
119};
120
121std::shared_ptr<XMLTextImportHelper::BackpatcherImpl>
123{
124 // n.b.: the shared_ptr stores the dtor!
125 return std::make_shared<BackpatcherImpl>();
126}
127
128static OUString GetSequenceNumber()
129{
130 return "SequenceNumber";
131}
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
148{
149 if (!m_xBackpatcherImpl->m_pFootnoteBackpatcher)
150 {
151 m_xBackpatcherImpl->m_pFootnoteBackpatcher.reset(
153 }
154 return *m_xBackpatcherImpl->m_pFootnoteBackpatcher;
155}
156
158{
159 if (!m_xBackpatcherImpl->m_pSequenceIdBackpatcher)
160 {
161 m_xBackpatcherImpl->m_pSequenceIdBackpatcher.reset(
163 }
164 return *m_xBackpatcherImpl->m_pSequenceIdBackpatcher;
165}
166
168{
169 if (!m_xBackpatcherImpl->m_pSequenceNameBackpatcher)
170 {
171 m_xBackpatcherImpl->m_pSequenceNameBackpatcher.reset(
172 new XMLPropertyBackpatcher<OUString>("SourceName"));
173 }
174 return *m_xBackpatcherImpl->m_pSequenceNameBackpatcher;
175}
176
178 const OUString& sXMLId,
179 sal_Int16 nAPIId)
180{
181 GetFootnoteBP().ResolveId(sXMLId, nAPIId);
182}
183
185 const OUString& sXMLId,
186 const Reference<XPropertySet> & xPropSet)
187{
188 GetFootnoteBP().SetProperty(xPropSet, sXMLId);
189}
190
192 const OUString& sXMLId,
193 const OUString& sName,
194 sal_Int16 nAPIId)
195{
196 GetSequenceIdBP().ResolveId(sXMLId, nAPIId);
197 GetSequenceNameBP().ResolveId(sXMLId, sName);
198}
199
201 const OUString& sXMLId,
202 const Reference<XPropertySet> & xPropSet)
203{
204 GetSequenceIdBP().SetProperty(xPropSet, sXMLId);
205 GetSequenceNameBP().SetProperty(xPropSet, sXMLId);
206}
207
208/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString GetSequenceNumber()
This class maintains an OUString->sal_Int16 mapping for cases in which an XPropertySet needs to be fi...
void SetProperty(const css::uno::Reference< css::beans::XPropertySet > &xPropSet, const OUString &sName)
Set property with the proper value for this name.
::std::vector< css::uno::Reference< css::beans::XPropertySet > > BackpatchListType
backpatch list type
XMLPropertyBackpatcher(OUString sPropertyName)
void ResolveId(const OUString &sName, A aValue)
resolve a known ID.
void InsertFootnoteID(const OUString &sXMLId, sal_Int16 nAPIId)
insert new footnote ID.
XMLPropertyBackpatcher< sal_Int16 > & GetFootnoteBP()
static std::shared_ptr< BackpatcherImpl > MakeBackpatcherImpl()
std::shared_ptr< BackpatcherImpl > m_xBackpatcherImpl
Definition: txtimp.hxx:103
void ProcessFootnoteReference(const OUString &sXMLId, const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
set the proper footnote reference ID, or put into backpatch list if ID is unknown
XMLPropertyBackpatcher< sal_Int16 > & GetSequenceIdBP()
void ProcessSequenceReference(const OUString &sXMLId, const css::uno::Reference< css::beans::XPropertySet > &xPropSet)
set sequence ID or insert into backpatch list
XMLPropertyBackpatcher< OUString > & GetSequenceNameBP()
void InsertSequenceID(const OUString &sXMLId, const OUString &sName, sal_Int16 nAPIId)
insert new sequence ID Also fixup open references from backpatch list to this ID.
const char * sName
::std::unique_ptr< XMLPropertyBackpatcher< OUString > > m_pSequenceNameBackpatcher
::std::unique_ptr< XMLPropertyBackpatcher< sal_Int16 > > m_pFootnoteBackpatcher
backpatcher for references to footnotes and endnotes
::std::unique_ptr< XMLPropertyBackpatcher< sal_Int16 > > m_pSequenceIdBackpatcher
backpatchers for references to sequences