xref: /AOO41X/main/xmloff/source/style/csmaphdl.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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 <csmaphdl.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <com/sun/star/style/CaseMap.hpp>
31 #include <com/sun/star/uno/Any.hxx>
32 
33 using ::rtl::OUString;
34 using ::rtl::OUStringBuffer;
35 
36 using namespace ::com::sun::star;
37 using namespace ::xmloff::token;
38 
39 static SvXMLEnumMapEntry pXML_Casemap_Enum[] =
40 {
41     { XML_NONE,                 style::CaseMap::NONE },
42     { XML_CASEMAP_LOWERCASE,    style::CaseMap::LOWERCASE },
43     { XML_CASEMAP_UPPERCASE,    style::CaseMap::UPPERCASE },
44     { XML_CASEMAP_CAPITALIZE,   style::CaseMap::TITLE },
45     { XML_TOKEN_INVALID,        0 }
46 };
47 
48 ///////////////////////////////////////////////////////////////////////////////
49 //
50 // class XMLPosturePropHdl
51 //
52 
~XMLCaseMapPropHdl()53 XMLCaseMapPropHdl::~XMLCaseMapPropHdl()
54 {
55     // nothing to do
56 }
57 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const58 sal_Bool XMLCaseMapPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
59 {
60     sal_uInt16 nVal;
61     sal_Bool bRet = SvXMLUnitConverter::convertEnum(
62         nVal, rStrImpValue, pXML_Casemap_Enum );
63     if( ( bRet ) )
64         rValue <<= nVal;
65 
66     return bRet;
67 }
68 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const69 sal_Bool XMLCaseMapPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
70 {
71     sal_Bool bRet = sal_False;
72     sal_uInt16 nValue = sal_uInt16();
73     OUStringBuffer aOut;
74 
75     if( rValue >>= nValue )
76     {
77         bRet = SvXMLUnitConverter::convertEnum(
78             aOut, nValue, pXML_Casemap_Enum );
79         if( bRet )
80             rStrExpValue = aOut.makeStringAndClear();
81     }
82 
83     return bRet;
84 }
85 
86 ///////////////////////////////////////////////////////////////////////////////
87 //
88 // class XMLCaseMapVariantHdl
89 //
90 
~XMLCaseMapVariantHdl()91 XMLCaseMapVariantHdl::~XMLCaseMapVariantHdl()
92 {
93     // nothing to do
94 }
95 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const96 sal_Bool XMLCaseMapVariantHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
97 {
98     sal_Bool bRet = sal_False;
99 
100     if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
101     {
102         rValue <<= (sal_Int16)style::CaseMap::SMALLCAPS;
103         bRet = sal_True;
104     }
105     else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL ) )
106     {
107         rValue <<= (sal_Int16)style::CaseMap::NONE;
108         bRet = sal_True;
109     }
110 
111     return bRet;
112 }
113 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const114 sal_Bool XMLCaseMapVariantHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
115 {
116     sal_uInt16 nValue = sal_uInt16();
117     OUStringBuffer aOut;
118 
119     if( rValue >>= nValue )
120     {
121         switch( nValue )
122         {
123         case style::CaseMap::NONE:
124             aOut.append( GetXMLToken(XML_CASEMAP_NORMAL) );
125             break;
126         case style::CaseMap::SMALLCAPS:
127             aOut.append( GetXMLToken(XML_CASEMAP_SMALL_CAPS) );
128             break;
129         }
130     }
131 
132     rStrExpValue = aOut.makeStringAndClear();
133     return rStrExpValue.getLength() != 0;
134 }
135