xref: /trunk/main/xmloff/source/text/XMLRedlineExport.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _XMLOFF_XMLREDLINEEXPORT_HXX
29 #define _XMLOFF_XMLREDLINEEXPORT_HXX
30 
31 #include <rtl/ustrbuf.hxx>
32 #include <com/sun/star/uno/Reference.h>
33 #include <com/sun/star/uno/Sequence.h>
34 
35 #include <list>
36 #include <map>
37 #include <set>
38 
39 class SvXMLExport;
40 namespace com { namespace sun { namespace star {
41     namespace beans { class XPropertySet; }
42     namespace beans { struct PropertyValue; }
43     namespace text { class XText; }
44     namespace text { class XTextContent; }
45     namespace text { class XTextSection; }
46  } } }
47 namespace rtl {
48     class OUString;
49     class OUStringBuffer;
50 }
51 
52 // store a list of redline properties
53 typedef ::std::list<
54             ::com::sun::star::uno::Reference<
55                 ::com::sun::star::beans::XPropertySet> > ChangesListType;
56 
57 // store a list of redline properties for each XText
58 typedef ::std::map<
59             ::com::sun::star::uno::Reference< ::com::sun::star::text::XText>,
60             ChangesListType* > ChangesMapType;
61 
62 
63 /**
64  * This class handles the export of redline portions.
65  * It is to be called from XMLTextParagraphExport.
66  */
67 class XMLRedlineExport
68 {
69     const ::rtl::OUString sDelete;
70     const ::rtl::OUString sDeletion;
71     const ::rtl::OUString sFormat;
72     const ::rtl::OUString sFormatChange;
73     const ::rtl::OUString sInsert;
74     const ::rtl::OUString sInsertion;
75     const ::rtl::OUString sIsCollapsed;
76     const ::rtl::OUString sIsStart;
77     const ::rtl::OUString sRedlineAuthor;
78     const ::rtl::OUString sRedlineComment;
79     const ::rtl::OUString sRedlineDateTime;
80     const ::rtl::OUString sRedlineSuccessorData;
81     const ::rtl::OUString sRedlineText;
82     const ::rtl::OUString sRedlineType;
83     const ::rtl::OUString sStyle;
84     const ::rtl::OUString sTextTable;
85     const ::rtl::OUString sUnknownChange;
86     const ::rtl::OUString sStartRedline;
87     const ::rtl::OUString sEndRedline;
88     const ::rtl::OUString sRedlineIdentifier;
89     const ::rtl::OUString sIsInHeaderFooter;
90     const ::rtl::OUString sRedlineProtectionKey;
91     const ::rtl::OUString sRecordChanges;
92     const ::rtl::OUString sMergeLastPara;
93 
94     const ::rtl::OUString sChangePrefix;
95 
96     SvXMLExport& rExport;
97 
98 
99     // handling of change recording:
100 
101     // To support change tracking in headers and footers we need to
102     // write these changes separately. To do this, we record the
103     // changes for headers and footers. For the main document body, we
104     // get the complete list of changes from the document, which
105     // should be much more efficient than recording all of those.
106 
107     ChangesMapType aChangeMap;              /// map of recorded changes
108 
109     /// list of current changes; is NULL or points to member of aChangeMap
110     ChangesListType* pCurrentChangesList;
111 
112 
113 public:
114     XMLRedlineExport(SvXMLExport& rExp);
115 
116     ~XMLRedlineExport();
117 
118     /// export a change
119     void ExportChange(
120         /// PropertySet of RedlinePortion
121         const ::com::sun::star::uno::Reference<
122                     ::com::sun::star::beans::XPropertySet> & rPropSet,
123         sal_Bool bAutoStyle);
124 
125     /// export the list of changes (complete list minus recorded changed)
126     void ExportChangesList(sal_Bool bAutoStyles);
127 
128     /// export the list of changes (recorded changes for this XText only)
129     void ExportChangesList(
130         const ::com::sun::star::uno::Reference<
131             ::com::sun::star::text::XText> & rText,
132         sal_Bool bAutoStyles);
133 
134     /// set the current XText for which changes should be recorded.
135     /// An empty XText means: don't record changes
136     void SetCurrentXText(
137         const ::com::sun::star::uno::Reference<
138             ::com::sun::star::text::XText> & rText);
139 
140     /// Do not record changes.
141     /// Same as SetCurrentXText(Reference<XText>) with empty argument.
142     void SetCurrentXText();
143 
144     /// export redline marks which start or end at start nodes,
145     /// i.e. that include the complete paragraph/table/section
146     void ExportStartOrEndRedline(
147         const ::com::sun::star::uno::Reference<
148                     ::com::sun::star::beans::XPropertySet> & rPropSet,
149         sal_Bool bStart);   /// start or end of text entity (e.g. paragraph)?
150 
151     /// convenience method, calls XPropertySet-version of this method
152     void ExportStartOrEndRedline(
153         /// XTextContent; must also be an XPropertySet
154         const ::com::sun::star::uno::Reference<
155                     ::com::sun::star::text::XTextContent> & rContent,
156         sal_Bool bStart);
157 
158     /// convenience method, calls XPropertySet-version of this method
159     void ExportStartOrEndRedline(
160         /// XTextSection; must also be an XPropertySet
161         const ::com::sun::star::uno::Reference<
162                     ::com::sun::star::text::XTextSection> & rSection,
163         sal_Bool bStart);
164 
165 private:
166 
167     /// export the change mark contained in the text body
168     void ExportChangeInline(
169         /// PropertySet of RedlinePortion
170         const ::com::sun::star::uno::Reference<
171                     ::com::sun::star::beans::XPropertySet> & rPropSet);
172 
173     /// export the auto styles used in this change
174     void ExportChangeAutoStyle(
175         /// PropertySet of RedlinePortion
176         const ::com::sun::star::uno::Reference<
177                     ::com::sun::star::beans::XPropertySet> & rPropSet);
178 
179     /// export the changes list (<text:tracked-changes>)
180     void ExportChangesListElements();
181 
182     /// export the auto styles needed by the changes list
183     void ExportChangesListAutoStyles();
184 
185     /// export the changed-region element
186     void ExportChangedRegion(
187         const ::com::sun::star::uno::Reference<
188                     ::com::sun::star::beans::XPropertySet> & rPropSet);
189 
190     /// export an change-info element (from a PropertySet)
191     void ExportChangeInfo(
192         const ::com::sun::star::uno::Reference<
193                     ::com::sun::star::beans::XPropertySet> & rPropSet);
194 
195     /// export an change-info element (from PropertyValues)
196     void ExportChangeInfo(
197         const ::com::sun::star::uno::Sequence<
198                     ::com::sun::star::beans::PropertyValue> & rValues);
199 
200     /// convert the change type from API to XML names
201     const ::rtl::OUString ConvertTypeName(const ::rtl::OUString& sApiName);
202 
203     /// Get ID string!
204     const ::rtl::OUString GetRedlineID(
205         const ::com::sun::star::uno::Reference<
206                     ::com::sun::star::beans::XPropertySet> & rPropSet);
207 
208     /// write a comment string as sequence of <text:p> elements
209     void WriteComment(const ::rtl::OUString& rComment);
210 };
211 
212 #endif
213