1*2d785d7eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2d785d7eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2d785d7eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2d785d7eSAndrew Rist  * distributed with this work for additional information
6*2d785d7eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2d785d7eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2d785d7eSAndrew Rist  * "License"); you may not use this file except in compliance
9*2d785d7eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2d785d7eSAndrew Rist  *
11*2d785d7eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2d785d7eSAndrew Rist  *
13*2d785d7eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2d785d7eSAndrew Rist  * software distributed under the License is distributed on an
15*2d785d7eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2d785d7eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2d785d7eSAndrew Rist  * specific language governing permissions and limitations
18*2d785d7eSAndrew Rist  * under the License.
19*2d785d7eSAndrew Rist  *
20*2d785d7eSAndrew Rist  *************************************************************/
21*2d785d7eSAndrew Rist 
22*2d785d7eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __SERIALIZATION_HXX
25cdf0e10cSrcweir #define __SERIALIZATION_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <map>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <sal/types.h>
30cdf0e10cSrcweir #include <rtl/ustring.hxx>
31cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
33cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
35cdf0e10cSrcweir #include <com/sun/star/xml/xpath/XXPathObject.hpp>
36cdf0e10cSrcweir #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace CSS = com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /**
41cdf0e10cSrcweir Serialize an XObject
42cdf0e10cSrcweir */
43cdf0e10cSrcweir 
44cdf0e10cSrcweir typedef std::map<rtl::OUString, rtl::OUString> PropMap;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir class CSerialization
47cdf0e10cSrcweir {
48cdf0e10cSrcweir protected:
49cdf0e10cSrcweir     CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment;
50cdf0e10cSrcweir     PropMap m_properties;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public:
~CSerialization()53cdf0e10cSrcweir     virtual ~CSerialization() {}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /**
56cdf0e10cSrcweir     sets the XObject that is to serialized
57cdf0e10cSrcweir     */
setSource(const CSS::uno::Reference<CSS::xml::dom::XDocumentFragment> & aFragment)58cdf0e10cSrcweir     virtual void setSource(const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         m_aFragment = aFragment;
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     /**
64cdf0e10cSrcweir     set the properties from the submission element
65cdf0e10cSrcweir     that control aspects of the serialization
66cdf0e10cSrcweir     eachs serialization may support individual properties
67cdf0e10cSrcweir     */
setProperties(const CSS::uno::Sequence<CSS::beans::NamedValue> & props)68cdf0e10cSrcweir     void setProperties(const CSS::uno::Sequence< CSS::beans::NamedValue >& props)
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         m_properties.clear();
71cdf0e10cSrcweir         rtl::OUString aValue;
72cdf0e10cSrcweir         for (sal_Int32 i=0; i<props.getLength(); i++)
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             if (props[i].Value >>= aValue)
75cdf0e10cSrcweir                 m_properties.insert(PropMap::value_type(props[i].Name, aValue));
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /**
80cdf0e10cSrcweir     start the serialization process
81cdf0e10cSrcweir     */
82cdf0e10cSrcweir     virtual void serialize()=0;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     /**
85cdf0e10cSrcweir     get the serialized bytes.
86cdf0e10cSrcweir     reads up to buffer->getLength() bytes and returns the number of
87cdf0e10cSrcweir     bytes read.
88cdf0e10cSrcweir     returns -1 on error
89cdf0e10cSrcweir     */
90cdf0e10cSrcweir     virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream() = 0;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir };
93cdf0e10cSrcweir 
94cdf0e10cSrcweir #endif
95