1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ownsubfilterservice.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/frame/DoubleInitializationException.hpp>
34 #include <com/sun/star/lang/XUnoTunnel.hpp>
36 #include <ownsubfilterservice.hxx>
37 #include <sfx2/objsh.hxx>
39 using namespace ::com::sun::star
;
43 //-------------------------------------------------------------------------
44 OwnSubFilterService::OwnSubFilterService( const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
)
45 : m_xFactory( xFactory
)
46 , m_pObjectShell( NULL
)
50 //-------------------------------------------------------------------------
51 OwnSubFilterService::~OwnSubFilterService()
55 //-------------------------------------------------------------------------
56 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OwnSubFilterService::impl_getStaticSupportedServiceNames()
58 uno::Sequence
< ::rtl::OUString
> aRet(2);
59 aRet
[0] = ::rtl::OUString::createFromAscii("com.sun.star.document.OwnSubFilter");
60 aRet
[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
64 //-------------------------------------------------------------------------
65 ::rtl::OUString SAL_CALL
OwnSubFilterService::impl_getStaticImplementationName()
67 return ::rtl::OUString::createFromAscii("com.sun.star.comp.document.OwnSubFilter");
70 //-------------------------------------------------------------------------
71 uno::Reference
< uno::XInterface
> SAL_CALL
OwnSubFilterService::impl_staticCreateSelfInstance(
72 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
74 return uno::Reference
< uno::XInterface
>( *new OwnSubFilterService( xServiceManager
) );
77 //-------------------------------------------------------------------------
78 uno::Reference
< lang::XSingleServiceFactory
> SAL_CALL
OwnSubFilterService::impl_createFactory(
79 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
81 return ::cppu::createSingleFactory( xServiceManager
,
82 OwnSubFilterService::impl_getStaticImplementationName(),
83 OwnSubFilterService::impl_staticCreateSelfInstance
,
84 OwnSubFilterService::impl_getStaticSupportedServiceNames() );
90 //-------------------------------------------------------------------------
91 sal_Bool SAL_CALL
OwnSubFilterService::filter( const uno::Sequence
< beans::PropertyValue
>& aDescriptor
)
92 throw (uno::RuntimeException
)
94 if ( !m_pObjectShell
)
95 throw uno::RuntimeException();
97 return m_pObjectShell
->ImportFromGeneratedStream_Impl( m_xStream
, aDescriptor
);
100 //-------------------------------------------------------------------------
101 void SAL_CALL
OwnSubFilterService::cancel()
102 throw (uno::RuntimeException
)
110 //-------------------------------------------------------------------------
111 void SAL_CALL
OwnSubFilterService::initialize( const uno::Sequence
< uno::Any
>& aArguments
)
112 throw (uno::Exception
, uno::RuntimeException
)
114 if ( !m_xFactory
.is() )
115 throw uno::RuntimeException();
117 if ( aArguments
.getLength() != 2 )
118 throw lang::IllegalArgumentException();
120 if ( m_pObjectShell
)
121 throw frame::DoubleInitializationException();
123 if ( ( aArguments
[1] >>= m_xStream
) && m_xStream
.is()
124 && ( aArguments
[0] >>= m_xModel
) && m_xModel
.is() )
126 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xObj( m_xModel
, uno::UNO_QUERY_THROW
);
127 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
128 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
130 m_pObjectShell
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
133 if ( !m_pObjectShell
)
134 throw lang::IllegalArgumentException();
140 //-------------------------------------------------------------------------
141 ::rtl::OUString SAL_CALL
OwnSubFilterService::getImplementationName()
142 throw ( uno::RuntimeException
)
144 return impl_getStaticImplementationName();
147 //-------------------------------------------------------------------------
148 sal_Bool SAL_CALL
OwnSubFilterService::supportsService( const ::rtl::OUString
& ServiceName
)
149 throw ( uno::RuntimeException
)
151 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_getStaticSupportedServiceNames();
153 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
154 if ( ServiceName
.compareTo( aSeq
[nInd
] ) == 0 )
160 //-------------------------------------------------------------------------
161 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OwnSubFilterService::getSupportedServiceNames()
162 throw ( uno::RuntimeException
)
164 return impl_getStaticSupportedServiceNames();