summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2014-06-04 14:08:52 +0200
committerDavid Tardon <dtardon@redhat.com>2014-06-04 18:11:48 +0200
commit062705bdc3cc95a1c200abb6d0a1fe6eae762aff (patch)
treeb4fd9c05636fe8ad2fb0904ed4461a64f40c216a
parentd6b8dbb8de4f434e4fbdff897fc4f16bec9b3aae (diff)
add convenience functions to handle dirs
Change-Id: I81c94565e09e0d839d95bf4f09b029838bb37ad5 (cherry picked from commit 31ba2cb2fcb3b9466c553cf12d50bc6437ee826f)
-rw-r--r--include/writerperfect/DirectoryStream.hxx3
-rw-r--r--writerperfect/source/common/DirectoryStream.cxx41
2 files changed, 44 insertions, 0 deletions
diff --git a/include/writerperfect/DirectoryStream.hxx b/include/writerperfect/DirectoryStream.hxx
index b8f3dadb6c14..2a7bffda307e 100644
--- a/include/writerperfect/DirectoryStream.hxx
+++ b/include/writerperfect/DirectoryStream.hxx
@@ -31,6 +31,9 @@ public:
explicit DirectoryStream(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent);
virtual ~DirectoryStream();
+ static DirectoryStream *createForParent(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent);
+ static bool isDirectory(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent);
+
virtual bool isStructured() SAL_OVERRIDE;
virtual unsigned subStreamCount() SAL_OVERRIDE;
virtual const char *subStreamName(unsigned id) SAL_OVERRIDE;
diff --git a/writerperfect/source/common/DirectoryStream.cxx b/writerperfect/source/common/DirectoryStream.cxx
index b720eececaaa..e22e8066505d 100644
--- a/writerperfect/source/common/DirectoryStream.cxx
+++ b/writerperfect/source/common/DirectoryStream.cxx
@@ -19,6 +19,7 @@
* For further information visit http://libwpd.sourceforge.net
*/
+#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
@@ -38,6 +39,7 @@
#include <writerperfect/DirectoryStream.hxx>
#include <writerperfect/WPXSvInputStream.hxx>
+namespace container = com::sun::star::container;
namespace io = com::sun::star::io;
namespace sdbc = com::sun::star::sdbc;
namespace ucb = com::sun::star::ucb;
@@ -112,6 +114,45 @@ DirectoryStream::~DirectoryStream()
delete m_pImpl;
}
+DirectoryStream *DirectoryStream::createForParent(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent) try
+{
+ if (!xContent.is())
+ return 0;
+
+ DirectoryStream *pDir(0);
+
+ const uno::Reference<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 = new writerperfect::DirectoryStream(xDirContent);
+ if (!pDir->isStructured())
+ pDir = 0;
+ }
+ }
+
+ return pDir;
+}
+catch (...)
+{
+return 0;
+}
+
+bool DirectoryStream::isDirectory(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent) try
+{
+ if (!xContent.is())
+ return false;
+
+ ucbhelper::Content aContent(xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
+ return aContent.isFolder();
+}
+catch (...)
+{
+ return false;
+}
+
bool DirectoryStream::isStructured()
{
return true;