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