1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 #ifndef _FILTERDETECT_HXX
36 #define _FILTERDETECT_HXX
37 
38 
39 #include <com/sun/star/document/XFilter.hpp>
40 #include <com/sun/star/document/XExporter.hpp>
41 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
42 #include <com/sun/star/document/XImporter.hpp>
43 #include <com/sun/star/lang/XInitialization.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <cppuhelper/implbase5.hxx>
46 
47 #ifndef _CPPUHELPER_IMPLBASE4_HXX_
48 #include <cppuhelper/implbase3.hxx>
49 #endif
50 
51 enum FilterType
52 {
53 	FILTER_IMPORT,
54 	FILTER_EXPORT
55 };
56 
57 /* This component will be instantiated for both import or export. Whether it calls
58  * setSourceDocument or setTargetDocument determines which Impl function the filter
59  * member calls */
60 class FilterDetect : public cppu::WeakImplHelper3 <com::sun::star::document::XExtendedFilterDetection,
61                      com::sun::star::lang::XInitialization,
62                      com::sun::star::lang::XServiceInfo>
63 {
64 protected:
65     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
66     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
67     ::rtl::OUString msFilterName;
68     ::com::sun::star::uno::Sequence< ::rtl::OUString > msUserData;
69     ::rtl::OUString msTemplateName;
70 
71     sal_Bool SAL_CALL exportImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
72 		throw (::com::sun::star::uno::RuntimeException);
73 
74     sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
75 		throw (::com::sun::star::uno::RuntimeException);
76 
77 public:
78 	FilterDetect( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF)
79         : mxMSF( rxMSF ) {}
80 
81 	virtual ~FilterDetect() {}
82 
83  	//XExtendedFilterDetection
84     virtual ::rtl::OUString SAL_CALL detect( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& lDescriptor )
85         throw( com::sun::star::uno::RuntimeException );
86 
87 	// XInitialization
88 
89     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
90 		throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
91 
92 	// XServiceInfo
93     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
94 		throw (::com::sun::star::uno::RuntimeException);
95 
96     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
97 		throw (::com::sun::star::uno::RuntimeException);
98 
99     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
100 		throw (::com::sun::star::uno::RuntimeException);
101 };
102 
103 
104 ::rtl::OUString FilterDetect_getImplementationName()
105 	throw ( ::com::sun::star::uno::RuntimeException );
106 
107 sal_Bool SAL_CALL FilterDetect_supportsService( const ::rtl::OUString& ServiceName )
108 	throw ( ::com::sun::star::uno::RuntimeException );
109 
110 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL FilterDetect_getSupportedServiceNames(  )
111 	throw ( ::com::sun::star::uno::RuntimeException );
112 
113 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
114 SAL_CALL FilterDetect_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
115 	throw ( ::com::sun::star::uno::Exception );
116 
117 #endif
118 
119