Update ooo320-m1
[ooovba.git] / xmloff / source / text / XMLPropertyBackpatcher.hxx
blobbd70ab2f3dae9a4c9ef5f683ea208d4e3a8fd39e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLPropertyBackpatcher.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #ifndef _XMLOFF_XMLPROPERTYBACKPATCHER_HXX
33 #define _XMLOFF_XMLPROPERTYBACKPATCHER_HXX
35 #ifndef __SGI_STL_MAP
36 #include <map>
37 #endif
39 #ifndef __SGI_STL_VECTOR
40 #include <vector>
41 #endif
42 #include <comphelper/stl_types.hxx>
44 namespace rtl { class OUString; }
45 namespace com { namespace sun { namespace star {
46 namespace beans { class XPropertySet; }
47 namespace uno { template<class A> class Reference; }
48 } } }
51 /** This class maintains an OUString->sal_Int16 mapping for cases in
52 * which an XPropertySet needs to be filled with values that are not
53 * yet known.
55 * A good example for appropriate use are footnotes and references to
56 * footnoes. Internally, the StarOffice API numbers footnotes, and
57 * references to footnotes refer to that internal numbering. In the
58 * XML file format, these numbers are replaced with name strings. Now
59 * if during import of a document a reference to a footnote is
60 * encountered, two things can happen: 1) The footnote already
61 * appeared in the document. In this case the name is already known
62 * and the proper ID can be requested from the footnote. 2) The
63 * footnote will appear later in the document. In this case the ID is
64 * not yet known, and the reference-ID property of the reference
65 * cannot be determined. Hence, the reference has to be stored and the
66 * ID needs to bet set later, when the footnote is eventually found in
67 * the document.
69 * This class simplifies this process: If the footnote is found,
70 * ResolveId with the XML name and the ID is called. When a reference
71 * is encountered, SetProperty gets called with the reference's
72 * XPropertySet and the XML name. All remaining tasks are handled by
73 * the class.
75 template <class A>
76 class XMLPropertyBackpatcher
79 /// name of property that gets set or backpatched
80 ::rtl::OUString sPropertyName;
82 /// should a default value be set for unresolved properties
83 sal_Bool bDefaultHandling;
85 /// should the sPreservePropertyName be preserved
86 sal_Bool bPreserveProperty;
88 /// name of the property to preserve
89 ::rtl::OUString sPreservePropertyName;
91 /// default value for unresolved properties (if bDefaultHandling)
92 A aDefault;
94 /// backpatch list type
95 typedef ::std::vector<
96 ::com::sun::star::uno::Reference<
97 ::com::sun::star::beans::XPropertySet> > BackpatchListType;
99 /* use void* instead of BackpatchListType to avoid linker problems
100 with long typenames. The real typename (commented out) contains
101 >1200 chars. */
103 /// backpatch list for unresolved IDs
104 //::std::map<const ::rtl::OUString, BackpatchListType*> aBackpatchListMap;
105 ::std::map<const ::rtl::OUString, void*, ::comphelper::UStringLess> aBackpatchListMap;
107 /// mapping of names -> IDs
108 ::std::map<const ::rtl::OUString, A, ::comphelper::UStringLess> aIDMap;
110 public:
112 XMLPropertyBackpatcher(
113 const ::rtl::OUString& sPropertyName);
115 XMLPropertyBackpatcher(
116 const ::rtl::OUString& sPropertyName,
117 const ::rtl::OUString& sPreservePropertyName,
118 sal_Bool bDefault,
119 A aDef);
121 XMLPropertyBackpatcher(
122 const sal_Char* pPropertyName);
124 XMLPropertyBackpatcher(
125 const sal_Char* pPropertyName,
126 const sal_Char* pPreservePropertyName,
127 sal_Bool bDefault,
128 A aDef);
130 ~XMLPropertyBackpatcher();
132 /// resolve a known ID.
133 /// Call this as soon as the value for a particular name is known.
134 void ResolveId(
135 const ::rtl::OUString& sName,
136 A aValue);
138 /// Set property with the proper value for this name. If the value
139 /// is not yet known, store the XPropertySet in the backpatch list.
140 /// Use this whenever the value should be set, even if it is not yet known.
141 /// const version
142 void SetProperty(
143 const ::com::sun::star::uno::Reference<
144 ::com::sun::star::beans::XPropertySet> & xPropSet,
145 const ::rtl::OUString& sName);
147 /// non-const version of SetProperty
148 void SetProperty(
149 ::com::sun::star::uno::Reference<
150 ::com::sun::star::beans::XPropertySet> & xPropSet,
151 const ::rtl::OUString& sName);
153 /// set default (if bDefaultHandling) for unresolved names
154 /// called by destructor
155 void SetDefault();
159 #endif