Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "excelfilter.hxx"
21 :
22 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 : #include <osl/diagnose.h>
24 :
25 : #include <oox/helper/binaryinputstream.hxx>
26 : #include "biffinputstream.hxx"
27 : #include "excelchartconverter.hxx"
28 : #include "excelvbaproject.hxx"
29 : #include "stylesbuffer.hxx"
30 : #include "themebuffer.hxx"
31 : #include "workbookfragment.hxx"
32 : #include "xestream.hxx"
33 :
34 : namespace oox {
35 : namespace xls {
36 :
37 : using namespace ::com::sun::star::lang;
38 : using namespace ::com::sun::star::sheet;
39 : using namespace ::com::sun::star::uno;
40 : using namespace ::com::sun::star::xml::sax;
41 : using namespace ::oox::core;
42 :
43 : using ::oox::drawingml::table::TableStyleListPtr;
44 :
45 201 : ExcelFilter::ExcelFilter( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
46 : XmlFilterBase( rxContext ),
47 201 : mpBookGlob( 0 )
48 : {
49 201 : }
50 :
51 402 : ExcelFilter::~ExcelFilter()
52 : {
53 : OSL_ENSURE( !mpBookGlob, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
54 402 : }
55 :
56 145 : void ExcelFilter::registerWorkbookGlobals( WorkbookGlobals& rBookGlob )
57 : {
58 145 : mpBookGlob = &rBookGlob;
59 145 : }
60 :
61 4760 : WorkbookGlobals& ExcelFilter::getWorkbookGlobals() const
62 : {
63 : OSL_ENSURE( mpBookGlob, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
64 4760 : return *mpBookGlob;
65 : }
66 :
67 145 : void ExcelFilter::unregisterWorkbookGlobals()
68 : {
69 145 : mpBookGlob = 0;
70 145 : }
71 :
72 145 : bool ExcelFilter::importDocument()
73 : {
74 : /* To activate the XLSX/XLSB dumper, insert the full path to the file
75 : file:///<path-to-oox-module>/source/dump/xlsbdumper.ini
76 : into the environment variable OOO_XLSBDUMPER and start the office with
77 : this variable (nonpro only). */
78 : //OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper );
79 :
80 145 : OUString aWorkbookPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
81 145 : if( aWorkbookPath.isEmpty() )
82 0 : return false;
83 :
84 : try
85 : {
86 : try
87 : {
88 145 : importDocumentProperties();
89 : }
90 0 : catch( const Exception& e )
91 : {
92 : SAL_WARN("sc", "exception when importing document properties " << e.Message);
93 : }
94 0 : catch( ... )
95 : {
96 : SAL_WARN("sc", "exception when importing document properties");
97 : }
98 : /* Construct the WorkbookGlobals object referred to by every instance of
99 : the class WorkbookHelper, and execute the import filter by constructing
100 : an instance of WorkbookFragment and loading the file. */
101 145 : WorkbookGlobalsRef xBookGlob(WorkbookHelper::constructGlobals(*this));
102 145 : if (xBookGlob.get() && importFragment(new WorkbookFragment(*xBookGlob, aWorkbookPath)))
103 : {
104 145 : return true;
105 0 : }
106 : }
107 0 : catch (...)
108 : {
109 : }
110 :
111 0 : return false;
112 : }
113 :
114 55 : bool ExcelFilter::exportDocument() throw()
115 : {
116 55 : return false;
117 : }
118 :
119 4475 : const ::oox::drawingml::Theme* ExcelFilter::getCurrentTheme() const
120 : {
121 4475 : return &WorkbookHelper( getWorkbookGlobals() ).getTheme();
122 : }
123 :
124 0 : ::oox::vml::Drawing* ExcelFilter::getVmlDrawing()
125 : {
126 0 : return 0;
127 : }
128 :
129 0 : const TableStyleListPtr ExcelFilter::getTableStyles()
130 : {
131 0 : return TableStyleListPtr();
132 : }
133 :
134 140 : ::oox::drawingml::chart::ChartConverter* ExcelFilter::getChartConverter()
135 : {
136 140 : return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
137 : }
138 :
139 0 : void ExcelFilter::useInternalChartDataTable( bool bInternal )
140 : {
141 0 : return WorkbookHelper( getWorkbookGlobals() ).useInternalChartDataTable( bInternal );
142 : }
143 :
144 145 : GraphicHelper* ExcelFilter::implCreateGraphicHelper() const
145 : {
146 145 : return new ExcelGraphicHelper( getWorkbookGlobals() );
147 : }
148 :
149 1 : ::oox::ole::VbaProject* ExcelFilter::implCreateVbaProject() const
150 : {
151 1 : return new ExcelVbaProject( getComponentContext(), Reference< XSpreadsheetDocument >( getModel(), UNO_QUERY ) );
152 : }
153 :
154 200 : sal_Bool SAL_CALL ExcelFilter::filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rDescriptor ) throw( ::com::sun::star::uno::RuntimeException, std::exception )
155 : {
156 200 : if ( XmlFilterBase::filter( rDescriptor ) )
157 145 : return true;
158 :
159 55 : if ( isExportFilter() )
160 : {
161 : Reference< XExporter > xExporter(
162 55 : new XclExpXmlStream( getComponentContext() ) );
163 :
164 55 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
165 55 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
166 :
167 55 : if ( xFilter.is() )
168 : {
169 55 : xExporter->setSourceDocument( xDocument );
170 55 : if ( xFilter->filter( rDescriptor ) )
171 55 : return true;
172 0 : }
173 : }
174 :
175 0 : return false;
176 : }
177 :
178 1 : OUString ExcelFilter::getImplementationName() throw (css::uno::RuntimeException, std::exception)
179 : {
180 1 : return OUString( "com.sun.star.comp.oox.xls.ExcelFilter" );
181 : }
182 :
183 : } // namespace xls
184 : } // namespace oox
185 :
186 :
187 : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
188 201 : com_sun_star_comp_oox_xls_ExcelFilter_get_implementation(::com::sun::star::uno::XComponentContext* context,
189 : ::com::sun::star::uno::Sequence<css::uno::Any> const &)
190 : {
191 201 : return cppu::acquire(new oox::xls::ExcelFilter(context));
192 30 : }
193 :
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|