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