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 OOX_CORE_FRAGMENTHANDLER_HXX
25 #define OOX_CORE_FRAGMENTHANDLER_HXX
26 
27 #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
28 #include <cppuhelper/implbase1.hxx>
29 #include "oox/core/contexthandler.hxx"
30 #include "oox/core/relations.hxx"
31 
32 namespace com { namespace sun { namespace star {
33     namespace io { class XInputStream; }
34 } } }
35 
36 namespace oox {
37 namespace core {
38 
39 // ============================================================================
40 
41 /** Base data of a fragment.
42 
43     This data is stored in a separate struct to make it accessible in every
44     child context handler of the fragment.
45  */
46 struct FragmentBaseData
47 {
48     XmlFilterBase&      mrFilter;
49     const ::rtl::OUString maFragmentPath;
50     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >
51                         mxLocator;
52     RelationsRef        mxRelations;
53 
54     explicit            FragmentBaseData(
55                             XmlFilterBase& rFilter,
56                             const ::rtl::OUString& rFragmentPath,
57                             RelationsRef xRelations );
58 };
59 
60 // ============================================================================
61 
62 /** Describes record identifiers used to create contexts in a binary stream.
63 
64     If a record is used to start a new context, usually the record identifier
65     increased by 1 is used to mark the end of this context, e.g. the Excel
66     record SHEETDATA == 0x0091 starts the <sheetData> context, and the record
67     SHEETDATA_END == 0x0092 ends this context. But some records are used to
68     start a new context, though there is no identifier to end this context,
69     e.g. the ROW or EXTROW records. These record identifiers can be marked by
70     setting the mnEndRecId member of this struct to -1.
71  */
72 struct RecordInfo
73 {
74     sal_Int32           mnStartRecId;       /// Record identifier for context start.
75     sal_Int32           mnEndRecId;         /// Record identifier for context end, -1 = no record.
76 };
77 
78 // ============================================================================
79 
80 typedef ::cppu::ImplInheritanceHelper1< ContextHandler, ::com::sun::star::xml::sax::XFastDocumentHandler > FragmentHandler_BASE;
81 
82 class FragmentHandler : public FragmentHandler_BASE
83 {
84 public:
85     explicit            FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath );
86     virtual             ~FragmentHandler();
87 
88     /** Returns the com.sun.star.xml.sax.XFastContextHandler interface of this context. */
89     inline ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler >
getFastContextHandler()90                         getFastContextHandler() { return static_cast< ContextHandler* >( this ); }
91 
92     // com.sun.star.xml.sax.XFastDocumentHandler interface --------------------
93 
94     virtual void SAL_CALL startDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
95     virtual void SAL_CALL endDocument() throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
96     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& rxLocator ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
97 
98     // com.sun.star.xml.sax.XFastContextHandler interface ---------------------
99 
100     virtual void SAL_CALL startFastElement( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
101     virtual void SAL_CALL startUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
102     virtual void SAL_CALL endFastElement( ::sal_Int32 Element ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
103     virtual void SAL_CALL endUnknownElement( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
104     virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 Element, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
105     virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( const ::rtl::OUString& Namespace, const ::rtl::OUString& Name, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
106     virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
107     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
108     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);
109 
110     // XML stream handling ----------------------------------------------------
111 
112     /** Opens the fragment stream referred by the own fragment path. Derived
113         classes may provide specilized stream implementations. */
114     virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
115                         openFragmentStream() const;
116 
117     // binary records ---------------------------------------------------------
118 
119     virtual const RecordInfo* getRecordInfos() const;
120 
121 protected:
122     explicit            FragmentHandler( XmlFilterBase& rFilter, const ::rtl::OUString& rFragmentPath, RelationsRef xRelations );
123 };
124 
125 typedef ::rtl::Reference< FragmentHandler > FragmentHandlerRef;
126 
127 // ============================================================================
128 
129 } // namespace core
130 } // namespace oox
131 
132 #endif
133