merged tag ooo/OOO330_m14
[LibreOffice.git] / xmlsecurity / tools / standalone / mscsfit / helper.hxx
blob0f95ef50c4ab3139e9298859f4a4f5a0c3697291
1 #include <stdio.h>
2 #include <rtl/ustring.hxx>
4 #include <cppuhelper/bootstrap.hxx>
5 #include <cppuhelper/implbase1.hxx>
6 #include <cppuhelper/servicefactory.hxx>
7 #include <ucbhelper/contentbroker.hxx>
8 #include <ucbhelper/configurationkeys.hxx>
10 #include <com/sun/star/lang/XComponent.hpp>
11 #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
12 #include <com/sun/star/registry/XImplementationRegistration.hpp>
13 #include <com/sun/star/document/XFilter.hpp>
14 #include <com/sun/star/document/XExporter.hpp>
15 #include <com/sun/star/document/XImporter.hpp>
16 #include <com/sun/star/io/XInputStream.hpp>
17 #include <com/sun/star/io/XOutputStream.hpp>
18 #include <com/sun/star/io/XActiveDataSource.hpp>
19 #include <com/sun/star/beans/PropertyValue.hpp>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
23 #include <com/sun/star/xml/crypto/XUriBinding.hpp>
24 #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp>
25 #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp>
27 #include <com/sun/star/xml/sax/XParser.hpp>
28 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
29 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
30 #include <com/sun/star/xml/sax/InputSource.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <com/sun/star/uno/XNamingService.hpp>
35 using namespace ::rtl ;
36 using namespace ::cppu ;
37 using namespace ::com::sun::star ;
38 using namespace ::com::sun::star::uno ;
39 using namespace ::com::sun::star::io ;
40 using namespace ::com::sun::star::ucb ;
41 using namespace ::com::sun::star::beans ;
42 using namespace ::com::sun::star::document ;
43 using namespace ::com::sun::star::lang ;
44 using namespace ::com::sun::star::bridge ;
45 using namespace ::com::sun::star::registry ;
46 using namespace ::com::sun::star::task ;
47 using namespace ::com::sun::star::xml ;
48 using namespace ::com::sun::star::xml::wrapper ;
49 using namespace ::com::sun::star::xml::sax ;
52 /**
53 * Helper: Implementation of XInputStream
55 class OInputStream : public WeakImplHelper1 < XInputStream >
57 public:
58 OInputStream( const Sequence< sal_Int8 >&seq ) : m_seq( seq ), nPos( 0 ) {}
60 virtual sal_Int32 SAL_CALL readBytes(
61 Sequence< sal_Int8 >& aData ,
62 sal_Int32 nBytesToRead
63 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
65 nBytesToRead = ( nBytesToRead > m_seq.getLength() - nPos ) ?
66 m_seq.getLength() - nPos :
67 nBytesToRead ;
68 aData = Sequence< sal_Int8 > ( &( m_seq.getConstArray()[nPos] ), nBytesToRead ) ;
69 nPos += nBytesToRead ;
70 return nBytesToRead ;
73 virtual sal_Int32 SAL_CALL readSomeBytes(
74 ::com::sun::star::uno::Sequence< sal_Int8 >& aData ,
75 sal_Int32 nMaxBytesToRead
76 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
78 return readBytes( aData, nMaxBytesToRead ) ;
81 virtual void SAL_CALL skipBytes(
82 sal_Int32 nBytesToSkip
83 ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
85 // not implemented
88 virtual sal_Int32 SAL_CALL available(
89 void
90 ) throw( NotConnectedException, IOException, RuntimeException )
92 return m_seq.getLength() - nPos ;
95 virtual void SAL_CALL closeInput(
96 void
97 ) throw( NotConnectedException, IOException, RuntimeException )
99 // not needed
102 private:
103 sal_Int32 nPos;
104 Sequence< sal_Int8> m_seq;
108 * Helper : create a input stream from a file
110 Reference< XInputStream > createStreamFromFile( const OUString sFile ) ;
113 * Helper: Implementation of XOutputStream
115 class OOutputStream : public WeakImplHelper1 < XOutputStream >
117 public:
118 OOutputStream( const char *pcFile ) {
119 strcpy( m_pcFile , pcFile ) ;
120 m_f = 0 ;
123 virtual void SAL_CALL writeBytes(
124 const Sequence< sal_Int8 >& aData
125 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
126 if( !m_f ) {
127 m_f = fopen( m_pcFile , "w" ) ;
130 fwrite( aData.getConstArray() , 1 , aData.getLength() , m_f ) ;
133 virtual void SAL_CALL flush(
134 void
135 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
136 fflush( m_f ) ;
139 virtual void SAL_CALL closeOutput(
140 void
141 ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) {
142 fclose( m_f ) ;
143 m_f = 0 ;
146 private:
147 char m_pcFile[256];
148 FILE *m_f;
152 * Helper: Implementation of XUriBinding
154 class OUriBinding : public WeakImplHelper1 < ::com::sun::star::xml::crypto::XUriBinding >
156 public:
157 OUriBinding() {
158 //Do nothing
161 OUriBinding(
162 ::rtl::OUString& aUri,
163 ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) {
164 m_vUris.push_back( aUri ) ;
165 m_vStreams.push_back( aInputStream ) ;
168 virtual void SAL_CALL setUriBinding(
169 const ::rtl::OUString& aUri ,
170 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aInputStream
171 ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) {
172 m_vUris.push_back( aUri ) ;
173 m_vStreams.push_back( aInputStream ) ;
176 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 ) {
177 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream ;
179 int size = m_vUris.size() ;
180 for( int i = 0 ; i<size ; ++i ) {
181 if( uri == m_vUris[i] ) {
182 xInputStream = m_vStreams[i];
183 break;
187 return xInputStream;
190 private:
191 std::vector< ::rtl::OUString > m_vUris ;
192 std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > > m_vStreams ;
196 * Helper : set a output stream to a file
198 Reference< XOutputStream > createStreamToFile( const OUString sFile ) ;
201 * Helper : get service manager and context
203 Reference< XMultiComponentFactory > serviceManager( Reference< XComponentContext >& xContext , OUString sUnoUrl , OUString sRdbUrl ) throw( RuntimeException , Exception ) ;