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

Generated by: LCOV version 1.10