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
;
53 * Helper: Implementation of XInputStream
55 class OInputStream
: public WeakImplHelper1
< XInputStream
>
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
:
68 aData
= Sequence
< sal_Int8
> ( &( m_seq
.getConstArray()[nPos
] ), nBytesToRead
) ;
69 nPos
+= 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
)
88 virtual sal_Int32 SAL_CALL
available(
90 ) throw( NotConnectedException
, IOException
, RuntimeException
)
92 return m_seq
.getLength() - nPos
;
95 virtual void SAL_CALL
closeInput(
97 ) throw( NotConnectedException
, IOException
, RuntimeException
)
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
>
118 OOutputStream( const char *pcFile
) {
119 strcpy( m_pcFile
, pcFile
) ;
123 virtual void SAL_CALL
writeBytes(
124 const Sequence
< sal_Int8
>& aData
125 ) throw( NotConnectedException
, BufferSizeExceededException
, RuntimeException
) {
127 m_f
= fopen( m_pcFile
, "w" ) ;
130 fwrite( aData
.getConstArray() , 1 , aData
.getLength() , m_f
) ;
133 virtual void SAL_CALL
flush(
135 ) throw( NotConnectedException
, BufferSizeExceededException
, RuntimeException
) {
139 virtual void SAL_CALL
closeOutput(
141 ) throw( NotConnectedException
, BufferSizeExceededException
, RuntimeException
) {
152 * Helper: Implementation of XUriBinding
154 class OUriBinding
: public WeakImplHelper1
< ::com::sun::star::xml::crypto::XUriBinding
>
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
];
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
) ;