LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextMarkImportContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 110 181 60.8 %
Date: 2012-08-25 Functions: 6 15 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 145 410 35.4 %

           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 "XMLTextMarkImportContext.hxx"
      30                 :            : 
      31                 :            : 
      32                 :            : #include <rtl/ustring.hxx>
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include <xmloff/xmluconv.hxx>
      35                 :            : #include <xmloff/xmltoken.hxx>
      36                 :            : #include <xmloff/xmlimp.hxx>
      37                 :            : #include <xmloff/nmspmap.hxx>
      38                 :            : #include "xmloff/xmlnmspe.hxx"
      39                 :            : #include <xmloff/odffields.hxx>
      40                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      41                 :            : #include <com/sun/star/text/XTextContent.hpp>
      42                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      43                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      44                 :            : #include <com/sun/star/container/XNamed.hpp>
      45                 :            : #include <com/sun/star/rdf/XMetadatable.hpp>
      46                 :            : 
      47                 :            : #include <com/sun/star/text/XFormField.hpp>
      48                 :            : 
      49                 :            : #include "RDFaImportHelper.hxx"
      50                 :            : 
      51                 :            : 
      52                 :            : using ::rtl::OUString;
      53                 :            : using ::rtl::OUStringBuffer;
      54                 :            : 
      55                 :            : using namespace ::com::sun::star;
      56                 :            : using namespace ::com::sun::star::text;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : using namespace ::com::sun::star::beans;
      59                 :            : using namespace ::com::sun::star::lang;
      60                 :            : using namespace ::com::sun::star::container;
      61                 :            : using namespace ::com::sun::star::xml::sax;
      62                 :            : using namespace ::xmloff::token;
      63                 :            : 
      64                 :            : using rtl::OUString;
      65                 :            : 
      66                 :            : 
      67                 :          0 : XMLFieldParamImportContext::XMLFieldParamImportContext(
      68                 :            :     SvXMLImport& rImport,
      69                 :            :     XMLTextImportHelper& rHlp,
      70                 :            :     sal_uInt16 nPrefix,
      71                 :            :     const OUString& rLocalName ) :
      72                 :            :         SvXMLImportContext(rImport, nPrefix, rLocalName),
      73                 :          0 :         rHelper(rHlp)
      74                 :            : {
      75                 :          0 : }
      76                 :            : 
      77                 :            : 
      78                 :          0 : void XMLFieldParamImportContext::StartElement(const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList> & xAttrList)
      79                 :            : {
      80                 :          0 :     SvXMLImport& rImport = GetImport();
      81                 :          0 :     ::rtl::OUString sName;
      82                 :          0 :     ::rtl::OUString sValue;
      83                 :            : 
      84 [ #  # ][ #  # ]:          0 :     sal_Int16 nLength = xAttrList->getLength();
      85         [ #  # ]:          0 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      86                 :            :     {
      87                 :          0 :         OUString sLocalName;
      88                 :          0 :         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
      89         [ #  # ]:          0 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      90   [ #  #  #  # ]:          0 :                               &sLocalName );
      91                 :            : 
      92 [ #  # ][ #  # ]:          0 :         if ( (XML_NAMESPACE_FIELD == nPrefix) &&
                 [ #  # ]
      93         [ #  # ]:          0 :              IsXMLToken(sLocalName, XML_NAME)   )
      94                 :            :         {
      95 [ #  # ][ #  # ]:          0 :             sName = xAttrList->getValueByIndex(nAttr);
      96                 :            :         }
      97 [ #  # ][ #  # ]:          0 :         if ( (XML_NAMESPACE_FIELD == nPrefix) &&
                 [ #  # ]
      98         [ #  # ]:          0 :              IsXMLToken(sLocalName, XML_VALUE)   )
      99                 :            :         {
     100 [ #  # ][ #  # ]:          0 :             sValue = xAttrList->getValueByIndex(nAttr);
     101                 :            :         }
     102                 :          0 :     }
     103 [ #  # ][ #  # ]:          0 :     if (rHelper.hasCurrentFieldCtx() && !sName.isEmpty()) {
         [ #  # ][ #  # ]
     104         [ #  # ]:          0 :         rHelper.addFieldParam(sName, sValue);
     105                 :          0 :     }
     106                 :          0 : }
     107                 :            : 
     108                 :            : 
     109 [ #  # ][ #  # ]:          0 : TYPEINIT1( XMLTextMarkImportContext, SvXMLImportContext);
     110                 :            : 
     111                 :       3835 : XMLTextMarkImportContext::XMLTextMarkImportContext(
     112                 :            :     SvXMLImport& rImport,
     113                 :            :     XMLTextImportHelper& rHlp,
     114                 :            :     sal_uInt16 nPrefix,
     115                 :            :     const OUString& rLocalName )
     116                 :            :     : SvXMLImportContext(rImport, nPrefix, rLocalName)
     117                 :            :     , m_rHelper(rHlp)
     118                 :       3835 :     , m_bHaveAbout(false)
     119                 :            : {
     120                 :       3835 : }
     121                 :            : 
     122                 :            : enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd,
     123                 :            :                     TypeBookmark, TypeBookmarkStart, TypeBookmarkEnd,
     124                 :            :                     TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd
     125                 :            :                   };
     126                 :            : 
     127                 :            : static SvXMLEnumMapEntry const lcl_aMarkTypeMap[] =
     128                 :            : {
     129                 :            :     { XML_REFERENCE_MARK,           TypeReference },
     130                 :            :     { XML_REFERENCE_MARK_START,     TypeReferenceStart },
     131                 :            :     { XML_REFERENCE_MARK_END,       TypeReferenceEnd },
     132                 :            :     { XML_BOOKMARK,                 TypeBookmark },
     133                 :            :     { XML_BOOKMARK_START,           TypeBookmarkStart },
     134                 :            :     { XML_BOOKMARK_END,             TypeBookmarkEnd },
     135                 :            :     { XML_FIELDMARK,                TypeFieldmark },
     136                 :            :     { XML_FIELDMARK_START,          TypeFieldmarkStart },
     137                 :            :     { XML_FIELDMARK_END,            TypeFieldmarkEnd },
     138                 :            :     { XML_TOKEN_INVALID,            0 },
     139                 :            : };
     140                 :            : 
     141                 :            : 
     142                 :         11 : static const char *lcl_getFormFieldmarkName(rtl::OUString &name)
     143                 :            : {
     144                 :            :     static const char sCheckbox[]=ODF_FORMCHECKBOX;
     145                 :            :     static const char sFormDropDown[]=ODF_FORMDROPDOWN;
     146   [ +  -  -  + ]:         22 :     if (name.compareToAscii("msoffice.field.FORMCHECKBOX")==0 ||
                 [ -  + ]
     147                 :         11 :             name.compareToAscii("ecma.office-open-xml.field.FORMCHECKBOX")==0)
     148                 :          0 :         return sCheckbox;
     149         [ -  + ]:         11 :     else if (name.compareToAscii(ODF_FORMCHECKBOX)==0)
     150                 :          0 :         return sCheckbox;
     151   [ +  -  -  + ]:         22 :     if (name.compareToAscii(ODF_FORMDROPDOWN)==0 ||
                 [ -  + ]
     152                 :         11 :             name.compareToAscii("ecma.office-open-xml.field.FORMDROPDOWN")==0)
     153                 :          0 :         return sFormDropDown;
     154                 :            :     else
     155                 :         11 :         return NULL;
     156                 :            : }
     157                 :            : 
     158                 :          0 : static rtl::OUString lcl_getFieldmarkName(rtl::OUString &name)
     159                 :            : {
     160                 :            :     static const char sFormtext[]=ODF_FORMTEXT;
     161   [ #  #  #  # ]:          0 :     if (name.compareToAscii("msoffice.field.FORMTEXT")==0 ||
                 [ #  # ]
     162                 :          0 :             name.compareToAscii("ecma.office-open-xml.field.FORMTEXT")==0)
     163                 :          0 :         return rtl::OUString::createFromAscii(sFormtext);
     164         [ #  # ]:          0 :     else if (name.compareToAscii(ODF_FORMTEXT)==0)
     165                 :          0 :         return rtl::OUString::createFromAscii(sFormtext);
     166                 :            :     else
     167                 :          0 :         return name;
     168                 :            : }
     169                 :            : 
     170                 :            : 
     171                 :       3835 : void XMLTextMarkImportContext::StartElement(
     172                 :            :     const Reference<XAttributeList> & xAttrList)
     173                 :            : {
     174         [ -  + ]:       3835 :     if (!FindName(GetImport(), xAttrList))
     175                 :            :     {
     176                 :          0 :         m_sBookmarkName = OUString();
     177                 :            :     }
     178                 :            : 
     179         [ -  + ]:       3835 :     if (IsXMLToken(GetLocalName(), XML_FIELDMARK_END))
     180                 :            :     {
     181                 :          0 :         m_sBookmarkName = m_rHelper.FindActiveBookmarkName();
     182                 :            :     }
     183                 :            : 
     184 [ +  - ][ -  + ]:       3835 :     if (IsXMLToken(GetLocalName(), XML_FIELDMARK_START) || IsXMLToken(GetLocalName(), XML_FIELDMARK))
                 [ -  + ]
     185                 :            :     {
     186         [ #  # ]:          0 :         if (m_sBookmarkName.isEmpty())
     187                 :            :         {
     188                 :          0 :             m_sBookmarkName = ::rtl::OUString("Unknown");
     189                 :            :         }
     190         [ #  # ]:          0 :         m_rHelper.pushFieldCtx( m_sBookmarkName, m_sFieldName );
     191                 :            :     }
     192                 :       3835 : }
     193                 :            : 
     194                 :       3835 : void XMLTextMarkImportContext::EndElement()
     195                 :            : {
     196                 :       3835 :     SvXMLImportContext::EndElement();
     197                 :            : 
     198 [ +  - ][ +  + ]:       3835 :     static const OUString sAPI_reference_mark( "com.sun.star.text.ReferenceMark");
     199 [ +  + ][ +  - ]:       3835 :     static const OUString sAPI_bookmark( "com.sun.star.text.Bookmark");
     200 [ +  + ][ +  - ]:       3835 :     static const OUString sAPI_fieldmark( "com.sun.star.text.Fieldmark");
     201 [ +  + ][ +  - ]:       3835 :     static const OUString sAPI_formfieldmark( "com.sun.star.text.FormFieldmark");
     202                 :            : 
     203         [ +  - ]:       3835 :     if (!m_sBookmarkName.isEmpty())
     204                 :            :     {
     205                 :            :         sal_uInt16 nTmp;
     206         [ +  - ]:       7670 :         if (SvXMLUnitConverter::convertEnum(nTmp, GetLocalName(),
     207         [ +  - ]:       3835 :                                             lcl_aMarkTypeMap))
     208                 :            :         {
     209   [ -  +  +  +  :       3835 :             switch ((lcl_MarkType)nTmp)
                   -  - ]
     210                 :            :             {
     211                 :            :                 case TypeReference:
     212                 :            :                     // export point reference mark
     213                 :          0 :                     CreateAndInsertMark(GetImport(),
     214                 :            :                         sAPI_reference_mark,
     215                 :            :                         m_sBookmarkName,
     216 [ #  # ][ #  # ]:          0 :                         m_rHelper.GetCursorAsRange()->getStart(),
     217   [ #  #  #  # ]:          0 :                         ::rtl::OUString());
     218                 :          0 :                     break;
     219                 :            : 
     220                 :            :                 case TypeFieldmark:
     221                 :            :                 case TypeBookmark:
     222                 :            :                     {
     223                 :         11 :                         const char *formFieldmarkName=lcl_getFormFieldmarkName(m_sFieldName);
     224 [ #  # ][ -  + ]:         11 :                         bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && formFieldmarkName!=NULL); //@TODO handle abbreviation cases..
     225                 :            :                         // export point bookmark
     226                 :            :                         const Reference<XInterface> xContent(
     227                 :         11 :                             CreateAndInsertMark(GetImport(),
     228                 :            :                                         (bImportAsField?sAPI_formfieldmark:sAPI_bookmark),
     229                 :            :                                 m_sBookmarkName,
     230 [ +  - ][ +  - ]:         11 :                                 m_rHelper.GetCursorAsRange()->getStart(),
     231 [ +  - ][ -  + ]:         22 :                                 m_sXmlId) );
                 [ +  - ]
     232         [ -  + ]:         11 :                         if ((lcl_MarkType)nTmp==TypeFieldmark) {
     233 [ #  # ][ #  # ]:          0 :                             if (xContent.is() && bImportAsField) {
                 [ #  # ]
     234                 :            :                                 // setup fieldmark...
     235         [ #  # ]:          0 :                                 Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
     236 [ #  # ][ #  # ]:          0 :                                 xFormField->setFieldType(rtl::OUString::createFromAscii(formFieldmarkName));
     237 [ #  # ][ #  # ]:          0 :                                 if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
         [ #  # ][ #  # ]
     238         [ #  # ]:          0 :                                     m_rHelper.setCurrentFieldParamsTo(xFormField);
     239                 :          0 :                                 }
     240                 :            :                             }
     241         [ #  # ]:          0 :                             m_rHelper.popFieldCtx();
     242                 :         11 :                         }
     243                 :            :                     }
     244                 :         11 :                     break;
     245                 :            : 
     246                 :            :                 case TypeFieldmarkStart:
     247                 :            :                 case TypeBookmarkStart:
     248                 :            :                     // save XTextRange for later construction of bookmark
     249                 :            :                     {
     250                 :            :                         ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes >
     251         [ +  - ]:       1912 :                             pRDFaAttributes;
     252 [ +  + ][ +  - ]:       1912 :                         if (m_bHaveAbout && (TypeBookmarkStart
     253                 :            :                                 == static_cast<lcl_MarkType>(nTmp)))
     254                 :            :                         {
     255                 :            :                             pRDFaAttributes =
     256         [ +  - ]:          8 :                                 GetImport().GetRDFaImportHelper().ParseRDFa(
     257                 :            :                                     m_sAbout, m_sProperty,
     258 [ +  - ][ +  - ]:          8 :                                     m_sContent, m_sDatatype);
                 [ +  - ]
     259                 :            :                         }
     260                 :            :                         m_rHelper.InsertBookmarkStartRange(
     261                 :            :                             m_sBookmarkName,
     262 [ +  - ][ +  - ]:       1912 :                             m_rHelper.GetCursorAsRange()->getStart(),
     263 [ +  - ][ +  - ]:       1912 :                             m_sXmlId, pRDFaAttributes);
                 [ +  - ]
     264                 :            :                     }
     265                 :       1912 :                     break;
     266                 :            : 
     267                 :            :                 case TypeFieldmarkEnd:
     268                 :            :                 case TypeBookmarkEnd:
     269                 :            :                 {
     270                 :            :                     // get old range, and construct
     271                 :       1912 :                     Reference<XTextRange> xStartRange;
     272                 :            :                     ::boost::shared_ptr< ::xmloff::ParsedRDFaAttributes >
     273         [ +  - ]:       1912 :                         pRDFaAttributes;
     274         [ +  - ]:       1912 :                     if (m_rHelper.FindAndRemoveBookmarkStartRange(
     275                 :            :                             m_sBookmarkName, xStartRange,
     276         [ +  - ]:       1912 :                             m_sXmlId, pRDFaAttributes))
     277                 :            :                     {
     278                 :            :                         Reference<XTextRange> xEndRange(
     279 [ +  - ][ +  - ]:       1912 :                             m_rHelper.GetCursorAsRange()->getStart());
                 [ +  - ]
     280                 :            : 
     281                 :            :                         // check if beginning and end are in same XText
     282 [ +  - ][ +  - ]:       1912 :                         if (xStartRange->getText() == xEndRange->getText())
         [ +  - ][ +  - ]
                 [ +  - ]
           [ +  -  #  # ]
     283                 :            :                         {
     284                 :            :                             // create range for insertion
     285                 :            :                             Reference<XTextCursor> xInsertionCursor =
     286 [ +  - ][ +  - ]:       1912 :                                 m_rHelper.GetText()->createTextCursorByRange(
     287         [ +  - ]:       1912 :                                     xEndRange);
     288                 :            :                             try {
     289 [ +  - ][ +  - ]:       1912 :                             xInsertionCursor->gotoRange(xStartRange, sal_True);
     290         [ #  # ]:          0 :                             } catch (uno::Exception&) {
     291                 :            :                                 OSL_ENSURE(false,
     292                 :            :                                     "cannot go to end position of bookmark");
     293                 :            :                             }
     294                 :            : 
     295                 :            :                             //DBG_ASSERT(! xInsertionCursor->isCollapsed(),
     296                 :            :                             //              "we want no point mark");
     297                 :            :                             // can't assert, because someone could
     298                 :            :                             // create a file with subsequence
     299                 :            :                             // start/end elements
     300                 :            : 
     301                 :            :                             Reference<XTextRange> xInsertionRange(
     302         [ +  - ]:       1912 :                                 xInsertionCursor, UNO_QUERY);
     303                 :            : 
     304 [ -  + ][ #  # ]:       1912 :                             bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmarkEnd && m_rHelper.hasCurrentFieldCtx());
                 [ #  # ]
     305                 :            : 
     306                 :            :                             // insert reference
     307                 :            :                             const Reference<XInterface> xContent(
     308                 :       1912 :                                 CreateAndInsertMark(GetImport(),
     309                 :            :                                                 (bImportAsField?sAPI_fieldmark:sAPI_bookmark),
     310                 :            :                                     m_sBookmarkName,
     311                 :            :                                     xInsertionRange,
     312 [ -  + ][ +  - ]:       3824 :                                     m_sXmlId) );
     313         [ +  + ]:       1912 :                             if (pRDFaAttributes)
     314                 :            :                             {
     315                 :            :                                 const Reference<rdf::XMetadatable>
     316         [ +  - ]:          8 :                                     xMeta(xContent, UNO_QUERY);
     317         [ +  - ]:          8 :                                 GetImport().GetRDFaImportHelper().AddRDFa(
     318         [ +  - ]:          8 :                                     xMeta, pRDFaAttributes);
     319                 :            :                             }
     320                 :            : 
     321         [ -  + ]:       1912 :                             if ((lcl_MarkType)nTmp==TypeFieldmarkEnd) {
     322 [ #  # ][ #  # ]:          0 :                                 if (xContent.is() && bImportAsField) {
                 [ #  # ]
     323                 :            :                                     // setup fieldmark...
     324         [ #  # ]:          0 :                                     Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
     325 [ #  # ][ #  # ]:          0 :                                     if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
         [ #  # ][ #  # ]
     326         [ #  # ]:          0 :                                         rtl::OUString givenTypeName=m_rHelper.getCurrentFieldType();
     327                 :          0 :                                         rtl::OUString fieldmarkTypeName=lcl_getFieldmarkName(givenTypeName);
     328                 :            : 
     329 [ #  # ][ #  # ]:          0 :                                         xFormField->setFieldType(fieldmarkTypeName);
     330         [ #  # ]:          0 :                                         m_rHelper.setCurrentFieldParamsTo(xFormField);
     331                 :          0 :                                     }
     332                 :            :                                 }
     333         [ #  # ]:          0 :                                 m_rHelper.popFieldCtx();
     334                 :       1912 :                             }
     335                 :       1912 :                         }
     336                 :            :                         // else: beginning/end in different XText -> ignore!
     337                 :            :                     }
     338                 :            :                     // else: no start found -> ignore!
     339         [ +  - ]:       1912 :                     break;
     340                 :            :                 }
     341                 :            : 
     342                 :            :                 case TypeReferenceStart:
     343                 :            :                 case TypeReferenceEnd:
     344                 :            :                     OSL_FAIL("reference start/end are handled in txtparai !");
     345                 :          0 :                     break;
     346                 :            : 
     347                 :            :                 default:
     348                 :            :                     OSL_FAIL("unknown mark type");
     349                 :       3835 :                     break;
     350                 :            :             }
     351                 :            :         }
     352                 :            :     }
     353                 :       3835 : }
     354                 :            : 
     355                 :          0 : SvXMLImportContext *XMLTextMarkImportContext::CreateChildContext( sal_uInt16 nPrefix,
     356                 :            :                                         const ::rtl::OUString& rLocalName,
     357                 :            :                                         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >&  )
     358                 :            : {
     359                 :          0 :     return new XMLFieldParamImportContext(GetImport(), m_rHelper,
     360         [ #  # ]:          0 :                 nPrefix, rLocalName);
     361                 :            : }
     362                 :            : 
     363                 :            : 
     364                 :       1999 : Reference<XTextContent> XMLTextMarkImportContext::CreateAndInsertMark(
     365                 :            :     SvXMLImport& rImport,
     366                 :            :     const OUString& sServiceName,
     367                 :            :     const OUString& sMarkName,
     368                 :            :     const Reference<XTextRange> & rRange,
     369                 :            :     const OUString& i_rXmlId)
     370                 :            : {
     371                 :            :     // create mark
     372                 :       1999 :     const Reference<XMultiServiceFactory> xFactory(rImport.GetModel(),
     373         [ +  - ]:       1999 :         UNO_QUERY);
     374                 :       1999 :     Reference<XInterface> xIfc;
     375                 :            : 
     376         [ +  - ]:       1999 :     if (xFactory.is())
     377                 :            :     {
     378 [ +  - ][ +  - ]:       1999 :         xIfc = xFactory->createInstance(sServiceName);
                 [ +  - ]
     379                 :            : 
     380         [ -  + ]:       1999 :         if (!xIfc.is())
     381                 :            :         {
     382                 :            :             OSL_FAIL("CreateAndInsertMark: cannot create service?");
     383         [ #  # ]:          0 :             return 0;
     384                 :            :         }
     385                 :            : 
     386                 :            :         // set name (unless there is no name (text:meta))
     387         [ +  - ]:       1999 :         const Reference<XNamed> xNamed(xIfc, UNO_QUERY);
     388         [ +  + ]:       1999 :         if (xNamed.is())
     389                 :            :         {
     390 [ +  - ][ +  - ]:       1923 :             xNamed->setName(sMarkName);
     391                 :            :         }
     392                 :            :         else
     393                 :            :         {
     394         [ -  + ]:         76 :             if (!sMarkName.isEmpty())
     395                 :            :             {
     396                 :            :                 OSL_FAIL("name given, but XNamed not supported?");
     397         [ #  # ]:          0 :                 return 0;
     398                 :            :             }
     399                 :            :         }
     400                 :            : 
     401                 :            :         // cast to XTextContent and attach to document
     402         [ +  - ]:       1999 :         const Reference<XTextContent> xTextContent(xIfc, UNO_QUERY);
     403         [ +  - ]:       1999 :         if (xTextContent.is())
     404                 :            :         {
     405                 :            :             try
     406                 :            :             {
     407                 :            :                 // if inserting marks, bAbsorb==sal_False will cause
     408                 :            :                 // collapsing of the given XTextRange.
     409 [ +  - ][ +  - ]:       3998 :                 rImport.GetTextImport()->GetText()->insertTextContent(rRange,
         [ +  - ][ +  - ]
                 [ +  - ]
     410         [ +  - ]:       1999 :                     xTextContent, sal_True);
     411                 :            : 
     412                 :            :                 // xml:id for RDF metadata -- after insertion!
     413         [ +  - ]:       1999 :                 rImport.SetXmlId(xIfc, i_rXmlId);
     414                 :            : 
     415                 :       1999 :                 return xTextContent;
     416                 :            :             }
     417   [ #  #  #  # ]:          0 :             catch (com::sun::star::lang::IllegalArgumentException &)
     418                 :            :             {
     419                 :            :                 OSL_FAIL("CreateAndInsertMark: cannot insert?");
     420         [ #  # ]:          0 :                 return 0;
     421                 :            :             }
     422 [ +  - ][ -  + ]:       1999 :         }
     423                 :            :     }
     424         [ #  # ]:       1999 :     return 0;
     425                 :            : }
     426                 :            : 
     427                 :       3835 : sal_Bool XMLTextMarkImportContext::FindName(
     428                 :            :     SvXMLImport& rImport,
     429                 :            :     const Reference<XAttributeList> & xAttrList)
     430                 :            : {
     431                 :       3835 :     sal_Bool bNameOK = sal_False;
     432                 :            : 
     433                 :            :     // find name attribute first
     434                 :       3835 :     const sal_Int16 nLength = xAttrList->getLength();
     435         [ +  + ]:       7730 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
     436                 :            :     {
     437                 :       3895 :         OUString sLocalName;
     438                 :       3895 :         const sal_uInt16 nPrefix = rImport.GetNamespaceMap().
     439         [ +  - ]:       3895 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
     440   [ +  -  +  - ]:       7790 :                               &sLocalName );
     441                 :            : 
     442 [ +  - ][ +  + ]:       7730 :         if ( (XML_NAMESPACE_TEXT == nPrefix) &&
                 [ +  + ]
     443         [ +  - ]:       3835 :              IsXMLToken(sLocalName, XML_NAME)   )
     444                 :            :         {
     445 [ +  - ][ +  - ]:       3835 :             m_sBookmarkName = xAttrList->getValueByIndex(nAttr);
     446                 :       3835 :             bNameOK = sal_True;
     447                 :            :         }
     448 [ +  + ][ +  - ]:         80 :         else if ( (XML_NAMESPACE_XML == nPrefix) &&
                 [ +  + ]
     449         [ +  - ]:         20 :              IsXMLToken(sLocalName, XML_ID)   )
     450                 :            :         {
     451 [ +  - ][ +  - ]:         20 :             m_sXmlId = xAttrList->getValueByIndex(nAttr);
     452                 :            :         }
     453         [ +  + ]:         40 :         else if ( XML_NAMESPACE_XHTML == nPrefix )
     454                 :            :         {
     455                 :            :             // RDFa
     456 [ +  - ][ +  + ]:         32 :             if ( IsXMLToken( sLocalName, XML_ABOUT) )
     457                 :            :             {
     458 [ +  - ][ +  - ]:          8 :                 m_sAbout = xAttrList->getValueByIndex(nAttr);
     459                 :          8 :                 m_bHaveAbout = true;
     460                 :            :             }
     461 [ +  - ][ +  + ]:         24 :             else if ( IsXMLToken( sLocalName, XML_PROPERTY) )
     462                 :            :             {
     463 [ +  - ][ +  - ]:          8 :                 m_sProperty = xAttrList->getValueByIndex(nAttr);
     464                 :            :             }
     465 [ +  - ][ +  + ]:         16 :             else if ( IsXMLToken( sLocalName, XML_CONTENT) )
     466                 :            :             {
     467 [ +  - ][ +  - ]:          8 :                 m_sContent = xAttrList->getValueByIndex(nAttr);
     468                 :            :             }
     469 [ +  - ][ +  - ]:          8 :             else if ( IsXMLToken( sLocalName, XML_DATATYPE) )
     470                 :            :             {
     471 [ +  - ][ +  - ]:          8 :                 m_sDatatype = xAttrList->getValueByIndex(nAttr);
     472                 :            :             }
     473                 :            :         }
     474 [ -  + ][ #  # ]:          8 :         else if ( (XML_NAMESPACE_FIELD == nPrefix) &&
                 [ -  + ]
     475         [ #  # ]:          0 :              IsXMLToken(sLocalName, XML_TYPE)   )
     476                 :            :         {
     477 [ #  # ][ #  # ]:          0 :             m_sFieldName = xAttrList->getValueByIndex(nAttr);
     478                 :            :         }
     479                 :       3895 :     }
     480                 :            : 
     481                 :       3835 :     return bNameOK;
     482                 :            : }
     483                 :            : 
     484                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10