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
23 #include <com/sun/star/container/XChild.hpp>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/ucb/XContent.hpp>
28 #include <com/sun/star/ucb/XContentAccess.hpp>
29 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
34 #include <comphelper/processfactory.hxx>
36 #include <rtl/ustring.hxx>
38 #include <ucbhelper/content.hxx>
40 #include <DirectoryStream.hxx>
41 #include <WPXSvInputStream.hxx>
44 namespace io
= css::io
;
45 namespace sdbc
= css::sdbc
;
46 namespace ucb
= css::ucb
;
47 namespace uno
= css::uno
;
49 namespace writerperfect
53 uno::Reference
<io::XInputStream
> findStream(ucbhelper::Content
& rContent
, std::u16string_view rName
)
55 uno::Reference
<io::XInputStream
> xInputStream
;
57 uno::Sequence
<OUString
> lPropNames
{ u
"Title"_ustr
};
60 const uno::Reference
<sdbc::XResultSet
> xResultSet(
61 rContent
.createCursor(lPropNames
, ucbhelper::INCLUDE_DOCUMENTS_ONLY
));
62 if (!xResultSet
->first())
65 const uno::Reference
<ucb::XContentAccess
> xContentAccess(xResultSet
, uno::UNO_QUERY
);
68 const uno::Reference
<sdbc::XRow
> xRow(xResultSet
, uno::UNO_QUERY
);
73 const OUString
aTitle(xRow
->getString(1));
76 const uno::Reference
<ucb::XContent
> xSubContent(xContentAccess
->queryContent());
77 ucbhelper::Content
aSubContent(xSubContent
,
78 uno::Reference
<ucb::XCommandEnvironment
>(),
79 comphelper::getProcessComponentContext());
80 xInputStream
= aSubContent
.openStream();
83 } while (xResultSet
->next());
85 catch (const uno::RuntimeException
&)
89 catch (const uno::Exception
&)
98 struct DirectoryStream::Impl
100 explicit Impl(uno::Reference
<ucb::XContent
> xContent
);
102 uno::Reference
<ucb::XContent
> xContent
;
105 DirectoryStream::Impl::Impl(uno::Reference
<ucb::XContent
> _xContent
)
106 : xContent(std::move(_xContent
))
110 DirectoryStream::DirectoryStream(const css::uno::Reference
<css::ucb::XContent
>& xContent
)
111 : m_pImpl(isDirectory(xContent
) ? new Impl(xContent
) : nullptr)
115 DirectoryStream::~DirectoryStream() {}
117 bool DirectoryStream::isDirectory(const css::uno::Reference
<css::ucb::XContent
>& xContent
)
124 ucbhelper::Content
aContent(xContent
, uno::Reference
<ucb::XCommandEnvironment
>(),
125 comphelper::getProcessComponentContext());
126 return aContent
.isFolder();
134 std::unique_ptr
<DirectoryStream
>
135 DirectoryStream::createForParent(const css::uno::Reference
<css::ucb::XContent
>& xContent
)
142 std::unique_ptr
<DirectoryStream
> pDir
;
144 const uno::Reference
<css::container::XChild
> xChild(xContent
, uno::UNO_QUERY
);
147 const uno::Reference
<ucb::XContent
> xDirContent(xChild
->getParent(), uno::UNO_QUERY
);
148 if (xDirContent
.is())
150 pDir
= std::make_unique
<DirectoryStream
>(xDirContent
);
151 if (!pDir
->isStructured())
164 css::uno::Reference
<css::ucb::XContent
> DirectoryStream::getContent() const
167 return css::uno::Reference
<css::ucb::XContent
>();
168 return m_pImpl
->xContent
;
171 bool DirectoryStream::isStructured() { return m_pImpl
!= nullptr; }
173 unsigned DirectoryStream::subStreamCount()
175 // TODO: implement me
179 const char* DirectoryStream::subStreamName(unsigned /* id */)
181 // TODO: implement me
185 bool DirectoryStream::existsSubStream(const char* /* name */)
187 // TODO: implement me
191 librevenge::RVNGInputStream
* DirectoryStream::getSubStreamByName(const char* const pName
)
196 ucbhelper::Content
aContent(m_pImpl
->xContent
, uno::Reference
<ucb::XCommandEnvironment
>(),
197 comphelper::getProcessComponentContext());
198 const uno::Reference
<io::XInputStream
> xInputStream(
199 findStream(aContent
, OUString::createFromAscii(pName
)));
200 if (xInputStream
.is())
201 return new WPXSvInputStream(xInputStream
);
206 librevenge::RVNGInputStream
* DirectoryStream::getSubStreamById(unsigned /* id */)
208 // TODO: implement me
212 const unsigned char* DirectoryStream::read(unsigned long, unsigned long& nNumBytesRead
)
218 int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE
) { return -1; }
220 long DirectoryStream::tell() { return 0; }
222 bool DirectoryStream::isEnd() { return true; }
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */