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 #ifndef _UOF2_SPLIT_HELPER_HXX_
25 #define _UOF2_SPLIT_HELPER_HXX_
26 
27 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
28 #include <com/sun/star/xml/sax/SAXException.hpp>
29 #include <com/sun/star/xml/sax/XAttributeList.hpp>
30 #include <com/sun/star/xml/sax/XLocator.hpp>
31 #include <cppuhelper/implbase1.hxx>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
34 #include <com/sun/star/embed/XStorage.hpp>
35 
36 #include <vector>
37 #include <map>
38 
39 
40 #include "uof2storage.hxx"
41 
42 struct NamespaceValue{
43 	::rtl::OUString aType;
44 	::rtl::OUString aValue;
NamespaceValueNamespaceValue45 	NamespaceValue( ::rtl::OUString & Type, ::rtl::OUString & Value ): aType(Type), aValue(Value) {}
operator ()NamespaceValue46 	sal_Bool operator () ( ::rtl::OUString & Type, ::rtl::OUString & Value )
47 	{ return ( aType == Type ) && ( aValue == Value ); }
48 };
49 
50 namespace XSLT{
51 
52 class UOF2SplitHandler : public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
53 {
54 	::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler >  m_xHandler;
55 	::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > & m_rStream;
56 	::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& m_rMultiFactory;
57 	::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >  m_xOutputStream;
58 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >  m_rInputStream;
59 
60 public :
61 
62 	UOF2SplitHandler(
63 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rFactory,
64 		::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rStream );
65 
66 	~UOF2SplitHandler();
67 
68 	// XDocumentHandler
69     virtual void SAL_CALL startDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
70     virtual void SAL_CALL endDocument() throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
71 	virtual void SAL_CALL startElement(const ::rtl::OUString& qName , const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& attriblist)
72         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
73 	virtual void SAL_CALL endElement(const ::rtl::OUString& qName )
74         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
75 	virtual void SAL_CALL characters(const ::rtl::OUString& rStr )
76         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
77 	virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& str)
78         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
79 	virtual void SAL_CALL processingInstruction(const ::rtl::OUString& str, const ::rtl::OUString& str2)
80         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
81 	virtual void SAL_CALL setDocumentLocator(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& doclocator)
82         throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
83 
84 private :
85 	void _Init();
86 	void Write( ::rtl::OUString & rOutFile , sal_Bool bStart ) throw( ::com::sun::star::uno::RuntimeException );
87 	void namespaceMap( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& attriblist );
88 
89 private :
90 	UOF2Storage * m_pStore;
91 	StorageRef	m_pMainStore;
92 	StorageRef  m_pCurStore;
93 	::rtl::OUString	aOutFileName;
94 	::std::map< ::rtl::OUString, NamespaceValue > aNamespaceMap;
95 	::std::vector< ::rtl::OUString > aUsedNamespace;
96 	sal_Bool	m_bIsStart;  // start a sub file
97 
98 
99 };
100 } // end namespace
101 #endif
102