xref: /trunk/main/comphelper/inc/comphelper/ofopxmlhelper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
69 public:
70     ~OFOPXMLHelper();
71 
72     // returns sequence of elements, where each element is described by sequence of tags,
73     // where each tag is described by StringPair ( First - name, Second - value )
74     // the first tag of each element sequence must be "Id"
75     static
76     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
77     SAL_CALL
78     ReadRelationsInfoSequence(
79         const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
80         const ::rtl::OUString aStreamName,
81         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory );
82 
83     // returns sequence containing two entries of type sequence<StringPair>
84     // the first sequence describes "Default" elements, where each element is described
85     // by StringPair object ( First - Extension, Second - ContentType )
86     // the second sequence describes "Override" elements, where each element is described
87     // by StringPair object ( First - PartName, Second - ContentType )
88     static
89     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >
90     SAL_CALL
91     ReadContentTypeSequence(
92         const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream,
93         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory );
94 
95     // writes sequence of elements, where each element is described by sequence of tags,
96     // where each tag is described by StringPair ( First - name, Second - value )
97     // the first tag of each element sequence must be "Id"
98     static
99     void SAL_CALL WriteRelationsInfoSequence(
100         const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
101         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence,
102         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory );
103 
104     // writes two entries of type sequence<StringPair>
105     // the first sequence describes "Default" elements, where each element is described
106     // by StringPair object ( First - Extension, Second - ContentType )
107     // the second sequence describes "Override" elements, where each element is described
108     // by StringPair object ( First - PartName, Second - ContentType )
109     static
110     void SAL_CALL WriteContentSequence(
111         const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream,
112         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence,
113         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence,
114         const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory );
115 
116     // XDocumentHandler
117     virtual void SAL_CALL startDocument();
118     virtual void SAL_CALL endDocument();
119     virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs );
120     virtual void SAL_CALL endElement( const ::rtl::OUString& aName );
121     virtual void SAL_CALL characters( const ::rtl::OUString& aChars );
122     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces );
123     virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData );
124     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator );
125 };
126 
127 } // namespace comphelper
128 
129 #endif
130