23 #include <rtl/ustring.hxx>
24 #include <rtl/ustrbuf.hxx>
26 #include <osl/diagnose.h>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/UnknownPropertyException.hpp>
30 #include <com/sun/star/container/XEnumerationAccess.hpp>
32 #include <com/sun/star/container/XEnumeration.hpp>
33 #include <com/sun/star/document/XRedlinesSupplier.hpp>
34 #include <com/sun/star/text/XText.hpp>
35 #include <com/sun/star/text/XTextContent.hpp>
36 #include <com/sun/star/text/XTextSection.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
47 #include <tools/datetime.hxx>
53 using ::com::sun::star::beans::PropertyValue;
54 using ::com::sun::star::beans::XPropertySet;
55 using ::com::sun::star::beans::UnknownPropertyException;
56 using ::com::sun::star::document::XRedlinesSupplier;
57 using ::com::sun::star::container::XEnumerationAccess;
58 using ::com::sun::star::container::XEnumeration;
59 using ::com::sun::star::text::XText;
60 using ::com::sun::star::text::XTextContent;
61 using ::com::sun::star::text::XTextSection;
62 using ::com::sun::star::uno::Any;
63 using ::com::sun::star::uno::Reference;
64 using ::com::sun::star::uno::Sequence;
72 , pCurrentChangesList(nullptr)
119 const Reference<XText> & rText,
128 ChangesMapType::iterator aFind =
aChangeMap.find(rText);
135 if (pChangesList->empty())
144 for (
auto const& change : *pChangesList)
153 const Reference<XText> & rText)
158 ChangesMapType::iterator aIter =
aChangeMap.find(rText);
184 Reference<XRedlinesSupplier> xSupplier(
rExport.
GetModel(), uno::UNO_QUERY);
188 Reference<XEnumerationAccess> aEnumAccess = xSupplier->getRedlines();
194 bool bEnabled = *o3tl::doAccess<bool>(aDocPropertySet->getPropertyValue(
198 if ( !(aEnumAccess->hasElements() || bEnabled) )
203 if ( !bEnabled != !aEnumAccess->hasElements() )
216 Reference<XEnumeration> aEnum = aEnumAccess->createEnumeration();
217 while (aEnum->hasMoreElements())
219 Any aAny = aEnum->nextElement();
224 "can't get XPropertySet; skipping Redline");
229 aAny = xPropSet->getPropertyValue(
"IsInHeaderFooter");
230 if (! *o3tl::doAccess<bool>(aAny))
249 Any aIsStart = rPropSet->getPropertyValue(
"IsStart");
250 Any aIsCollapsed = rPropSet->getPropertyValue(
"IsCollapsed");
252 if ( *o3tl::doAccess<bool>(aIsStart) ||
253 *o3tl::doAccess<bool>(aIsCollapsed) )
258 Any aAny = rPropSet->getPropertyValue(
"RedlineText");
259 Reference<XText> xText;
271 Reference<XRedlinesSupplier> xSupplier(
rExport.
GetModel(), uno::UNO_QUERY);
275 Reference<XEnumerationAccess> aEnumAccess = xSupplier->getRedlines();
278 if (!aEnumAccess->hasElements())
282 Reference<XEnumeration> aEnum = aEnumAccess->createEnumeration();
283 while (aEnum->hasMoreElements())
285 Any aAny = aEnum->nextElement();
290 "can't get XPropertySet; skipping Redline");
296 aAny = xPropSet->getPropertyValue(
"IsInHeaderFooter");
297 if (! *o3tl::doAccess<bool>(aAny))
310 Any aAny = rPropSet->getPropertyValue(
"IsCollapsed");
311 bool bCollapsed = *o3tl::doAccess<bool>(aAny);
318 aAny = rPropSet->getPropertyValue(
"IsStart");
319 const bool bStart = *o3tl::doAccess<bool>(aAny);
331 eElement,
false,
false);
343 Any aAny = rPropSet->getPropertyValue(
"MergeLastPara");
344 if( ! *o3tl::doAccess<bool>(aAny) )
355 aAny = rPropSet->getPropertyValue(
"RedlineType");
364 aAny = rPropSet->getPropertyValue(
"RedlineText");
365 Reference<XText> xText;
378 aAny = rPropSet->getPropertyValue(
"RedlineSuccessorData");
379 Sequence<PropertyValue> aSuccessorData;
380 aAny >>= aSuccessorData;
384 if (aSuccessorData.hasElements())
401 std::u16string_view sApiName)
403 if (sApiName ==
u"Delete")
407 else if (sApiName ==
u"Insert")
411 else if (sApiName ==
u"Format")
417 OSL_FAIL(
"unknown redline type");
418 static const OUString sUnknownChange(
"UnknownChange");
419 return sUnknownChange;
428 Any aAny = rPropSet->getPropertyValue(
"RedlineIdentifier");
445 Any aAny = rPropSet->getPropertyValue(
"RedlineAuthor");
458 aAny = rPropSet->getPropertyValue(
"RedlineDateTime");
459 util::DateTime aDateTime;
464 ? util::DateTime(0, 0, 0, 0, 1, 1, 1970,
true)
465 : aDateTime,
nullptr);
473 aAny = rPropSet->getPropertyValue(
"RedlineComment");
480 const Sequence<PropertyValue> & rPropertyValues)
489 for(
const PropertyValue& rVal : rPropertyValues)
491 if( rVal.Name ==
"RedlineAuthor" )
505 else if( rVal.Name ==
"RedlineComment" )
507 rVal.Value >>= sComment;
509 else if( rVal.Name ==
"RedlineDateTime" )
511 util::DateTime aDateTime;
512 rVal.Value >>= aDateTime;
515 ? util::DateTime(0, 0, 0, 0, 1, 1, 1970,
true)
516 : aDateTime,
nullptr);
522 else if( rVal.Name ==
"RedlineType" )
528 "hierarchical change must be insertion");
541 if( ! rPropSet.is() )
548 aAny = rPropSet->getPropertyValue(bStart ? OUString(
"StartRedline") : OUString(
"EndRedline"));
550 catch(
const UnknownPropertyException&)
556 Sequence<PropertyValue> aValues;
560 bool bIsCollapsed =
false;
561 bool bIsStart =
true;
564 for(
const auto& rValue : std::as_const(aValues))
566 if (rValue.Name ==
"RedlineIdentifier")
568 rValue.Value >>= sId;
571 else if (rValue.Name ==
"IsCollapsed")
573 bIsCollapsed = *o3tl::doAccess<bool>(rValue.Value);
575 else if (rValue.Name ==
"IsStart")
577 bIsStart = *o3tl::doAccess<bool>(rValue.Value);
584 SAL_WARN_IF( sId.isEmpty(),
"xmloff",
"Redlines must have IDs" );
600 const Reference<XTextContent> & rContent,
610 OSL_FAIL(
"XPropertySet expected");
615 const Reference<XTextSection> & rSection,
625 OSL_FAIL(
"XPropertySet expected");
631 if (rComment.empty())
637 std::u16string_view aSubString;
ChangesMapType aChangeMap
bool IsOptionSet(EOption eOption)
constexpr sal_uInt16 XML_NAMESPACE_OFFICE
void ExportStartOrEndRedline(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bStart)
export redline marks which start or end at start nodes, i.e.
size_t GetInfoID(const OUString sPersonalInfo) const
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
const OUString sFormatChange
void WriteComment(std::u16string_view rComment)
write a comment string as sequence of elements
void SAL_DLLPRIVATE AddAttributeIdLegacy(sal_uInt16 const nLegacyPrefix, OUString const &rValue)
add xml:id and legacy namespace id
const css::uno::Reference< css::frame::XModel > & GetModel() const
OUString const & ConvertTypeName(std::u16string_view sApiName)
convert the change type from API to XML names
void ExportChangeInline(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export the change mark contained in the text body
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
void ExportChangesList(bool bAutoStyles)
export the list of changes (complete list minus recorded changed)
ChangesVectorType * pCurrentChangesList
map of recorded changes
void ExportChangesListAutoStyles()
export the auto styles needed by the changes list
void ExportChangesListElements()
export the changes list ()
#define DBG_ASSERT(sCon, aError)
bool getNextToken(std::u16string_view &rToken)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
static OUString GetRedlineID(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
Get ID string!
void ExportChange(const css::uno::Reference< css::beans::XPropertySet > &rPropSet, bool bAutoStyle)
export a change
static void convertDateTime(OUStringBuffer &rBuffer, const css::util::DateTime &rDateTime, sal_Int16 const *pTimeZoneOffset, bool bAddTimeIf0AM=false)
constexpr sal_uInt16 XML_NAMESPACE_DC
void ExportChangeAutoStyle(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export the auto styles used in this change
::std::vector< css::uno::Reference< css::beans::XPropertySet > > ChangesVectorType
const OUString sInsertion
#define SAL_WARN_IF(condition, area, stream)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Handling of tokens in XML:
void Characters(const OUString &rChars)
XMLTokenEnum
The enumeration of all XML tokens.
void SetCurrentXText()
Do not record changes.
void ExportChangedRegion(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export the changed-region element
XMLRedlineExport(SvXMLExport &rExp)
void ExportChangeInfo(const css::uno::Reference< css::beans::XPropertySet > &rPropSet)
export a change-info element (from a PropertySet)