Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _CONVERT_HXX
21 : #define _CONVERT_HXX
22 :
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <map>
25 :
26 : namespace com { namespace sun { namespace star { namespace uno
27 : {
28 : class Any;
29 : class Type;
30 : } } } }
31 : namespace rtl { class OUString; }
32 :
33 : namespace xforms
34 : {
35 :
36 : struct TypeLess
37 : {
38 0 : bool operator()( const com::sun::star::uno::Type& rType1,
39 : const com::sun::star::uno::Type& rType2 ) const
40 0 : { return rType1.getTypeName() < rType2.getTypeName(); }
41 : };
42 :
43 : class Convert
44 : {
45 : typedef com::sun::star::uno::Type Type_t;
46 : typedef com::sun::star::uno::Sequence<com::sun::star::uno::Type> Types_t;
47 : typedef com::sun::star::uno::Any Any_t;
48 :
49 : // hold conversion objects
50 : typedef rtl::OUString (*fn_toXSD)( const Any_t& );
51 : typedef Any_t (*fn_toAny)( const rtl::OUString& );
52 : typedef std::pair<fn_toXSD,fn_toAny> Convert_t;
53 : typedef std::map<Type_t,Convert_t,TypeLess> Map_t;
54 : Map_t maMap;
55 :
56 : Convert();
57 :
58 : void init();
59 :
60 : public:
61 : /** get/create Singleton class */
62 : static Convert& get();
63 :
64 : /// can we convert this type?
65 : bool hasType( const Type_t& );
66 :
67 : /// get list of convertable types
68 : Types_t getTypes();
69 :
70 : /// convert any to XML representation
71 : rtl::OUString toXSD( const Any_t& rAny );
72 :
73 : /// convert XML representation to Any of given type
74 : Any_t toAny( const rtl::OUString&, const Type_t& );
75 :
76 : /** translates the whitespaces in a given string, according
77 : to a given <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type>.
78 :
79 : @param _rString
80 : the string to convert
81 : @param _nWhitespaceTreatment
82 : a constant from the <type scope="com::sun::star::xsd">WhiteSpaceTreatment</type> group, specifying
83 : how to handle whitespaces
84 : @return
85 : the converted string
86 : */
87 : static ::rtl::OUString convertWhitespace(
88 : const ::rtl::OUString& _rString,
89 : sal_Int16 _nWhitespaceTreatment
90 : );
91 :
92 : /** replace all occurrences 0x08, 0x0A, 0x0D with 0x20
93 : */
94 : static ::rtl::OUString replaceWhitespace( const ::rtl::OUString& _rString );
95 :
96 : /** replace all sequences of 0x08, 0x0A, 0x0D, 0x20 with a single 0x20.
97 : also strip leading/trailing whitespace.
98 : */
99 : static ::rtl::OUString collapseWhitespace( const ::rtl::OUString& _rString );
100 : };
101 :
102 : } // namespace xforms
103 :
104 : #endif
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|