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 
23 
24 #ifndef _COMPHELPER_OFOPXMLHELPER_HXX
25 #define _COMPHELPER_OFOPXMLHELPER_HXX
26 
27 #ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
28 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
29 #endif
30 #include <com/sun/star/beans/StringPair.hpp>
31 #include <com/sun/star/io/XInputStream.hpp>
32 #include <com/sun/star/io/XOutputStream.hpp>
33 #include <cppuhelper/implbase1.hxx>
34 #include <comphelper/comphelperdllapi.h>
35 
36 
37 namespace comphelper
38 {
39 
40 // this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format
41 class COMPHELPER_DLLPUBLIC OFOPXMLHelper : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
42 {
43 	sal_uInt16 m_nFormat; // which format to parse
44 
45 	// Relations info related strings
46 	::rtl::OUString m_aRelListElement;
47 	::rtl::OUString m_aRelElement;
48 	::rtl::OUString m_aIDAttr;
49 	::rtl::OUString m_aTypeAttr;
50 	::rtl::OUString m_aTargetModeAttr;
51 	::rtl::OUString m_aTargetAttr;
52 
53 	// ContentType related strings
54 	::rtl::OUString m_aTypesElement;
55 	::rtl::OUString m_aDefaultElement;
56 	::rtl::OUString m_aOverrideElement;
57 	::rtl::OUString m_aExtensionAttr;
58 	::rtl::OUString m_aPartNameAttr;
59 	::rtl::OUString m_aContentTypeAttr;
60 
61 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aResultSeq;
62 	::com::sun::star::uno::Sequence< ::rtl::OUString > m_aElementsSeq; // stack of elements being parsed
63 
64 	OFOPXMLHelper( sal_uInt16 nFormat ); // must not be created directly
65 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetParsingResult();
66 
67 	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 )
68 	throw( ::com::sun::star::uno::Exception );
69 
70 public:
71 	~OFOPXMLHelper();
72 
73 	// returns sequence of elements, where each element is described by sequence of tags,
74 	// where each tag is described by StringPair ( First - name, Second - value )
75 	// the first tag of each element sequence must be "Id"
76 	static
77 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
78 	SAL_CALL
79 	ReadRelationsInfoSequence(
80 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
81 		const ::rtl::OUString aStreamName,
82 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
83 			throw( ::com::sun::star::uno::Exception );
84 
85 	// returns sequence containing two entries of type sequence<StringPair>
86 	// the first sequence describes "Default" elements, where each element is described
87 	// by StringPair object ( First - Extension, Second - ContentType )
88 	// the second sequence describes "Override" elements, where each element is described
89 	// by StringPair object ( First - PartName, Second - ContentType )
90 	static
91 	::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
92 	SAL_CALL
93 	ReadContentTypeSequence(
94 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
95 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
96 			throw( ::com::sun::star::uno::Exception );
97 
98 	// writes sequence of elements, where each element is described by sequence of tags,
99 	// where each tag is described by StringPair ( First - name, Second - value )
100 	// the first tag of each element sequence must be "Id"
101 	static
102 	void SAL_CALL WriteRelationsInfoSequence(
103 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
104 		const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence,
105 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
106 			throw( ::com::sun::star::uno::Exception );
107 
108 	// writes two entries of type sequence<StringPair>
109 	// the first sequence describes "Default" elements, where each element is described
110 	// by StringPair object ( First - Extension, Second - ContentType )
111 	// the second sequence describes "Override" elements, where each element is described
112 	// by StringPair object ( First - PartName, Second - ContentType )
113 	static
114 	void SAL_CALL WriteContentSequence(
115 		const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
116 		const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence,
117 		const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence,
118 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory )
119 			throw( ::com::sun::star::uno::Exception );
120 
121 	// XDocumentHandler
122     virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
123     virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
124     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);
125     virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
126     virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
127     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
128     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);
129     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);
130 };
131 
132 } // namespace comphelper
133 
134 #endif
135 
136