summaryrefslogtreecommitdiff
path: root/writerperfect
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2017-01-17 19:13:28 +0100
committerDavid Tardon <dtardon@redhat.com>2017-01-29 20:21:29 +0100
commit69c03000038e96d120f57b8259763e27907b8470 (patch)
tree996476144e64fcaa0a9c9044553c4e35df953cee /writerperfect
parent05ce36d2e2bada48ee97d6a7c45e3bcf71dff29a (diff)
eliminate some code duplicity
Change-Id: I7792ddd691f81744971d45e1155e3192b24155dc
Diffstat (limited to 'writerperfect')
-rw-r--r--writerperfect/inc/DirectoryStream.hxx3
-rw-r--r--writerperfect/qa/unit/DirectoryStreamTest.cxx38
-rw-r--r--writerperfect/source/common/DirectoryStream.cxx38
-rw-r--r--writerperfect/source/impress/KeynoteImportFilter.cxx32
4 files changed, 58 insertions, 53 deletions
diff --git a/writerperfect/inc/DirectoryStream.hxx b/writerperfect/inc/DirectoryStream.hxx
index dce2a63a82f2..36b818d272a5 100644
--- a/writerperfect/inc/DirectoryStream.hxx
+++ b/writerperfect/inc/DirectoryStream.hxx
@@ -41,6 +41,9 @@ public:
virtual ~DirectoryStream() override;
static bool isDirectory(const css::uno::Reference<css::ucb::XContent> &xContent);
+ static std::unique_ptr<DirectoryStream> createForParent(const css::uno::Reference<css::ucb::XContent> &xContent);
+
+ const css::uno::Reference<css::ucb::XContent> getContent() const;
virtual bool isStructured() override;
virtual unsigned subStreamCount() override;
diff --git a/writerperfect/qa/unit/DirectoryStreamTest.cxx b/writerperfect/qa/unit/DirectoryStreamTest.cxx
index 0b347ac40d71..730ce41aa718 100644
--- a/writerperfect/qa/unit/DirectoryStreamTest.cxx
+++ b/writerperfect/qa/unit/DirectoryStreamTest.cxx
@@ -20,7 +20,6 @@
#include <test/bootstrapfixture.hxx>
#include <DirectoryStream.hxx>
-#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/ucb/XContent.hpp>
namespace ucb = com::sun::star::ucb;
@@ -64,35 +63,6 @@ static const char g_aDirPath[] = "/writerperfect/qa/unit/data/stream/test.dir";
static const char g_aNondirPath[] = "/writerperfect/qa/unit/data/stream/test.dir/mimetype";
static const char g_aNonexistentPath[] = "/writerperfect/qa/unit/data/stream/foo/bar";
-std::unique_ptr<DirectoryStream> createForParent(const css::uno::Reference<css::ucb::XContent> &xContent)
-{
- try
- {
- if (!xContent.is())
- return nullptr;
-
- unique_ptr<DirectoryStream> pDir;
-
- const uno::Reference<css::container::XChild> xChild(xContent, uno::UNO_QUERY);
- if (xChild.is())
- {
- const uno::Reference<ucb::XContent> xDirContent(xChild->getParent(), uno::UNO_QUERY);
- if (xDirContent.is())
- {
- pDir = o3tl::make_unique<DirectoryStream>(xDirContent);
- if (!pDir->isStructured())
- pDir.reset();
- }
- }
-
- return pDir;
- }
- catch (...)
- {
- return nullptr;
- }
-}
-
DirectoryStreamTest::DirectoryStreamTest()
{
const uno::Reference<ucb::XCommandEnvironment> xCmdEnv;
@@ -107,17 +77,17 @@ DirectoryStreamTest::DirectoryStreamTest()
void DirectoryStreamTest::testConstruction()
{
- const unique_ptr<DirectoryStream> pDir(createForParent(m_xFile));
+ const unique_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile));
CPPUNIT_ASSERT(bool(pDir));
CPPUNIT_ASSERT(pDir->isStructured());
// this should work for dirs too
- const unique_ptr<DirectoryStream> pDir2(createForParent(m_xDir));
+ const unique_ptr<DirectoryStream> pDir2(DirectoryStream::createForParent(m_xDir));
CPPUNIT_ASSERT(bool(pDir2));
CPPUNIT_ASSERT(pDir2->isStructured());
// for nonexistent dirs nothing is created
- const unique_ptr<DirectoryStream> pNondir(createForParent(m_xNonexistent));
+ const unique_ptr<DirectoryStream> pNondir(DirectoryStream::createForParent(m_xNonexistent));
CPPUNIT_ASSERT(!pNondir);
// even if we try harder, just an empty shell is created
@@ -169,7 +139,7 @@ void DirectoryStreamTest::testStructuredOperations()
DirectoryStream aDir(m_xDir);
lcl_testStructuredOperations(aDir);
- unique_ptr<DirectoryStream> pDir(createForParent(m_xFile));
+ unique_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile));
CPPUNIT_ASSERT(bool(pDir));
lcl_testStructuredOperations(*pDir.get());
}
diff --git a/writerperfect/source/common/DirectoryStream.cxx b/writerperfect/source/common/DirectoryStream.cxx
index 3122844cde36..dd4be4c05be7 100644
--- a/writerperfect/source/common/DirectoryStream.cxx
+++ b/writerperfect/source/common/DirectoryStream.cxx
@@ -32,6 +32,8 @@
#include <comphelper/processfactory.hxx>
+#include <o3tl/make_unique.hxx>
+
#include <rtl/ustring.hxx>
#include <ucbhelper/content.hxx>
@@ -128,6 +130,42 @@ bool DirectoryStream::isDirectory(const css::uno::Reference<css::ucb::XContent>
}
}
+std::unique_ptr<DirectoryStream> DirectoryStream::createForParent(const css::uno::Reference<css::ucb::XContent> &xContent)
+{
+ try
+ {
+ if (!xContent.is())
+ return nullptr;
+
+ std::unique_ptr<DirectoryStream> pDir;
+
+ const uno::Reference<css::container::XChild> xChild(xContent, uno::UNO_QUERY);
+ if (xChild.is())
+ {
+ const uno::Reference<ucb::XContent> xDirContent(xChild->getParent(), uno::UNO_QUERY);
+ if (xDirContent.is())
+ {
+ pDir = o3tl::make_unique<DirectoryStream>(xDirContent);
+ if (!pDir->isStructured())
+ pDir.reset();
+ }
+ }
+
+ return pDir;
+ }
+ catch (...)
+ {
+ return nullptr;
+ }
+}
+
+const css::uno::Reference<css::ucb::XContent> DirectoryStream::getContent() const
+{
+ if (!m_pImpl)
+ return css::uno::Reference<css::ucb::XContent>();
+ return m_pImpl->xContent;
+}
+
bool DirectoryStream::isStructured()
{
if (!m_pImpl)
diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx
index 143131fd65b5..5aa2a6b48c92 100644
--- a/writerperfect/source/impress/KeynoteImportFilter.cxx
+++ b/writerperfect/source/impress/KeynoteImportFilter.cxx
@@ -10,7 +10,6 @@
#include <memory>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/ucb/XContent.hpp>
@@ -48,7 +47,6 @@ using writerperfect::DocumentHandler;
using writerperfect::WPXSvInputStream;
namespace beans = com::sun::star::beans;
-namespace container = com::sun::star::container;
namespace ucb = com::sun::star::ucb;
bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &)
@@ -159,25 +157,21 @@ OUString SAL_CALL KeynoteImportFilter::detect(css::uno::Sequence< css::beans::Pr
if (bIsPackage) // we passed a directory stream, but the filter claims it's APXL file?
return OUString();
- const Reference < container::XChild > xChild(xContent, UNO_QUERY);
- if (xChild.is())
+ const std::shared_ptr<writerperfect::DirectoryStream> pDir = writerperfect::DirectoryStream::createForParent(xContent);
+ input = pDir;
+ if (bool(input))
{
- const Reference < ucb::XContent > xPackageContent(xChild->getParent(), UNO_QUERY);
- if (xPackageContent.is())
+ if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get()))
{
- input.reset(new writerperfect::DirectoryStream(xPackageContent));
- if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get()))
- {
- xContent = xPackageContent;
- bUCBContentChanged = true;
- bIsPackage = true;
- }
- else
- {
- // The passed stream has been detected as APXL file, but its parent dir is not a valid Keynote
- // package? Something is wrong here...
- return OUString();
- }
+ xContent = pDir->getContent();
+ bUCBContentChanged = true;
+ bIsPackage = true;
+ }
+ else
+ {
+ // The passed stream has been detected as APXL file, but its parent dir is not a valid Keynote
+ // package? Something is wrong here...
+ return OUString();
}
}
}