1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include <rtl/ustring.hxx>
29 namespace com::sun::star
{
30 namespace beans
{ class XPropertySet
; }
31 namespace uno
{ template<class A
> class Reference
; }
35 /** This class maintains an OUString->sal_Int16 mapping for cases in
36 * which an XPropertySet needs to be filled with values that are not
39 * A good example for appropriate use are footnotes and references to
40 * footnotes. Internally, the LibreOffice API numbers footnotes, and
41 * references to footnotes refer to that internal numbering. In the
42 * XML file format, these numbers are replaced with name strings. Now
43 * if during import of a document a reference to a footnote is
44 * encountered, two things can happen: 1) The footnote already
45 * appeared in the document. In this case the name is already known
46 * and the proper ID can be requested from the footnote. 2) The
47 * footnote will appear later in the document. In this case the ID is
48 * not yet known, and the reference-ID property of the reference
49 * cannot be determined. Hence, the reference has to be stored and the
50 * ID needs to bet set later, when the footnote is eventually found in
53 * This class simplifies this process: If the footnote is found,
54 * ResolveId with the XML name and the ID is called. When a reference
55 * is encountered, SetProperty gets called with the reference's
56 * XPropertySet and the XML name. All remaining tasks are handled by
60 class XMLPropertyBackpatcher
63 /// name of property that gets set or backpatched
64 OUString sPropertyName
;
66 /// backpatch list type
67 typedef ::std::vector
<
68 css::uno::Reference
<css::beans::XPropertySet
> > BackpatchListType
;
70 /// backpatch list for unresolved IDs
71 ::std::map
<const OUString
, std::unique_ptr
<BackpatchListType
>> aBackpatchListMap
;
73 /// mapping of names -> IDs
74 ::std::map
<const OUString
, A
> aIDMap
;
78 explicit XMLPropertyBackpatcher(
79 OUString sPropertyName
);
81 ~XMLPropertyBackpatcher();
83 /// resolve a known ID.
84 /// Call this as soon as the value for a particular name is known.
86 const OUString
& sName
,
89 /// Set property with the proper value for this name. If the value
90 /// is not yet known, store the XPropertySet in the backpatch list.
91 /// Use this whenever the value should be set, even if it is not yet known.
93 const css::uno::Reference
<css::beans::XPropertySet
> & xPropSet
,
94 const OUString
& sName
);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */