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 .
21 #ifndef INCLUDED_XMLOFF_SOURCE_TEXT_XMLPROPERTYBACKPATCHER_HXX
22 #define INCLUDED_XMLOFF_SOURCE_TEXT_XMLPROPERTYBACKPATCHER_HXX
27 namespace com
{ namespace sun
{ namespace star
{
28 namespace beans
{ class XPropertySet
; }
29 namespace uno
{ template<class A
> class Reference
; }
33 /** This class maintains an OUString->sal_Int16 mapping for cases in
34 * which an XPropertySet needs to be filled with values that are not
37 * A good example for appropriate use are footnotes and references to
38 * footnoes. Internally, the StarOffice API numbers footnotes, and
39 * references to footnotes refer to that internal numbering. In the
40 * XML file format, these numbers are replaced with name strings. Now
41 * if during import of a document a reference to a footnote is
42 * encountered, two things can happen: 1) The footnote already
43 * appeared in the document. In this case the name is already known
44 * and the proper ID can be requested from the footnote. 2) The
45 * footnote will appear later in the document. In this case the ID is
46 * not yet known, and the reference-ID property of the reference
47 * cannot be determined. Hence, the reference has to be stored and the
48 * ID needs to bet set later, when the footnote is eventually found in
51 * This class simplifies this process: If the footnote is found,
52 * ResolveId with the XML name and the ID is called. When a reference
53 * is encountered, SetProperty gets called with the reference's
54 * XPropertySet and the XML name. All remaining tasks are handled by
58 class XMLPropertyBackpatcher
61 /// name of property that gets set or backpatched
62 OUString sPropertyName
;
64 /// should a default value be set for unresolved properties
65 bool bDefaultHandling
;
67 /// should the sPreservePropertyName be preserved
68 bool bPreserveProperty
;
70 /// name of the property to preserve
71 OUString sPreservePropertyName
;
73 /// backpatch list type
74 typedef ::std::vector
<
75 ::com::sun::star::uno::Reference
<
76 ::com::sun::star::beans::XPropertySet
> > BackpatchListType
;
78 /* use void* instead of BackpatchListType to avoid linker problems
79 with long typenames. The real typename (commented out) contains
82 /// backpatch list for unresolved IDs
83 //::std::map<const OUString, BackpatchListType*> aBackpatchListMap;
84 ::std::map
<const OUString
, void*> aBackpatchListMap
;
86 /// mapping of names -> IDs
87 ::std::map
<const OUString
, A
> aIDMap
;
91 XMLPropertyBackpatcher(
92 const OUString
& sPropertyName
);
94 ~XMLPropertyBackpatcher();
96 /// resolve a known ID.
97 /// Call this as soon as the value for a particular name is known.
99 const OUString
& sName
,
102 /// Set property with the proper value for this name. If the value
103 /// is not yet known, store the XPropertySet in the backpatch list.
104 /// Use this whenever the value should be set, even if it is not yet known.
107 const ::com::sun::star::uno::Reference
<
108 ::com::sun::star::beans::XPropertySet
> & xPropSet
,
109 const OUString
& sName
);
111 /// non-const version of SetProperty
113 ::com::sun::star::uno::Reference
<
114 ::com::sun::star::beans::XPropertySet
> & xPropSet
,
115 const OUString
& sName
);
117 /// set default (if bDefaultHandling) for unresolved names
118 /// called by destructor
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */