1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _COMPHELPER_OFOPXMLHELPER_HXX
21 #define _COMPHELPER_OFOPXMLHELPER_HXX
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <com/sun/star/beans/StringPair.hpp>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/io/XOutputStream.hpp>
27 #include <cppuhelper/implbase1.hxx>
28 #include <comphelper/comphelperdllapi.h>
34 // this helper class is designed to allow to parse ContentType- and Relationship-related information from OfficeOpenXML format
35 class COMPHELPER_DLLPUBLIC OFOPXMLHelper
: public cppu::WeakImplHelper1
< com::sun::star::xml::sax::XDocumentHandler
>
37 sal_uInt16 m_nFormat
; // which format to parse
39 // Relations info related strings
40 OUString m_aRelListElement
;
41 OUString m_aRelElement
;
44 OUString m_aTargetModeAttr
;
45 OUString m_aTargetAttr
;
47 // ContentType related strings
48 OUString m_aTypesElement
;
49 OUString m_aDefaultElement
;
50 OUString m_aOverrideElement
;
51 OUString m_aExtensionAttr
;
52 OUString m_aPartNameAttr
;
53 OUString m_aContentTypeAttr
;
55 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
> > m_aResultSeq
;
56 ::com::sun::star::uno::Sequence
< OUString
> m_aElementsSeq
; // stack of elements being parsed
58 OFOPXMLHelper( sal_uInt16 nFormat
); // must not be created directly
59 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
> > GetParsingResult();
61 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 OUString
& aStringID
, sal_uInt16 nFormat
, const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
)
62 throw( ::com::sun::star::uno::Exception
);
67 // returns sequence of elements, where each element is described by sequence of tags,
68 // where each tag is described by StringPair ( First - name, Second - value )
69 // the first tag of each element sequence must be "Id"
71 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
> >
73 ReadRelationsInfoSequence(
74 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInStream
,
75 const OUString aStreamName
,
76 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
)
77 throw( ::com::sun::star::uno::Exception
);
79 // returns sequence containing two entries of type sequence<StringPair>
80 // the first sequence describes "Default" elements, where each element is described
81 // by StringPair object ( First - Extension, Second - ContentType )
82 // the second sequence describes "Override" elements, where each element is described
83 // by StringPair object ( First - PartName, Second - ContentType )
85 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
> >
87 ReadContentTypeSequence(
88 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInStream
,
89 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
)
90 throw( ::com::sun::star::uno::Exception
);
92 // writes sequence of elements, where each element is described by sequence of tags,
93 // where each tag is described by StringPair ( First - name, Second - value )
94 // the first tag of each element sequence must be "Id"
96 void SAL_CALL
WriteRelationsInfoSequence(
97 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>& xOutStream
,
98 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
> >& aSequence
,
99 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
)
100 throw( ::com::sun::star::uno::Exception
);
102 // writes two entries of type sequence<StringPair>
103 // the first sequence describes "Default" elements, where each element is described
104 // by StringPair object ( First - Extension, Second - ContentType )
105 // the second sequence describes "Override" elements, where each element is described
106 // by StringPair object ( First - PartName, Second - ContentType )
108 void SAL_CALL
WriteContentSequence(
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>& xOutStream
,
110 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
>& aDefaultsSequence
,
111 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::StringPair
>& aOverridesSequence
,
112 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> xContext
)
113 throw( ::com::sun::star::uno::Exception
);
116 virtual void SAL_CALL
startDocument() throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
117 virtual void SAL_CALL
endDocument() throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
118 virtual void SAL_CALL
startElement( const 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
);
119 virtual void SAL_CALL
endElement( const OUString
& aName
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
120 virtual void SAL_CALL
characters( const OUString
& aChars
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
121 virtual void SAL_CALL
ignorableWhitespace( const OUString
& aWhitespaces
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
122 virtual void SAL_CALL
processingInstruction( const OUString
& aTarget
, const OUString
& aData
) throw (::com::sun::star::xml::sax::SAXException
, ::com::sun::star::uno::RuntimeException
);
123 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
);
126 } // namespace comphelper
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */