fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / writerperfect / source / common / DirectoryStream.cxx
blob1f46389809825c9919e19c8e4ac5731922b40cb1
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 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
51 namespace
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";
60 try
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));
71 if (aTitle == rName)
73 const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
74 ucbhelper::Content aSubContent(xSubContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
75 xInputStream = aSubContent.openStream();
76 break;
79 while (xResultSet->next());
82 catch (const uno::RuntimeException &)
84 // ignore
86 catch (const uno::Exception &)
88 // ignore
91 return xInputStream;
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()
115 delete m_pImpl;
118 DirectoryStream *DirectoryStream::createForParent(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
122 if (!xContent.is())
123 return 0;
125 DirectoryStream *pDir(0);
127 const uno::Reference<container::XChild> xChild(xContent, uno::UNO_QUERY);
128 if (xChild.is())
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())
136 delete pDir;
137 pDir = 0;
142 return pDir;
144 catch (...)
146 return 0;
150 bool DirectoryStream::isDirectory(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
154 if (!xContent.is())
155 return false;
157 ucbhelper::Content aContent(xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
158 return aContent.isFolder();
160 catch (...)
162 return false;
166 bool DirectoryStream::isStructured()
168 if (!m_pImpl)
169 return false;
171 return true;
174 unsigned DirectoryStream::subStreamCount()
176 // TODO: implement me
177 return 0;
180 const char *DirectoryStream::subStreamName(unsigned /* id */)
182 // TODO: implement me
183 return 0;
186 bool DirectoryStream::existsSubStream(const char * /* name */)
188 // TODO: implement me
189 return false;
192 librevenge::RVNGInputStream *DirectoryStream::getSubStreamByName(const char *const pName)
194 if (!m_pImpl)
195 return 0;
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);
202 return 0;
205 librevenge::RVNGInputStream *DirectoryStream::getSubStreamById(unsigned /* id */)
207 // TODO: implement me
208 return 0;
211 const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead)
213 nNumBytesRead = 0;
214 return 0;
217 int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE)
219 return -1;
222 long DirectoryStream::tell()
224 return 0;
227 bool DirectoryStream::isEnd()
229 return true;
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */