Kaydet (Commit) 69c03000 authored tarafından David Tardon's avatar David Tardon

eliminate some code duplicity

Change-Id: I7792ddd691f81744971d45e1155e3192b24155dc
üst 05ce36d2
......@@ -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;
......
......@@ -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());
}
......
......@@ -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)
......
......@@ -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();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment