LCOV - code coverage report
Current view: top level - xmloff/source/text - txtftne.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 161 0.0 %
Date: 2014-04-14 Functions: 0 5 0.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 :     sal_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           0 : void XMLTextParagraphExport::exportTextFootnoteConfiguration()
     208             : {
     209             :     // footnote settings
     210           0 :     Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
     211           0 :                                                      UNO_QUERY);
     212             :     Reference<XPropertySet> aFootnoteConfiguration(
     213           0 :         aFootnotesSupplier->getFootnoteSettings());
     214           0 :     exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, false);
     215             : 
     216             :     // endnote settings
     217           0 :     Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
     218           0 :                                                    UNO_QUERY);
     219             :     Reference<XPropertySet> aEndnoteConfiguration(
     220           0 :         aEndnotesSupplier->getEndnoteSettings());
     221           0 :     exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, true);
     222           0 : }
     223             : 
     224             : 
     225           0 : 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           0 :     Any aAny = rPropSet->getPropertyValue(sProperty);
     237           0 :     OUString sTmp;
     238           0 :     aAny >>= sTmp;
     239           0 :     if (!bOmitIfEmpty || !sTmp.isEmpty())
     240             :     {
     241           0 :         if( bEncodeName )
     242           0 :             sTmp = rExport.EncodeStyleName( sTmp );
     243           0 :         rExport.AddAttribute(nPrefix, eElement, sTmp);
     244           0 :     }
     245           0 : }
     246             : 
     247           0 : void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
     248             :     const Reference<XPropertySet> & rFootnoteConfig,
     249             :     bool bIsEndnote)
     250             : {
     251           0 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
     252             :                              GetXMLToken( bIsEndnote ? XML_ENDNOTE
     253           0 :                                                      : XML_FOOTNOTE ) );
     254             :     // default/paragraph style
     255           0 :     lcl_exportString( GetExport(), rFootnoteConfig,
     256             :                       sParaStyleName,
     257             :                       XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
     258           0 :                       true, true);
     259             : 
     260             :     // citation style
     261           0 :     lcl_exportString( GetExport(), rFootnoteConfig,
     262             :                       sCharStyleName,
     263             :                       XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
     264           0 :                       true, true);
     265             : 
     266             :     // citation body style
     267           0 :     lcl_exportString( GetExport(), rFootnoteConfig,
     268             :                       sAnchorCharStyleName,
     269             :                       XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
     270           0 :                       true, true);
     271             : 
     272             :     // page style
     273           0 :     lcl_exportString( GetExport(), rFootnoteConfig,
     274             :                       sPageStyleName,
     275             :                       XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
     276           0 :                       true, true );
     277             : 
     278             :     // prefix
     279           0 :     lcl_exportString( GetExport(), rFootnoteConfig, sPrefix,
     280           0 :                       XML_NAMESPACE_STYLE, XML_NUM_PREFIX, false, true);
     281             : 
     282             :     // suffix
     283           0 :     lcl_exportString( GetExport(), rFootnoteConfig, sSuffix,
     284           0 :                       XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, false, true);
     285             : 
     286             : 
     287             : 
     288           0 :     Any aAny;
     289             : 
     290             :     // numbering style
     291           0 :     OUStringBuffer sBuffer;
     292           0 :     aAny = rFootnoteConfig->getPropertyValue(sNumberingType);
     293           0 :     sal_Int16 nNumbering = 0;
     294           0 :     aAny >>= nNumbering;
     295           0 :     GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
     296           0 :     GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     297           0 :                              sBuffer.makeStringAndClear() );
     298           0 :     GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering);
     299           0 :     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           0 :     aAny = rFootnoteConfig->getPropertyValue(sStartAt);
     307           0 :     sal_Int16 nOffset = 0;
     308           0 :     aAny >>= nOffset;
     309           0 :     ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nOffset);
     310           0 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
     311           0 :                              sBuffer.makeStringAndClear());
     312             : 
     313             :     // some properties are for footnotes only
     314           0 :     if (!bIsEndnote)
     315             :     {
     316             :         // footnotes position
     317           0 :         aAny = rFootnoteConfig->getPropertyValue(
     318           0 :             sPositionEndOfDoc);
     319           0 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
     320           0 :                                  ( (*(sal_Bool *)aAny.getValue()) ?
     321           0 :                                         XML_DOCUMENT : XML_PAGE ) );
     322             : 
     323           0 :         aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting);
     324           0 :         sal_Int16 nTmp = 0;
     325           0 :         aAny >>= nTmp;
     326             :         enum XMLTokenEnum eElement;
     327           0 :         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           0 :                 eElement = XML_DOCUMENT;
     338           0 :                 break;
     339             :         }
     340           0 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT,
     341           0 :                                  XML_START_NUMBERING_AT, eElement);
     342             :     }
     343             : 
     344             :     // element
     345             :     SvXMLElementExport aFootnoteConfigElement(
     346           0 :         GetExport(), XML_NAMESPACE_TEXT,
     347             :         XML_NOTES_CONFIGURATION,
     348           0 :         true, true);
     349             : 
     350             :     // two element for footnote content
     351           0 :     if (!bIsEndnote)
     352             :     {
     353           0 :         OUString sTmp;
     354             : 
     355             :         // end notice / quo vadis
     356           0 :         aAny = rFootnoteConfig->getPropertyValue(sEndNotice);
     357           0 :         aAny >>= sTmp;
     358             : 
     359           0 :         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           0 :         aAny = rFootnoteConfig->getPropertyValue(sBeginNotice);
     369           0 :         aAny >>= sTmp;
     370             : 
     371           0 :         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           0 :         }
     378           0 :     }
     379           0 : }
     380             : 
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10