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 _XMLOFF_FORMS_PROPERTYEXPORT_HXX_ 25 #define _XMLOFF_FORMS_PROPERTYEXPORT_HXX_ 26 27 #include "formattributes.hxx" 28 #include <comphelper/stl_types.hxx> 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 #include <com/sun/star/beans/XPropertyState.hpp> 31 #include <callbacks.hxx> 32 #include <xmloff/xmlexp.hxx> 33 #include "callbacks.hxx" 34 #include "strings.hxx" 35 36 //......................................................................... 37 namespace xmloff 38 { 39 //......................................................................... 40 41 #define BOOLATTR_DEFAULT_FALSE 0x00 42 #define BOOLATTR_DEFAULT_TRUE 0x01 43 #define BOOLATTR_DEFAULT_VOID 0x02 44 #define BOOLATTR_DEFAULT_MASK 0x03 45 46 #define BOOLATTR_INVERSE_SEMANTICS 0x04 47 // if sal_True, indicates that the semantic of the property referred by <arg>_pPropertyName</arg> 48 // is inverse to the semantic of the XML attribute.<br/> 49 // I.e. if the property value is <TRUE/>, <FALSE/> has to be written and vice versa. 50 // <p>Be careful with <arg>_bDefault</arg> and <arg>_bInverseSemantics</arg>: if <arg>_bInverseSemantics</arg> 51 // is <TRUE/>, the current property value is inverted <em>before</em> comparing it to the default.</p> 52 53 class IFormsExportContext; 54 //===================================================================== 55 //= OPropertyExport 56 //===================================================================== 57 /** provides export related tools for attribute handling 58 59 <p>(The name is somewhat misleading. It's not only a PropertyExport, but in real a ElementExport. 60 Anyway.)</p> 61 */ 62 class OPropertyExport 63 { 64 private: 65 DECLARE_STL_STDKEY_SET(::rtl::OUString, StringSet); 66 StringSet m_aRemainingProps; 67 // see examinePersistence 68 69 void exportRelativeTargetLocation(const ConstAsciiString& _sPropertyName,sal_Int32 _nProperty,bool _bAddType); 70 71 protected: 72 IFormsExportContext& m_rContext; 73 74 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > 75 m_xProps; 76 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > 77 m_xPropertyInfo; 78 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState > 79 m_xPropertyState; 80 81 // caching 82 ::rtl::OUString m_sValueTrue; 83 ::rtl::OUString m_sValueFalse; 84 85 public: 86 /** constructs an object capable of handling attributes for export 87 @param _rContext 88 the export context to which's attribute list the property translation should be added 89 @param m_xControl 90 the property set to be exported 91 */ 92 OPropertyExport(IFormsExportContext& _rContext, 93 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxProps); 94 95 protected: 96 /** examines a property set given for all properties which's value are to made persistent 97 98 <p>upon return the <method>m_aRemainingProps</method> will be filled with the names of all properties 99 which need to be stored</p> 100 */ 101 void examinePersistence(); 102 103 /** 104 */ 105 void exportRemainingProperties(); 106 107 /** indicates that a property has been handled by a derived class, without using the helper methods of this 108 class. 109 110 <p>Calling this method is necessary in case you use the suggested mechanism for the generic export of 111 properties. This means that you want to use <method>exportRemainingProperties</method>, which exports 112 all properties which need to ('cause they haven't been exported with one of the other type-specific 113 methods).</p> 114 115 <p>In this case you should call exportedProperty for every property you export yourself, so the property 116 will be flagged as <em>already handled</em></p> 117 */ exportedProperty(const::rtl::OUString & _rPropertyName)118 void exportedProperty(const ::rtl::OUString& _rPropertyName) 119 { m_aRemainingProps.erase(_rPropertyName); } 120 121 /** add an attribute which is represented by a string property to the export context 122 123 @param _nNamespaceKey 124 the key of the namespace to use for the attribute name. Is used with the namespace map 125 provided by the export context. 126 @param _pAttributeName 127 the name of the attribute to add. Must not contain any namespace 128 @param _pPropertyName 129 the name of the property to ask the control for 130 */ 131 void exportStringPropertyAttribute( 132 const sal_uInt16 _nNamespaceKey, 133 const sal_Char* _pAttributeName, 134 const ::rtl::OUString& _rPropertyName 135 ); 136 137 /** add an attribute which is represented by a boolean property to the export context 138 139 @param _nNamespaceKey 140 the key of the namespace to use for the attribute name. Is used with the namespace map 141 provided by the export context. 142 @param _pAttributeName 143 the name of the attribute to add. Must not contain any namespace (it's added automatically) 144 @param _pPropertyName 145 the name of the property to ask the control for 146 @param _nBooleanAttributeFlags 147 specifies the default and the "alignment" (inverse semantics) of the boolean property 148 */ 149 void exportBooleanPropertyAttribute( 150 const sal_uInt16 _nNamespaceKey, 151 const sal_Char* _pAttributeName, 152 const ::rtl::OUString& _rPropertyName, 153 const sal_Int8 _nBooleanAttributeFlags); 154 155 /** add an attribute which is represented by a sal_Int16 property to the export context 156 157 @param _nNamespaceKey 158 the key of the namespace to use for the attribute name. Is used with the namespace map 159 provided by the export context. 160 @param _pAttributeName 161 the name of the attribute to add. Must not contain any namespace (it's added automatically) 162 @param _pPropertyName 163 the name of the property to ask the control for 164 @param _nDefault 165 the default of the attribute. If the current property value equals this default, no 166 attribute is added. 167 */ 168 void exportInt16PropertyAttribute( 169 const sal_uInt16 _nNamespaceKey, 170 const sal_Char* _pAttributeName, 171 const ::rtl::OUString& _rPropertyName, 172 const sal_Int16 _nDefault); 173 174 /** add an attribute which is represented by a sal_Int32 property to the export context 175 176 @param _nNamespaceKey 177 the key of the namespace to use for the attribute name. Is used with the namespace map 178 provided by the export context. 179 @param _pAttributeName 180 the name of the attribute to add. Must not contain any namespace (it's added automatically) 181 @param _pPropertyName 182 the name of the property to ask the control for 183 @param _nDefault 184 the default of the attribute. If the current property value equals this default, no 185 attribute is added. 186 */ 187 void exportInt32PropertyAttribute( 188 const sal_uInt16 _nNamespaceKey, 189 const sal_Char* _pAttributeName, 190 const ::rtl::OUString& _rPropertyName, 191 const sal_Int32 _nDefault); 192 193 /** add an attribute which is represented by a enum property to the export context 194 195 @param _nNamespaceKey 196 the key of the namespace to use for the attribute name. Is used with the namespace map 197 provided by the export context. 198 @param _pAttributeName 199 the name of the attribute to add. Must not contain any namespace (it's added automatically) 200 @param _pPropertyName 201 the name of the property to ask the control for 202 @param _pValueMap 203 the map to use when converting the property value to an attribute value 204 @param _nDefault 205 the default of the attribute. If the current property value equals this default, no 206 attribute is added. 207 */ 208 void exportEnumPropertyAttribute( 209 const sal_uInt16 _nNamespaceKey, 210 const sal_Char* _pAttributeName, 211 const sal_Char* _pPropertyName, 212 const SvXMLEnumMapEntry* _pValueMap, 213 const sal_Int32 _nDefault, 214 const sal_Bool _bVoidDefault = sal_False); 215 216 // some very special methods for some very special attribute/property pairs 217 218 /** add the hlink:target-frame attribute to the export context. 219 220 <p>The value of this attribute is extracted from the TargetFrame property of the object given.</p> 221 222 <p>The property needs a special handling because conflicts between the default values for the attribute 223 and the property.</p> 224 */ 225 void exportTargetFrameAttribute(); 226 227 /** add the form:href attribute to the export context. 228 229 <p>The value of this attribute is extracted from the TargetURL property of the object given.</p> 230 231 <p>The property needs a special handling because the URL's need to be made relative</p> 232 233 <p>If _bAddType is set, an additional xlink:type="simple" attribute is also added.</p> 234 */ exportTargetLocationAttribute(bool _bAddType)235 inline void exportTargetLocationAttribute(bool _bAddType) { exportRelativeTargetLocation(PROPERTY_TARGETURL,CCA_TARGET_LOCATION,_bAddType); } 236 237 /** add the form:image attribute to the export context. 238 239 <p>The value of this attribute is extracted from the ImageURL property of the object given.</p> 240 241 <p>The property needs a special handling because the URL's need to be made relative</p> 242 */ exportImageDataAttribute()243 inline void exportImageDataAttribute() { exportRelativeTargetLocation(PROPERTY_IMAGEURL,CCA_IMAGE_DATA,false); } 244 245 /** flag the style properties as 'already exported' 246 247 <p>We don't have style support right now, so the only thing the method does is removing the style-relevant 248 properties from the list of yet-to-be-exported properties (<member>m_aRemainingProps</member>)</p> 249 */ 250 void flagStyleProperties(); 251 252 /** add an arbitrary attribute extracted from an arbitrary property to the export context 253 254 <p>The current value of the property specified with <arg>_pPropertyName</arg> is taken and converted 255 into a string, no matter what type it has. (Okay, there are the usual limitations: We know Date, Datetime, 256 double, integer ... to name just a few).</p> 257 258 <p>In case the property value is <NULL/> (void), no attribute is added</p> 259 260 <p>In case the property value is an empty string, and the property is a not allowed to be <NULL/> (void), 261 no attribute is added</p> 262 263 <p>In case the property value is a sequence of any type, no attribute is added, 'cause sequences can't be 264 transported as attribute. In the debug version, an additional assertion will occur if you nonetheless try 265 to do this.</p> 266 267 @param _nNamespaceKey 268 the key of the namespace to use for the attribute name. Is used with the namespace map 269 provided by the export context. 270 @param _pAttributeName 271 the name of the attribute to add. Must not contain any namespace (it's added automatically) 272 @param _pPropertyName 273 the name of the property to ask the object for 274 */ 275 void exportGenericPropertyAttribute( 276 const sal_uInt16 _nAttributeNamespaceKey, 277 const sal_Char* _pAttributeName, 278 const sal_Char* _pPropertyName); 279 280 /** exports a property value, which is a string sequence, as attribute 281 282 <p>The elements of the string sequence given are quoted and concatenated, with the characters used for 283 this to be chosen by the caller</p> 284 285 <p>If you use the quote character, no check (except assertions) is made if one of the list items 286 contains the quote character</p> 287 288 <p>If you don't use the quote character, no check (except assertions) is made if one of the list items 289 contains the separator character (which would be deadly when reimporting the string)</p> 290 291 @param _nNamespaceKey 292 the key of the namespace to use for the attribute name. Is used with the namespace map 293 provided by the export context. 294 @param _pAttributeName 295 the name of the attribute to add. Must not contain any namespace (it's added automatically) 296 @param _pPropertyName 297 the name of the property to ask the object for 298 @param _aQuoteCharacter 299 the character to use to quote the sequence elements with. May be 0, in this case no quoting happens 300 @param _aListSeparator 301 the character to use to separate the list entries 302 */ 303 void exportStringSequenceAttribute( 304 const sal_uInt16 _nAttributeNamespaceKey, 305 const sal_Char* _pAttributeName, 306 const ::rtl::OUString& _rPropertyName, 307 const sal_Unicode _aQuoteCharacter = '"', 308 const sal_Unicode _aListSeparator = ','); 309 310 /** determines whether the given property is to be exported 311 312 <p>Currently, the method simply checks whether the property's state is <em>not</em> PropertyState.DEFAULT, 313 or whether the property is a dynamic property (i.e. added via an <code>XPropertyContainer</code>). 314 So, take care when using the method - the heuristics is not applicable for all properties.</p> 315 */ 316 bool shouldExportProperty( const ::rtl::OUString& i_propertyName ) const; 317 318 /** tries to convert an arbitrary <type scope="com.sun:star.uno">Any</type> into an string 319 320 <p>If the type contained in the Any is not supported, the returned string will be empty. In the 321 debug version, an additional assertion occurs.</p> 322 323 @param _rValue 324 the value to convert 325 */ 326 ::rtl::OUString implConvertAny( 327 const ::com::sun::star::uno::Any& _rValue); 328 329 /** 330 @return 331 token which can be used in the <code>form:property</code> element's <code>type</code> attribute 332 to describe the type of a value.<br/> 333 Possible types returned are 334 <ul> 335 <li><b>boolean</b>: <arg>_rValue</arg> was interpreted as boolean value before converting 336 it into a string</li> 337 <li><b>float</b>: <arg>_rValue</arg> was interpreted as 64 bit floating point 16bit integer, 32bit integer or 64 bit integer value before 338 converting it into a string</li> 339 <li><b>string</b>: <arg>_rValue</arg> did not need any conversion as it already was a string</li> 340 </ul> 341 If the type is not convertable, float is returned 342 */ 343 ::xmloff::token::XMLTokenEnum implGetPropertyXMLType(const ::com::sun::star::uno::Type& _rType); 344 345 #ifdef DBG_UTIL 346 void AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue); 347 void AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue ); 348 void AddAttributeASCII( sal_uInt16 nPrefix, const sal_Char *pName, const sal_Char *pValue ); 349 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue); 350 void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue ); 351 #else 352 // in the product version, inline this, so it does not cost us extra time calling into our method AddAttribute(sal_uInt16 _nPrefix,const sal_Char * _pName,const::rtl::OUString & _rValue)353 inline void AddAttribute(sal_uInt16 _nPrefix, const sal_Char* _pName, const ::rtl::OUString& _rValue) 354 { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _pName, _rValue); } AddAttribute(sal_uInt16 _nPrefix,const::rtl::OUString & _rName,const::rtl::OUString & _rValue)355 inline void AddAttribute( sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, const ::rtl::OUString& _rValue ) 356 { m_rContext.getGlobalContext().AddAttribute( _nPrefix, _rName, _rValue ); } AddAttributeASCII(sal_uInt16 _nPrefix,const sal_Char * _pName,const sal_Char * pValue)357 inline void AddAttributeASCII( sal_uInt16 _nPrefix, const sal_Char* _pName, const sal_Char *pValue ) 358 { m_rContext.getGlobalContext().AddAttributeASCII(_nPrefix, _pName, pValue); } AddAttribute(sal_uInt16 _nPrefix,::xmloff::token::XMLTokenEnum _eName,const::rtl::OUString & _rValue)359 inline void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, const ::rtl::OUString& _rValue) 360 { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _rValue); } AddAttribute(sal_uInt16 _nPrefix,::xmloff::token::XMLTokenEnum _eName,::xmloff::token::XMLTokenEnum _eValue)361 inline void AddAttribute(sal_uInt16 _nPrefix, ::xmloff::token::XMLTokenEnum _eName, ::xmloff::token::XMLTokenEnum _eValue ) 362 { m_rContext.getGlobalContext().AddAttribute(_nPrefix, _eName, _eValue); } 363 #endif 364 365 #ifdef DBG_UTIL 366 protected: 367 /** check a given property set for the existence and type correctness of a given property 368 369 <p>This method is available in the non-product version only.</p> 370 371 @param _rPropertyName 372 the name of the property to ask the control model for 373 @param _pType 374 the expected type of the property. May be NULL, in this case no type check is made. 375 @return sal_True, if the property exists and is of the correct type 376 */ 377 void dbg_implCheckProperty( 378 const ::rtl::OUString& _rPropertyName, 379 const ::com::sun::star::uno::Type* _pType); 380 381 // void dbg_implCheckProperty( 382 // const sal_Char* _rPropertyName, 383 // const ::com::sun::star::uno::Type* _pType) 384 // { 385 // dbg_implCheckProperty(::rtl::OUString::createFromAscii(_rPropertyName), _pType); 386 // } 387 #endif 388 }; 389 390 //===================================================================== 391 //= helper 392 //===================================================================== 393 #ifdef DBG_UTIL 394 #define DBG_CHECK_PROPERTY(name, type) \ 395 dbg_implCheckProperty(name, &::getCppuType(static_cast< type* >(NULL))) 396 397 #define DBG_CHECK_PROPERTY_NO_TYPE(name) \ 398 dbg_implCheckProperty(name, NULL) 399 400 #define DBG_CHECK_PROPERTY_ASCII( name, type ) \ 401 dbg_implCheckProperty( ::rtl::OUString::createFromAscii( name ), &::getCppuType(static_cast< type* >(NULL))) 402 403 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) \ 404 dbg_implCheckProperty( ::rtl::OUString::createFromAscii( name ), NULL ) 405 #else 406 #define DBG_CHECK_PROPERTY(name, type) 407 #define DBG_CHECK_PROPERTY_NO_TYPE(name) 408 #define DBG_CHECK_PROPERTY_ASCII_NO_TYPE( name ) 409 #endif 410 411 //......................................................................... 412 } // namespace xmloff 413 //......................................................................... 414 415 #endif // _XMLOFF_FORMS_PROPERTYEXPORT_HXX_ 416 417 418