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 10 : OUString ExcelFilter_getImplementationName()
45 : {
46 10 : return OUString( "com.sun.star.comp.oox.xls.ExcelFilter" );
47 : }
48 :
49 10 : Sequence< OUString > ExcelFilter_getSupportedServiceNames()
50 : {
51 10 : Sequence< OUString > aSeq( 2 );
52 10 : aSeq[ 0 ] = "com.sun.star.document.ImportFilter";
53 10 : aSeq[ 1 ] = "com.sun.star.document.ExportFilter";
54 10 : return aSeq;
55 : }
56 :
57 166 : Reference< XInterface > ExcelFilter_create(
58 : const Reference< XComponentContext >& rxContext )
59 : {
60 166 : return static_cast< ::cppu::OWeakObject* >( new ExcelFilter( rxContext ) );
61 : }
62 :
63 166 : ExcelFilter::ExcelFilter( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
64 : XmlFilterBase( rxContext ),
65 166 : mpBookGlob( 0 )
66 : {
67 166 : }
68 :
69 332 : ExcelFilter::~ExcelFilter()
70 : {
71 : OSL_ENSURE( !mpBookGlob, "ExcelFilter::~ExcelFilter - workbook data not cleared" );
72 332 : }
73 :
74 128 : void ExcelFilter::registerWorkbookGlobals( WorkbookGlobals& rBookGlob )
75 : {
76 128 : mpBookGlob = &rBookGlob;
77 128 : }
78 :
79 2264 : WorkbookGlobals& ExcelFilter::getWorkbookGlobals() const
80 : {
81 : OSL_ENSURE( mpBookGlob, "ExcelFilter::getWorkbookGlobals - missing workbook data" );
82 2264 : return *mpBookGlob;
83 : }
84 :
85 128 : void ExcelFilter::unregisterWorkbookGlobals()
86 : {
87 128 : mpBookGlob = 0;
88 128 : }
89 :
90 128 : bool ExcelFilter::importDocument()
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 128 : OUString aWorkbookPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
99 128 : if( aWorkbookPath.isEmpty() )
100 0 : return false;
101 :
102 : try
103 : {
104 : /* Construct the WorkbookGlobals object referred to by every instance of
105 : the class WorkbookHelper, and execute the import filter by constructing
106 : an instance of WorkbookFragment and loading the file. */
107 128 : WorkbookGlobalsRef xBookGlob(WorkbookHelper::constructGlobals(*this));
108 128 : if (xBookGlob.get() && importFragment(new WorkbookFragment(*xBookGlob, aWorkbookPath)))
109 : {
110 : try
111 : {
112 128 : importDocumentProperties();
113 : }
114 0 : catch( const Exception& e )
115 : {
116 : SAL_WARN("sc", "exception when importing document properties " << e.Message);
117 : }
118 0 : catch( ... )
119 : {
120 : SAL_WARN("sc", "exception when importing document properties");
121 : }
122 128 : return true;
123 0 : }
124 : }
125 0 : catch (...)
126 : {
127 : }
128 :
129 0 : return false;
130 : }
131 :
132 38 : bool ExcelFilter::exportDocument() throw()
133 : {
134 38 : return false;
135 : }
136 :
137 2068 : const ::oox::drawingml::Theme* ExcelFilter::getCurrentTheme() const
138 : {
139 2068 : 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 68 : ::oox::drawingml::chart::ChartConverter* ExcelFilter::getChartConverter()
153 : {
154 68 : return WorkbookHelper( getWorkbookGlobals() ).getChartConverter();
155 : }
156 :
157 0 : void ExcelFilter::useInternalChartDataTable( bool bInternal )
158 : {
159 0 : return WorkbookHelper( getWorkbookGlobals() ).useInternalChartDataTable( bInternal );
160 : }
161 :
162 128 : GraphicHelper* ExcelFilter::implCreateGraphicHelper() const
163 : {
164 128 : return new ExcelGraphicHelper( getWorkbookGlobals() );
165 : }
166 :
167 2 : ::oox::ole::VbaProject* ExcelFilter::implCreateVbaProject() const
168 : {
169 2 : return new ExcelVbaProject( getComponentContext(), Reference< XSpreadsheetDocument >( getModel(), UNO_QUERY ) );
170 : }
171 :
172 166 : 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 )
173 : {
174 166 : if ( XmlFilterBase::filter( rDescriptor ) )
175 128 : return true;
176 :
177 38 : if ( isExportFilter() )
178 : {
179 : Reference< XExporter > xExporter(
180 38 : new XclExpXmlStream( getComponentContext() ) );
181 :
182 38 : Reference< XComponent > xDocument( getModel(), UNO_QUERY );
183 38 : Reference< XFilter > xFilter( xExporter, UNO_QUERY );
184 :
185 38 : if ( xFilter.is() )
186 : {
187 38 : xExporter->setSourceDocument( xDocument );
188 38 : if ( xFilter->filter( rDescriptor ) )
189 38 : return true;
190 0 : }
191 : }
192 :
193 0 : return false;
194 : }
195 :
196 0 : OUString ExcelFilter::implGetImplementationName() const
197 : {
198 0 : return ExcelFilter_getImplementationName();
199 : }
200 :
201 : } // namespace xls
202 48 : } // namespace oox
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|