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

Generated by: LCOV version 1.10