update dev300-m58
[ooovba.git] / xmlsecurity / tools / demo / util.cxx
blobc67e258c22013ee6d42d44ffe70db8b32cb6cfba
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: util.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlsecurity.hxx"
34 #include "util.hxx"
36 #include <stdio.h>
38 #include <com/sun/star/registry/XImplementationRegistration.hpp>
39 #include <cppuhelper/bootstrap.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <unotools/streamhelper.hxx>
42 #include <tools/string.hxx>
44 namespace cssu = com::sun::star::uno;
45 namespace cssl = com::sun::star::lang;
46 namespace cssxc = com::sun::star::xml::crypto;
47 namespace cssi = com::sun::star::io;
49 using namespace ::com::sun::star;
51 cssu::Reference< cssl::XMultiServiceFactory > CreateDemoServiceFactory()
53 cssu::Reference< cssl::XMultiServiceFactory > xMSF;
55 try
57 cssu::Reference< cssl::XMultiComponentFactory > xLocalServiceManager = NULL ;
58 cssu::Reference< cssu::XComponentContext > xLocalComponentContext = NULL ;
60 cssu::Reference< ::com::sun::star::registry::XSimpleRegistry > xSimpleRegistry
61 = ::cppu::createSimpleRegistry();
62 OSL_ENSURE( xSimpleRegistry.is(),
63 "serviceManager - "
64 "Cannot create simple registry" ) ;
66 xSimpleRegistry->open(rtl::OUString::createFromAscii( "demo.rdb" ), sal_True, sal_False);
67 OSL_ENSURE( xSimpleRegistry->isValid() ,
68 "serviceManager - "
69 "Cannot open xml security registry rdb" ) ;
71 xLocalComponentContext = ::cppu::bootstrap_InitialComponentContext( xSimpleRegistry ) ;
72 OSL_ENSURE( xLocalComponentContext.is() ,
73 "serviceManager - "
74 "Cannot create intial component context" ) ;
76 xLocalServiceManager = xLocalComponentContext->getServiceManager() ;
77 OSL_ENSURE( xLocalServiceManager.is() ,
78 "serviceManager - "
79 "Cannot create intial service manager" ) ;
81 xMSF = cssu::Reference< cssl::XMultiServiceFactory >(xLocalServiceManager, cssu::UNO_QUERY) ;
83 ::comphelper::setProcessServiceFactory( xMSF );
85 catch( cssu::Exception& e )
87 fprintf( stderr , "Error creating ServiceManager, Exception is %s\n" , rtl::OUStringToOString( e.Message , RTL_TEXTENCODING_ASCII_US ).getStr() ) ;
88 exit (-1);
91 return xMSF;
94 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > OpenInputStream( const ::rtl::OUString& rStreamName )
96 SvFileStream* pStream = new SvFileStream( rStreamName, STREAM_READ );
97 pStream->Seek( STREAM_SEEK_TO_END );
98 ULONG nBytes = pStream->Tell();
99 pStream->Seek( STREAM_SEEK_TO_BEGIN );
100 SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
101 uno::Reference< io::XInputStream > xInputStream = new utl::OInputStreamHelper( xLockBytes, nBytes );
103 return xInputStream;
107 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > OpenOutputStream( const ::rtl::OUString& rStreamName )
109 SvFileStream* pStream = new SvFileStream( rStreamName, STREAM_WRITE );
110 SvLockBytesRef xLockBytes = new SvLockBytes( pStream, TRUE );
111 uno::Reference< io::XOutputStream > xOutputStream = new utl::OOutputStreamHelper( xLockBytes );
113 return xOutputStream;