LCOV - code coverage report
Current view: top level - xmloff/source/forms - propertyimport.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 10 15 66.7 %
Date: 2014-11-03 Functions: 8 14 57.1 %
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_PROPERTYIMPORT_HXX
      21             : #define INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <set>
      26             : 
      27             : #include <xmloff/xmlictxt.hxx>
      28             : #include "formattributes.hxx"
      29             : #include <rtl/ref.hxx>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : #include "layerimport.hxx"
      32             : 
      33             : namespace com { namespace sun { namespace star { namespace util {
      34             :     struct Time;
      35             :     struct Date;
      36             : } } } }
      37             : 
      38             : namespace xmloff
      39             : {
      40             : 
      41             :     //= PropertyConversion
      42             :     class PropertyConversion
      43             :     {
      44             :     public:
      45             :         static ::com::sun::star::uno::Any convertString(
      46             :             const ::com::sun::star::uno::Type& _rExpectedType,
      47             :             const OUString& _rReadCharacters,
      48             :             const SvXMLEnumMapEntry* _pEnumMap = NULL,
      49             :             const bool _bInvertBoolean = false
      50             :         );
      51             : 
      52             :         static ::com::sun::star::uno::Type xmlTypeToUnoType( const OUString& _rType );
      53             :     };
      54             : 
      55             :     class OFormLayerXMLImport_Impl;
      56             :     //= OPropertyImport
      57             :     /** Helper class for importing property values
      58             : 
      59             :         <p>This class imports properties which are stored as attributes as well as properties which
      60             :         are stored in </em>&lt;form:properties&gt;</em> elements.</p>
      61             :     */
      62          76 :     class OPropertyImport : public SvXMLImportContext
      63             :     {
      64             :         friend class OSinglePropertyContext;
      65             :         friend class OListPropertyContext;
      66             : 
      67             :     protected:
      68             :         typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray;
      69             :         PropertyValueArray          m_aValues;
      70             :         PropertyValueArray          m_aGenericValues;
      71             :             // the values which the instance collects between StartElement and EndElement
      72             : 
      73             :         typedef std::set<OUString> StringSet;
      74             :         StringSet                   m_aEncounteredAttributes;
      75             : 
      76             :         OFormLayerXMLImport_Impl&       m_rContext;
      77             : 
      78             :         bool                    m_bTrackAttributes;
      79             : 
      80             :         // TODO: think about the restriction that the class does not know anything about the object it is importing.
      81             :         // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as
      82             :         // style properties) can be done in our own EndElement instead of letting derived classes do this.
      83             : 
      84             :     public:
      85             :         OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const OUString& _rName);
      86             : 
      87             :         virtual SvXMLImportContext* CreateChildContext(
      88             :             sal_uInt16 _nPrefix, const OUString& _rLocalName,
      89             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
      90             : 
      91             :         virtual void StartElement(
      92             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
      93             :         virtual void Characters(const OUString& _rChars) SAL_OVERRIDE;
      94             : 
      95             :     protected:
      96             :         /** handle one single attribute.
      97             : 
      98             :             <p>This is called for every attribute of the element. This class' implementaion checks if the attribute
      99             :             describes a property, if so, it is added to <member>m_aValues</member>.</p>
     100             : 
     101             :             <p>All non-property attributes should be handled in derived classes.</p>
     102             : 
     103             :             @param _nNamespaceKey
     104             :                 key of the namespace used in the attribute
     105             :             @param _rLocalName
     106             :                 local (relative to the namespace) attribute name
     107             :             @param _rValue
     108             :                 attribute value
     109             :         */
     110             :         virtual bool handleAttribute(sal_uInt16 _nNamespaceKey,
     111             :             const OUString& _rLocalName,
     112             :             const OUString& _rValue);
     113             : 
     114             :         /** determine if the element imported by the object had an given attribute.
     115             :             <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
     116             :             All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
     117             :         */
     118             :         bool    encounteredAttribute(const OUString& _rAttributeName) const;
     119             : 
     120             :         /** determine if the element imported by the object had an given attribute.
     121             :             <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace.
     122             :             All form relevant attributes are in the same namespace, so this would be an redundant information.</p>
     123             :         */
     124             :         bool    encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(OUString::createFromAscii(_pAttributeName)); }
     125             : 
     126             :         /** enables the tracking of the encountered attributes
     127             :             <p>The tracking will raise the import costs a little bit, but it's cheaper than
     128             :             derived classes tracking this themself.</p>
     129             :         */
     130          56 :         void        enableTrackAttributes() { m_bTrackAttributes = true; }
     131             : 
     132         232 :         inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
     133             :         {
     134         232 :             m_aValues.push_back(_rProp);
     135         232 :         }
     136             : 
     137           0 :         inline void implPushBackPropertyValue( const OUString& _rName, const ::com::sun::star::uno::Any& _rValue )
     138             :         {
     139             :             m_aValues.push_back( ::com::sun::star::beans::PropertyValue(
     140           0 :                 _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) );
     141           0 :         }
     142             : 
     143         124 :         inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp)
     144             :         {
     145         124 :             m_aGenericValues.push_back(_rProp);
     146         124 :         }
     147             :     };
     148             :     typedef tools::SvRef<OPropertyImport> OPropertyImportRef;
     149             : 
     150             :     //= OPropertyElementsContext
     151             :     /** helper class for importing the &lt;form:properties&gt; element
     152             :     */
     153         148 :     class OPropertyElementsContext : public SvXMLImportContext
     154             :     {
     155             :     protected:
     156             :         OPropertyImportRef  m_xPropertyImporter;    // to add the properties
     157             : 
     158             :     public:
     159             :         OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     160             :                 const OPropertyImportRef& _rPropertyImporter);
     161             : 
     162             :         virtual SvXMLImportContext* CreateChildContext(
     163             :             sal_uInt16 _nPrefix, const OUString& _rLocalName,
     164             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
     165             : 
     166             : #if OSL_DEBUG_LEVEL > 0
     167             :         virtual void StartElement(
     168             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
     169             :         virtual void Characters(const OUString& _rChars) SAL_OVERRIDE;
     170             : #endif
     171             :     };
     172             : 
     173             :     //= OSinglePropertyContext
     174             :     /** helper class for importing a single &lt;form:property&gt; element
     175             :     */
     176         248 :     class OSinglePropertyContext : public SvXMLImportContext
     177             :     {
     178             :         OPropertyImportRef          m_xPropertyImporter;    // to add the properties
     179             : 
     180             :     public:
     181             :         OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     182             :                 const OPropertyImportRef& _rPropertyImporter);
     183             : 
     184             :         virtual SvXMLImportContext* CreateChildContext(
     185             :             sal_uInt16 _nPrefix, const OUString& _rLocalName,
     186             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
     187             : 
     188             :         virtual void StartElement(
     189             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
     190             :     };
     191             : 
     192             :     //= OListPropertyContext
     193           0 :     class OListPropertyContext : public SvXMLImportContext
     194             :     {
     195             :         OPropertyImportRef                  m_xPropertyImporter;
     196             :         OUString                     m_sPropertyName;
     197             :         OUString                     m_sPropertyType;
     198             :         ::std::vector< OUString >    m_aListValues;
     199             : 
     200             :     public:
     201             :         OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     202             :                 const OPropertyImportRef& _rPropertyImporter );
     203             : 
     204             :         virtual void StartElement(
     205             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList ) SAL_OVERRIDE;
     206             : 
     207             :         virtual void EndElement() SAL_OVERRIDE;
     208             : 
     209             :         virtual SvXMLImportContext* CreateChildContext(
     210             :             sal_uInt16 _nPrefix, const OUString& _rLocalName,
     211             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList) SAL_OVERRIDE;
     212             :     };
     213             : 
     214             :     //= OListValueContext
     215           0 :     class OListValueContext : public SvXMLImportContext
     216             :     {
     217             :         OUString& m_rListValueHolder;
     218             : 
     219             :     public:
     220             :         OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const OUString& _rName,
     221             :             OUString& _rListValueHolder );
     222             : 
     223             :         virtual void StartElement(
     224             :             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList ) SAL_OVERRIDE;
     225             :     };
     226             : 
     227             : }   // namespace xmloff
     228             : 
     229             : #endif // INCLUDED_XMLOFF_SOURCE_FORMS_PROPERTYIMPORT_HXX
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10