1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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" };
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));
71 const uno::Reference
<ucb::XContent
> xSubContent(xContentAccess
->queryContent());
72 ucbhelper::Content
aSubContent(xSubContent
, uno::Reference
<ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext());
73 xInputStream
= aSubContent
.openStream();
77 while (xResultSet
->next());
80 catch (const uno::RuntimeException
&)
84 catch (const uno::Exception
&)
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
)
122 ucbhelper::Content
aContent(xContent
, uno::Reference
<ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext());
123 return aContent
.isFolder();
131 bool DirectoryStream::isStructured()
139 unsigned DirectoryStream::subStreamCount()
141 // TODO: implement me
145 const char *DirectoryStream::subStreamName(unsigned /* id */)
147 // TODO: implement me
151 bool DirectoryStream::existsSubStream(const char * /* name */)
153 // TODO: implement me
157 librevenge::RVNGInputStream
*DirectoryStream::getSubStreamByName(const char *const pName
)
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
);
170 librevenge::RVNGInputStream
*DirectoryStream::getSubStreamById(unsigned /* id */)
172 // TODO: implement me
176 const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead
)
182 int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE
)
187 long DirectoryStream::tell()
192 bool DirectoryStream::isEnd()
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */