1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __SERIALIZATION_HXX
29 #define __SERIALIZATION_HXX
30 
31 #include <map>
32 
33 #include <sal/types.h>
34 #include <rtl/ustring.hxx>
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <com/sun/star/io/XInputStream.hpp>
39 #include <com/sun/star/xml/xpath/XXPathObject.hpp>
40 #include <com/sun/star/xml/dom/XDocumentFragment.hpp>
41 
42 namespace CSS = com::sun::star;
43 
44 /**
45 Serialize an XObject
46 */
47 
48 typedef std::map<rtl::OUString, rtl::OUString> PropMap;
49 
50 class CSerialization
51 {
52 protected:
53     CSS::uno::Reference< CSS::xml::dom::XDocumentFragment > m_aFragment;
54     PropMap m_properties;
55 
56 public:
57     virtual ~CSerialization() {}
58 
59     /**
60     sets the XObject that is to serialized
61     */
62     virtual void setSource(const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
63     {
64         m_aFragment = aFragment;
65     }
66 
67     /**
68     set the properties from the submission element
69     that control aspects of the serialization
70     eachs serialization may support individual properties
71     */
72     void setProperties(const CSS::uno::Sequence< CSS::beans::NamedValue >& props)
73     {
74         m_properties.clear();
75         rtl::OUString aValue;
76         for (sal_Int32 i=0; i<props.getLength(); i++)
77         {
78             if (props[i].Value >>= aValue)
79                 m_properties.insert(PropMap::value_type(props[i].Name, aValue));
80         }
81     }
82 
83     /**
84     start the serialization process
85     */
86     virtual void serialize()=0;
87 
88     /**
89     get the serialized bytes.
90     reads up to buffer->getLength() bytes and returns the number of
91     bytes read.
92     returns -1 on error
93     */
94     virtual CSS::uno::Reference< CSS::io::XInputStream > getInputStream() = 0;
95 
96 };
97 
98 #endif
99