1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/frame/DoubleInitializationException.hpp>
30 #include <com/sun/star/lang/XUnoTunnel.hpp>
32 #include <ownsubfilterservice.hxx>
33 #include <sfx2/objsh.hxx>
35 using namespace ::com::sun::star
;
39 //-------------------------------------------------------------------------
40 OwnSubFilterService::OwnSubFilterService( const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
)
41 : m_xFactory( xFactory
)
42 , m_pObjectShell( NULL
)
46 //-------------------------------------------------------------------------
47 OwnSubFilterService::~OwnSubFilterService()
51 //-------------------------------------------------------------------------
52 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OwnSubFilterService::impl_getStaticSupportedServiceNames()
54 uno::Sequence
< ::rtl::OUString
> aRet(2);
55 aRet
[0] = ::rtl::OUString("com.sun.star.document.OwnSubFilter");
56 aRet
[1] = ::rtl::OUString("com.sun.star.comp.document.OwnSubFilter");
60 //-------------------------------------------------------------------------
61 ::rtl::OUString SAL_CALL
OwnSubFilterService::impl_getStaticImplementationName()
63 return ::rtl::OUString("com.sun.star.comp.document.OwnSubFilter");
66 //-------------------------------------------------------------------------
67 uno::Reference
< uno::XInterface
> SAL_CALL
OwnSubFilterService::impl_staticCreateSelfInstance(
68 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
70 return uno::Reference
< uno::XInterface
>( *new OwnSubFilterService( xServiceManager
) );
73 //-------------------------------------------------------------------------
74 uno::Reference
< lang::XSingleServiceFactory
> SAL_CALL
OwnSubFilterService::impl_createFactory(
75 const uno::Reference
< lang::XMultiServiceFactory
>& xServiceManager
)
77 return ::cppu::createSingleFactory( xServiceManager
,
78 OwnSubFilterService::impl_getStaticImplementationName(),
79 OwnSubFilterService::impl_staticCreateSelfInstance
,
80 OwnSubFilterService::impl_getStaticSupportedServiceNames() );
86 //-------------------------------------------------------------------------
87 sal_Bool SAL_CALL
OwnSubFilterService::filter( const uno::Sequence
< beans::PropertyValue
>& aDescriptor
)
88 throw (uno::RuntimeException
)
90 if ( !m_pObjectShell
)
91 throw uno::RuntimeException();
93 return m_pObjectShell
->ImportFromGeneratedStream_Impl( m_xStream
, aDescriptor
);
96 //-------------------------------------------------------------------------
97 void SAL_CALL
OwnSubFilterService::cancel()
98 throw (uno::RuntimeException
)
106 //-------------------------------------------------------------------------
107 void SAL_CALL
OwnSubFilterService::initialize( const uno::Sequence
< uno::Any
>& aArguments
)
108 throw (uno::Exception
, uno::RuntimeException
)
110 if ( !m_xFactory
.is() )
111 throw uno::RuntimeException();
113 if ( aArguments
.getLength() != 2 )
114 throw lang::IllegalArgumentException();
116 if ( m_pObjectShell
)
117 throw frame::DoubleInitializationException();
119 if ( ( aArguments
[1] >>= m_xStream
) && m_xStream
.is()
120 && ( aArguments
[0] >>= m_xModel
) && m_xModel
.is() )
122 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xObj( m_xModel
, uno::UNO_QUERY_THROW
);
123 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
124 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
126 m_pObjectShell
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
129 if ( !m_pObjectShell
)
130 throw lang::IllegalArgumentException();
136 //-------------------------------------------------------------------------
137 ::rtl::OUString SAL_CALL
OwnSubFilterService::getImplementationName()
138 throw ( uno::RuntimeException
)
140 return impl_getStaticImplementationName();
143 //-------------------------------------------------------------------------
144 sal_Bool SAL_CALL
OwnSubFilterService::supportsService( const ::rtl::OUString
& ServiceName
)
145 throw ( uno::RuntimeException
)
147 uno::Sequence
< ::rtl::OUString
> aSeq
= impl_getStaticSupportedServiceNames();
149 for ( sal_Int32 nInd
= 0; nInd
< aSeq
.getLength(); nInd
++ )
150 if ( ServiceName
.compareTo( aSeq
[nInd
] ) == 0 )
156 //-------------------------------------------------------------------------
157 uno::Sequence
< ::rtl::OUString
> SAL_CALL
OwnSubFilterService::getSupportedServiceNames()
158 throw ( uno::RuntimeException
)
160 return impl_getStaticSupportedServiceNames();
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */