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/io/XInputStream.hpp>
23 : #include <com/sun/star/sdbc/XResultSet.hpp>
24 : #include <com/sun/star/sdbc/XRow.hpp>
25 : #include <com/sun/star/ucb/XContent.hpp>
26 : #include <com/sun/star/ucb/XContentAccess.hpp>
27 : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
28 :
29 : #include <com/sun/star/uno/Reference.hxx>
30 : #include <com/sun/star/uno/Sequence.hxx>
31 :
32 : #include <comphelper/processfactory.hxx>
33 :
34 : #include <rtl/ustring.hxx>
35 :
36 : #include <ucbhelper/content.hxx>
37 :
38 : #include "DirectoryStream.hxx"
39 : #include "WPXSvStream.hxx"
40 :
41 : namespace io = com::sun::star::io;
42 : namespace sdbc = com::sun::star::sdbc;
43 : namespace ucb = com::sun::star::ucb;
44 : namespace uno = com::sun::star::uno;
45 :
46 : namespace writerperfect
47 : {
48 :
49 : namespace
50 : {
51 :
52 0 : uno::Reference<io::XInputStream> findStream(ucbhelper::Content &rContent, const rtl::OUString &rName)
53 : {
54 0 : uno::Reference<io::XInputStream> xInputStream;
55 :
56 0 : uno::Sequence<rtl::OUString> lPropNames(1);
57 0 : lPropNames[0] = "Title";
58 : try
59 : {
60 : const uno::Reference<sdbc::XResultSet> xResultSet(
61 0 : rContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY));
62 0 : if (xResultSet->first())
63 : {
64 0 : const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet, uno::UNO_QUERY_THROW);
65 0 : const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
66 0 : do
67 : {
68 0 : const rtl::OUString aTitle(xRow->getString(1));
69 0 : if (aTitle == rName)
70 : {
71 0 : const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
72 0 : ucbhelper::Content aSubContent(xSubContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
73 0 : xInputStream = aSubContent.openStream();
74 0 : break;
75 0 : }
76 0 : } while (xResultSet->next());
77 0 : }
78 : }
79 0 : catch (const uno::RuntimeException &)
80 : {
81 : // ignore
82 : }
83 0 : catch (const uno::Exception &)
84 : {
85 : // ignore
86 : }
87 :
88 0 : return xInputStream;
89 : }
90 :
91 : }
92 :
93 0 : struct DirectoryStream::Impl
94 : {
95 : Impl(const uno::Reference<ucb::XContent> &rxContent);
96 :
97 : uno::Reference<ucb::XContent> xContent;
98 : };
99 :
100 0 : DirectoryStream::Impl::Impl(const uno::Reference<ucb::XContent> &rxContent)
101 0 : : xContent(rxContent)
102 : {
103 0 : }
104 :
105 0 : DirectoryStream::DirectoryStream(const com::sun::star::uno::Reference<com::sun::star::ucb::XContent> &xContent)
106 0 : : m_pImpl(new Impl(xContent))
107 : {
108 0 : }
109 :
110 0 : DirectoryStream::~DirectoryStream()
111 : {
112 0 : delete m_pImpl;
113 0 : }
114 :
115 0 : bool DirectoryStream::isOLEStream()
116 : {
117 0 : return true;
118 : }
119 :
120 0 : WPXInputStream *DirectoryStream::getDocumentOLEStream(const char *const pName)
121 : {
122 0 : WPXInputStream *input = 0;
123 :
124 0 : ucbhelper::Content aContent(m_pImpl->xContent, uno::Reference<ucb::XCommandEnvironment>(), comphelper::getProcessComponentContext());
125 0 : const uno::Reference<io::XInputStream> xInputStream(findStream(aContent, rtl::OUString::createFromAscii(pName)));
126 0 : if (xInputStream.is())
127 0 : input = new WPXSvInputStream(xInputStream);
128 :
129 0 : return input;
130 : }
131 :
132 0 : const unsigned char *DirectoryStream::read(unsigned long, unsigned long &nNumBytesRead)
133 : {
134 0 : nNumBytesRead = 0;
135 0 : return 0;
136 : }
137 :
138 0 : int DirectoryStream::seek(long, WPX_SEEK_TYPE)
139 : {
140 0 : return -1;
141 : }
142 :
143 0 : long DirectoryStream::tell()
144 : {
145 0 : return 0;
146 : }
147 :
148 0 : bool DirectoryStream::atEOS()
149 : {
150 0 : return true;
151 : }
152 :
153 : }
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|