Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / writerperfect / source / common / DirectoryStream.cxx
blob3122844cde365defa4bdf6fb7929427a2c875721
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* writerperfect
3 * Version: MPL 2.0 / LGPLv2.1+
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * Major Contributor(s):
10 * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch)
12 * For minor contributions see the git repository.
14 * Alternatively, the contents of this file may be used under the terms
15 * of the GNU Lesser General Public License Version 2.1 or later
16 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
17 * applicable instead of those above.
19 * For further information visit http://libwpd.sourceforge.net
22 #include <com/sun/star/container/XChild.hpp>
23 #include <com/sun/star/io/XInputStream.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <com/sun/star/sdbc/XRow.hpp>
26 #include <com/sun/star/ucb/XContent.hpp>
27 #include <com/sun/star/ucb/XContentAccess.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
33 #include <comphelper/processfactory.hxx>
35 #include <rtl/ustring.hxx>
37 #include <ucbhelper/content.hxx>
39 #include <DirectoryStream.hxx>
40 #include <WPXSvInputStream.hxx>
42 namespace io = com::sun::star::io;
43 namespace sdbc = com::sun::star::sdbc;
44 namespace ucb = com::sun::star::ucb;
45 namespace uno = com::sun::star::uno;
47 namespace writerperfect
50 namespace
53 uno::Reference<io::XInputStream> findStream(ucbhelper::Content &rContent, const rtl::OUString &rName)
55 uno::Reference<io::XInputStream> xInputStream;
57 uno::Sequence<OUString> lPropNames { "Title" };
58 try
60 const uno::Reference<sdbc::XResultSet> xResultSet(
61 rContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY));
62 if (xResultSet->first())
64 const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY_THROW);
65 const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
68 const rtl::OUString aTitle(xRow->getString(1));
69 if (aTitle == rName)
71 const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
72 ucbhelper::Content aSubContent(xSubContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
73 xInputStream = aSubContent.openStream();
74 break;
77 while (xResultSet->next());
80 catch (const uno::RuntimeException &)
82 // ignore
84 catch (const uno::Exception &)
86 // ignore
89 return xInputStream;
94 struct DirectoryStream::Impl
96 explicit Impl(const uno::Reference<ucb::XContent> &rxContent);
98 uno::Reference<ucb::XContent> xContent;
101 DirectoryStream::Impl::Impl(const uno::Reference<ucb::XContent> &rxContent)
102 : xContent(rxContent)
106 DirectoryStream::DirectoryStream(const css::uno::Reference<css::ucb::XContent> &xContent)
107 : m_pImpl(isDirectory(xContent) ? new Impl(xContent) : nullptr)
111 DirectoryStream::~DirectoryStream()
115 bool DirectoryStream::isDirectory(const css::uno::Reference<css::ucb::XContent> &xContent)
119 if (!xContent.is())
120 return false;
122 ucbhelper::Content aContent(xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
123 return aContent.isFolder();
125 catch (...)
127 return false;
131 bool DirectoryStream::isStructured()
133 if (!m_pImpl)
134 return false;
136 return true;
139 unsigned DirectoryStream::subStreamCount()
141 // TODO: implement me
142 return 0;
145 const char *DirectoryStream::subStreamName(unsigned /* id */)
147 // TODO: implement me
148 return nullptr;
151 bool DirectoryStream::existsSubStream(const char * /* name */)
153 // TODO: implement me
154 return false;
157 librevenge::RVNGInputStream *DirectoryStream::getSubStreamByName(const char *const pName)
159 if (!m_pImpl)
160 return nullptr;
162 ucbhelper::Content aContent(m_pImpl->xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
163 const uno::Reference<io::XInputStream> xInputStream(findStream(aContent, rtl::OUString::createFromAscii(pName)));
164 if (xInputStream.is())
165 return new WPXSvInputStream(xInputStream);
167 return nullptr;
170 librevenge::RVNGInputStream *DirectoryStream::getSubStreamById(unsigned /* id */)
172 // TODO: implement me
173 return nullptr;
176 const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead)
178 nNumBytesRead = 0;
179 return nullptr;
182 int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE)
184 return -1;
187 long DirectoryStream::tell()
189 return 0;
192 bool DirectoryStream::isEnd()
194 return true;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */