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