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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <tools/debug.hxx>
31 #include <xmloff/EnumPropertyHdl.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <comphelper/extract.hxx>
34 #include <rtl/ustring.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 
41 using namespace ::com::sun::star::uno;
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 //
45 // class XMLEnumPropertyHdl
46 //
47 
48 XMLEnumPropertyHdl::~XMLEnumPropertyHdl()
49 {
50 	// Nothing to do
51 }
52 
53 sal_Bool XMLEnumPropertyHdl::importXML( const OUString& rStrImpValue, Any& rValue, const SvXMLUnitConverter& ) const
54 {
55 	sal_uInt16 nValue = 0;
56 
57 	if( SvXMLUnitConverter::convertEnum( nValue, rStrImpValue, mpEnumMap ) )
58 	{
59 		switch( mrType.getTypeClass() )
60 		{
61 		case TypeClass_ENUM:
62 			rValue = ::cppu::int2enum( nValue, mrType );
63 			break;
64 		case TypeClass_LONG:
65 			rValue <<= (sal_Int32) nValue;
66 			break;
67 		case TypeClass_SHORT:
68 			rValue <<= (sal_Int16) nValue;
69 			break;
70 		case TypeClass_BYTE:
71 			rValue <<= (sal_Int8) nValue;
72 			break;
73 		default:
74 			DBG_ERROR( "Wrong type for enum property handler!" );
75 			return sal_False;
76 		}
77 		return sal_True;
78 	}
79 
80 	return sal_False;
81 }
82 
83 sal_Bool XMLEnumPropertyHdl::exportXML( OUString& rStrExpValue, const Any& rValue, const SvXMLUnitConverter& ) const
84 {
85 	sal_Int32 nValue = 0;
86 	if(!(rValue >>= nValue ))
87 		if(!::cppu::enum2int(nValue, rValue) )
88 			return sal_False;
89 
90 	OUStringBuffer aOut;
91 
92 	if(!SvXMLUnitConverter::convertEnum( aOut, nValue, mpEnumMap ))
93 		return sal_False;
94 
95 	rStrExpValue = aOut.makeStringAndClear();
96 	return sal_True;
97 }
98 
99