summaryrefslogtreecommitdiff
path: root/xmlsecurity
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-07 09:58:12 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-03-07 15:00:14 +0100
commit170e0e028085745564c2755ba7e02b0a327b9e7d (patch)
tree6fe8d4988ab984200b33efe8997e196770c50a31 /xmlsecurity
parente451b03e8c21ad23cb1abfd6dd68b6d1e8188121 (diff)
xmlsecurity: extract final signature export logic from DigitalSignaturesDialog
To be able to unit-test this later without creating a vcl dialog. Change-Id: I4794e212ffefc2efa3bddaf58e6c6bf2a4ea8d9a
Diffstat (limited to 'xmlsecurity')
-rw-r--r--xmlsecurity/inc/documentsignaturemanager.hxx2
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx44
-rw-r--r--xmlsecurity/source/helper/documentsignaturemanager.cxx52
3 files changed, 48 insertions, 50 deletions
diff --git a/xmlsecurity/inc/documentsignaturemanager.hxx b/xmlsecurity/inc/documentsignaturemanager.hxx
index 918c02e37896..361de61e3bec 100644
--- a/xmlsecurity/inc/documentsignaturemanager.hxx
+++ b/xmlsecurity/inc/documentsignaturemanager.hxx
@@ -57,6 +57,8 @@ public:
void remove(sal_uInt16 nPosition);
/// Read signatures from either a temp stream or the real storage.
void read(bool bUseTempStream, bool bCacheLastSignature = true);
+ /// Write signatures back to the persistent storage.
+ void write();
};
#endif // INCLUDED_XMLSECURITY_INC_XMLSECURITY_DOCUMENTSIGNATUREMANAGER_HXX
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 1dc929d1b1f3..97cd7cd56b99 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -24,12 +24,7 @@
#include <sax/tools/converter.hxx>
#include <com/sun/star/embed/XStorage.hpp>
-#include <com/sun/star/embed/StorageFormats.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/io/XSeekable.hpp>
-#include <com/sun/star/io/XTruncate.hpp>
-#include <com/sun/star/io/TempFile.hpp>
-#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/security/NoPasswordException.hpp>
@@ -333,44 +328,7 @@ IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, SignatureHighlightHdl, SvTreeList
IMPL_LINK_NOARG_TYPED(DigitalSignaturesDialog, OKButtonHdl, Button*, void)
{
- // Export all other signatures...
- SignatureStreamHelper aStreamHelper = maSignatureManager.ImplOpenSignatureStream(embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false);
-
- if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
- {
- // ODF
- uno::Reference< io::XOutputStream > xOutputStream(
- aStreamHelper.xSignatureStream, uno::UNO_QUERY );
- uno::Reference< com::sun::star::xml::sax::XWriter> xSaxWriter =
- maSignatureManager.maSignatureHelper.CreateDocumentHandlerWithHeader( xOutputStream );
-
- uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, UNO_QUERY_THROW);
- size_t nInfos = maSignatureManager.maCurrentSignatureInformations.size();
- for( size_t n = 0 ; n < nInfos ; ++n )
- XMLSignatureHelper::ExportSignature(
- xDocumentHandler, maSignatureManager.maCurrentSignatureInformations[ n ] );
-
- XMLSignatureHelper::CloseDocumentHandler( xDocumentHandler);
-
- }
- else if (aStreamHelper.xSignatureStorage.is() && aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
- {
- // OOXML
- size_t nSignatureCount = maSignatureManager.maCurrentSignatureInformations.size();
- maSignatureManager.maSignatureHelper.ExportSignatureContentTypes(maSignatureManager.mxStore, nSignatureCount);
- maSignatureManager.maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
-
- for (size_t i = 0; i < nSignatureCount; ++i)
- maSignatureManager.maSignatureHelper.ExportOOXMLSignature(maSignatureManager.mxStore, aStreamHelper.xSignatureStorage, maSignatureManager.maCurrentSignatureInformations[i], i + 1);
- }
-
- // If stream was not provided, we are responsible for committing it....
- if ( !maSignatureManager.mxSignatureStream.is() )
- {
- uno::Reference< embed::XTransactedObject > xTrans(
- aStreamHelper.xSignatureStorage, uno::UNO_QUERY );
- xTrans->commit();
- }
+ maSignatureManager.write();
EndDialog(RET_OK);
}
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index f22d93714720..667eba29aba0 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -69,12 +69,12 @@ bool DocumentSignatureManager::isXML(const OUString& rURI)
for (int i = 0; i < m_manifest.getLength(); i++)
{
- const uno::Sequence<css::beans::PropertyValue>& entry = m_manifest[i];
+ const uno::Sequence<beans::PropertyValue>& entry = m_manifest[i];
OUString sPath, sMediaType;
bool bEncrypted = false;
for (int j = 0; j < entry.getLength(); j++)
{
- const css::beans::PropertyValue& prop = entry[j];
+ const beans::PropertyValue& prop = entry[j];
if (prop.Name.equals(sPropFullPath))
prop.Value >>= sPath;
@@ -127,10 +127,10 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3
if (bTempStream)
{
- if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ if (nStreamOpenMode & embed::ElementModes::TRUNCATE)
{
//We write always into a new temporary stream.
- mxTempSignatureStream.set(css::io::TempFile::create(mxContext), uno::UNO_QUERY_THROW);
+ mxTempSignatureStream.set(io::TempFile::create(mxContext), uno::UNO_QUERY_THROW);
if (aHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
aHelper.xSignatureStream = mxTempSignatureStream;
else
@@ -167,11 +167,11 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3
}
}
- if (nStreamOpenMode & css::embed::ElementModes::TRUNCATE)
+ if (nStreamOpenMode & embed::ElementModes::TRUNCATE)
{
if (aHelper.xSignatureStream.is() && aHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
{
- css::uno::Reference<css::io::XTruncate> xTruncate(aHelper.xSignatureStream, uno::UNO_QUERY_THROW);
+ uno::Reference<io::XTruncate> xTruncate(aHelper.xSignatureStream, uno::UNO_QUERY_THROW);
xTruncate->truncate();
}
}
@@ -338,7 +338,7 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur
maSignatureHelper.StartMission();
- SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(css::embed::ElementModes::READ, bUseTempStream);
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::READ, bUseTempStream);
if (aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML && aStreamHelper.xSignatureStream.is())
{
uno::Reference< io::XInputStream > xInputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY);
@@ -351,4 +351,42 @@ void DocumentSignatureManager::read(bool bUseTempStream, bool bCacheLastSignatur
maCurrentSignatureInformations = maSignatureHelper.GetSignatureInformations();
}
+void DocumentSignatureManager::write()
+{
+ // Export all other signatures...
+ SignatureStreamHelper aStreamHelper = ImplOpenSignatureStream(embed::ElementModes::WRITE|embed::ElementModes::TRUNCATE, false);
+
+ if (aStreamHelper.xSignatureStream.is() && aStreamHelper.nStorageFormat != embed::StorageFormats::OFOPXML)
+ {
+ // ODF
+ uno::Reference< io::XOutputStream > xOutputStream(aStreamHelper.xSignatureStream, uno::UNO_QUERY);
+ uno::Reference<xml::sax::XWriter> xSaxWriter = maSignatureHelper.CreateDocumentHandlerWithHeader(xOutputStream);
+
+ uno::Reference< xml::sax::XDocumentHandler> xDocumentHandler(xSaxWriter, uno::UNO_QUERY_THROW);
+ size_t nInfos = maCurrentSignatureInformations.size();
+ for (size_t n = 0 ; n < nInfos ; ++n)
+ XMLSignatureHelper::ExportSignature(xDocumentHandler, maCurrentSignatureInformations[n]);
+
+ XMLSignatureHelper::CloseDocumentHandler(xDocumentHandler);
+
+ }
+ else if (aStreamHelper.xSignatureStorage.is() && aStreamHelper.nStorageFormat == embed::StorageFormats::OFOPXML)
+ {
+ // OOXML
+ size_t nSignatureCount = maCurrentSignatureInformations.size();
+ maSignatureHelper.ExportSignatureContentTypes(mxStore, nSignatureCount);
+ maSignatureHelper.ExportSignatureRelations(aStreamHelper.xSignatureStorage, nSignatureCount);
+
+ for (size_t i = 0; i < nSignatureCount; ++i)
+ maSignatureHelper.ExportOOXMLSignature(mxStore, aStreamHelper.xSignatureStorage, maCurrentSignatureInformations[i], i + 1);
+ }
+
+ // If stream was not provided, we are responsible for committing it....
+ if (!mxSignatureStream.is())
+ {
+ uno::Reference<embed::XTransactedObject> xTrans(aStreamHelper.xSignatureStorage, uno::UNO_QUERY);
+ xTrans->commit();
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */