/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* writerperfect * Version: MPL 2.0 / LGPLv2.1+ * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Major Contributor(s): * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch) * * For minor contributions see the git repository. * * Alternatively, the contents of this file may be used under the terms * of the GNU Lesser General Public License Version 2.1 or later * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are * applicable instead of those above. * * For further information visit http://libwpd.sourceforge.net */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace io = com::sun::star::io; namespace sdbc = com::sun::star::sdbc; namespace ucb = com::sun::star::ucb; namespace uno = com::sun::star::uno; namespace writerperfect { namespace { uno::Reference findStream(ucbhelper::Content& rContent, const OUString& rName) { uno::Reference xInputStream; uno::Sequence lPropNames{ "Title" }; try { const uno::Reference xResultSet( rContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY)); if (xResultSet->first()) { const uno::Reference xContentAccess(xResultSet, uno::UNO_QUERY_THROW); const uno::Reference xRow(xResultSet, uno::UNO_QUERY_THROW); do { const OUString aTitle(xRow->getString(1)); if (aTitle == rName) { const uno::Reference xSubContent(xContentAccess->queryContent()); ucbhelper::Content aSubContent(xSubContent, uno::Reference(), comphelper::getProcessComponentContext()); xInputStream = aSubContent.openStream(); break; } } while (xResultSet->next()); } } catch (const uno::RuntimeException&) { // ignore } catch (const uno::Exception&) { // ignore } return xInputStream; } } struct DirectoryStream::Impl { explicit Impl(const uno::Reference& rxContent); uno::Reference xContent; }; DirectoryStream::Impl::Impl(const uno::Reference& rxContent) : xContent(rxContent) { } DirectoryStream::DirectoryStream(const css::uno::Reference& xContent) : m_pImpl(isDirectory(xContent) ? new Impl(xContent) : nullptr) { } DirectoryStream::~DirectoryStream() {} bool DirectoryStream::isDirectory(const css::uno::Reference& xContent) { try { if (!xContent.is()) return false; ucbhelper::Content aContent(xContent, uno::Reference(), comphelper::getProcessComponentContext()); return aContent.isFolder(); } catch (...) { return false; } } std::unique_ptr DirectoryStream::createForParent(const css::uno::Reference& xContent) { try { if (!xContent.is()) return nullptr; std::unique_ptr pDir; const uno::Reference xChild(xContent, uno::UNO_QUERY); if (xChild.is()) { const uno::Reference xDirContent(xChild->getParent(), uno::UNO_QUERY); if (xDirContent.is()) { pDir = std::make_unique(xDirContent); if (!pDir->isStructured()) pDir.reset(); } } return pDir; } catch (...) { return nullptr; } } css::uno::Reference DirectoryStream::getContent() const { if (!m_pImpl) return css::uno::Reference(); return m_pImpl->xContent; } bool DirectoryStream::isStructured() { return m_pImpl != nullptr; } unsigned DirectoryStream::subStreamCount() { // TODO: implement me return 0; } const char* DirectoryStream::subStreamName(unsigned /* id */) { // TODO: implement me return nullptr; } bool DirectoryStream::existsSubStream(const char* /* name */) { // TODO: implement me return false; } librevenge::RVNGInputStream* DirectoryStream::getSubStreamByName(const char* const pName) { if (!m_pImpl) return nullptr; ucbhelper::Content aContent(m_pImpl->xContent, uno::Reference(), comphelper::getProcessComponentContext()); const uno::Reference xInputStream( findStream(aContent, OUString::createFromAscii(pName))); if (xInputStream.is()) return new WPXSvInputStream(xInputStream); return nullptr; } librevenge::RVNGInputStream* DirectoryStream::getSubStreamById(unsigned /* id */) { // TODO: implement me return nullptr; } const unsigned char* DirectoryStream::read(unsigned long, unsigned long& nNumBytesRead) { nNumBytesRead = 0; return nullptr; } int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE) { return -1; } long DirectoryStream::tell() { return 0; } bool DirectoryStream::isEnd() { return true; } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */