summaryrefslogtreecommitdiff
path: root/sw/source/filter/indexing/IndexingExportFilter.cxx
blob: 13001764a573682da0c6529df8382e95b7ed3ee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * 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/.
 */

#include <IndexingExportFilter.hxx>
#include <IndexingExport.hxx>

#include <unotxdoc.hxx>
#include <docsh.hxx>

#include <unotools/mediadescriptor.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <comphelper/servicehelper.hxx>

#include <com/sun/star/io/XOutputStream.hpp>
#include <svl/outstrm.hxx>

using namespace css;

namespace sw
{
sal_Bool IndexingExportFilter::filter(const uno::Sequence<beans::PropertyValue>& aDescriptor)
{
    bool bReturn = false;

    utl::MediaDescriptor aMediaDesc = aDescriptor;

    // Actually get the SwRootFrame to call dumpAsXml
    auto pXTextDocument = comphelper::getFromUnoTunnel<SwXTextDocument>(m_xSourceDocument);
    if (pXTextDocument)
    {
        uno::Reference<io::XOutputStream> xOutputStream = aMediaDesc.getUnpackedValueOrDefault(
            utl::MediaDescriptor::PROP_OUTPUTSTREAM, uno::Reference<io::XOutputStream>());

        std::unique_ptr<SvStream> pStream(new SvOutputStream(xOutputStream));
        SwDocShell* pShell = pXTextDocument->GetDocShell();
        SwDoc* pDoc = pShell->GetDoc();
        if (pDoc)
        {
            IndexingExport aIndexingExport(*pStream, pDoc);
            bReturn = aIndexingExport.runExport();
        }
    }

    return bReturn;
}

} // end namespace sw

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_comp_Writer_IndexingExportFilter_get_implementation(
    css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
{
    return cppu::acquire(new sw::IndexingExportFilter());
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */