merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / tools / standalone / csfit / helper.hxx
blob14a116444b63afe2bade47eb0be420080724fcbe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include <stdio.h>
29 /*#include <libxml/xmlstring.h>
32 #include <rtl/ustring.hxx>
33 #include <pk11func.h>
35 #include <cppuhelper/bootstrap.hxx>
36 #include <cppuhelper/implbase1.hxx>
37 #include <cppuhelper/servicefactory.hxx>
38 #include <ucbhelper/contentbroker.hxx>
39 #include <ucbhelper/configurationkeys.hxx>
41 #include <com/sun/star/lang/XComponent.hpp>
42 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
43 #include <com/sun/star/registry/XImplementationRegistration.hpp>
44 #include <com/sun/star/document/XFilter.hpp>
45 #include <com/sun/star/document/XExporter.hpp>
46 #include <com/sun/star/document/XImporter.hpp>
47 #include <com/sun/star/io/XInputStream.hpp>
48 #include <com/sun/star/io/XOutputStream.hpp>
49 #include <com/sun/star/io/XActiveDataSource.hpp>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
54 #include <com/sun/star/xml/crypto/XUriBinding.hpp>
55 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
56 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
58 #include <com/sun/star/xml/sax/XParser.hpp>
59 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
60 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
61 #include <com/sun/star/xml/sax/InputSource.hpp>
62 #include <com/sun/star/io/XInputStream.hpp>
63 #include <com/sun/star/io/XOutputStream.hpp>
64 #include <com/sun/star/uno/XNamingService.hpp>
66 using namespace ::rtl ;
67 using namespace ::cppu ;
68 using namespace ::com::sun::star ;
69 using namespace ::com::sun::star::uno ;
70 using namespace ::com::sun::star::io ;
71 using namespace ::com::sun::star::ucb ;
72 using namespace ::com::sun::star::beans ;
73 using namespace ::com::sun::star::document ;
74 using namespace ::com::sun::star::lang ;
75 using namespace ::com::sun::star::bridge ;
76 using namespace ::com::sun::star::registry ;
77 using namespace ::com::sun::star::task ;
78 using namespace ::com::sun::star::xml ;
79 using namespace ::com::sun::star::xml::wrapper ;
80 using namespace ::com::sun::star::xml::sax ;
83 /**
84 * Helper: Implementation of XInputStream
86 class OInputStream : public WeakImplHelper1 < XInputStream >
88 public:
89 OInputStream( const Sequence< sal_Int8 >&seq ) : m_seq( seq ), nPos( 0 ) {}
91 virtual sal_Int32 SAL_CALL readBytes(
92 Sequence< sal_Int8 >& aData ,
93 sal_Int32 nBytesToRead
94 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
96 nBytesToRead = ( nBytesToRead > m_seq.getLength() - nPos ) ?
97 m_seq.getLength() - nPos :
98 nBytesToRead ;
99 aData = Sequence< sal_Int8 > ( &( m_seq.getConstArray()[nPos] ), nBytesToRead ) ;
100 nPos += nBytesToRead ;
101 return nBytesToRead ;
104 virtual sal_Int32 SAL_CALL readSomeBytes(
105 ::com::sun::star::uno::Sequence< sal_Int8 >& aData ,
106 sal_Int32 nMaxBytesToRead
107 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
109 return readBytes( aData, nMaxBytesToRead ) ;
112 virtual void SAL_CALL skipBytes(
113 sal_Int32 nBytesToSkip
114 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
116 // not implemented
119 virtual sal_Int32 SAL_CALL available(
120 void
121 ) throw( NotConnectedException, IOException, RuntimeException )
123 return m_seq.getLength() - nPos ;
126 virtual void SAL_CALL closeInput(
127 void
128 ) throw( NotConnectedException, IOException, RuntimeException )
130 // not needed
133 private:
134 sal_Int32 nPos;
135 Sequence< sal_Int8> m_seq;
139 * Helper : create a input stream from a file
141 Reference< XInputStream > createStreamFromFile( const OUString sFile ) ;
144 * Helper: Implementation of XOutputStream
146 class OOutputStream : public WeakImplHelper1 < XOutputStream >
148 public:
149 OOutputStream( const char *pcFile ) {
150 strcpy( m_pcFile , pcFile ) ;
151 m_f = 0 ;
154 virtual void SAL_CALL writeBytes(
155 const Sequence< sal_Int8 >& aData
156 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
157 if( !m_f ) {
158 m_f = fopen( m_pcFile , "w" ) ;
161 fwrite( aData.getConstArray() , 1 , aData.getLength() , m_f ) ;
164 virtual void SAL_CALL flush(
165 void
166 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
167 fflush( m_f ) ;
170 virtual void SAL_CALL closeOutput(
171 void
172 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
173 fclose( m_f ) ;
174 m_f = 0 ;
177 private:
178 char m_pcFile[256];
179 FILE *m_f;
183 * Helper: Implementation of XUriBinding
185 class OUriBinding : public WeakImplHelper1 < ::com::sun::star::xml::crypto::XUriBinding >
187 public:
188 OUriBinding() {
189 //Do nothing
192 OUriBinding(
193 ::rtl::OUString& aUri,
194 ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) {
195 m_vUris.push_back( aUri ) ;
196 m_vStreams.push_back( aInputStream ) ;
199 virtual void SAL_CALL setUriBinding(
200 const ::rtl::OUString& aUri ,
201 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aInputStream
202 ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) {
203 m_vUris.push_back( aUri ) ;
204 m_vStreams.push_back( aInputStream ) ;
207 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getUriBinding( const ::rtl::OUString& uri ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) {
208 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream ;
210 int size = m_vUris.size() ;
211 for( int i = 0 ; i<size ; ++i ) {
212 if( uri == m_vUris[i] ) {
213 xInputStream = m_vStreams[i];
214 break;
218 return xInputStream;
221 private:
222 std::vector< ::rtl::OUString > m_vUris ;
223 std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > > m_vStreams ;
227 * Helper : set a output stream to a file
229 Reference< XOutputStream > createStreamToFile( const OUString sFile ) ;
232 * Helper : get service manager and context
234 Reference< XMultiComponentFactory > serviceManager( Reference< XComponentContext >& xContext , OUString sUnoUrl , OUString sRdbUrl ) throw( RuntimeException , Exception ) ;
237 * Helper : Get password function for PKCS11 slot
239 char* PriPK11PasswordFunc( PK11SlotInfo *slot , PRBool retry , void* arg ) ;