1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_ucb.hxx"
30 
31 /**************************************************************************
32                                 TODO
33  **************************************************************************
34 
35  *************************************************************************/
36 
37 #include "cppuhelper/factory.hxx"
38 
39 #include "tdoc_documentcontentfactory.hxx"
40 
41 using namespace com::sun::star;
42 using namespace tdoc_ucp;
43 
44 //=========================================================================
45 //=========================================================================
46 //
47 // DocumentContentFactory Implementation.
48 //
49 //=========================================================================
50 //=========================================================================
51 
52 DocumentContentFactory::DocumentContentFactory(
53             const uno::Reference< lang::XMultiServiceFactory >& xSMgr )
54 : m_xSMgr( xSMgr )
55 {
56 }
57 
58 //=========================================================================
59 // virtual
60 DocumentContentFactory::~DocumentContentFactory()
61 {
62 }
63 
64 //=========================================================================
65 //
66 // XServiceInfo methods.
67 //
68 //=========================================================================
69 
70 // virtual
71 ::rtl::OUString SAL_CALL DocumentContentFactory::getImplementationName()
72     throw ( uno::RuntimeException )
73 {
74     return getImplementationName_Static();
75 }
76 
77 //=========================================================================
78 // virtual
79 sal_Bool SAL_CALL
80 DocumentContentFactory::supportsService( const ::rtl::OUString& ServiceName )
81     throw ( uno::RuntimeException )
82 {
83     uno::Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
84     const rtl::OUString * pArray = aSNL.getConstArray();
85     for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
86     {
87         if ( pArray[ i ] == ServiceName )
88             return sal_True;
89     }
90     return sal_False;
91 }
92 
93 //=========================================================================
94 // virtual
95 uno::Sequence< ::rtl::OUString > SAL_CALL
96 DocumentContentFactory::getSupportedServiceNames()
97     throw ( uno::RuntimeException )
98 {
99     return getSupportedServiceNames_Static();
100 }
101 
102 //=========================================================================
103 // static
104 rtl::OUString DocumentContentFactory::getImplementationName_Static()
105 {
106     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
107         "com.sun.star.comp.ucb.TransientDocumentsDocumentContentFactory" ) );
108 }
109 
110 //=========================================================================
111 // static
112 uno::Sequence< rtl::OUString >
113 DocumentContentFactory::getSupportedServiceNames_Static()
114 {
115     uno::Sequence< rtl::OUString > aSNS( 1 );
116     aSNS.getArray()[ 0 ]
117         = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
118             "com.sun.star.frame.TransientDocumentsDocumentContentFactory" ) );
119     return aSNS;
120 }
121 
122 //=========================================================================
123 //
124 // XTransientDocumentsDocumentContentFactory methods.
125 //
126 //=========================================================================
127 
128 // virtual
129 uno::Reference< ucb::XContent > SAL_CALL
130 DocumentContentFactory::createDocumentContent(
131         const uno::Reference< frame::XModel >& Model )
132     throw ( lang::IllegalArgumentException, uno::RuntimeException )
133 {
134     uno::Reference< frame::XTransientDocumentsDocumentContentFactory > xDocFac;
135     try
136     {
137         xDocFac
138             = uno::Reference< frame::XTransientDocumentsDocumentContentFactory >(
139                 m_xSMgr->createInstance(
140                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
141                         "com.sun.star.ucb.TransientDocumentsContentProvider" ) )
142                     ),
143                 uno::UNO_QUERY );
144     }
145     catch ( uno::Exception const & )
146     {
147         // handled below.
148     }
149 
150     if ( xDocFac.is() )
151         return xDocFac->createDocumentContent( Model );
152 
153     throw uno::RuntimeException(
154         rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
155             "Unable to obtain document content factory!" ) ),
156         static_cast< cppu::OWeakObject * >( this ) );
157 }
158 
159 //=========================================================================
160 //
161 // Service factory implementation.
162 //
163 //=========================================================================
164 
165 static uno::Reference< uno::XInterface > SAL_CALL
166 DocumentContentFactory_CreateInstance(
167     const uno::Reference< lang::XMultiServiceFactory> & rSMgr )
168     throw( uno::Exception )
169 {
170     lang::XServiceInfo * pX = static_cast< lang::XServiceInfo * >(
171         new DocumentContentFactory( rSMgr ) );
172     return uno::Reference< uno::XInterface >::query( pX );
173 }
174 
175 //=========================================================================
176 // static
177 uno::Reference< lang::XSingleServiceFactory >
178 DocumentContentFactory::createServiceFactory(
179     const uno::Reference< lang::XMultiServiceFactory >& rxServiceMgr )
180 {
181     return uno::Reference< lang::XSingleServiceFactory >(
182             cppu::createOneInstanceFactory(
183                 rxServiceMgr,
184                 DocumentContentFactory::getImplementationName_Static(),
185                 DocumentContentFactory_CreateInstance,
186                 DocumentContentFactory::getSupportedServiceNames_Static() ) );
187 }
188 
189