1*2f86921cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2f86921cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2f86921cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2f86921cSAndrew Rist  * distributed with this work for additional information
6*2f86921cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2f86921cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2f86921cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2f86921cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2f86921cSAndrew Rist  *
11*2f86921cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2f86921cSAndrew Rist  *
13*2f86921cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2f86921cSAndrew Rist  * software distributed under the License is distributed on an
15*2f86921cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2f86921cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2f86921cSAndrew Rist  * specific language governing permissions and limitations
18*2f86921cSAndrew Rist  * under the License.
19*2f86921cSAndrew Rist  *
20*2f86921cSAndrew Rist  *************************************************************/
21*2f86921cSAndrew Rist 
22*2f86921cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucb.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir /**************************************************************************
28cdf0e10cSrcweir                                 TODO
29cdf0e10cSrcweir  **************************************************************************
30cdf0e10cSrcweir 
31cdf0e10cSrcweir  *************************************************************************/
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "cppuhelper/factory.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "tdoc_documentcontentfactory.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir using namespace tdoc_ucp;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //=========================================================================
41cdf0e10cSrcweir //=========================================================================
42cdf0e10cSrcweir //
43cdf0e10cSrcweir // DocumentContentFactory Implementation.
44cdf0e10cSrcweir //
45cdf0e10cSrcweir //=========================================================================
46cdf0e10cSrcweir //=========================================================================
47cdf0e10cSrcweir 
DocumentContentFactory(const uno::Reference<lang::XMultiServiceFactory> & xSMgr)48cdf0e10cSrcweir DocumentContentFactory::DocumentContentFactory(
49cdf0e10cSrcweir             const uno::Reference< lang::XMultiServiceFactory >& xSMgr )
50cdf0e10cSrcweir : m_xSMgr( xSMgr )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //=========================================================================
55cdf0e10cSrcweir // virtual
~DocumentContentFactory()56cdf0e10cSrcweir DocumentContentFactory::~DocumentContentFactory()
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //=========================================================================
61cdf0e10cSrcweir //
62cdf0e10cSrcweir // XServiceInfo methods.
63cdf0e10cSrcweir //
64cdf0e10cSrcweir //=========================================================================
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // virtual
getImplementationName()67cdf0e10cSrcweir ::rtl::OUString SAL_CALL DocumentContentFactory::getImplementationName()
68cdf0e10cSrcweir     throw ( uno::RuntimeException )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     return getImplementationName_Static();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir //=========================================================================
74cdf0e10cSrcweir // virtual
75cdf0e10cSrcweir sal_Bool SAL_CALL
supportsService(const::rtl::OUString & ServiceName)76cdf0e10cSrcweir DocumentContentFactory::supportsService( const ::rtl::OUString& ServiceName )
77cdf0e10cSrcweir     throw ( uno::RuntimeException )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
80cdf0e10cSrcweir     const rtl::OUString * pArray = aSNL.getConstArray();
81cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         if ( pArray[ i ] == ServiceName )
84cdf0e10cSrcweir             return sal_True;
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir     return sal_False;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir //=========================================================================
90cdf0e10cSrcweir // virtual
91cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL
getSupportedServiceNames()92cdf0e10cSrcweir DocumentContentFactory::getSupportedServiceNames()
93cdf0e10cSrcweir     throw ( uno::RuntimeException )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     return getSupportedServiceNames_Static();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //=========================================================================
99cdf0e10cSrcweir // static
getImplementationName_Static()100cdf0e10cSrcweir rtl::OUString DocumentContentFactory::getImplementationName_Static()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
103cdf0e10cSrcweir         "com.sun.star.comp.ucb.TransientDocumentsDocumentContentFactory" ) );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //=========================================================================
107cdf0e10cSrcweir // static
108cdf0e10cSrcweir uno::Sequence< rtl::OUString >
getSupportedServiceNames_Static()109cdf0e10cSrcweir DocumentContentFactory::getSupportedServiceNames_Static()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aSNS( 1 );
112cdf0e10cSrcweir     aSNS.getArray()[ 0 ]
113cdf0e10cSrcweir         = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
114cdf0e10cSrcweir             "com.sun.star.frame.TransientDocumentsDocumentContentFactory" ) );
115cdf0e10cSrcweir     return aSNS;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir //=========================================================================
119cdf0e10cSrcweir //
120cdf0e10cSrcweir // XTransientDocumentsDocumentContentFactory methods.
121cdf0e10cSrcweir //
122cdf0e10cSrcweir //=========================================================================
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // virtual
125cdf0e10cSrcweir uno::Reference< ucb::XContent > SAL_CALL
createDocumentContent(const uno::Reference<frame::XModel> & Model)126cdf0e10cSrcweir DocumentContentFactory::createDocumentContent(
127cdf0e10cSrcweir         const uno::Reference< frame::XModel >& Model )
128cdf0e10cSrcweir     throw ( lang::IllegalArgumentException, uno::RuntimeException )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     uno::Reference< frame::XTransientDocumentsDocumentContentFactory > xDocFac;
131cdf0e10cSrcweir     try
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         xDocFac
134cdf0e10cSrcweir             = uno::Reference< frame::XTransientDocumentsDocumentContentFactory >(
135cdf0e10cSrcweir                 m_xSMgr->createInstance(
136cdf0e10cSrcweir                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
137cdf0e10cSrcweir                         "com.sun.star.ucb.TransientDocumentsContentProvider" ) )
138cdf0e10cSrcweir                     ),
139cdf0e10cSrcweir                 uno::UNO_QUERY );
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir     catch ( uno::Exception const & )
142cdf0e10cSrcweir     {
143cdf0e10cSrcweir         // handled below.
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if ( xDocFac.is() )
147cdf0e10cSrcweir         return xDocFac->createDocumentContent( Model );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     throw uno::RuntimeException(
150cdf0e10cSrcweir         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
151cdf0e10cSrcweir             "Unable to obtain document content factory!" ) ),
152cdf0e10cSrcweir         static_cast< cppu::OWeakObject * >( this ) );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir //=========================================================================
156cdf0e10cSrcweir //
157cdf0e10cSrcweir // Service factory implementation.
158cdf0e10cSrcweir //
159cdf0e10cSrcweir //=========================================================================
160cdf0e10cSrcweir 
161cdf0e10cSrcweir static uno::Reference< uno::XInterface > SAL_CALL
DocumentContentFactory_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)162cdf0e10cSrcweir DocumentContentFactory_CreateInstance(
163cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory> & rSMgr )
164cdf0e10cSrcweir     throw( uno::Exception )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     lang::XServiceInfo * pX = static_cast< lang::XServiceInfo * >(
167cdf0e10cSrcweir         new DocumentContentFactory( rSMgr ) );
168cdf0e10cSrcweir     return uno::Reference< uno::XInterface >::query( pX );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //=========================================================================
172cdf0e10cSrcweir // static
173cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory >
createServiceFactory(const uno::Reference<lang::XMultiServiceFactory> & rxServiceMgr)174cdf0e10cSrcweir DocumentContentFactory::createServiceFactory(
175cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& rxServiceMgr )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     return uno::Reference< lang::XSingleServiceFactory >(
178cdf0e10cSrcweir             cppu::createOneInstanceFactory(
179cdf0e10cSrcweir                 rxServiceMgr,
180cdf0e10cSrcweir                 DocumentContentFactory::getImplementationName_Static(),
181cdf0e10cSrcweir                 DocumentContentFactory_CreateInstance,
182cdf0e10cSrcweir                 DocumentContentFactory::getSupportedServiceNames_Static() ) );
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185