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 :
24 : #include "oox/helper/binaryinputstream.hxx"
25 : #include "biffinputstream.hxx"
26 : #include "excelchartconverter.hxx"
27 : #include "excelvbaproject.hxx"
28 : #include "stylesbuffer.hxx"
29 : #include "themebuffer.hxx"
30 : #include "workbookfragment.hxx"
31 : #include "xestream.hxx"
32 :
33 : namespace oox {
34 : namespace xls {
35 :
36 : using namespace ::com::sun::star::lang;
37 : using namespace ::com::sun::star::sheet;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::xml::sax;
40 : using namespace ::oox::core;
41 :
42 : using ::oox::drawingml::table::TableStyleListPtr;
43 :
44 5 : OUString ExcelFilter_getImplementationName()
45 : {
46 5 : return OUString( "com.sun.star.comp.oox.xls.ExcelFilter" );
47 : }
48 :
49 5 : Sequence< OUString > ExcelFilter_getSupportedServiceNames()
50 : {
51 5 : Sequence< OUString > aSeq( 2 );
52 5 : aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
53 5 : aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
54 5 : return aSeq;
55 : }
56 :
57 58 : Reference< XInterface > ExcelFilter_create(
58 : const Reference< XComponentContext >& rxContext )
59 : {
60 58 : return static_cast< ::cppu::OWeakObject* >( new ExcelFilter( rxContext ) );
61 : }
62 :
63 58 : ExcelFilter::ExcelFilter( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
64 : XmlFilterBase( rxContext ),
65 58 : mpBookGlob( 0 )
66 : {
67 58 : }
68 :
69 116 : ExcelFilter::~ExcelFilter()
70 : {
71 : OSL_ENSURE( !mpBookGlob, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
72 116 : }
73 :
74 44 : void ExcelFilter::registerWorkbookGlobals( WorkbookGlobals& rBookGlob )
75 : {
76 44 : mpBookGlob = &rBookGlob;
77 44 : }
78 :
79 707 : WorkbookGlobals& ExcelFilter::getWorkbookGlobals() const
80 : {
81 : OSL_ENSURE( mpBookGlob, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
82 707 : return *mpBookGlob;
83 : }
84 :
85 44 : void ExcelFilter::unregisterWorkbookGlobals()
86 : {
87 44 : mpBookGlob = 0;
88 44 : }
89 :
90 44 : bool ExcelFilter::importDocument() throw()
91 : {
92 : /* To activate the XLSX/XLSB dumper, insert the full path to the file
93 : file:///<path-to-oox-module>/source/dump/xlsbdumper.ini
94 : into the environment variable OOO_XLSBDUMPER and start the office with
95 : this variable (nonpro only). */
96 : //OOX_DUMP_FILE( ::oox::dump::xlsb::Dumper );
97 :
98 44 : OUString aWorkbookPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
99 44 : if( aWorkbookPath.isEmpty() )
100 0 : return false;
101 :
102 : /* Construct the WorkbookGlobals object referred to by every instance of
103 : the class WorkbookHelper, and execute the import filter by constructing
104 : an instance of WorkbookFragment and loading the file. */
105 88 : WorkbookGlobalsRef xBookGlob;
106 : try
107 : {
108 44 : xBookGlob = WorkbookHelper::constructGlobals( *this );
109 : }
110 0 : catch (...)
111 : {
112 : }
113 44 : if ( xBookGlob.get() && importFragment( new WorkbookFragment( *xBookGlob, aWorkbookPath ) ) )
114 : {
115 : try
116 : {
117 44 : importDocumentProperties();
118 : }
119 0 : catch( const Exception& e )
120 : {
121 : SAL_WARN("sc", "exception when importing document properties " << e.Message);
122 : }
123 0 : catch( ... )
124 : {
125 : SAL_WARN("sc", "exception when importing document properties");
126 : }
127 44 : return true;
128 : }
129 44 : return false;
130 : }
131 :
132 14 : bool ExcelFilter::exportDocument() throw()
133 : {
134 14 : return false;
135 : }
136 :
137 643 : const ::oox::drawingml::Theme* ExcelFilter::getCurrentTheme() const
138 : {
139 643 : return &WorkbookHelper( getWorkbookGlobals() ).getTheme();
140 : }
141 :
142 0 : ::oox::vml::Drawing* ExcelFilter::getVmlDrawing()
143 : {
144 0 : return 0;
145 : }
146 :
147 0 : const TableStyleListPtr ExcelFilter::getTableStyles()
148 : {
149 0 : return TableStyleListPtr();
150 : }
151 :
152 20 : ::oox::drawingml::chart::ChartConverter* ExcelFilter::getChartConverter()
153 : {
154 20 : return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
155 : }
156 :
157 0 : void ExcelFilter::useInternalChartDataTable( bool bInternal )
158 : {
159 0 : return WorkbookHelper( getWorkbookGlobals() ).useInternalChartDataTable( bInternal );
160 : }
161 :
162 44 : GraphicHelper* ExcelFilter::implCreateGraphicHelper() const
163 : {
164 44 : return new ExcelGraphicHelper( getWorkbookGlobals() );
165 : }
166 :
167 0 : ::oox::ole::VbaProject* ExcelFilter::implCreateVbaProject() const
168 : {
169 0 : return new ExcelVbaProject( getComponentContext(), Reference< XSpreadsheetDocument >( getModel(), UNO_QUERY ) );
170 : }
171 :
172 :
173 58 : 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 )
174 : {
175 58 : if ( XmlFilterBase::filter( rDescriptor ) )
176 44 : return true;
177 :
178 14 : if ( isExportFilter() )
179 : {
180 : Reference< XExporter > xExporter(
181 14 : new XclExpXmlStream( getComponentContext() ) );
182 :
183 14 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
184 14 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
185 :
186 14 : if ( xFilter.is() )
187 : {
188 14 : xExporter->setSourceDocument( xDocument );
189 14 : if ( xFilter->filter( rDescriptor ) )
190 14 : return true;
191 0 : }
192 : }
193 :
194 0 : return false;
195 : }
196 :
197 0 : OUString ExcelFilter::implGetImplementationName() const
198 : {
199 0 : return ExcelFilter_getImplementationName();
200 : }
201 :
202 : } // namespace xls
203 18 : } // namespace oox
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|