20#include <com/sun/star/embed/ElementModes.hpp>
24#include <osl/diagnose.h>
31#include <com/sun/star/beans/XPropertySet.hpp>
32#include <com/sun/star/io/IOException.hpp>
33#include <com/sun/star/io/XOutputStream.hpp>
34#include <com/sun/star/util/DateTime.hpp>
35#include <com/sun/star/util/MeasureUnit.hpp>
36#include <com/sun/star/xml/sax/InputSource.hpp>
37#include <com/sun/star/xml/sax/Writer.hpp>
38#include <com/sun/star/xml/sax/SAXParseException.hpp>
48 const css::uno::Reference< css::uno::XComponentContext >& rContext,
49 const css::uno::Sequence < css::util::RevisionTag >& rVersions,
50 const OUString &rFileName,
51 Reference< XDocumentHandler >
const &rHandler )
52:
SvXMLExport( rContext,
"", rFileName, util::MeasureUnit::
CM, rHandler ),
53 maVersions( rVersions )
80 for (
const util::RevisionTag& rInfo :
maVersions )
106 const css::uno::Reference< css::uno::XComponentContext >& rContext,
107 css::uno::Sequence < css::util::RevisionTag >& rVersions )
108: SvXMLImport(rContext,
""),
109 maVersions( rVersions )
117 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& )
137css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
139 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList)
153 const Reference< XFastAttributeList > & xAttrList )
160 util::RevisionTag aInfo;
161 for (
auto &aIter : rAttribList)
163 switch( aIter.getToken() )
168 aInfo.Identifier = aIter.toString();
174 aInfo.Comment = aIter.toString();
180 aInfo.Author = aIter.toString();
185 util::DateTime aTime;
187 aInfo.TimeStamp = aTime;
196 uno::Sequence < util::RevisionTag >& aList = rImport.
GetList();
197 sal_Int32
nLength = aList.getLength();
199 aList.getArray()[
nLength] = aInfo;
206 std::u16string_view rString,
207 util::DateTime& rDateTime )
209 bool bSuccess =
true;
211 std::u16string_view aDateStr, aTimeStr;
212 size_t nPos = rString.find(
'T' );
213 if (
nPos != std::u16string_view::npos )
215 aDateStr = rString.substr( 0,
nPos );
216 aTimeStr = rString.substr(
nPos + 1 );
222 sal_Int32 nMonth = 1;
228 auto pStr = aDateStr.begin();
229 sal_Int32 nDateTokens = 1;
230 while ( pStr != aDateStr.end() )
236 if ( nDateTokens > 3 || aDateStr.empty() )
244 else if ( nDateTokens >= 2 )
249 else if ( nDateTokens >= 3 )
258 if ( bSuccess && !aTimeStr.empty() )
260 pStr = aTimeStr.begin();
261 sal_Int32 nTimeTokens = 1;
262 while ( pStr != aTimeStr.end() )
268 if ( nTimeTokens > 3 )
276 else if ( nTimeTokens >= 2 )
281 else if ( nTimeTokens >= 3 )
293 rDateTime.Day = sal::static_int_cast< sal_uInt16 >(nDay);
294 rDateTime.Month = sal::static_int_cast< sal_uInt16 >(nMonth);
295 rDateTime.Year = sal::static_int_cast< sal_uInt16 >(nYear);
296 rDateTime.Hours = sal::static_int_cast< sal_uInt16 >(nHour);
297 rDateTime.Minutes = sal::static_int_cast< sal_uInt16 >(nMin);
298 rDateTime.Seconds = sal::static_int_cast< sal_uInt16 >(nSec);
311 Reference< uno::XComponentContext > xContext =
314 Reference< XWriter > xWriter = Writer::create(xContext);
322 uno::Reference< io::XStream > xVerStream = xRoot->openStreamElement(
324 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
325 if ( !xVerStream.is() )
326 throw uno::RuntimeException();
328 Reference< io::XOutputStream > xOut = xVerStream->getOutputStream();
330 throw uno::RuntimeException(
"The stream was successfully opened for writing already!");
332 xWriter->setOutputStream(xOut);
340 catch( uno::Exception& )
348 css::uno::Sequence < css::util::RevisionTag > aVersions;
353 if ( xRoot.is() && xRoot->hasByName( sDocName ) && xRoot->isStreamElement( sDocName ) )
357 InputSource aParserInput;
359 uno::Reference< beans::XPropertySet > xProps( xRoot, uno::UNO_QUERY );
360 OSL_ENSURE( xProps.is(),
"Storage must implement XPropertySet!" );
364 xProps->getPropertyValue(
"URL") >>= aParserInput.sSystemId;
366 catch( uno::Exception& )
370 uno::Reference< io::XStream > xDocStream = xRoot->openStreamElement(
372 embed::ElementModes::READ );
373 if ( !xDocStream.is() )
374 throw uno::RuntimeException();
376 aParserInput.aInputStream = xDocStream->getInputStream();
377 OSL_ENSURE( aParserInput.aInputStream.is(),
378 "The stream was successfully opened for reading, the input part must be accessible!" );
379 if ( !aParserInput.aInputStream.is() )
380 throw uno::RuntimeException();
388 xImport->parseStream( aParserInput );
390 catch( SAXParseException& ) {}
391 catch( SAXException& ) {}
392 catch( io::IOException& ) {}
395 catch( uno::Exception& )
405 return "XMLVersionListPersistence";
409 OUString
const & ServiceName)
414css::uno::Sequence<OUString>
417 return css::uno::Sequence<OUString>{
418 "com.sun.star.document.DocumentRevisionListPersistence"};
421extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
423 css::uno::XComponentContext *,
424 css::uno::Sequence<css::uno::Any>
const &)
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
SvXMLNamespaceMap & GetNamespaceMap_()
void addChaffWhenEncryptedStorage()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
This class deliberately does not support XWeak, to improve performance when loading large documents.
void AddAtIndex(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey)
static sal_uInt16 GetIndexByKey(sal_uInt16 nKey)
virtual ~XMLVersionContext() override
static bool ParseISODateTimeString(std::u16string_view rString, css::util::DateTime &rDateTime)
XMLVersionContext(XMLVersionListImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XMLVersionListContext(XMLVersionListImport &rImport)
virtual ~XMLVersionListContext() override
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttribs) override
XMLVersionListImport & GetImport()
ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID) override
XMLVersionListExport(const css::uno::Reference< css::uno::XComponentContext > &rContext, const css::uno::Sequence< css::util::RevisionTag > &rVersions, const OUString &rFileName, css::uno::Reference< css::xml::sax::XDocumentHandler > const &rHandler)
const css::uno::Sequence< css::util::RevisionTag > & maVersions
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
css::uno::Sequence< css::util::RevisionTag > & GetList()
virtual ~XMLVersionListImport() noexcept override
XMLVersionListImport(const css::uno::Reference< css::uno::XComponentContext > &rContext, css::uno::Sequence< css::util::RevisionTag > &rVersions)
virtual void SAL_CALL store(const css::uno::Reference< css::embed::XStorage > &Storage, const css::uno::Sequence< css::util::RevisionTag > &List) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString SAL_CALL getImplementationName() override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
virtual css::uno::Sequence< css::util::RevisionTag > SAL_CALL load(const css::uno::Reference< css::embed::XStorage > &Storage) override
const std::vector< sal_Int32 > & getFastAttributeTokens() const
Reference< XComponentContext > getProcessComponentContext()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const sal_uInt16 XML_NAMESPACE_NONE
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
XMLTokenEnum
The enumeration of all XML tokens.
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)
constexpr sal_uInt16 XML_NAMESPACE_DC
constexpr sal_uInt16 XML_NAMESPACE_FRAMEWORK
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * XMLVersionListPersistence_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
constexpr OUStringLiteral XMLN_VERSIONSLIST