1*cdf0e10cSrcweir #include <stdio.h> 2*cdf0e10cSrcweir #include <rtl/ustring.hxx> 3*cdf0e10cSrcweir 4*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 5*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 6*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 7*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 8*cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx> 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 11*cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp> 12*cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp> 13*cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp> 14*cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp> 15*cdf0e10cSrcweir #include <com/sun/star/document/XImporter.hpp> 16*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 17*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 18*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp> 19*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 20*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 21*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 22*cdf0e10cSrcweir 23*cdf0e10cSrcweir #include <com/sun/star/xml/crypto/XUriBinding.hpp> 24*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLDocumentWrapper.hpp> 25*cdf0e10cSrcweir #include <com/sun/star/xml/wrapper/XXMLElementWrapper.hpp> 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 28*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 29*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 30*cdf0e10cSrcweir #include <com/sun/star/xml/sax/InputSource.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/uno/XNamingService.hpp> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace ::rtl ; 36*cdf0e10cSrcweir using namespace ::cppu ; 37*cdf0e10cSrcweir using namespace ::com::sun::star ; 38*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 39*cdf0e10cSrcweir using namespace ::com::sun::star::io ; 40*cdf0e10cSrcweir using namespace ::com::sun::star::ucb ; 41*cdf0e10cSrcweir using namespace ::com::sun::star::beans ; 42*cdf0e10cSrcweir using namespace ::com::sun::star::document ; 43*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 44*cdf0e10cSrcweir using namespace ::com::sun::star::bridge ; 45*cdf0e10cSrcweir using namespace ::com::sun::star::registry ; 46*cdf0e10cSrcweir using namespace ::com::sun::star::task ; 47*cdf0e10cSrcweir using namespace ::com::sun::star::xml ; 48*cdf0e10cSrcweir using namespace ::com::sun::star::xml::wrapper ; 49*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax ; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir /** 53*cdf0e10cSrcweir * Helper: Implementation of XInputStream 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir class OInputStream : public WeakImplHelper1 < XInputStream > 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir public: 58*cdf0e10cSrcweir OInputStream( const Sequence< sal_Int8 >&seq ) : m_seq( seq ), nPos( 0 ) {} 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readBytes( 61*cdf0e10cSrcweir Sequence< sal_Int8 >& aData , 62*cdf0e10cSrcweir sal_Int32 nBytesToRead 63*cdf0e10cSrcweir ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir nBytesToRead = ( nBytesToRead > m_seq.getLength() - nPos ) ? 66*cdf0e10cSrcweir m_seq.getLength() - nPos : 67*cdf0e10cSrcweir nBytesToRead ; 68*cdf0e10cSrcweir aData = Sequence< sal_Int8 > ( &( m_seq.getConstArray()[nPos] ), nBytesToRead ) ; 69*cdf0e10cSrcweir nPos += nBytesToRead ; 70*cdf0e10cSrcweir return nBytesToRead ; 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL readSomeBytes( 74*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 >& aData , 75*cdf0e10cSrcweir sal_Int32 nMaxBytesToRead 76*cdf0e10cSrcweir ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir return readBytes( aData, nMaxBytesToRead ) ; 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir virtual void SAL_CALL skipBytes( 82*cdf0e10cSrcweir sal_Int32 nBytesToSkip 83*cdf0e10cSrcweir ) throw( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir // not implemented 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir virtual sal_Int32 SAL_CALL available( 89*cdf0e10cSrcweir void 90*cdf0e10cSrcweir ) throw( NotConnectedException, IOException, RuntimeException ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir return m_seq.getLength() - nPos ; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir virtual void SAL_CALL closeInput( 96*cdf0e10cSrcweir void 97*cdf0e10cSrcweir ) throw( NotConnectedException, IOException, RuntimeException ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir // not needed 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir private: 103*cdf0e10cSrcweir sal_Int32 nPos; 104*cdf0e10cSrcweir Sequence< sal_Int8> m_seq; 105*cdf0e10cSrcweir } ; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir /** 108*cdf0e10cSrcweir * Helper : create a input stream from a file 109*cdf0e10cSrcweir */ 110*cdf0e10cSrcweir Reference< XInputStream > createStreamFromFile( const OUString sFile ) ; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir /** 113*cdf0e10cSrcweir * Helper: Implementation of XOutputStream 114*cdf0e10cSrcweir */ 115*cdf0e10cSrcweir class OOutputStream : public WeakImplHelper1 < XOutputStream > 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir public: 118*cdf0e10cSrcweir OOutputStream( const char *pcFile ) { 119*cdf0e10cSrcweir strcpy( m_pcFile , pcFile ) ; 120*cdf0e10cSrcweir m_f = 0 ; 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir virtual void SAL_CALL writeBytes( 124*cdf0e10cSrcweir const Sequence< sal_Int8 >& aData 125*cdf0e10cSrcweir ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) { 126*cdf0e10cSrcweir if( !m_f ) { 127*cdf0e10cSrcweir m_f = fopen( m_pcFile , "w" ) ; 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir fwrite( aData.getConstArray() , 1 , aData.getLength() , m_f ) ; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir virtual void SAL_CALL flush( 134*cdf0e10cSrcweir void 135*cdf0e10cSrcweir ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) { 136*cdf0e10cSrcweir fflush( m_f ) ; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir virtual void SAL_CALL closeOutput( 140*cdf0e10cSrcweir void 141*cdf0e10cSrcweir ) throw( NotConnectedException , BufferSizeExceededException , RuntimeException ) { 142*cdf0e10cSrcweir fclose( m_f ) ; 143*cdf0e10cSrcweir m_f = 0 ; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private: 147*cdf0e10cSrcweir char m_pcFile[256]; 148*cdf0e10cSrcweir FILE *m_f; 149*cdf0e10cSrcweir } ; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir /** 152*cdf0e10cSrcweir * Helper: Implementation of XUriBinding 153*cdf0e10cSrcweir */ 154*cdf0e10cSrcweir class OUriBinding : public WeakImplHelper1 < ::com::sun::star::xml::crypto::XUriBinding > 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir public: 157*cdf0e10cSrcweir OUriBinding() { 158*cdf0e10cSrcweir //Do nothing 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir OUriBinding( 162*cdf0e10cSrcweir ::rtl::OUString& aUri, 163*cdf0e10cSrcweir ::com::sun::star::uno::Reference< com::sun::star::io::XInputStream >& aInputStream ) { 164*cdf0e10cSrcweir m_vUris.push_back( aUri ) ; 165*cdf0e10cSrcweir m_vStreams.push_back( aInputStream ) ; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir virtual void SAL_CALL setUriBinding( 169*cdf0e10cSrcweir const ::rtl::OUString& aUri , 170*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& aInputStream 171*cdf0e10cSrcweir ) throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException ) { 172*cdf0e10cSrcweir m_vUris.push_back( aUri ) ; 173*cdf0e10cSrcweir m_vStreams.push_back( aInputStream ) ; 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir 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*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream ; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir int size = m_vUris.size() ; 180*cdf0e10cSrcweir for( int i = 0 ; i<size ; ++i ) { 181*cdf0e10cSrcweir if( uri == m_vUris[i] ) { 182*cdf0e10cSrcweir xInputStream = m_vStreams[i]; 183*cdf0e10cSrcweir break; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir return xInputStream; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir private: 191*cdf0e10cSrcweir std::vector< ::rtl::OUString > m_vUris ; 192*cdf0e10cSrcweir std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > > m_vStreams ; 193*cdf0e10cSrcweir } ; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir /** 196*cdf0e10cSrcweir * Helper : set a output stream to a file 197*cdf0e10cSrcweir */ 198*cdf0e10cSrcweir Reference< XOutputStream > createStreamToFile( const OUString sFile ) ; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir /** 201*cdf0e10cSrcweir * Helper : get service manager and context 202*cdf0e10cSrcweir */ 203*cdf0e10cSrcweir Reference< XMultiComponentFactory > serviceManager( Reference< XComponentContext >& xContext , OUString sUnoUrl , OUString sRdbUrl ) throw( RuntimeException , Exception ) ; 204*cdf0e10cSrcweir 205