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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include <tools/debug.hxx> 27 #include <xmloff/xmluconv.hxx> 28 #include <rtl/ustrbuf.hxx> 29 #include <com/sun/star/uno/Any.hxx> 30 #include <xmloff/XMLConstantsPropertyHandler.hxx> 31 32 using namespace ::com::sun::star::uno; 33 using ::rtl::OUString; 34 using ::rtl::OUStringBuffer; 35 36 using ::xmloff::token::XMLTokenEnum; 37 38 XMLConstantsPropertyHandler::XMLConstantsPropertyHandler( 39 const SvXMLEnumMapEntry *pM, 40 enum XMLTokenEnum eDflt ) : 41 pMap( pM ), 42 eDefault( eDflt ) 43 { 44 } 45 46 XMLConstantsPropertyHandler::~XMLConstantsPropertyHandler() 47 { 48 } 49 50 sal_Bool XMLConstantsPropertyHandler::importXML( 51 const OUString& rStrImpValue, 52 Any& rValue, 53 const SvXMLUnitConverter& ) const 54 { 55 sal_uInt16 nEnum; 56 sal_Bool bRet = SvXMLUnitConverter::convertEnum( 57 nEnum, rStrImpValue, pMap ); 58 59 if( bRet ) 60 rValue <<= (sal_Int16)nEnum; 61 62 return bRet; 63 } 64 65 sal_Bool XMLConstantsPropertyHandler::exportXML( 66 OUString& rStrExpValue, 67 const Any& rValue, 68 const SvXMLUnitConverter& ) const 69 { 70 OUStringBuffer aOut; 71 72 sal_Bool bRet = false; 73 74 sal_Int32 nEnum = 0; 75 76 if( rValue.hasValue() && (rValue.getValueTypeClass() == TypeClass_ENUM)) 77 { 78 nEnum = *((sal_Int32*)rValue.getValue()); 79 bRet = true; 80 } 81 else 82 { 83 bRet = (rValue >>= nEnum ); 84 } 85 86 if( bRet ) 87 { 88 if( (nEnum >= 0) && (nEnum <= 0xffff) ) 89 { 90 sal_uInt16 nConst = static_cast<sal_uInt16>( nEnum ); 91 92 bRet = SvXMLUnitConverter::convertEnum( 93 aOut, nConst, pMap, eDefault ); 94 95 rStrExpValue = aOut.makeStringAndClear(); 96 } 97 else 98 { 99 DBG_ERROR("XMLConstantsPropertyHandler::exportXML() constant is out of range for implementation using sal_uInt16"); 100 } 101 } 102 else 103 { 104 DBG_ERROR("XMLConstantsPropertyHandler::exportXML() could not convert any to sal_Int32"); 105 } 106 107 return bRet; 108 } 109 110