LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/text - txtftne.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 161 46.6 %
Date: 2013-07-09 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             :     sal_Bool bAutoStyles, sal_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             :         sal_Bool bHasHyperlink;
      96           0 :         sal_Bool bIsUICharStyle = sal_False;
      97           0 :         sal_Bool bHasAutoStyle = sal_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 :                                        sal_False, sal_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, sal_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, sal_False, sal_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             :     sal_Bool bAutoStyles,
     158             :     sal_Bool bIsEndnote,
     159             :     sal_Bool bIsProgress )
     160             : {
     161           0 :     if (bAutoStyles)
     162             :     {
     163           0 :         exportText(rText, bAutoStyles, bIsProgress, sal_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, sal_False, sal_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, sal_False, sal_False);
     195           0 :             GetExport().Characters(rTextString);
     196             :         }
     197             : 
     198             :         {
     199           0 :             SvXMLElementExport aBody(GetExport(), XML_NAMESPACE_TEXT,
     200           0 :                                      XML_NOTE_BODY, sal_False, sal_False);
     201           0 :             exportText(rText, bAutoStyles, bIsProgress, sal_True );
     202           0 :         }
     203             :     }
     204           0 : }
     205             : 
     206             : 
     207          15 : void XMLTextParagraphExport::exportTextFootnoteConfiguration()
     208             : {
     209             :     // footnote settings
     210          15 :     Reference<XFootnotesSupplier> aFootnotesSupplier(GetExport().GetModel(),
     211          15 :                                                      UNO_QUERY);
     212             :     Reference<XPropertySet> aFootnoteConfiguration(
     213          30 :         aFootnotesSupplier->getFootnoteSettings());
     214          15 :     exportTextFootnoteConfigurationHelper(aFootnoteConfiguration, sal_False);
     215             : 
     216             :     // endnote settings
     217          15 :     Reference<XEndnotesSupplier> aEndnotesSupplier(GetExport().GetModel(),
     218          30 :                                                    UNO_QUERY);
     219             :     Reference<XPropertySet> aEndnoteConfiguration(
     220          30 :         aEndnotesSupplier->getEndnoteSettings());
     221          30 :     exportTextFootnoteConfigurationHelper(aEndnoteConfiguration, sal_True);
     222          15 : }
     223             : 
     224             : 
     225         180 : 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             :     sal_Bool bEncodeName,
     232             :     sal_Bool bOmitIfEmpty)
     233             : {
     234             :     DBG_ASSERT( eElement != XML_TOKEN_INVALID, "need element token");
     235             : 
     236         180 :     Any aAny = rPropSet->getPropertyValue(sProperty);
     237         360 :     OUString sTmp;
     238         180 :     aAny >>= sTmp;
     239         180 :     if (!bOmitIfEmpty || !sTmp.isEmpty())
     240             :     {
     241           0 :         if( bEncodeName )
     242           0 :             sTmp = rExport.EncodeStyleName( sTmp );
     243           0 :         rExport.AddAttribute(nPrefix, eElement, sTmp);
     244         180 :     }
     245         180 : }
     246             : 
     247          30 : void XMLTextParagraphExport::exportTextFootnoteConfigurationHelper(
     248             :     const Reference<XPropertySet> & rFootnoteConfig,
     249             :     sal_Bool bIsEndnote)
     250             : {
     251          30 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
     252             :                              GetXMLToken( bIsEndnote ? XML_ENDNOTE
     253          60 :                                                      : XML_FOOTNOTE ) );
     254             :     // default/paragraph style
     255          30 :     lcl_exportString( GetExport(), rFootnoteConfig,
     256             :                       sParaStyleName,
     257             :                       XML_NAMESPACE_TEXT, XML_DEFAULT_STYLE_NAME,
     258          60 :                       sal_True, sal_True);
     259             : 
     260             :     // citation style
     261          30 :     lcl_exportString( GetExport(), rFootnoteConfig,
     262             :                       sCharStyleName,
     263             :                       XML_NAMESPACE_TEXT, XML_CITATION_STYLE_NAME,
     264          60 :                       sal_True, sal_True);
     265             : 
     266             :     // citation body style
     267          30 :     lcl_exportString( GetExport(), rFootnoteConfig,
     268             :                       sAnchorCharStyleName,
     269             :                       XML_NAMESPACE_TEXT, XML_CITATION_BODY_STYLE_NAME,
     270          60 :                       sal_True, sal_True);
     271             : 
     272             :     // page style
     273          30 :     lcl_exportString( GetExport(), rFootnoteConfig,
     274             :                       sPageStyleName,
     275             :                       XML_NAMESPACE_TEXT, XML_MASTER_PAGE_NAME,
     276          60 :                       sal_True, sal_True );
     277             : 
     278             :     // prefix
     279          30 :     lcl_exportString( GetExport(), rFootnoteConfig, sPrefix,
     280          60 :                       XML_NAMESPACE_STYLE, XML_NUM_PREFIX, sal_False, sal_True);
     281             : 
     282             :     // suffix
     283          30 :     lcl_exportString( GetExport(), rFootnoteConfig, sSuffix,
     284          60 :                       XML_NAMESPACE_STYLE, XML_NUM_SUFFIX, sal_False, sal_True);
     285             : 
     286             : 
     287             : 
     288          30 :     Any aAny;
     289             : 
     290             :     // numbering style
     291          60 :     OUStringBuffer sBuffer;
     292          30 :     aAny = rFootnoteConfig->getPropertyValue(sNumberingType);
     293          30 :     sal_Int16 nNumbering = 0;
     294          30 :     aAny >>= nNumbering;
     295          30 :     GetExport().GetMM100UnitConverter().convertNumFormat( sBuffer, nNumbering);
     296          30 :     GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
     297          60 :                              sBuffer.makeStringAndClear() );
     298          30 :     GetExport().GetMM100UnitConverter().convertNumLetterSync( sBuffer, nNumbering);
     299          30 :     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          30 :     aAny = rFootnoteConfig->getPropertyValue(sStartAt);
     307          30 :     sal_Int16 nOffset = 0;
     308          30 :     aAny >>= nOffset;
     309          30 :     ::sax::Converter::convertNumber(sBuffer, (sal_Int32)nOffset);
     310          30 :     GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_START_VALUE,
     311          60 :                              sBuffer.makeStringAndClear());
     312             : 
     313             :     // some properties are for footnotes only
     314          30 :     if (!bIsEndnote)
     315             :     {
     316             :         // footnotes position
     317          45 :         aAny = rFootnoteConfig->getPropertyValue(
     318          30 :             sPositionEndOfDoc);
     319          15 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FOOTNOTES_POSITION,
     320          15 :                                  ( (*(sal_Bool *)aAny.getValue()) ?
     321          30 :                                         XML_DOCUMENT : XML_PAGE ) );
     322             : 
     323          15 :         aAny = rFootnoteConfig->getPropertyValue(sFootnoteCounting);
     324          15 :         sal_Int16 nTmp = 0;
     325          15 :         aAny >>= nTmp;
     326             :         enum XMLTokenEnum eElement;
     327          15 :         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          15 :                 eElement = XML_DOCUMENT;
     338          15 :                 break;
     339             :         }
     340          15 :         GetExport().AddAttribute(XML_NAMESPACE_TEXT,
     341          15 :                                  XML_START_NUMBERING_AT, eElement);
     342             :     }
     343             : 
     344             :     // element
     345             :     SvXMLElementExport aFootnoteConfigElement(
     346          30 :         GetExport(), XML_NAMESPACE_TEXT,
     347             :         XML_NOTES_CONFIGURATION,
     348          30 :         sal_True, sal_True);
     349             : 
     350             :     // two element for footnote content
     351          30 :     if (!bIsEndnote)
     352             :     {
     353          15 :         OUString sTmp;
     354             : 
     355             :         // end notice / quo vadis
     356          15 :         aAny = rFootnoteConfig->getPropertyValue(sEndNotice);
     357          15 :         aAny >>= sTmp;
     358             : 
     359          15 :         if (!sTmp.isEmpty())
     360             :         {
     361           0 :             SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
     362             :                                      XML_FOOTNOTE_CONTINUATION_NOTICE_FORWARD,
     363           0 :                                      sal_True, sal_False);
     364           0 :             GetExport().Characters(sTmp);
     365             :         }
     366             : 
     367             :         // begin notice / ergo sum
     368          15 :         aAny = rFootnoteConfig->getPropertyValue(sBeginNotice);
     369          15 :         aAny >>= sTmp;
     370             : 
     371          15 :         if (!sTmp.isEmpty())
     372             :         {
     373           0 :             SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_TEXT,
     374             :                                      XML_FOOTNOTE_CONTINUATION_NOTICE_BACKWARD,
     375           0 :                                      sal_True, sal_False);
     376           0 :             GetExport().Characters(sTmp);
     377          15 :         }
     378          60 :     }
     379          30 : }
     380             : 
     381             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10