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