LCOV - code coverage report
Current view: top level - libreoffice/xmloff/source/forms - propertyexport.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 15 0.0 %
Date: 2012-12-27 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10