xref: /aoo41x/main/forms/source/xforms/convert.hxx (revision 2d785d7e)
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 _CONVERT_HXX
25cdf0e10cSrcweir #define _CONVERT_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
28cdf0e10cSrcweir #include <map>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace uno
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     class Any;
33cdf0e10cSrcweir     class Type;
34cdf0e10cSrcweir } } } }
35cdf0e10cSrcweir namespace rtl { class OUString; }
36cdf0e10cSrcweir class ConvertImpl;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace xforms
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir struct TypeLess
42cdf0e10cSrcweir {
operator ()xforms::TypeLess43cdf0e10cSrcweir     bool operator()( const com::sun::star::uno::Type& rType1,
44cdf0e10cSrcweir                      const com::sun::star::uno::Type& rType2 ) const
45cdf0e10cSrcweir     { return rType1.getTypeName() < rType2.getTypeName(); }
46cdf0e10cSrcweir };
47cdf0e10cSrcweir 
48cdf0e10cSrcweir class Convert
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     typedef com::sun::star::uno::Type Type_t;
51cdf0e10cSrcweir     typedef com::sun::star::uno::Sequence<com::sun::star::uno::Type> Types_t;
52cdf0e10cSrcweir     typedef com::sun::star::uno::Any Any_t;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     // hold conversion objects
55cdf0e10cSrcweir     typedef rtl::OUString (*fn_toXSD)( const Any_t& );
56cdf0e10cSrcweir     typedef Any_t (*fn_toAny)( const rtl::OUString& );
57cdf0e10cSrcweir     typedef std::pair<fn_toXSD,fn_toAny> Convert_t;
58cdf0e10cSrcweir     typedef std::map<Type_t,Convert_t,TypeLess> Map_t;
59cdf0e10cSrcweir     Map_t maMap;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     Convert();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     void init();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir     /** get/create Singleton class */
67cdf0e10cSrcweir     static Convert& get();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /// can we convert this type?
70cdf0e10cSrcweir     bool hasType( const Type_t& );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /// get list of convertable types
73cdf0e10cSrcweir     Types_t getTypes();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /// convert any to XML representation
76cdf0e10cSrcweir     rtl::OUString toXSD( const Any_t& rAny );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     /// convert XML representation to Any of given type
79cdf0e10cSrcweir     Any_t toAny( const rtl::OUString&, const Type_t& );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     /** translates the whitespaces in a given string, according
82cdf0e10cSrcweir         to a given <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type>.
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         @param _rString
85cdf0e10cSrcweir             the string to convert
86cdf0e10cSrcweir         @param _nWhitespaceTreatment
87cdf0e10cSrcweir             a constant from the <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type> group, specifying
88cdf0e10cSrcweir             how to handle whitespaces
89cdf0e10cSrcweir         @return
90cdf0e10cSrcweir             the converted string
91cdf0e10cSrcweir     */
92cdf0e10cSrcweir     static ::rtl::OUString convertWhitespace(
93cdf0e10cSrcweir             const ::rtl::OUString& _rString,
94cdf0e10cSrcweir             sal_Int16   _nWhitespaceTreatment
95cdf0e10cSrcweir     );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /** replace all occurences 0x08, 0x0A, 0x0D with 0x20
98cdf0e10cSrcweir     */
99cdf0e10cSrcweir     static ::rtl::OUString replaceWhitespace( const ::rtl::OUString& _rString );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /** replace all sequences of 0x08, 0x0A, 0x0D, 0x20 with a single 0x20.
102cdf0e10cSrcweir         also strip leading/trailing whitespace.
103cdf0e10cSrcweir     */
104cdf0e10cSrcweir     static ::rtl::OUString collapseWhitespace( const ::rtl::OUString& _rString );
105cdf0e10cSrcweir };
106cdf0e10cSrcweir 
107cdf0e10cSrcweir } // namespace xforms
108cdf0e10cSrcweir 
109cdf0e10cSrcweir #endif
110