1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "docxexportfilter.hxx"
25 #include "rtfexportfilter.hxx"
26 #include "rtfimportfilter.hxx"
27 #include "docxexport.hxx"
28 
29 #include <docsh.hxx>
30 #include <pam.hxx>
31 #include <unotxdoc.hxx>
32 
33 #include <cppuhelper/factory.hxx>
34 
35 using namespace ::comphelper;
36 using namespace ::com::sun::star;
37 using ::rtl::OUString;
38 
39 #define S( x ) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
40 
DocxExportFilter(const uno::Reference<lang::XMultiServiceFactory> & rMSF)41 DocxExportFilter::DocxExportFilter( const uno::Reference< lang::XMultiServiceFactory >& rMSF )
42 	: oox::core::XmlFilterBase( rMSF )
43 {
44 }
45 
exportDocument()46 bool DocxExportFilter::exportDocument()
47 {
48 	OSL_TRACE(, "DocxExportFilter::exportDocument()\n" ); // DEBUG remove me
49 
50 	// get SwDoc*
51 	uno::Reference< uno::XInterface > xIfc( getModel(), uno::UNO_QUERY );
52 	SwXTextDocument *pTxtDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
53 	if ( !pTxtDoc )
54 		return false;
55 
56 	SwDoc *pDoc = pTxtDoc->GetDocShell()->GetDoc();
57 	if ( !pDoc )
58 		return false;
59 
60 	// get SwPaM*
61 	// FIXME so far we get SwPaM for the entire document; probably we should
62 	// be able to output just the selection as well - though no idea how to
63 	// get the correct SwPaM* then...
64 	SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
65 	aPam.SetMark();
66 	aPam.Move( fnMoveBackward, fnGoDoc );
67 
68 	SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() );
69 
70 	// export the document
71 	// (in a separate block so that it's destructed before the commit)
72 	{
73 		DocxExport aExport( this, pDoc, pCurPam, &aPam );
74 		aExport.ExportDocument( true ); // FIXME support exporting selection only
75 	}
76 
77 	commit();
78 
79 	// delete the pCurPam
80 	if ( pCurPam )
81 	{
82 		while ( pCurPam->GetNext() != pCurPam )
83 			delete pCurPam->GetNext();
84 		delete pCurPam;
85 	}
86 
87 	return true;
88 }
89 
90 //////////////////////////////////////////////////////////////////////////
91 // UNO stuff so that the filter is registered
92 //////////////////////////////////////////////////////////////////////////
93 
94 #define IMPL_NAME "com.sun.star.comp.Writer.DocxExport"
95 
DocxExport_getImplementationName()96 OUString DocxExport_getImplementationName()
97 {
98 	return OUString( RTL_CONSTASCII_USTRINGPARAM( IMPL_NAME ) );
99 }
100 
implGetImplementationName() const101 OUString DocxExportFilter::implGetImplementationName() const
102 {
103 	return DocxExport_getImplementationName();
104 }
105 
DocxExport_getSupportedServiceNames()106 uno::Sequence< OUString > SAL_CALL DocxExport_getSupportedServiceNames() throw()
107 {
108 	const OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.ExportFilter" ) );
109 	const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
110 	return aSeq;
111 }
112 
DocxExport_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)113 uno::Reference< uno::XInterface > SAL_CALL DocxExport_createInstance(const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception )
114 {
115 	return (cppu::OWeakObject*) new DocxExportFilter( rSMgr );
116 }
117 
118 #ifdef __cplusplus
119 extern "C"
120 {
121 #endif
122 
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)123 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ )
124 {
125 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
126 }
127 
128 // ------------------------
129 // - component_getFactory -
130 // ------------------------
131 
component_getFactory(const sal_Char * pImplName,void * pServiceManager,void *)132 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ )
133 {
134 	OSL_TRACE("%s, pImplName is '%s'", OSL_THIS_FUNC, pImplName);
135 	uno::Reference< lang::XSingleServiceFactory > xFactory;
136 	void* pRet = 0;
137 
138 	if ( rtl_str_compare( pImplName, IMPL_NAME ) == 0 )
139 	{
140 		const OUString aServiceName( OUString::createFromAscii( IMPL_NAME ) );
141 
142 		xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory(
143 					reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ),
144 					DocxExport_getImplementationName(),
145 					DocxExport_createInstance,
146 					DocxExport_getSupportedServiceNames() ) );
147 	} else if ( rtl_str_compare( pImplName, IMPL_NAME_RTFEXPORT ) == 0 ) {
148 		const OUString aServiceName( OUString::createFromAscii( IMPL_NAME_RTFEXPORT ) );
149 
150 		xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory(
151 					reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ),
152 					RtfExport_getImplementationName(),
153 					RtfExport_createInstance,
154 					RtfExport_getSupportedServiceNames() ) );
155 	} else if ( rtl_str_compare( pImplName, IMPL_NAME_RTFIMPORT ) == 0 ) {
156 		const OUString aServiceName( OUString::createFromAscii( IMPL_NAME_RTFIMPORT ) );
157 
158 		xFactory = uno::Reference< lang::XSingleServiceFactory >( ::cppu::createSingleFactory(
159 					reinterpret_cast< lang::XMultiServiceFactory* >( pServiceManager ),
160 					RtfImport_getImplementationName(),
161 					RtfImport_createInstance,
162 					RtfImport_getSupportedServiceNames() ) );
163 	}
164 
165 	if ( xFactory.is() )
166 	{
167 		xFactory->acquire();
168 		pRet = xFactory.get();
169 	}
170 
171 	return pRet;
172 }
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 /* vim: set noet sw=4 ts=4: */
179