LCOV - code coverage report
Current view: top level - writerperfect/source/common - DirectoryStream.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 68 83 81.9 %
Date: 2015-06-13 12:38:46 Functions: 14 18 77.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* writerperfect
       3             :  * Version: MPL 2.0 / LGPLv2.1+
       4             :  *
       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/.
       8             :  *
       9             :  * Major Contributor(s):
      10             :  * Copyright (C) 2007 Fridrich Strba (fridrich.strba@bluewin.ch)
      11             :  *
      12             :  * For minor contributions see the git repository.
      13             :  *
      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.
      18             :  *
      19             :  * For further information visit http://libwpd.sourceforge.net
      20             :  */
      21             : 
      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>
      29             : 
      30             : #include <com/sun/star/uno/Reference.hxx>
      31             : #include <com/sun/star/uno/Sequence.hxx>
      32             : 
      33             : #include <comphelper/processfactory.hxx>
      34             : 
      35             : #include <rtl/ustring.hxx>
      36             : 
      37             : #include <ucbhelper/content.hxx>
      38             : 
      39             : #include <DirectoryStream.hxx>
      40             : #include <WPXSvInputStream.hxx>
      41             : 
      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;
      47             : 
      48             : namespace writerperfect
      49             : {
      50             : 
      51             : namespace
      52             : {
      53             : 
      54           2 : uno::Reference<io::XInputStream> findStream(ucbhelper::Content &rContent, const rtl::OUString &rName)
      55             : {
      56           2 :     uno::Reference<io::XInputStream> xInputStream;
      57             : 
      58           4 :     uno::Sequence<rtl::OUString> lPropNames(1);
      59           2 :     lPropNames[0] = "Title";
      60             :     try
      61             :     {
      62             :         const uno::Reference<sdbc::XResultSet> xResultSet(
      63           2 :             rContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY));
      64           2 :         if (xResultSet->first())
      65             :         {
      66           2 :             const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY_THROW);
      67           4 :             const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
      68           4 :             do
      69             :             {
      70           6 :                 const rtl::OUString aTitle(xRow->getString(1));
      71           6 :                 if (aTitle == rName)
      72             :                 {
      73           2 :                     const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
      74           4 :                     ucbhelper::Content aSubContent(xSubContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
      75           2 :                     xInputStream = aSubContent.openStream();
      76           4 :                     break;
      77           4 :                 }
      78             :             }
      79           6 :             while (xResultSet->next());
      80           2 :         }
      81             :     }
      82           0 :     catch (const uno::RuntimeException &)
      83             :     {
      84             :         // ignore
      85             :     }
      86           0 :     catch (const uno::Exception &)
      87             :     {
      88             :         // ignore
      89             :     }
      90             : 
      91           4 :     return xInputStream;
      92             : }
      93             : 
      94             : }
      95             : 
      96           5 : struct DirectoryStream::Impl
      97             : {
      98             :     explicit Impl(const uno::Reference<ucb::XContent> &rxContent);
      99             : 
     100             :     uno::Reference<ucb::XContent> xContent;
     101             : };
     102             : 
     103           5 : DirectoryStream::Impl::Impl(const uno::Reference<ucb::XContent> &rxContent)
     104           5 :     : xContent(rxContent)
     105             : {
     106           5 : }
     107             : 
     108           8 : DirectoryStream::DirectoryStream(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
     109           8 :     : m_pImpl(isDirectory(xContent) ? new Impl(xContent) : 0)
     110             : {
     111           8 : }
     112             : 
     113          20 : DirectoryStream::~DirectoryStream()
     114             : {
     115           8 :     delete m_pImpl;
     116          12 : }
     117             : 
     118           4 : DirectoryStream *DirectoryStream::createForParent(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
     119             : {
     120             :     try
     121             :     {
     122           4 :         if (!xContent.is())
     123           0 :             return 0;
     124             : 
     125           4 :         DirectoryStream *pDir(0);
     126             : 
     127           4 :         const uno::Reference<container::XChild> xChild(xContent, uno::UNO_QUERY);
     128           4 :         if (xChild.is())
     129             :         {
     130           4 :             const uno::Reference<ucb::XContent> xDirContent(xChild->getParent(), uno::UNO_QUERY);
     131           4 :             if (xDirContent.is())
     132             :             {
     133           4 :                 pDir = new writerperfect::DirectoryStream(xDirContent);
     134           4 :                 if (!pDir->isStructured())
     135             :                 {
     136           1 :                     delete pDir;
     137           1 :                     pDir = 0;
     138             :                 }
     139           4 :             }
     140             :         }
     141             : 
     142           4 :         return pDir;
     143             :     }
     144           0 :     catch (...)
     145             :     {
     146           0 :         return 0;
     147             :     }
     148             : }
     149             : 
     150          11 : bool DirectoryStream::isDirectory(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
     151             : {
     152             :     try
     153             :     {
     154          11 :         if (!xContent.is())
     155           0 :             return false;
     156             : 
     157          11 :         ucbhelper::Content aContent(xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
     158          14 :         return aContent.isFolder();
     159             :     }
     160           6 :     catch (...)
     161             :     {
     162           3 :         return false;
     163             :     }
     164             : }
     165             : 
     166           9 : bool DirectoryStream::isStructured()
     167             : {
     168           9 :     if (!m_pImpl)
     169           2 :         return false;
     170             : 
     171           7 :     return true;
     172             : }
     173             : 
     174           0 : unsigned DirectoryStream::subStreamCount()
     175             : {
     176             :     // TODO: implement me
     177           0 :     return 0;
     178             : }
     179             : 
     180           0 : const char *DirectoryStream::subStreamName(unsigned /* id */)
     181             : {
     182             :     // TODO: implement me
     183           0 :     return 0;
     184             : }
     185             : 
     186           0 : bool DirectoryStream::existsSubStream(const char * /* name */)
     187             : {
     188             :     // TODO: implement me
     189           0 :     return false;
     190             : }
     191             : 
     192           2 : librevenge::RVNGInputStream *DirectoryStream::getSubStreamByName(const char *const pName)
     193             : {
     194           2 :     if (!m_pImpl)
     195           0 :         return 0;
     196             : 
     197           2 :     ucbhelper::Content aContent(m_pImpl->xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
     198           4 :     const uno::Reference<io::XInputStream> xInputStream(findStream(aContent, rtl::OUString::createFromAscii(pName)));
     199           2 :     if (xInputStream.is())
     200           2 :         return new WPXSvInputStream(xInputStream);
     201             : 
     202           2 :     return 0;
     203             : }
     204             : 
     205           0 : librevenge::RVNGInputStream *DirectoryStream::getSubStreamById(unsigned /* id */)
     206             : {
     207             :     // TODO: implement me
     208           0 :     return 0;
     209             : }
     210             : 
     211           2 : const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead)
     212             : {
     213           2 :     nNumBytesRead = 0;
     214           2 :     return 0;
     215             : }
     216             : 
     217           2 : int DirectoryStream::seek(long, librevenge::RVNG_SEEK_TYPE)
     218             : {
     219           2 :     return -1;
     220             : }
     221             : 
     222           2 : long DirectoryStream::tell()
     223             : {
     224           2 :     return 0;
     225             : }
     226             : 
     227           2 : bool DirectoryStream::isEnd()
     228             : {
     229           2 :     return true;
     230             : }
     231             : 
     232             : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11