xref: /AOO41X/main/comphelper/inc/comphelper/ofopxmlhelper.hxx (revision 9877b273795ec465a3ce9c15d738eb34c0455705)
1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _COMPHELPER_OFOPXMLHELPER_HXX
25cdf0e10cSrcweir #define _COMPHELPER_OFOPXMLHELPER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
28cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <com/sun/star/beans/StringPair.hpp>
31cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
32cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
33cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
34cdf0e10cSrcweir #include <comphelper/comphelperdllapi.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace comphelper
38cdf0e10cSrcweir {
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format
41cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OFOPXMLHelper : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 	sal_uInt16 m_nFormat; // which format to parse
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	// Relations info related strings
46cdf0e10cSrcweir 	::rtl::OUString m_aRelListElement;
47cdf0e10cSrcweir 	::rtl::OUString m_aRelElement;
48cdf0e10cSrcweir 	::rtl::OUString m_aIDAttr;
49cdf0e10cSrcweir 	::rtl::OUString m_aTypeAttr;
50cdf0e10cSrcweir 	::rtl::OUString m_aTargetModeAttr;
51cdf0e10cSrcweir 	::rtl::OUString m_aTargetAttr;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	// ContentType related strings
54cdf0e10cSrcweir 	::rtl::OUString m_aTypesElement;
55cdf0e10cSrcweir 	::rtl::OUString m_aDefaultElement;
56cdf0e10cSrcweir 	::rtl::OUString m_aOverrideElement;
57cdf0e10cSrcweir 	::rtl::OUString m_aExtensionAttr;
58cdf0e10cSrcweir 	::rtl::OUString m_aPartNameAttr;
59cdf0e10cSrcweir 	::rtl::OUString m_aContentTypeAttr;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aResultSeq;
62cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::rtl::OUString > m_aElementsSeq; // stack of elements being parsed
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	OFOPXMLHelper( sal_uInt16 nFormat ); // must not be created directly
65cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetParsingResult();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	static COMPHELPER_DLLPRIVATE ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL ReadSequence_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const ::rtl::OUString& aStringID, sal_uInt16 nFormat, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
68cdf0e10cSrcweir 	throw( ::com::sun::star::uno::Exception );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir public:
71cdf0e10cSrcweir 	~OFOPXMLHelper();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	// returns sequence of elements, where each element is described by sequence of tags,
74cdf0e10cSrcweir 	// where each tag is described by StringPair ( First - name, Second - value )
75cdf0e10cSrcweir 	// the first tag of each element sequence must be "Id"
76cdf0e10cSrcweir 	static
77cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
78cdf0e10cSrcweir 	SAL_CALL
79cdf0e10cSrcweir 	ReadRelationsInfoSequence(
80cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
81cdf0e10cSrcweir 		const ::rtl::OUString aStreamName,
82cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
83cdf0e10cSrcweir 			throw( ::com::sun::star::uno::Exception );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	// returns sequence containing two entries of type sequence<StringPair>
86cdf0e10cSrcweir 	// the first sequence describes "Default" elements, where each element is described
87cdf0e10cSrcweir 	// by StringPair object ( First - Extension, Second - ContentType )
88cdf0e10cSrcweir 	// the second sequence describes "Override" elements, where each element is described
89cdf0e10cSrcweir 	// by StringPair object ( First - PartName, Second - ContentType )
90cdf0e10cSrcweir 	static
91cdf0e10cSrcweir 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
92cdf0e10cSrcweir 	SAL_CALL
93cdf0e10cSrcweir 	ReadContentTypeSequence(
94cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
95cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
96cdf0e10cSrcweir 			throw( ::com::sun::star::uno::Exception );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	// writes sequence of elements, where each element is described by sequence of tags,
99cdf0e10cSrcweir 	// where each tag is described by StringPair ( First - name, Second - value )
100cdf0e10cSrcweir 	// the first tag of each element sequence must be "Id"
101cdf0e10cSrcweir 	static
102cdf0e10cSrcweir 	void SAL_CALL WriteRelationsInfoSequence(
103cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
104cdf0e10cSrcweir 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence,
105cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
106cdf0e10cSrcweir 			throw( ::com::sun::star::uno::Exception );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	// writes two entries of type sequence<StringPair>
109cdf0e10cSrcweir 	// the first sequence describes "Default" elements, where each element is described
110cdf0e10cSrcweir 	// by StringPair object ( First - Extension, Second - ContentType )
111cdf0e10cSrcweir 	// the second sequence describes "Override" elements, where each element is described
112cdf0e10cSrcweir 	// by StringPair object ( First - PartName, Second - ContentType )
113cdf0e10cSrcweir 	static
114cdf0e10cSrcweir 	void SAL_CALL WriteContentSequence(
115cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
116cdf0e10cSrcweir 		const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence,
117cdf0e10cSrcweir 		const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence,
118cdf0e10cSrcweir 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
119cdf0e10cSrcweir 			throw( ::com::sun::star::uno::Exception );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	// XDocumentHandler
122cdf0e10cSrcweir     virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir     virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
124cdf0e10cSrcweir     virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
125cdf0e10cSrcweir     virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
126cdf0e10cSrcweir     virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
128cdf0e10cSrcweir     virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
129cdf0e10cSrcweir     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
130cdf0e10cSrcweir };
131cdf0e10cSrcweir 
132cdf0e10cSrcweir } // namespace comphelper
133cdf0e10cSrcweir 
134cdf0e10cSrcweir #endif
135cdf0e10cSrcweir 
136