LCOV - code coverage report
Current view: top level - include/xmloff - xmlprmap.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 21 22 95.5 %
Date: 2014-04-11 Functions: 12 12 100.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_XMLPRMAP_HXX
      21             : #define INCLUDED_XMLOFF_XMLPRMAP_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : #include <xmloff/dllapi.h>
      25             : #include <com/sun/star/uno/Sequence.hxx>
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : 
      29             : #include <vector>
      30             : #include <xmloff/uniref.hxx>
      31             : #include <xmloff/maptype.hxx>
      32             : #include <xmloff/xmltypes.hxx>
      33             : #include <xmloff/prhdlfac.hxx>
      34             : 
      35             : #include <tools/debug.hxx>
      36             : 
      37             : class SvXMLUnitConverter;
      38             : class XMLPropertyHandler;
      39             : 
      40             : 
      41             : 
      42             : /** Helper-class for XML-im/export:
      43             :     - Holds a pointer to a given array of XMLPropertyMapEntry
      44             :     - Provides several methods to access data from this array
      45             :     - Holds a Sequence of XML-names (for properties)
      46             :     - The filter takes all properties of the XPropertySet which are also
      47             :       in the XMLPropertyMapEntry and which are have not a default value
      48             :       and put them into a vector of XMLPropertyStae
      49             :     - this class knows how to compare, im/export properties
      50             : 
      51             :     Attention: At all methods, which get an index as parameter, there is no
      52             :                range validation to save runtime !!
      53             : */
      54     7123766 : struct XMLPropertySetMapperEntry_Impl
      55             : {
      56             :     OUString                           sXMLAttributeName;
      57             :     OUString                           sAPIPropertyName;
      58             :     sal_Int32                          nType;
      59             :     sal_uInt16                         nXMLNameSpace;
      60             :     sal_Int16                          nContextId;
      61             :     SvtSaveOptions::ODFDefaultVersion  nEarliestODFVersionForExport;
      62             :     bool                               bImportOnly;
      63             :     const XMLPropertyHandler          *pHdl;
      64             : 
      65             :     XMLPropertySetMapperEntry_Impl(
      66             :         const XMLPropertyMapEntry& rMapEntry,
      67             :         const UniReference< XMLPropertyHandlerFactory >& rFactory );
      68             : 
      69             :     XMLPropertySetMapperEntry_Impl(
      70             :         const XMLPropertySetMapperEntry_Impl& rEntry );
      71             : 
      72     6695444 :     sal_uInt32 GetPropType() const { return nType & XML_TYPE_PROP_MASK; }
      73             : };
      74             : 
      75             : class XMLOFF_DLLPUBLIC XMLPropertySetMapper : public UniRefBase
      76             : {
      77             :     ::std::vector< XMLPropertySetMapperEntry_Impl > aMapEntries;
      78             :     ::std::vector< UniReference < XMLPropertyHandlerFactory > > aHdlFactories;
      79             :     bool mbOnlyExportMappings;
      80             : 
      81             : public:
      82             :     /** The last element of the XMLPropertyMapEntry-array must contain NULL-values.
      83             : 
      84             :         @param  bForExport
      85             :                 If TRUE, only entries that have the mbImportOnly flag not set
      86             :                 will be in the mappings.
      87             :       */
      88             :     XMLPropertySetMapper(
      89             :             const XMLPropertyMapEntry* pEntries,
      90             :             const UniReference< XMLPropertyHandlerFactory >& rFactory,
      91             :             bool bForExport );
      92             :     virtual ~XMLPropertySetMapper();
      93             : 
      94             :     void AddMapperEntry( const UniReference < XMLPropertySetMapper >& rMapper );
      95             : 
      96             :     /** Return number of entries in input-array */
      97      239729 :     sal_Int32   GetEntryCount() const { return aMapEntries.size(); }
      98             : 
      99             :     /** Returns the flags of an entry */
     100     1819890 :     sal_uInt32 GetEntryFlags( sal_Int32 nIndex ) const
     101             :     {
     102             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     103     1819890 :         return aMapEntries[nIndex].nType & ~MID_FLAG_MASK;
     104             :     }
     105             : 
     106             :     /** Returns the type of an entry */
     107        7062 :     sal_uInt32 GetEntryType( sal_Int32 nIndex,
     108             :                              bool bWithFlags = true ) const
     109             :     {
     110             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     111        7062 :         sal_uInt32 nType = aMapEntries[nIndex].nType;
     112        7062 :         if( !bWithFlags )
     113           0 :             nType = nType & MID_FLAG_MASK;
     114        7062 :         return nType;
     115             :     }
     116             : 
     117             :     /** Returns the namespace-key of an entry */
     118       34297 :     sal_uInt16 GetEntryNameSpace( sal_Int32 nIndex ) const
     119             :     {
     120             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     121       34297 :         return aMapEntries[nIndex].nXMLNameSpace;
     122             :     }
     123             : 
     124             :     /** Returns the 'local' XML-name of the entry */
     125       34297 :     const OUString& GetEntryXMLName( sal_Int32 nIndex ) const
     126             :     {
     127             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     128       34297 :         return aMapEntries[nIndex].sXMLAttributeName;
     129             :     }
     130             : 
     131             :     /** Returns the entry API name */
     132     1788475 :     const OUString& GetEntryAPIName( sal_Int32 nIndex ) const
     133             :     {
     134             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     135     1788475 :         return aMapEntries[nIndex].sAPIPropertyName;
     136             :     }
     137             : 
     138             :     /** returns the entry context id. -1 is a valid index here. */
     139      476744 :     sal_Int16 GetEntryContextId( sal_Int32 nIndex ) const
     140             :     {
     141             :         DBG_ASSERT( (nIndex >= -1) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     142      476744 :         return nIndex == -1 ? 0 : aMapEntries[nIndex].nContextId;
     143             :     }
     144             : 
     145             :     /** returns the earliest odf version for which this property should be exported. */
     146      327506 :     SvtSaveOptions::ODFDefaultVersion GetEarliestODFVersionForExport( sal_Int32 nIndex ) const
     147             :     {
     148             :         DBG_ASSERT( (nIndex >= -1) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     149      327506 :         return nIndex == -1 ? SvtSaveOptions::ODFVER_UNKNOWN : aMapEntries[nIndex].nEarliestODFVersionForExport;
     150             :     }
     151             : 
     152             :     /** Returns the index of an entry with the given XML-name and namespace
     153             :         If there is no matching entry the method returns -1 */
     154             :     sal_Int32 GetEntryIndex( sal_uInt16 nNamespace,
     155             :                                    const OUString& rStrName,
     156             :                                    sal_uInt32 nPropType,
     157             :                                    sal_Int32 nStartAt = -1 ) const;
     158             : 
     159             :     /** Retrieves a PropertyHandler for that property which placed at nIndex in the XMLPropertyMapEntry-array */
     160       96991 :     const XMLPropertyHandler* GetPropertyHandler( sal_Int32 nIndex ) const
     161             :     {
     162             :         DBG_ASSERT( (nIndex >= 0) && (nIndex < (sal_Int32)aMapEntries.size() ), "illegal access to invalid entry!" );
     163       96991 :         return aMapEntries[nIndex].pHdl;
     164             :     }
     165             : 
     166             :     /** import/export
     167             :         This methods calls the respective im/export-method of the respective PropertyHandler. */
     168             :     virtual bool exportXML( OUString& rStrExpValue,
     169             :                                 const XMLPropertyState& rProperty,
     170             :                                 const SvXMLUnitConverter& rUnitConverter ) const;
     171             :     virtual bool importXML( const OUString& rStrImpValue,
     172             :                                 XMLPropertyState& rProperty,
     173             :                                 const SvXMLUnitConverter& rUnitConverter ) const;
     174             : 
     175             :     /** searches for an entry that matches the given api name, namespace and local name or -1 if nothing found */
     176             :     sal_Int32 FindEntryIndex( const sal_Char* sApiName,
     177             :                               sal_uInt16 nNameSpace,
     178             :                               const OUString& sXMLName ) const;
     179             : 
     180             :     /** searches for an entry that matches the given ContextId or gives -1 if nothing found */
     181             :     sal_Int32 FindEntryIndex( const sal_Int16 nContextId ) const;
     182             : 
     183             :     /** Remove an entry */
     184             :     void RemoveEntry( sal_Int32 nIndex );
     185             : };
     186             : 
     187             : #endif // INCLUDED_XMLOFF_XMLPRMAP_HXX
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10