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: ...@@ -41,6 +41,9 @@ public:
virtual ~DirectoryStream() override; virtual ~DirectoryStream() override;
static bool isDirectory(const css::uno::Reference<css::ucb::XContent> &xContent); 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 bool isStructured() override;
virtual unsigned subStreamCount() override; virtual unsigned subStreamCount() override;
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <test/bootstrapfixture.hxx> #include <test/bootstrapfixture.hxx>
#include <DirectoryStream.hxx> #include <DirectoryStream.hxx>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/ucb/XContent.hpp> #include <com/sun/star/ucb/XContent.hpp>
namespace ucb = com::sun::star::ucb; namespace ucb = com::sun::star::ucb;
...@@ -64,35 +63,6 @@ static const char g_aDirPath[] = "/writerperfect/qa/unit/data/stream/test.dir"; ...@@ -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_aNondirPath[] = "/writerperfect/qa/unit/data/stream/test.dir/mimetype";
static const char g_aNonexistentPath[] = "/writerperfect/qa/unit/data/stream/foo/bar"; 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() DirectoryStreamTest::DirectoryStreamTest()
{ {
const uno::Reference<ucb::XCommandEnvironment> xCmdEnv; const uno::Reference<ucb::XCommandEnvironment> xCmdEnv;
...@@ -107,17 +77,17 @@ DirectoryStreamTest::DirectoryStreamTest() ...@@ -107,17 +77,17 @@ DirectoryStreamTest::DirectoryStreamTest()
void DirectoryStreamTest::testConstruction() 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(bool(pDir));
CPPUNIT_ASSERT(pDir->isStructured()); CPPUNIT_ASSERT(pDir->isStructured());
// this should work for dirs too // 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(bool(pDir2));
CPPUNIT_ASSERT(pDir2->isStructured()); CPPUNIT_ASSERT(pDir2->isStructured());
// for nonexistent dirs nothing is created // 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); CPPUNIT_ASSERT(!pNondir);
// even if we try harder, just an empty shell is created // even if we try harder, just an empty shell is created
...@@ -169,7 +139,7 @@ void DirectoryStreamTest::testStructuredOperations() ...@@ -169,7 +139,7 @@ void DirectoryStreamTest::testStructuredOperations()
DirectoryStream aDir(m_xDir); DirectoryStream aDir(m_xDir);
lcl_testStructuredOperations(aDir); lcl_testStructuredOperations(aDir);
unique_ptr<DirectoryStream> pDir(createForParent(m_xFile)); unique_ptr<DirectoryStream> pDir(DirectoryStream::createForParent(m_xFile));
CPPUNIT_ASSERT(bool(pDir)); CPPUNIT_ASSERT(bool(pDir));
lcl_testStructuredOperations(*pDir.get()); lcl_testStructuredOperations(*pDir.get());
} }
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include <comphelper/processfactory.hxx> #include <comphelper/processfactory.hxx>
#include <o3tl/make_unique.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
...@@ -128,6 +130,42 @@ bool DirectoryStream::isDirectory(const css::uno::Reference<css::ucb::XContent> ...@@ -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() bool DirectoryStream::isStructured()
{ {
if (!m_pImpl) if (!m_pImpl)
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyValue.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/io/XInputStream.hpp>
#include <com/sun/star/uno/Reference.h> #include <com/sun/star/uno/Reference.h>
#include <com/sun/star/ucb/XContent.hpp> #include <com/sun/star/ucb/XContent.hpp>
...@@ -48,7 +47,6 @@ using writerperfect::DocumentHandler; ...@@ -48,7 +47,6 @@ using writerperfect::DocumentHandler;
using writerperfect::WPXSvInputStream; using writerperfect::WPXSvInputStream;
namespace beans = com::sun::star::beans; namespace beans = com::sun::star::beans;
namespace container = com::sun::star::container;
namespace ucb = com::sun::star::ucb; namespace ucb = com::sun::star::ucb;
bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &) bool KeynoteImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdpGenerator &rGenerator, utl::MediaDescriptor &)
...@@ -159,16 +157,13 @@ OUString SAL_CALL KeynoteImportFilter::detect(css::uno::Sequence< css::beans::Pr ...@@ -159,16 +157,13 @@ 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? if (bIsPackage) // we passed a directory stream, but the filter claims it's APXL file?
return OUString(); return OUString();
const Reference < container::XChild > xChild(xContent, UNO_QUERY); const std::shared_ptr<writerperfect::DirectoryStream> pDir = writerperfect::DirectoryStream::createForParent(xContent);
if (xChild.is()) input = pDir;
if (bool(input))
{ {
const Reference < ucb::XContent > xPackageContent(xChild->getParent(), UNO_QUERY);
if (xPackageContent.is())
{
input.reset(new writerperfect::DirectoryStream(xPackageContent));
if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get())) if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT == libetonyek::EtonyekDocument::isSupported(input.get()))
{ {
xContent = xPackageContent; xContent = pDir->getContent();
bUCBContentChanged = true; bUCBContentChanged = true;
bIsPackage = true; bIsPackage = true;
} }
...@@ -180,7 +175,6 @@ OUString SAL_CALL KeynoteImportFilter::detect(css::uno::Sequence< css::beans::Pr ...@@ -180,7 +175,6 @@ OUString SAL_CALL KeynoteImportFilter::detect(css::uno::Sequence< css::beans::Pr
} }
} }
} }
}
// we do not need to insert ComponentData if this is not a package // we do not need to insert ComponentData if this is not a package
if (!bIsPackage && (nComponentDataLocation == -1)) if (!bIsPackage && (nComponentDataLocation == -1))
......
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