LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLPropertyBackpatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 76 35.5 %
Date: 2012-08-25 Functions: 10 23 43.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 154 7.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      30                 :            : #include <com/sun/star/uno/Reference.h>
      31                 :            : 
      32                 :            : #include <rtl/ustring.hxx>
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include "XMLPropertyBackpatcher.hxx"
      35                 :            : #include <xmloff/txtimp.hxx>    // XMLTextImportHelper partially implemented here
      36                 :            : 
      37                 :            : 
      38                 :            : using ::rtl::OUString;
      39                 :            : using ::std::vector;
      40                 :            : using ::std::map;
      41                 :            : using ::com::sun::star::uno::Reference;
      42                 :            : using ::com::sun::star::uno::Any;
      43                 :            : using ::com::sun::star::beans::XPropertySet;
      44                 :            : 
      45                 :            : 
      46                 :            : template<class A>
      47                 :          3 : XMLPropertyBackpatcher<A>::XMLPropertyBackpatcher(
      48                 :            :     const ::rtl::OUString& sPropName)
      49                 :            : :   sPropertyName(sPropName)
      50                 :            : ,   bDefaultHandling(sal_False)
      51                 :            : ,   bPreserveProperty(sal_False)
      52 [ #  # ][ #  # ]:          3 : ,   sPreservePropertyName()
         [ +  - ][ +  - ]
      53                 :            : {
      54                 :          3 : }
      55                 :            : 
      56                 :            : 
      57                 :            : template<class A>
      58                 :          3 : XMLPropertyBackpatcher<A>::~XMLPropertyBackpatcher()
      59                 :            : {
      60 [ #  # ][ +  - ]:          3 :     SetDefault();
      61                 :          3 : }
      62                 :            : 
      63                 :            : 
      64                 :            : template<class A>
      65                 :          3 : void XMLPropertyBackpatcher<A>::ResolveId(
      66                 :            :     const OUString& sName,
      67                 :            :     A aValue)
      68                 :            : {
      69                 :            :     // insert ID into ID map
      70                 :          3 :     aIDMap[sName] = aValue;
      71                 :            : 
      72                 :            :     // backpatch old references, if backpatch list exists
      73   [ #  #  -  + ]:          3 :     if (aBackpatchListMap.count(sName))
      74                 :            :     {
      75                 :            :         // aah, we have a backpatch list!
      76                 :            :         BackpatchListType* pList =
      77 [ #  # ][ #  # ]:          0 :             (BackpatchListType*)aBackpatchListMap[sName];
      78                 :            : 
      79                 :            :         // a) remove list from list map
      80 [ #  # ][ #  # ]:          0 :         aBackpatchListMap.erase(sName);
      81                 :            : 
      82                 :            :         // b) for every item, set SequenceNumber
      83                 :            :         //    (and preserve Property, if appropriate)
      84                 :          0 :         Any aAny;
      85   [ #  #  #  # ]:          0 :         aAny <<= aValue;
      86 [ #  # ][ #  # ]:          0 :         if (bPreserveProperty)
      87                 :            :         {
      88                 :            :             // preserve version
      89 [ #  # ][ #  # ]:          0 :             for(BackpatchListType::iterator aIter = pList->begin();
         [ #  # ][ #  # ]
      90                 :            :                 aIter != pList->end();
      91                 :            :                 ++aIter)
      92                 :            :             {
      93                 :          0 :                 Reference<XPropertySet> xProp = (*aIter);
      94   [ #  #  #  # ]:          0 :                 Any aPres = xProp->getPropertyValue(sPreservePropertyName);
         [ #  # ][ #  # ]
      95 [ #  # ][ #  # ]:          0 :                 xProp->setPropertyValue(sPropertyName, aAny);
         [ #  # ][ #  # ]
      96 [ #  # ][ #  # ]:          0 :                 xProp->setPropertyValue(sPreservePropertyName, aPres);
         [ #  # ][ #  # ]
      97                 :            :             }
      98                 :            :         }
      99                 :            :         else
     100                 :            :         {
     101                 :            :             // without preserve
     102 [ #  # ][ #  # ]:          0 :             for(BackpatchListType::iterator aIter = pList->begin();
         [ #  # ][ #  # ]
     103                 :            :                 aIter != pList->end();
     104                 :            :                 ++aIter)
     105                 :            :             {
     106 [ #  # ][ #  # ]:          0 :                 (*aIter)->setPropertyValue(sPropertyName, aAny);
         [ #  # ][ #  # ]
     107                 :            :             }
     108                 :            :         }
     109                 :            : 
     110                 :            :         // c) delete list
     111 [ #  # ][ #  # ]:          0 :         delete pList;
     112                 :            :     }
     113                 :            :     // else: no backpatch list -> then we're finished
     114                 :          3 : }
     115                 :            : 
     116                 :            : template<class A>
     117                 :          0 : void XMLPropertyBackpatcher<A>::SetProperty(
     118                 :            :     const Reference<XPropertySet> & xPropSet,
     119                 :            :     const OUString& sName)
     120                 :            : {
     121                 :          0 :     Reference<XPropertySet> xNonConstPropSet(xPropSet);
     122 [ #  # ][ #  # ]:          0 :     SetProperty(xNonConstPropSet, sName);
     123                 :          0 : }
     124                 :            : 
     125                 :            : template<class A>
     126                 :          0 : void XMLPropertyBackpatcher<A>::SetProperty(
     127                 :            :     Reference<XPropertySet> & xPropSet,
     128                 :            :     const OUString& sName)
     129                 :            : {
     130 [ #  # ][ #  # ]:          0 :     if (aIDMap.count(sName))
     131                 :            :     {
     132                 :            :         // we know this ID -> set property
     133                 :          0 :         Any aAny;
     134   [ #  #  #  # ]:          0 :         aAny <<= aIDMap[sName];
         [ #  # ][ #  # ]
     135 [ #  # ][ #  # ]:          0 :         xPropSet->setPropertyValue(sPropertyName, aAny);
         [ #  # ][ #  # ]
     136                 :            :     }
     137                 :            :     else
     138                 :            :     {
     139                 :            :         // ID unknown -> into backpatch list for later fixup
     140 [ #  # ][ #  # ]:          0 :         if (! aBackpatchListMap.count(sName))
     141                 :            :         {
     142                 :            :             // create backpatch list for this name
     143 [ #  # ][ #  # ]:          0 :             BackpatchListType* pTmp = new BackpatchListType() ;
     144                 :          0 :             aBackpatchListMap[sName] = (void*)pTmp;
     145                 :            :         }
     146                 :            : 
     147                 :            :         // insert footnote
     148                 :          0 :         ((BackpatchListType*)aBackpatchListMap[sName])->push_back(xPropSet);
     149                 :            :     }
     150                 :          0 : }
     151                 :            : 
     152                 :            : template<class A>
     153                 :          3 : void XMLPropertyBackpatcher<A>::SetDefault()
     154                 :            : {
     155                 :          3 :     if (bDefaultHandling)
     156                 :            :     {
     157                 :            :         // not implemented yet
     158                 :            :     }
     159                 :          3 : }
     160                 :            : 
     161                 :            : // force instantiation of templates
     162                 :            : template class XMLPropertyBackpatcher<sal_Int16>;
     163                 :            : template class XMLPropertyBackpatcher<OUString>;
     164                 :            : 
     165 [ +  - ][ +  - ]:        964 : struct SAL_DLLPRIVATE XMLTextImportHelper::BackpatcherImpl
     166                 :            : {
     167                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     168                 :            :     /// backpatcher for references to footnotes and endnotes
     169                 :            :     ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> >
     170                 :            :         m_pFootnoteBackpatcher;
     171                 :            : 
     172                 :            :     /// backpatchers for references to sequences
     173                 :            :     ::std::auto_ptr< XMLPropertyBackpatcher<sal_Int16> >
     174                 :            :         m_pSequenceIdBackpatcher;
     175                 :            : 
     176                 :            :     ::std::auto_ptr< XMLPropertyBackpatcher< ::rtl::OUString> >
     177                 :            :         m_pSequenceNameBackpatcher;
     178                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     179                 :            : };
     180                 :            : 
     181                 :            : ::boost::shared_ptr<XMLTextImportHelper::BackpatcherImpl>
     182                 :        482 : XMLTextImportHelper::MakeBackpatcherImpl()
     183                 :            : {
     184                 :            :     // n.b.: the shared_ptr stores the dtor!
     185         [ +  - ]:        482 :     return ::boost::shared_ptr<BackpatcherImpl>(new BackpatcherImpl);
     186                 :            : }
     187                 :            : 
     188                 :          3 : static ::rtl::OUString const& GetSequenceNumber()
     189                 :            : {
     190                 :            :     static ::rtl::OUString s_SequenceNumber(
     191 [ +  - ][ +  - ]:          3 :         RTL_CONSTASCII_USTRINGPARAM("SequenceNumber"));
         [ +  - ][ #  # ]
     192                 :          3 :     return s_SequenceNumber;
     193                 :            : }
     194                 :            : 
     195                 :            : //
     196                 :            : // XMLTextImportHelper
     197                 :            : //
     198                 :            : // Code from XMLTextImportHelper using the XMLPropertyBackpatcher is
     199                 :            : // implemented here. The reason is that in the unxsols2 environment,
     200                 :            : // all templates are instatiated as file local (switch
     201                 :            : // -instances=static), and thus are not accessible from the outside.
     202                 :            : //
     203                 :            : // The previous solution was to force additional instantiation of
     204                 :            : // XMLPropertyBackpatcher in txtimp.cxx. This solution combines all
     205                 :            : // usage of the XMLPropertyBackpatcher in XMLPropertyBackpatcher.cxx
     206                 :            : // instead.
     207                 :            : //
     208                 :            : 
     209                 :          3 : XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetFootnoteBP()
     210                 :            : {
     211         [ +  - ]:          3 :     if (!m_pBackpatcherImpl->m_pFootnoteBackpatcher.get())
     212                 :            :     {
     213                 :          3 :         m_pBackpatcherImpl->m_pFootnoteBackpatcher.reset(
     214         [ +  - ]:          6 :             new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber()));
     215                 :            :     }
     216                 :          3 :     return *m_pBackpatcherImpl->m_pFootnoteBackpatcher;
     217                 :            : }
     218                 :            : 
     219                 :          0 : XMLPropertyBackpatcher<sal_Int16>& XMLTextImportHelper::GetSequenceIdBP()
     220                 :            : {
     221         [ #  # ]:          0 :     if (!m_pBackpatcherImpl->m_pSequenceIdBackpatcher.get())
     222                 :            :     {
     223                 :          0 :         m_pBackpatcherImpl->m_pSequenceIdBackpatcher.reset(
     224         [ #  # ]:          0 :             new XMLPropertyBackpatcher<sal_Int16>(GetSequenceNumber()));
     225                 :            :     }
     226                 :          0 :     return *m_pBackpatcherImpl->m_pSequenceIdBackpatcher;
     227                 :            : }
     228                 :            : 
     229                 :          0 : XMLPropertyBackpatcher<OUString>& XMLTextImportHelper::GetSequenceNameBP()
     230                 :            : {
     231                 :            :     static ::rtl::OUString s_SourceName(
     232 [ #  # ][ #  # ]:          0 :         RTL_CONSTASCII_USTRINGPARAM("SourceName"));
         [ #  # ][ #  # ]
     233         [ #  # ]:          0 :     if (!m_pBackpatcherImpl->m_pSequenceNameBackpatcher.get())
     234                 :            :     {
     235                 :          0 :         m_pBackpatcherImpl->m_pSequenceNameBackpatcher.reset(
     236         [ #  # ]:          0 :             new XMLPropertyBackpatcher<OUString>(s_SourceName));
     237                 :            :     }
     238                 :          0 :     return *m_pBackpatcherImpl->m_pSequenceNameBackpatcher;
     239                 :            : }
     240                 :            : 
     241                 :          3 : void XMLTextImportHelper::InsertFootnoteID(
     242                 :            :     const OUString& sXMLId,
     243                 :            :     sal_Int16 nAPIId)
     244                 :            : {
     245                 :          3 :     GetFootnoteBP().ResolveId(sXMLId, nAPIId);
     246                 :          3 : }
     247                 :            : 
     248                 :          0 : void XMLTextImportHelper::ProcessFootnoteReference(
     249                 :            :     const OUString& sXMLId,
     250                 :            :     const Reference<XPropertySet> & xPropSet)
     251                 :            : {
     252                 :          0 :     GetFootnoteBP().SetProperty(xPropSet, sXMLId);
     253                 :          0 : }
     254                 :            : 
     255                 :          0 : void XMLTextImportHelper::InsertSequenceID(
     256                 :            :     const OUString& sXMLId,
     257                 :            :     const OUString& sName,
     258                 :            :     sal_Int16 nAPIId)
     259                 :            : {
     260                 :          0 :     GetSequenceIdBP().ResolveId(sXMLId, nAPIId);
     261 [ #  # ][ #  # ]:          0 :     GetSequenceNameBP().ResolveId(sXMLId, sName);
     262                 :          0 : }
     263                 :            : 
     264                 :          0 : void XMLTextImportHelper::ProcessSequenceReference(
     265                 :            :     const OUString& sXMLId,
     266                 :            :     const Reference<XPropertySet> & xPropSet)
     267                 :            : {
     268                 :          0 :     GetSequenceIdBP().SetProperty(xPropSet, sXMLId);
     269                 :          0 :     GetSequenceNameBP().SetProperty(xPropSet, sXMLId);
     270                 :          0 : }
     271                 :            : 
     272                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10