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 __SERIALIZATION_HXX
25 #define __SERIALIZATION_HXX
26 
27 #include <map>
28 
29 #include <sal/types.h>
30 #include <rtl/ustring.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/beans/NamedValue.hpp>
34 #include <com/sun/star/io/XInputStream.hpp>
35 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
36 #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
37 
38 namespace CSS = com::sun::star;
39 
40 /**
41 Serialize an XObject
42 */
43 
44 typedef std::map<rtl::OUString, rtl::OUString> PropMap;
45 
46 class CSerialization
47 {
48 protected:
49     CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment;
50     PropMap m_properties;
51 
52 public:
~CSerialization()53     virtual ~CSerialization() {}
54 
55     /**
56     sets the XObject that is to serialized
57     */
setSource(const CSS::uno::Reference<CSS::xml::dom::XDocumentFragment> & aFragment)58     virtual void setSource(const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
59     {
60         m_aFragment = aFragment;
61     }
62 
63     /**
64     set the properties from the submission element
65     that control aspects of the serialization
66     eachs serialization may support individual properties
67     */
setProperties(const CSS::uno::Sequence<CSS::beans::NamedValue> & props)68     void setProperties(const CSS::uno::Sequence< CSS::beans::NamedValue >& props)
69     {
70         m_properties.clear();
71         rtl::OUString aValue;
72         for (sal_Int32 i=0; i<props.getLength(); i++)
73         {
74             if (props[i].Value >>= aValue)
75                 m_properties.insert(PropMap::value_type(props[i].Name, aValue));
76         }
77     }
78 
79     /**
80     start the serialization process
81     */
82     virtual void serialize()=0;
83 
84     /**
85     get the serialized bytes.
86     reads up to buffer->getLength() bytes and returns the number of
87     bytes read.
88     returns -1 on error
89     */
90     virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream() = 0;
91 
92 };
93 
94 #endif
95