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