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 container
= com::sun::star::container
;
43 namespace io
= com::sun::star::io
;
44 namespace sdbc
= com::sun::star::sdbc
;
45 namespace ucb
= com::sun::star::ucb
;
46 namespace uno
= com::sun::star::uno
;
48 namespace writerperfect
54 uno::Reference
<io::XInputStream
> findStream(ucbhelper::Content
&rContent
, const rtl::OUString
&rName
)
56 uno::Reference
<io::XInputStream
> xInputStream
;
58 uno::Sequence
<rtl::OUString
> lPropNames(1);
59 lPropNames
[0] = "Title";
62 const uno::Reference
<sdbc::XResultSet
> xResultSet(
63 rContent
.createCursor(lPropNames
, ucbhelper::INCLUDE_DOCUMENTS_ONLY
));
64 if (xResultSet
->first())
66 const uno::Reference
<ucb::XContentAccess
> xContentAccess(xResultSet
, uno::UNO_QUERY_THROW
);
67 const uno::Reference
<sdbc::XRow
> xRow(xResultSet
, uno::UNO_QUERY_THROW
);
70 const rtl::OUString
aTitle(xRow
->getString(1));
73 const uno::Reference
<ucb::XContent
> xSubContent(xContentAccess
->queryContent());
74 ucbhelper::Content
aSubContent(xSubContent
, uno::Reference
<ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext());
75 xInputStream
= aSubContent
.openStream();
79 while (xResultSet
->next());
82 catch (const uno::RuntimeException
&)
86 catch (const uno::Exception
&)
96 struct DirectoryStream::Impl
98 Impl(const uno::Reference
<ucb::XContent
> &rxContent
);
100 uno::Reference
<ucb::XContent
> xContent
;
103 DirectoryStream::Impl::Impl(const uno::Reference
<ucb::XContent
> &rxContent
)
104 : xContent(rxContent
)
108 DirectoryStream::DirectoryStream(const com::sun::star::uno::Reference
<com::sun::star::ucb::XContent
> &xContent
)
109 : m_pImpl(isDirectory(xContent
) ? new Impl(xContent
) : 0)
113 DirectoryStream::~DirectoryStream()
118 DirectoryStream
*DirectoryStream::createForParent(const com::sun::star::uno::Reference
<com::sun::star::ucb::XContent
> &xContent
)
125 DirectoryStream
*pDir(0);
127 const uno::Reference
<container::XChild
> xChild(xContent
, uno::UNO_QUERY
);
130 const uno::Reference
<ucb::XContent
> xDirContent(xChild
->getParent(), uno::UNO_QUERY
);
131 if (xDirContent
.is())
133 pDir
= new writerperfect::DirectoryStream(xDirContent
);
134 if (!pDir
->isStructured())
150 bool DirectoryStream::isDirectory(const com::sun::star::uno::Reference
<com::sun::star::ucb::XContent
> &xContent
)
157 ucbhelper::Content
aContent(xContent
, uno::Reference
<ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext());
158 return aContent
.isFolder();
166 bool DirectoryStream::isStructured()
174 unsigned DirectoryStream::subStreamCount()
176 // TODO: implement me
180 const char *DirectoryStream::subStreamName(unsigned /* id */)
182 // TODO: implement me
186 bool DirectoryStream::existsSubStream(const char * /* name */)
188 // TODO: implement me
192 librevenge::RVNGInputStream
*DirectoryStream::getSubStreamByName(const char *const pName
)
197 ucbhelper::Content
aContent(m_pImpl
->xContent
, uno::Reference
<ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext());
198 const uno::Reference
<io::XInputStream
> xInputStream(findStream(aContent
, rtl::OUString::createFromAscii(pName
)));
199 if (xInputStream
.is())
200 return new WPXSvInputStream(xInputStream
);
205 librevenge::RVNGInputStream
*DirectoryStream::getSubStreamById(unsigned /* id */)
207 // TODO: implement me
211 const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead
)
217 int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE
)
222 long DirectoryStream::tell()
227 bool DirectoryStream::isEnd()
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */