LCOV - code coverage report
Current view: top level - xmloff/source/text - txtftne.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 75 161 46.6 %
Date: 2014-11-03 Functions: 3 5 60.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             : 
      21             : 
      22             : /** @#file
      23             :  *
      24             :  * This file implements XMLTextParagraphExport methods to export
      25             :  * - footnotes
      26             :  * - endnotes
      27             :  * - footnote configuration elements
      28             :  * - endnote configuration elements
      29             :  */
      30             : #include <tools/debug.hxx>
      31             : #include <rtl/ustrbuf.hxx>
      32             : #include <com/sun/star/lang/XServiceInfo.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/beans/XPropertyState.hpp>
      35             : #include <com/sun/star/text/XTextDocument.hpp>
      36             : #include <com/sun/star/text/XText.hpp>
      37             : #include <com/sun/star/text/XTextContent.hpp>
      38             : #include <com/sun/star/text/XFootnote.hpp>
      39             : #include <com/sun/star/text/XFootnotesSupplier.hpp>
      40             : #include <com/sun/star/text/XEndnotesSupplier.hpp>
      41             : #include <com/sun/star/text/FootnoteNumbering.hpp>
      42             : #include <com/sun/star/container/XNameReplace.hpp>
      43             : #include <sax/tools/converter.hxx>
      44             : #include <xmloff/xmltoken.hxx>
      45             : #include <xmloff/xmlnmspe.hxx>
      46             : #include <xmloff/xmlnumfe.hxx>
      47             : #include <xmloff/xmluconv.hxx>
      48             : #include <xmloff/nmspmap.hxx>
      49             : #include <xmloff/xmlexp.hxx>
      50             : #include <xmloff/families.hxx>
      51             : #include <xmloff/xmlnume.hxx>
      52             : #include "XMLTextCharStyleNamesElementExport.hxx"
      53             : #include <xmloff/XMLEventExport.hxx>
      54             : #include <xmloff/txtparae.hxx>
      55             : 
      56             : 
      57             : using namespace ::com::sun::star;
      58             : using namespace ::com::sun::star::uno;
      59             : using namespace ::com::sun::star::lang;
      60             : using namespace ::com::sun::star::beans;
      61             : using namespace ::com::sun::star::text;
      62             : using namespace ::com::sun::star::container;
      63             : using namespace ::xmloff::token;
      64             : 
      65             : 
      66           0 : void XMLTextParagraphExport::exportTextFootnote(
      67             :     const Reference<XPropertySet> & rPropSet,
      68             :     const OUString& rText,
      69             :     bool bAutoStyles, bool bIsProgress )
      70             : {
      71             :     // get footnote and associated text
      72           0 :     Any aAny;
      73           0 :     aAny = rPropSet->getPropertyValue(sFootnote);
      74           0 :     Reference<XFootnote> xFootnote;
      75           0 :     aAny >>= xFootnote;
      76           0 :     Reference<XText> xText(xFootnote, UNO_QUERY);
      77             : 
      78             :     // are we an endnote?
      79           0 :     Reference<XServiceInfo> xServiceInfo( xFootnote, UNO_QUERY );
      80           0 :     bool bIsEndnote = xServiceInfo->supportsService(sTextEndnoteService);
      81             : 
      82           0 :     if (bAutoStyles)
      83             :     {
      84             :         // handle formatting of citation mark
      85           0 :         Add( XML_STYLE_FAMILY_TEXT_TEXT, rPropSet );
      86             : 
      87             :         // handle formatting within footnote
      88             :         exportTextFootnoteHelper(xFootnote, xText, rText,
      89           0 :                                  bAutoStyles, bIsEndnote, bIsProgress );
      90             :     }
      91             :     else
      92             :     {
      93             :         // create span (for citation mark) if necessary; footnote content
      94             :         // wil be handled via exportTextFootnoteHelper, exportText
      95             :         bool bHasHyperlink;
      96           0 :         bool bIsUICharStyle = false;
      97           0 :         bool bHasAutoStyle = false;
      98             : 
      99             :         OUString sStyle = FindTextStyleAndHyperlink( rPropSet, bHasHyperlink,
     100           0 :                                                      bIsUICharStyle, bHasAutoStyle );
     101             : 
     102             :         // export hyperlink (if we have one)
     103           0 :         Reference < XPropertySetInfo > xPropSetInfo;
     104           0 :         if( bHasHyperlink )
     105             :         {
     106           0 :             Reference<XPropertyState> xPropState( rPropSet, UNO_QUERY );
     107           0 :             xPropSetInfo = rPropSet->getPropertySetInfo();
     108             :             bHasHyperlink =
     109           0 :                 addHyperlinkAttributes( rPropSet, xPropState, xPropSetInfo );
     110             :         }
     111           0 :         SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink,
     112             :                                        XML_NAMESPACE_TEXT, XML_A,
     113           0 :                                        false, false );
     114             : 
     115           0 :         if( bHasHyperlink )
     116             :         {
     117             :             // export events (if supported)
     118           0 :             OUString sHyperLinkEvents("HyperLinkEvents");
     119           0 :             if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
     120             :             {
     121           0 :                 Any a = rPropSet->getPropertyValue(sHyperLinkEvents);
     122           0 :                 Reference<XNameReplace> xName;
     123           0 :                 a >>= xName;
     124           0 :                 GetExport().GetEventExport().Export(xName, false);
     125           0 :             }
     126             :         }
     127             : 
     128             :         {
     129             :             XMLTextCharStyleNamesElementExport aCharStylesExport(
     130           0 :                 GetExport(), bIsUICharStyle &&
     131             :                              aCharStyleNamesPropInfoCache.hasProperty(
     132           0 :                                                     rPropSet ), bHasAutoStyle,
     133           0 :                 rPropSet, sCharStyleNames );
     134           0 :             if( !sStyle.isEmpty() )
     135             :             {
     136           0 :                 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
     137           0 :                                           GetExport().EncodeStyleName( sStyle ) );
     138           0 :                 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
     139           0 :                                           XML_SPAN, false, false );
     140             :                 exportTextFootnoteHelper(xFootnote, xText, rText,
     141           0 :                                          bAutoStyles, bIsEndnote, bIsProgress );
     142             :             }
     143             :             else
     144             :             {
     145             :                 exportTextFootnoteHelper(xFootnote, xText, rText,
     146           0 :                                          bAutoStyles, bIsEndnote, bIsProgress );
     147           0 :             }
     148           0 :         }
     149           0 :     }
     150           0 : }
     151             : 
     152             : 
     153           0 : void XMLTextParagraphExport::exportTextFootnoteHelper(
     154             :     const Reference<XFootnote> & rFootnote,
     155             :     const Reference<XText> & rText,
     156             :     const OUString& rTextString,
     157             :     bool bAutoStyles,
     158             :     bool bIsEndnote,
     159             :     bool bIsProgress )
     160             : {
     161           0 :     if (bAutoStyles)
     162             :     {
     163           0 :         exportText(rText, bAutoStyles, bIsProgress, true );
     164             :     }
     165             :     else
     166             :     {
     167             :         // export reference Id (for reference fields)
     168           0 :         Reference<XPropertySet> xPropSet(rFootnote, UNO_QUERY);
     169           0 :         Any aAny = xPropSet->getPropertyValue(sReferenceId);
     170           0 :         sal_Int32 nNumber = 0;
     171           0 :         aAny >>= nNumber;
     172           0 :         OUStringBuffer aBuf;
     173           0 :         aBuf.appendAscii("ftn");
     174           0 :         aBuf.append(nNumber);
     175           0 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_ID,
     176           0 :                                  aBuf.makeStringAndClear());
     177           0 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
     178             :                                  GetXMLToken( bIsEndnote ? XML_ENDNOTE
     179           0 :                                                           : XML_FOOTNOTE ) );
     180             : 
     181           0 :         SvXMLElementExport aNote(GetExport(), XML_NAMESPACE_TEXT,
     182           0 :                                  XML_NOTE, false, false);
     183             :         {
     184             :             // handle label vs. automatic numbering
     185           0 :             OUString sLabel = rFootnote->getLabel();
     186           0 :             if (!sLabel.isEmpty())
     187             :             {
     188           0 :                 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_LABEL,
     189           0 :                                          sLabel);
     190             :             }
     191             :             // else: automatic numbering -> no attribute
     192             : 
     193           0 :             SvXMLElementExport aCite(GetExport(), XML_NAMESPACE_TEXT,
     194           0 :                                      XML_NOTE_CITATION, false, false);
     195           0 :             GetExport().Characters(rTextString);
     196             :         }
     197             : 
     198             :         {
     199           0 :             SvXMLElementExport aBody(GetExport(), XML_NAMESPACE_TEXT,
     200           0 :                                      XML_NOTE_BODY, false, false);
     201           0 :             exportText(rText, bAutoStyles, bIsProgress, true );
     202           0 :         }
     203             :     }
     204           0 : }
     205             : 
     206             : 
     207          58 : void XMLTextParagraphExport::exportTextFootnoteConfiguration()
     208             : {
     209             :     // footnote settings
     210          58 :     Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
     211          58 :                                                      UNO_QUERY);
     212             :     Reference<XPropertySet> aFootnoteConfiguration(
     213         116 :         aFootnotesSupplier->getFootnoteSettings());
     214          58 :     exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, false);
     215             : 
     216             :     // endnote settings
     217          58 :     Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
     218         116 :                                                    UNO_QUERY);
     219             :     Reference<XPropertySet> aEndnoteConfiguration(
     220         116 :         aEndnotesSupplier->getEndnoteSettings());
     221         116 :     exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, true);
     222          58 : }
     223             : 
     224             : 
     225         696 : static void lcl_exportString(
     226             :     SvXMLExport& rExport,
     227             :     const Reference<XPropertySet> & rPropSet,
     228             :     const OUString& sProperty,
     229             :     sal_uInt16 nPrefix,
     230             :     enum XMLTokenEnum eElement,
     231             :     bool bEncodeName,
     232             :     bool bOmitIfEmpty)
     233             : {
     234             :     DBG_ASSERT( eElement != XML_TOKEN_INVALID, "need element token");
     235             : 
     236         696 :     Any aAny = rPropSet->getPropertyValue(sProperty);
     237        1392 :     OUString sTmp;
     238         696 :     aAny >>= sTmp;
     239         696 :     if (!bOmitIfEmpty || !sTmp.isEmpty())
     240             :     {
     241           0 :         if( bEncodeName )
     242           0 :             sTmp = rExport.EncodeStyleName( sTmp );
     243           0 :         rExport.AddAttribute(nPrefix, eElement, sTmp);
     244         696 :     }
     245         696 : }
     246             : 
     247         116 : void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
     248             :     const Reference<XPropertySet> & rFootnoteConfig,
     249             :     bool bIsEndnote)
     250             : {
     251         116 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
     252             :                              GetXMLToken( bIsEndnote ? XML_ENDNOTE
     253         232 :                                                      : XML_FOOTNOTE ) );
     254             :     // default/paragraph style
     255         116 :     lcl_exportString( GetExport(), rFootnoteConfig,
     256             :                       sParaStyleName,
     257             :                       XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
     258         232 :                       true, true);
     259             : 
     260             :     // citation style
     261         116 :     lcl_exportString( GetExport(), rFootnoteConfig,
     262             :                       sCharStyleName,
     263             :                       XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
     264         232 :                       true, true);
     265             : 
     266             :     // citation body style
     267         116 :     lcl_exportString( GetExport(), rFootnoteConfig,
     268             :                       sAnchorCharStyleName,
     269             :                       XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
     270         232 :                       true, true);
     271             : 
     272             :     // page style
     273         116 :     lcl_exportString( GetExport(), rFootnoteConfig,
     274             :                       sPageStyleName,
     275             :                       XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
     276         232 :                       true, true );
     277             : 
     278             :     // prefix
     279         116 :     lcl_exportString( GetExport(), rFootnoteConfig, sPrefix,
     280         232 :                       XML_NAMESPACE_STYLE, XML_NUM_PREFIX, false, true);
     281             : 
     282             :     // suffix
     283         116 :     lcl_exportString( GetExport(), rFootnoteConfig, sSuffix,
     284         232 :                       XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, false, true);
     285             : 
     286             : 
     287             : 
     288         116 :     Any aAny;
     289             : 
     290             :     // numbering style
     291         232 :     OUStringBuffer sBuffer;
     292         116 :     aAny = rFootnoteConfig->getPropertyValue(sNumberingType);
     293         116 :     sal_Int16 nNumbering = 0;
     294         116 :     aAny >>= nNumbering;
     295         116 :     GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
     296         116 :     GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     297         232 :                              sBuffer.makeStringAndClear() );
     298         116 :     GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering);
     299         116 :     if (!sBuffer.isEmpty() )
     300             :     {
     301           0 :         GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
     302           0 :                                  sBuffer.makeStringAndClear());
     303             :     }
     304             : 
     305             :     // StartAt / start-value
     306         116 :     aAny = rFootnoteConfig->getPropertyValue(sStartAt);
     307         116 :     sal_Int16 nOffset = 0;
     308         116 :     aAny >>= nOffset;
     309         116 :     ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nOffset);
     310         116 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
     311         232 :                              sBuffer.makeStringAndClear());
     312             : 
     313             :     // some properties are for footnotes only
     314         116 :     if (!bIsEndnote)
     315             :     {
     316             :         // footnotes position
     317         174 :         aAny = rFootnoteConfig->getPropertyValue(
     318         116 :             sPositionEndOfDoc);
     319          58 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
     320          58 :                                  ( (*(sal_Bool *)aAny.getValue()) ?
     321         116 :                                         XML_DOCUMENT : XML_PAGE ) );
     322             : 
     323          58 :         aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting);
     324          58 :         sal_Int16 nTmp = 0;
     325          58 :         aAny >>= nTmp;
     326             :         enum XMLTokenEnum eElement;
     327          58 :         switch (nTmp)
     328             :         {
     329             :             case FootnoteNumbering::PER_PAGE:
     330           0 :                 eElement = XML_PAGE;
     331           0 :                 break;
     332             :             case FootnoteNumbering::PER_CHAPTER:
     333           0 :                 eElement = XML_CHAPTER;
     334           0 :                 break;
     335             :             case FootnoteNumbering::PER_DOCUMENT:
     336             :             default:
     337          58 :                 eElement = XML_DOCUMENT;
     338          58 :                 break;
     339             :         }
     340          58 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT,
     341          58 :                                  XML_START_NUMBERING_AT, eElement);
     342             :     }
     343             : 
     344             :     // element
     345             :     SvXMLElementExport aFootnoteConfigElement(
     346         116 :         GetExport(), XML_NAMESPACE_TEXT,
     347             :         XML_NOTES_CONFIGURATION,
     348         116 :         true, true);
     349             : 
     350             :     // two element for footnote content
     351         116 :     if (!bIsEndnote)
     352             :     {
     353          58 :         OUString sTmp;
     354             : 
     355             :         // end notice / quo vadis
     356          58 :         aAny = rFootnoteConfig->getPropertyValue(sEndNotice);
     357          58 :         aAny >>= sTmp;
     358             : 
     359          58 :         if (!sTmp.isEmpty())
     360             :         {
     361           0 :             SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
     362             :                                      XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD,
     363           0 :                                      true, false);
     364           0 :             GetExport().Characters(sTmp);
     365             :         }
     366             : 
     367             :         // begin notice / ergo sum
     368          58 :         aAny = rFootnoteConfig->getPropertyValue(sBeginNotice);
     369          58 :         aAny >>= sTmp;
     370             : 
     371          58 :         if (!sTmp.isEmpty())
     372             :         {
     373           0 :             SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
     374             :                                      XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD,
     375           0 :                                      true, false);
     376           0 :             GetExport().Characters(sTmp);
     377          58 :         }
     378         232 :     }
     379         116 : }
     380             : 
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10