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