1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 **************************************************************/
21
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 //This file is about the conversion of the UOF v2.0 and ODF document format
24 #include "precompiled_filter.hxx"
25
26
27 #include <cppuhelper/implbase4.hxx>
28 #include <com/sun/star/xml/sax/XParser.hpp>
29 #include <com/sun/star/xml/sax/InputSource.hpp>
30 #include <com/sun/star/xml/sax/SAXException.hpp>
31
32 #include "uof2splitter.hxx"
33
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::xml::sax;
37 using namespace osl;
38
39 namespace XSLT {
40
UOF2Splitter(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & rMultiFactory,const::rtl::OUString & rURL)41 UOF2Splitter::UOF2Splitter( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rMultiFactory,
42 const ::rtl::OUString & rURL )
43 : m_rMultiFactory( rMultiFactory )
44 ,aURL( rURL )
45 ,m_aThread( 0 )
46 {
47 }
48
~UOF2Splitter()49 UOF2Splitter::~UOF2Splitter()
50 {
51 if( m_aThread )
52 {
53 osl_joinWithThread( m_aThread );
54 osl_destroyThread( m_aThread );
55 }
56 }
57
58 // XActiveDataControl
addListener(const::com::sun::star::uno::Reference<::com::sun::star::io::XStreamListener> & rxListener)59 void UOF2Splitter::addListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException)
60 {
61 m_StreamListeners.insert( rxListener );
62 }
63
removeListener(const::com::sun::star::uno::Reference<::com::sun::star::io::XStreamListener> & rxListener)64 void UOF2Splitter::removeListener ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener> & rxListener ) throw( ::com::sun::star::uno::RuntimeException)
65 {
66 m_StreamListeners.erase( rxListener );
67 }
68
start(void)69 void UOF2Splitter::start (void) throw( ::com::sun::star::uno::RuntimeException)
70 {
71 if ( !m_xStream.is() )
72 return;
73
74 try {
75 typedef ::std::set< ::com::sun::star::uno::Reference< ::com::sun::star::io::XStreamListener > > set_Listeners;
76 set_Listeners::const_iterator start_it = m_StreamListeners.begin();
77 for( ; start_it != m_StreamListeners.end(); start_it++ )
78 {
79 Reference< XStreamListener > xListener = *start_it;
80 xListener->started();
81 }
82
83 try{
84 InputSource aInput;
85 aInput.sSystemId = aURL;
86 aInput.sPublicId = aURL;
87 aInput.aInputStream = m_xInputStream;
88 Reference< XParser > xParser( m_rMultiFactory->createInstance( ::rtl::OUString::createFromAscii("com.sun.star.xml.sax.Parser") ), UNO_QUERY );
89 xParser->setDocumentHandler( new UOF2SplitHandler( m_rMultiFactory, m_xStream ) );
90 xParser->parseStream( aInput );
91 }
92 catch( Exception& e)
93 {
94 OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
95 }
96 set_Listeners::const_iterator close_it = m_StreamListeners.begin();
97 for( ; close_it != m_StreamListeners.end(); close_it++ )
98 {
99 Reference< XStreamListener > xListener = *close_it;
100 xListener->closed();
101 }
102 }
103 catch( Exception& e)
104 {
105 OSL_ENSURE(0, ::rtl::OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
106 }
107 }
108
terminate(void)109 void UOF2Splitter::terminate (void) throw( ::com::sun::star::uno::RuntimeException)
110 {
111 }
112
113 // XActiveDataSink
setInputStream(const::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & rxInputStream)114 void UOF2Splitter::setInputStream ( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> &rxInputStream) throw( ::com::sun::star::uno::RuntimeException)
115 {
116 m_xInputStream = rxInputStream;
117 }
118
getInputStream(void)119 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream> UOF2Splitter::getInputStream(void) throw( ::com::sun::star::uno::RuntimeException)
120 {
121 return m_xInputStream;
122 }
123
124 // XActiveDataStreamer
setStream(const::com::sun::star::uno::Reference<::com::sun::star::io::XStream> & rxStream)125 void UOF2Splitter::setStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> &rxStream) throw( ::com::sun::star::uno::RuntimeException)
126 {
127 m_xStream = rxStream;
128 }
129
getStream(void)130 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream> UOF2Splitter::getStream (void) throw( ::com::sun::star::uno::RuntimeException)
131 {
132 return m_xStream;
133 }
134
135 }
136