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 #include "precompiled_reportdesign.hxx"
24 #include "xmlImage.hxx"
25 #include "xmlfilter.hxx"
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include <xmloff/xmluconv.hxx>
30 #include "xmlEnums.hxx"
31 #include "xmlComponent.hxx"
32 #include "xmlReportElement.hxx"
33 #include "xmlControlProperty.hxx"
34 #include "xmlHelper.hxx"
35 #include <tools/debug.hxx>
36 #include <unotools/pathoptions.hxx>
37
38 #include <comphelper/componentcontext.hxx>
39 #include <com/sun/star/awt/ImageScaleMode.hpp>
40
41 namespace rptxml
42 {
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::xml::sax;
DBG_NAME(rpt_OXMLImage)46 DBG_NAME( rpt_OXMLImage )
47
48
49 // -----------------------------------------------------------------------------
50 OXMLImage::OXMLImage( ORptFilter& rImport,
51 sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
52 const Reference< XAttributeList > & _xAttrList
53 ,const Reference< XImageControl > & _xComponent
54 ,OXMLTable* _pContainer) :
55 OXMLReportElementBase( rImport, nPrfx, rLName,_xComponent.get(),_pContainer)
56 {
57 DBG_CTOR( rpt_OXMLImage,NULL);
58
59 OSL_ENSURE(m_xComponent.is(),"Component is NULL!");
60 const SvXMLNamespaceMap& rMap = m_rImport.GetNamespaceMap();
61 const SvXMLTokenMap& rTokenMap = m_rImport.GetControlElemTokenMap();
62 static const ::rtl::OUString s_sTRUE = ::xmloff::token::GetXMLToken(XML_TRUE);
63
64 const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
65 try
66 {
67 for(sal_Int16 i = 0; i < nLength; ++i)
68 {
69 ::rtl::OUString sLocalName;
70 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
71 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
72 /* const */ rtl::OUString sValue = _xAttrList->getValueByIndex( i );
73
74 switch( rTokenMap.Get( nPrefix, sLocalName ) )
75 {
76 case XML_TOK_IMAGE_DATA:
77 {
78 SvtPathOptions aPathOptions;
79 sValue = aPathOptions.SubstituteVariable(sValue);
80 _xComponent->setImageURL(rImport.GetAbsoluteReference( sValue ));
81 }
82
83 break;
84 case XML_TOK_PRESERVE_IRI:
85 _xComponent->setPreserveIRI(s_sTRUE == sValue);
86 break;
87 case XML_TOK_SCALE:
88 {
89 sal_uInt16 nRet = awt::ImageScaleMode::NONE;
90 if ( s_sTRUE == sValue )
91 {
92 nRet = awt::ImageScaleMode::ANISOTROPIC;
93 }
94 else
95 {
96 const SvXMLEnumMapEntry* aXML_EnumMap = OXMLHelper::GetImageScaleOptions();
97 SvXMLUnitConverter::convertEnum( nRet, sValue, aXML_EnumMap );
98 }
99 _xComponent->setScaleMode( nRet );
100 }
101 break;
102 case XML_TOK_DATA_FORMULA:
103 _xComponent->setDataField(ORptFilter::convertFormula(sValue));
104 break;
105 default:
106 break;
107 }
108 }
109 }
110 catch(Exception&)
111 {
112 OSL_ENSURE(0,"Exception catched while filling the image props");
113 }
114 }
115 // -----------------------------------------------------------------------------
116
~OXMLImage()117 OXMLImage::~OXMLImage()
118 {
119
120 DBG_DTOR( rpt_OXMLImage,NULL);
121 }
122 // -----------------------------------------------------------------------------
123
124 //----------------------------------------------------------------------------
125 } // namespace rptxml
126 // -----------------------------------------------------------------------------
127