1*06b3ce53SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*06b3ce53SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*06b3ce53SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*06b3ce53SAndrew Rist * distributed with this work for additional information
6*06b3ce53SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*06b3ce53SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*06b3ce53SAndrew Rist * "License"); you may not use this file except in compliance
9*06b3ce53SAndrew Rist * with the License. You may obtain a copy of the License at
10*06b3ce53SAndrew Rist *
11*06b3ce53SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*06b3ce53SAndrew Rist *
13*06b3ce53SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*06b3ce53SAndrew Rist * software distributed under the License is distributed on an
15*06b3ce53SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*06b3ce53SAndrew Rist * KIND, either express or implied. See the License for the
17*06b3ce53SAndrew Rist * specific language governing permissions and limitations
18*06b3ce53SAndrew Rist * under the License.
19*06b3ce53SAndrew Rist *
20*06b3ce53SAndrew Rist *************************************************************/
21*06b3ce53SAndrew Rist
22*06b3ce53SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlsecurity.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "util.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp>
32cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
33cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
34cdf0e10cSrcweir #include <unotools/streamhelper.hxx>
35cdf0e10cSrcweir #include <tools/string.hxx>
36cdf0e10cSrcweir
37cdf0e10cSrcweir namespace cssu = com::sun::star::uno;
38cdf0e10cSrcweir namespace cssl = com::sun::star::lang;
39cdf0e10cSrcweir namespace cssxc = com::sun::star::xml::crypto;
40cdf0e10cSrcweir namespace cssi = com::sun::star::io;
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir
CreateDemoServiceFactory()44cdf0e10cSrcweir cssu::Reference< cssl::XMultiServiceFactory > CreateDemoServiceFactory()
45cdf0e10cSrcweir {
46cdf0e10cSrcweir cssu::Reference< cssl::XMultiServiceFactory > xMSF;
47cdf0e10cSrcweir
48cdf0e10cSrcweir try
49cdf0e10cSrcweir {
50cdf0e10cSrcweir cssu::Reference< cssl::XMultiComponentFactory > xLocalServiceManager = NULL ;
51cdf0e10cSrcweir cssu::Reference< cssu::XComponentContext > xLocalComponentContext = NULL ;
52cdf0e10cSrcweir
53cdf0e10cSrcweir cssu::Reference< ::com::sun::star::registry::XSimpleRegistry > xSimpleRegistry
54cdf0e10cSrcweir = ::cppu::createSimpleRegistry();
55cdf0e10cSrcweir OSL_ENSURE( xSimpleRegistry.is(),
56cdf0e10cSrcweir "serviceManager - "
57cdf0e10cSrcweir "Cannot create simple registry" ) ;
58cdf0e10cSrcweir
59cdf0e10cSrcweir xSimpleRegistry->open(rtl::OUString::createFromAscii( "demo.rdb" ), sal_True, sal_False);
60cdf0e10cSrcweir OSL_ENSURE( xSimpleRegistry->isValid() ,
61cdf0e10cSrcweir "serviceManager - "
62cdf0e10cSrcweir "Cannot open xml security registry rdb" ) ;
63cdf0e10cSrcweir
64cdf0e10cSrcweir xLocalComponentContext = ::cppu::bootstrap_InitialComponentContext( xSimpleRegistry ) ;
65cdf0e10cSrcweir OSL_ENSURE( xLocalComponentContext.is() ,
66cdf0e10cSrcweir "serviceManager - "
67cdf0e10cSrcweir "Cannot create intial component context" ) ;
68cdf0e10cSrcweir
69cdf0e10cSrcweir xLocalServiceManager = xLocalComponentContext->getServiceManager() ;
70cdf0e10cSrcweir OSL_ENSURE( xLocalServiceManager.is() ,
71cdf0e10cSrcweir "serviceManager - "
72cdf0e10cSrcweir "Cannot create intial service manager" ) ;
73cdf0e10cSrcweir
74cdf0e10cSrcweir xMSF = cssu::Reference< cssl::XMultiServiceFactory >(xLocalServiceManager, cssu::UNO_QUERY) ;
75cdf0e10cSrcweir
76cdf0e10cSrcweir ::comphelper::setProcessServiceFactory( xMSF );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir catch( cssu::Exception& e )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir fprintf( stderr , "Error creating ServiceManager, Exception is %s\n" , rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
81cdf0e10cSrcweir exit (-1);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir return xMSF;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
OpenInputStream(const::rtl::OUString & rStreamName)87cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > OpenInputStream( const ::rtl::OUString& rStreamName )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir SvFileStream* pStream = new SvFileStream( rStreamName, STREAM_READ );
90cdf0e10cSrcweir pStream->Seek( STREAM_SEEK_TO_END );
91cdf0e10cSrcweir sal_uLong nBytes = pStream->Tell();
92cdf0e10cSrcweir pStream->Seek( STREAM_SEEK_TO_BEGIN );
93cdf0e10cSrcweir SvLockBytesRef xLockBytes = new SvLockBytes( pStream, sal_True );
94cdf0e10cSrcweir uno::Reference< io::XInputStream > xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
95cdf0e10cSrcweir
96cdf0e10cSrcweir return xInputStream;
97cdf0e10cSrcweir
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
OpenOutputStream(const::rtl::OUString & rStreamName)100cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > OpenOutputStream( const ::rtl::OUString& rStreamName )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir SvFileStream* pStream = new SvFileStream( rStreamName, STREAM_WRITE );
103cdf0e10cSrcweir SvLockBytesRef xLockBytes = new SvLockBytes( pStream, sal_True );
104cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutputStream = new utl::OOutputStreamHelper( xLockBytes );
105cdf0e10cSrcweir
106cdf0e10cSrcweir return xOutputStream;
107cdf0e10cSrcweir }
108