2 #include "osl/diagnose.h"
3 #include "rtl/ustring.h"
6 * Helper : create a input stream from a file
8 Reference
< XInputStream
> createStreamFromFile( const OUString sFile
)
10 const sal_Char
* pcFile
;
13 aString
= OUStringToOString( sFile
, RTL_TEXTENCODING_ASCII_US
) ;
14 pcFile
= aString
.getStr() ;
15 if( pcFile
!= NULL
) {
16 FILE *f
= fopen( pcFile
, "rb" );
17 Reference
< XInputStream
> r
;
20 fseek( f
, 0 , SEEK_END
);
21 int nLength
= ftell( f
);
22 fseek( f
, 0 , SEEK_SET
);
24 Sequence
<sal_Int8
> seqIn(nLength
);
25 fread( seqIn
.getArray() , nLength
, 1 , f
);
27 r
= Reference
< XInputStream
> ( new OInputStream( seqIn
) );
39 * Helper : set a output stream to a file
41 Reference
< XOutputStream
> createStreamToFile( const OUString sFile
)
43 const sal_Char
* pcFile
;
46 aString
= OUStringToOString( sFile
, RTL_TEXTENCODING_ASCII_US
) ;
47 pcFile
= aString
.getStr() ;
49 return Reference
< XOutputStream
>( new OOutputStream( pcFile
) ) ;
55 * Helper : get service manager and context
57 Reference
< XMultiComponentFactory
> serviceManager( Reference
< XComponentContext
>& xContext
, OUString sUnoUrl
, OUString sRdbUrl
) throw( RuntimeException
, Exception
)
59 Reference
< XMultiComponentFactory
> xLocalServiceManager
= NULL
;
60 Reference
< XComponentContext
> xLocalComponentContext
= NULL
;
61 Reference
< XMultiComponentFactory
> xUsedServiceManager
= NULL
;
62 Reference
< XComponentContext
> xUsedComponentContext
= NULL
;
64 OSL_ENSURE( !sUnoUrl
.equalsAscii( "" ) ,
66 "No uno URI specified" ) ;
68 OSL_ENSURE( !sRdbUrl
.equalsAscii( "" ) ,
70 "No rdb URI specified" ) ;
72 if( sUnoUrl
.equalsAscii( "local" ) ) {
73 Reference
< XSimpleRegistry
> xSimpleRegistry
= createSimpleRegistry();
74 OSL_ENSURE( xSimpleRegistry
.is() ,
76 "Cannot create simple registry" ) ;
78 //xSimpleRegistry->open(OUString::createFromAscii("xmlsecurity.rdb"), sal_False, sal_False);
79 xSimpleRegistry
->open(sRdbUrl
, sal_True
, sal_False
);
80 OSL_ENSURE( xSimpleRegistry
->isValid() ,
82 "Cannot open xml security registry rdb" ) ;
84 xLocalComponentContext
= bootstrap_InitialComponentContext( xSimpleRegistry
) ;
85 OSL_ENSURE( xLocalComponentContext
.is() ,
87 "Cannot create intial component context" ) ;
89 xLocalServiceManager
= xLocalComponentContext
->getServiceManager() ;
90 OSL_ENSURE( xLocalServiceManager
.is() ,
92 "Cannot create intial service manager" ) ;
95 * Because of the exception rasied from
96 * ucbhelper/source/provider/provconf.cxx, lin 323
97 * I do not use the content broker at present
98 ********************************************************************
100 if( ::ucb::ContentBroker::get() == NULL ) {
101 Reference< lang::XMultiServiceFactory > xSvmg( xLocalServiceManager , UNO_QUERY ) ;
102 OSL_ENSURE( xLocalServiceManager.is() ,
104 "Cannot get multi-service factory" ) ;
106 Sequence< Any > args( 2 ) ;
107 args[ 0 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL ) ;
108 args[ 1 ] <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE ) ;
109 if( ! ::ucb::ContentBroker::initialize( xSvmg , args ) ) {
110 throw RuntimeException( OUString::createFromAscii( "Cannot inlitialize ContentBroker" ) , Reference< XInterface >() , Any() ) ;
113 ********************************************************************/
115 // MARKER(update_precomp.py): autogen include statement, do not remove
116 #include "precompiled_xmlsecurity.hxx"
118 xUsedComponentContext
= xLocalComponentContext
;
119 xUsedServiceManager
= xLocalServiceManager
;
121 Reference
< XComponentContext
> xLocalComponentContext
= defaultBootstrap_InitialComponentContext() ;
122 OSL_ENSURE( xLocalComponentContext
.is() ,
124 "Cannot create intial component context" ) ;
126 Reference
< XMultiComponentFactory
> xLocalServiceManager
= xLocalComponentContext
->getServiceManager();
127 OSL_ENSURE( xLocalServiceManager
.is() ,
129 "Cannot create intial service manager" ) ;
131 Reference
< XInterface
> urlResolver
=
132 xLocalServiceManager
->createInstanceWithContext( OUString::createFromAscii("com.sun.star.bridge.UnoUrlResolver") , xLocalComponentContext
) ;
133 OSL_ENSURE( urlResolver
.is() ,
135 "Cannot get service instance of \"bridge.UnoUrlResolver\"" ) ;
137 Reference
< XUnoUrlResolver
> xUnoUrlResolver( urlResolver
, UNO_QUERY
) ;
138 OSL_ENSURE( xUnoUrlResolver
.is() ,
140 "Cannot get interface of \"XUnoUrlResolver\" from service \"bridge.UnoUrlResolver\"" ) ;
142 Reference
< XInterface
> initialObject
= xUnoUrlResolver
->resolve( sUnoUrl
) ;
143 OSL_ENSURE( initialObject
.is() ,
145 "Cannot resolve uno url" ) ;
148 * Method 1: with Naming Service
149 ********************************************************************
150 Reference< XNamingService > xNamingService( initialObject , UNO_QUERY ) ;
151 OSL_ENSURE( xNamingService.is() ,
153 "Cannot get interface of \"XNamingService\" from URL resolver" ) ;
155 Reference< XInterface > serviceManager =
156 xNamingService->getRegisteredObject( OUString::createFromAscii( "StarOffice.ServiceManager" ) ) ;
157 OSL_ENSURE( serviceManager.is() ,
159 "Cannot get service instance of \"StarOffice.ServiceManager\"" ) ;
161 xUsedServiceManager = Reference< XMultiComponentFactory >( serviceManager , UNO_QUERY );
162 OSL_ENSURE( xUsedServiceManager.is() ,
164 "Cannot get interface of \"XMultiComponentFactory\" from service \"StarOffice.ServiceManager\"" ) ;
166 Reference< XPropertySet > xPropSet( xUsedServiceManager , UNO_QUERY ) ;
167 OSL_ENSURE( xPropSet.is() ,
169 "Cannot get interface of \"XPropertySet\" from service \"StarOffice.ServiceManager\"" ) ;
171 xPropSet->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext ;
172 OSL_ENSURE( xUsedComponentContext.is() ,
174 "Cannot create remote component context" ) ;
176 ********************************************************************/
179 * Method 2: with Componnent context
180 ********************************************************************
181 Reference< XPropertySet > xPropSet( initialObject , UNO_QUERY ) ;
182 OSL_ENSURE( xPropSet.is() ,
184 "Cannot get interface of \"XPropertySet\" from URL resolver" ) ;
186 xPropSet->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext ;
187 OSL_ENSURE( xUsedComponentContext.is() ,
189 "Cannot create remote component context" ) ;
191 xUsedServiceManager = xUsedComponentContext->getServiceManager();
192 OSL_ENSURE( xUsedServiceManager.is() ,
194 "Cannot create remote service manager" ) ;
195 ********************************************************************/
198 * Method 3: with Service Manager
199 ********************************************************************/
200 xUsedServiceManager
= Reference
< XMultiComponentFactory
>( initialObject
, UNO_QUERY
);
201 OSL_ENSURE( xUsedServiceManager
.is() ,
203 "Cannot create remote service manager" ) ;
205 Reference
< XPropertySet
> xPropSet( xUsedServiceManager
, UNO_QUERY
) ;
206 OSL_ENSURE( xPropSet
.is() ,
208 "Cannot get interface of \"XPropertySet\" from service \"StarOffice.ServiceManager\"" ) ;
210 xPropSet
->getPropertyValue( OUString::createFromAscii( "DefaultContext" ) ) >>= xUsedComponentContext
;
211 OSL_ENSURE( xUsedComponentContext
.is() ,
213 "Cannot create remote component context" ) ;
214 /********************************************************************/
217 xContext
= xUsedComponentContext
;
218 return xUsedServiceManager
;