[Libreoffice-commits] core.git: Branch 'aoo/trunk' - xmloff/inc xmloff/source

Oliver-Rainer Wittmann orw at apache.org
Tue Jan 14 06:07:41 PST 2014


 xmloff/inc/xmloff/txtparae.hxx  |   12 +
 xmloff/inc/xmloff/xmlexp.hxx    |   18 +-
 xmloff/source/core/xmlexp.cxx   |  220 ++++++++++++++++---------------
 xmloff/source/text/txtimp.cxx   |    3 
 xmloff/source/text/txtparae.cxx |  279 ++++++++++++----------------------------
 xmloff/source/text/txtparai.cxx |  100 +++++++-------
 6 files changed, 278 insertions(+), 354 deletions(-)

New commits:
commit 71d322a8ce0f5f5cbfd66fd689ff10b3490c1ee4
Author: Oliver-Rainer Wittmann <orw at apache.org>
Date:   Tue Jan 14 13:10:51 2014 +0000

    123457: improve ODF filter - suppress import and export of hyperlinks without an URL

diff --git a/xmloff/inc/xmloff/txtparae.hxx b/xmloff/inc/xmloff/txtparae.hxx
index 01e1ba9..d25a597 100644
--- a/xmloff/inc/xmloff/txtparae.hxx
+++ b/xmloff/inc/xmloff/txtparae.hxx
@@ -107,13 +107,21 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport
     ::rtl::OUString             sOpenRubyCharStyle;
     sal_Bool                    bOpenRuby;
 
-    // --> OD 2008-05-07 #refactorlists#
     XMLTextListsHelper* mpTextListsHelper;
     ::std::vector< XMLTextListsHelper* > maTextListsHelperStack;
-    // <--
 
     enum FrameType { FT_TEXT, FT_GRAPHIC, FT_EMBEDDED, FT_SHAPE };
 
+
+    void exportTextRangeSpan(
+            const ::com::sun::star::uno::Reference< com::sun::star::text::XTextRange > & rTextRange,
+            ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xPropSet,
+            ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySetInfo > & xPropSetInfo,
+            const sal_Bool bIsUICharStyle,
+            const sal_Bool bHasAutoStyle,
+            const ::rtl::OUString& sStyle,
+            sal_Bool& rPrevCharIsSpace );
+
 protected:
 
     const ::rtl::OUString sActualSize;
diff --git a/xmloff/inc/xmloff/xmlexp.hxx b/xmloff/inc/xmloff/xmlexp.hxx
index 44012cf..162b2c4 100644
--- a/xmloff/inc/xmloff/xmlexp.hxx
+++ b/xmloff/inc/xmloff/xmlexp.hxx
@@ -684,14 +684,16 @@ inline void SvXMLExport::SetGraphicResolver(
 // Helper class to export an element.
 class XMLOFF_DLLPUBLIC SvXMLElementExport
 {
-    SvXMLExport& rExport;
-    ::rtl::OUString aName;
-    sal_Bool bIgnWS : 1;
-    sal_Bool bDoSomething : 1;
-
-    SAL_DLLPRIVATE void StartElement( SvXMLExport& rExp, sal_uInt16 nPrefix,
-                       const ::rtl::OUString& rName,
-                       sal_Bool bIgnWSOutside );
+    SvXMLExport& mrExport;
+    ::rtl::OUString maElementName;
+    const sal_Bool mbIgnoreWhitespaceInside :1;
+    const sal_Bool mbDoSomething :1;
+
+    SAL_DLLPRIVATE
+    void StartElement(
+        const sal_uInt16 nPrefix,
+        const ::rtl::OUString& rName,
+        const sal_Bool bIgnoreWhitespaceOutside );
 
 public:
 
diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx
index 3c875b1..3f48d7d 100644
--- a/xmloff/source/core/xmlexp.cxx
+++ b/xmloff/source/core/xmlexp.cxx
@@ -2627,12 +2627,10 @@ SvXMLExport::AddAttributesRDFa(
     mpImpl->mpRDFaHelper->AddRDFa(xMeta);
 }
 
-// --> OD 2008-11-26 #158694#
 sal_Bool SvXMLExport::exportTextNumberElement() const
 {
     return mpImpl->mbExportTextNumberElement;
 }
-// <--
 
 sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
 {
@@ -2643,116 +2641,132 @@ sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
     return mpImpl->mbNullDateInitialized;
 }
 
-//=============================================================================
 
-void SvXMLElementExport::StartElement( SvXMLExport& rExp,
-                                       sal_uInt16 nPrefixKey,
-                                       const OUString& rLName,
-                                       sal_Bool bIWSOutside )
-{
-    aName = rExp.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
-    rExp.StartElement(aName, bIWSOutside);
-}
-
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_uInt16 nPrefixKey,
-                                        const sal_Char *pLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( sal_True )
-{
-    OUString sLName( OUString::createFromAscii(pLName) );
-    StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
-}
-
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_uInt16 nPrefixKey,
-                                        const OUString& rLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( sal_True )
-{
-    StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
-}
-
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_uInt16 nPrefixKey,
-                                        enum XMLTokenEnum eLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( sal_True )
-{
-    StartElement( rExp, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
-}
-
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_Bool bDoSth,
-                                        sal_uInt16 nPrefixKey,
-                                        const sal_Char *pLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( bDoSth )
-{
-    if( bDoSomething )
-    {
-        OUString sLName( OUString::createFromAscii(pLName) );
-        StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
-    }
-}
-
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_Bool bDoSth,
-                                        sal_uInt16 nPrefixKey,
-                                        const OUString& rLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( bDoSth )
-{
-    if( bDoSomething )
-        StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
-}
+//=============================================================================
 
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        sal_Bool bDoSth,
-                                        sal_uInt16 nPrefixKey,
-                                        enum XMLTokenEnum eLName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( bDoSth )
-{
-    if( bDoSomething )
-        StartElement( rExport, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
-}
 
-SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
-                                        const OUString& rQName,
-                                        sal_Bool bIWSOutside,
-                                        sal_Bool bIWSInside ) :
-    rExport( rExp ),
-    bIgnWS( bIWSInside ),
-    bDoSomething( sal_True )
-{
-    aName = rQName;
+void SvXMLElementExport::StartElement(
+    const sal_uInt16 nPrefixKey,
+    const OUString& rLName,
+    const sal_Bool bIgnoreWhitespaceOutside )
+{
+    maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
+    mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_uInt16 nPrefixKey,
+    const sal_Char *pLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( sal_True )
+{
+    const OUString sLName( OUString::createFromAscii( pLName ) );
+    StartElement( nPrefixKey, sLName, bIWSOutside );
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_uInt16 nPrefixKey,
+    const OUString& rLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( sal_True )
+{
+    StartElement( nPrefixKey, rLName, bIWSOutside );
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_uInt16 nPrefixKey,
+    enum XMLTokenEnum eLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( sal_True )
+{
+    StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_Bool bDoSth,
+    sal_uInt16 nPrefixKey,
+    const sal_Char *pLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( bDoSth )
+{
+    if ( mbDoSomething )
+    {
+        const OUString sLName( OUString::createFromAscii( pLName ) );
+        StartElement( nPrefixKey, sLName, bIWSOutside );
+    }
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_Bool bDoSth,
+    sal_uInt16 nPrefixKey,
+    const OUString& rLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( bDoSth )
+{
+    if ( mbDoSomething )
+        StartElement( nPrefixKey, rLName, bIWSOutside );
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    sal_Bool bDoSth,
+    sal_uInt16 nPrefixKey,
+    enum XMLTokenEnum eLName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( bDoSth )
+{
+    if ( mbDoSomething )
+        StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
+}
+
+SvXMLElementExport::SvXMLElementExport(
+    SvXMLExport& rExp,
+    const OUString& rQName,
+    sal_Bool bIWSOutside,
+    sal_Bool bIWSInside )
+    : mrExport( rExp )
+    , maElementName()
+    , mbIgnoreWhitespaceInside( bIWSInside )
+    , mbDoSomething( sal_True )
+{
+    maElementName = rQName;
     rExp.StartElement( rQName, bIWSOutside );
 }
 
 SvXMLElementExport::~SvXMLElementExport()
 {
-    if( bDoSomething )
+    if ( mbDoSomething )
     {
-        rExport.EndElement( aName, bIgnWS );
+        mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
     }
 }
 
diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx
index 202c83b..620376e 100644
--- a/xmloff/source/text/txtimp.cxx
+++ b/xmloff/source/text/txtimp.cxx
@@ -2125,7 +2125,8 @@ void XMLTextImportHelper::SetOutlineStyles( sal_Bool bSetEmptyLevels )
                         {
                             if (!lcl_HasListStyle(
                                     m_pImpl->m_pOutlineStylesCandidates[i][j],
-                                    m_pImpl->m_xParaStyles, GetXMLImport(),
+                                    m_pImpl->m_xParaStyles,
+                                    GetXMLImport(),
                                     s_NumberingStyleName,
                                     sOutlineStyleName))
                             {
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 33c7f96..c57a6a4 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -3147,202 +3147,84 @@ void XMLTextParagraphExport::setTextEmbeddedGraphicURL(
 }
 
 sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
-        const Reference < XPropertySet > & rPropSet,
-        const Reference < XPropertyState > & rPropState,
-        const Reference < XPropertySetInfo > & rPropSetInfo )
+    const Reference< XPropertySet > & rPropSet,
+    const Reference< XPropertyState > & rPropState,
+    const Reference< XPropertySetInfo > & rPropSetInfo )
 {
     sal_Bool bExport = sal_False;
     OUString sHRef, sName, sTargetFrame, sUStyleName, sVStyleName;
     sal_Bool bServerMap = sal_False;
 
-/*    bool bHyperLinkURL = false;
-    bool bHyperLinkName = false;
-    bool bHyperLinkTarget = false;
-    bool bServer = false;
-    bool bUnvisitedCharStyleName = false;
-    bool bVisitedCharStyleName = false;
-
-    const Reference< XMultiPropertySet > xMultiPropertySet( rPropSet, UNO_QUERY );
-    if ( xMultiPropertySet.is() )
-    {
-    sal_uInt32 nCount = 0;
-    Sequence< OUString > aPropertyNames( 6 );
-      OUString* pArray = aPropertyNames.getArray();
-
-    if ( rPropSetInfo->hasPropertyByName( sServerMap ) )
-    {
-        bServer = true;
-        pArray[ nCount++ ] = sServerMap;
-    }
-    if ( rPropSetInfo->hasPropertyByName( sHyperLinkName ) )
-    {
-        bHyperLinkName = true;
-        pArray[ nCount++ ] = sHyperLinkName;
-    }
-    if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) )
-    {
-        bHyperLinkTarget = true;
-        pArray[ nCount++ ] = sHyperLinkTarget;
-    }
-    if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) )
+    if ( rPropSetInfo->hasPropertyByName( sHyperLinkURL )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkURL ) ) )
     {
-        bHyperLinkURL = true;
-        pArray[ nCount++ ] = sHyperLinkURL;
-    }
-    if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) )
-    {
-        bUnvisitedCharStyleName = true;
-        pArray[ nCount++ ] = sUnvisitedCharStyleName;
-    }
-    if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) )
-    {
-        bVisitedCharStyleName = true;
-        pArray[ nCount++ ] = sVisitedCharStyleName;
+        rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
+        if ( !sHRef.isEmpty() )
+            bExport = sal_True;
     }
-
-    aPropertyNames.realloc( nCount );
-
-    if ( nCount )
+    if ( sHRef.isEmpty() )
     {
-        Sequence< PropertyState > aPropertyStates( nCount );
-          PropertyState* pStateArray = aPropertyStates.getArray();
-
-        if ( rPropState.is() )
-            aPropertyStates = rPropState->getPropertyStates( aPropertyNames );
-
-        Sequence< Any > aPropertyValues ( xMultiPropertySet->getPropertyValues( aPropertyNames ) );
-        Any* pValueArray = aPropertyValues.getArray();
-
-        sal_uInt32 nIdx = 0;
-
-        if ( bServer )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                bServerMap = *(sal_Bool *)pValueArray[ nIdx ].getValue();
-                if( bServerMap  )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-        if ( bHyperLinkName )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                pValueArray[ nIdx ] >>= sName;
-                if( sName.getLength() > 0 )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-        if ( bHyperLinkTarget )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                pValueArray[ nIdx ] >>= sTargetFrame;
-                if( sTargetFrame.getLength() )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-        if ( bHyperLinkURL )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                pValueArray[ nIdx ] >>= sHRef;
-                if( sHRef.getLength() > 0 )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-        if ( bUnvisitedCharStyleName )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                pValueArray[ nIdx ] >>= sUStyleName;
-                if( sUStyleName.getLength() )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-        if ( bVisitedCharStyleName )
-        {
-            if ( !rPropState.is() || PropertyState_DIRECT_VALUE == pStateArray[ nIdx ] )
-            {
-                pValueArray[ nIdx ] >>= sVStyleName;
-                if( sVStyleName.getLength() )
-                    bExport = sal_True;
-            }
-            ++nIdx;
-        }
-    }
+        // hyperlink without an URL does not make sense
+        OSL_ENSURE( false, "hyperlink without an URL --> no export to ODF" );
+        return sal_False;
     }
-    else
-    {*/
-    if( rPropSetInfo->hasPropertyByName( sHyperLinkURL ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-                    rPropState->getPropertyState( sHyperLinkURL ) ) )
-    {
-        rPropSet->getPropertyValue( sHyperLinkURL ) >>= sHRef;
 
-        if( sHRef.getLength() > 0 )
-            bExport = sal_True;
-    }
 
-    if( rPropSetInfo->hasPropertyByName( sHyperLinkName ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-                    rPropState->getPropertyState( sHyperLinkName ) ) )
+    if ( rPropSetInfo->hasPropertyByName( sHyperLinkName )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkName ) ) )
     {
         rPropSet->getPropertyValue( sHyperLinkName ) >>= sName;
-        if( sName.getLength() > 0 )
+        if ( !sName.isEmpty() )
             bExport = sal_True;
     }
 
-    if( rPropSetInfo->hasPropertyByName( sHyperLinkTarget ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-                    rPropState->getPropertyState( sHyperLinkTarget ) ) )
+    if ( rPropSetInfo->hasPropertyByName( sHyperLinkTarget )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sHyperLinkTarget ) ) )
     {
         rPropSet->getPropertyValue( sHyperLinkTarget ) >>= sTargetFrame;
-        if( sTargetFrame.getLength() )
+        if ( !sTargetFrame.isEmpty() )
             bExport = sal_True;
     }
 
-    if( rPropSetInfo->hasPropertyByName( sServerMap ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-                    rPropState->getPropertyState( sServerMap ) ) )
+    if ( rPropSetInfo->hasPropertyByName( sServerMap )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sServerMap ) ) )
     {
-        bServerMap = *(sal_Bool *)rPropSet->getPropertyValue( sServerMap ).getValue();
-        if( bServerMap  )
+        bServerMap = *(sal_Bool *) rPropSet->getPropertyValue( sServerMap ).getValue();
+        if ( bServerMap )
             bExport = sal_True;
     }
 
-    if( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-            rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
+    if ( rPropSetInfo->hasPropertyByName( sUnvisitedCharStyleName )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sUnvisitedCharStyleName ) ) )
     {
         rPropSet->getPropertyValue( sUnvisitedCharStyleName ) >>= sUStyleName;
-        if( sUStyleName.getLength() )
+        if ( !sUStyleName.isEmpty() )
             bExport = sal_True;
     }
 
-    if( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName ) &&
-        ( !rPropState.is() || PropertyState_DIRECT_VALUE ==
-            rPropState->getPropertyState( sVisitedCharStyleName ) ) )
+    if ( rPropSetInfo->hasPropertyByName( sVisitedCharStyleName )
+         && ( !rPropState.is()
+              || PropertyState_DIRECT_VALUE == rPropState->getPropertyState( sVisitedCharStyleName ) ) )
     {
         rPropSet->getPropertyValue( sVisitedCharStyleName ) >>= sVStyleName;
-        if( sVStyleName.getLength() )
+        if ( !sVStyleName.isEmpty() )
             bExport = sal_True;
     }
 
-    if( bExport )
+    if ( bExport )
     {
         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
         GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, GetExport().GetRelativeReference( sHRef ) );
 
-        if( sName.getLength() > 0 )
+        if( !sName.isEmpty() )
             GetExport().AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME, sName );
 
-        if( sTargetFrame.getLength() )
+        if( !sTargetFrame.isEmpty() )
         {
             GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
                                       XML_TARGET_FRAME_NAME, sTargetFrame );
@@ -3356,11 +3238,11 @@ sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
             GetExport().AddAttribute( XML_NAMESPACE_OFFICE,
                                       XML_SERVER_MAP, XML_TRUE );
 
-        if( sUStyleName.getLength() )
+        if( !sUStyleName.isEmpty() )
             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
               XML_STYLE_NAME, GetExport().EncodeStyleName( sUStyleName ) );
 
-        if( sVStyleName.getLength() )
+        if( !sVStyleName.isEmpty() )
             GetExport().AddAttribute( XML_NAMESPACE_TEXT,
               XML_VISITED_STYLE_NAME, GetExport().EncodeStyleName( sVStyleName ) );
     }
@@ -3368,13 +3250,40 @@ sal_Bool XMLTextParagraphExport::addHyperlinkAttributes(
     return bExport;
 }
 
+void XMLTextParagraphExport::exportTextRangeSpan(
+    const com::sun::star::uno::Reference< com::sun::star::text::XTextRange > & rTextRange,
+    Reference< XPropertySet > & xPropSet,
+    Reference < XPropertySetInfo > & xPropSetInfo,
+    const sal_Bool bIsUICharStyle,
+    const sal_Bool bHasAutoStyle,
+    const OUString& sStyle,
+    sal_Bool& rPrevCharIsSpace )
+{
+    XMLTextCharStyleNamesElementExport aCharStylesExport(
+            GetExport(),
+            bIsUICharStyle && aCharStyleNamesPropInfoCache.hasProperty( xPropSet, xPropSetInfo ),
+            bHasAutoStyle,
+            xPropSet,
+            sCharStyleNames );
+
+    if ( !sStyle.isEmpty() )
+    {
+        GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sStyle ) );
+    }
+    {
+        SvXMLElementExport aElement( GetExport(), !sStyle.isEmpty(), XML_NAMESPACE_TEXT, XML_SPAN, sal_False, sal_False );
+        const OUString aText( rTextRange->getString() );
+        exportText( aText, rPrevCharIsSpace );
+    }
+}
+
 void XMLTextParagraphExport::exportTextRange(
-        const Reference < XTextRange > & rTextRange,
+        const Reference< XTextRange > & rTextRange,
         sal_Bool bAutoStyles,
         sal_Bool& rPrevCharIsSpace )
 {
-    Reference < XPropertySet > xPropSet( rTextRange, UNO_QUERY );
-    if( bAutoStyles )
+    Reference< XPropertySet > xPropSet( rTextRange, UNO_QUERY );
+    if ( bAutoStyles )
     {
         Add( XML_STYLE_FAMILY_TEXT_TEXT, xPropSet );
     }
@@ -3383,49 +3292,35 @@ void XMLTextParagraphExport::exportTextRange(
         sal_Bool bHyperlink = sal_False;
         sal_Bool bIsUICharStyle = sal_False;
         sal_Bool bHasAutoStyle = sal_False;
-
-        OUString sStyle(FindTextStyleAndHyperlink( xPropSet, bHyperlink,
-                                                        bIsUICharStyle, bHasAutoStyle ));
+        const OUString sStyle(
+            FindTextStyleAndHyperlink( xPropSet, bHyperlink, bIsUICharStyle, bHasAutoStyle ) );
 
         Reference < XPropertySetInfo > xPropSetInfo;
-        if( bHyperlink )
+        sal_Bool bHyperlinkAttrsAdded = sal_False;
+        if ( bHyperlink )
         {
             Reference< XPropertyState > xPropState( xPropSet, UNO_QUERY );
-            xPropSetInfo.set(xPropSet->getPropertySetInfo());
-            bHyperlink = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
+            xPropSetInfo.set( xPropSet->getPropertySetInfo() );
+            bHyperlinkAttrsAdded = addHyperlinkAttributes( xPropSet, xPropState, xPropSetInfo );
         }
-        SvXMLElementExport aElem( GetExport(), bHyperlink, XML_NAMESPACE_TEXT,
-                                  XML_A, sal_False, sal_False );
-        if( bHyperlink )
+
+        if ( bHyperlink && bHyperlinkAttrsAdded )
         {
+            SvXMLElementExport aElem( GetExport(), sal_True, XML_NAMESPACE_TEXT, XML_A, sal_False, sal_False );
+
             // export events (if supported)
-            OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
-                "HyperLinkEvents"));
-            if (xPropSetInfo->hasPropertyByName(sHyperLinkEvents))
+            static const OUString sHyperLinkEvents( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkEvents" ) );
+            if ( xPropSetInfo->hasPropertyByName( sHyperLinkEvents ) )
             {
-                Reference<XNameReplace> xName(xPropSet->getPropertyValue(sHyperLinkEvents), uno::UNO_QUERY);
-                GetExport().GetEventExport().Export(xName, sal_False);
+                Reference< XNameReplace > xName( xPropSet->getPropertyValue( sHyperLinkEvents ), uno::UNO_QUERY );
+                GetExport().GetEventExport().Export( xName, sal_False );
             }
-        }
 
+            exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
+        }
+        else
         {
-            XMLTextCharStyleNamesElementExport aCharStylesExport(
-                GetExport(), bIsUICharStyle &&
-                             aCharStyleNamesPropInfoCache.hasProperty(
-                                                    xPropSet, xPropSetInfo ), bHasAutoStyle,
-                xPropSet, sCharStyleNames );
-
-            OUString aText(rTextRange->getString());
-            if( sStyle.getLength() )
-                GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
-                          GetExport().EncodeStyleName( sStyle ) );
-            {
-                // in a block to make sure it is destroyed before the text:a element
-                SvXMLElementExport aElement( GetExport(), sStyle.getLength() > 0,
-                                          XML_NAMESPACE_TEXT, XML_SPAN, sal_False,
-                                          sal_False );
-                exportText( aText, rPrevCharIsSpace );
-            }
+            exportTextRangeSpan( rTextRange, xPropSet, xPropSetInfo, bIsUICharStyle, bHasAutoStyle, sStyle, rPrevCharIsSpace );
         }
     }
 }
diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx
index d40afb2..9b9a8f0 100644
--- a/xmloff/source/text/txtparai.cxx
+++ b/xmloff/source/text/txtparai.cxx
@@ -338,10 +338,10 @@ public:
 
 class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
 {
-    XMLHints_Impl&  rHints;
-    XMLHyperlinkHint_Impl   *pHint;
+    XMLHints_Impl&  mrHints;
+    XMLHyperlinkHint_Impl   *mpHint;
 
-    sal_Bool&       rIgnoreLeadingSpace;
+    sal_Bool&       mrbIgnoreLeadingSpace;
 
 public:
 
@@ -367,71 +367,77 @@ public:
 TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
 
 XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
-        SvXMLImport& rImport,
-        sal_uInt16 nPrfx,
-        const OUString& rLName,
-        const Reference< xml::sax::XAttributeList > & xAttrList,
-        XMLHints_Impl& rHnts,
-        sal_Bool& rIgnLeadSpace ) :
-    SvXMLImportContext( rImport, nPrfx, rLName ),
-    rHints( rHnts ),
-    pHint( new XMLHyperlinkHint_Impl(
-              GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
-    rIgnoreLeadingSpace( rIgnLeadSpace )
+    SvXMLImport& rImport,
+    sal_uInt16 nPrfx,
+    const OUString& rLName,
+    const Reference< xml::sax::XAttributeList > & xAttrList,
+    XMLHints_Impl& rHnts,
+    sal_Bool& rIgnLeadSpace )
+    : SvXMLImportContext( rImport, nPrfx, rLName )
+    , mrHints( rHnts )
+    , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
+    , mrbIgnoreLeadingSpace( rIgnLeadSpace )
 {
     OUString sShow;
-    const SvXMLTokenMap& rTokenMap =
-        GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
+    const SvXMLTokenMap& rTokenMap = GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
 
     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
-    for( sal_Int16 i=0; i < nAttrCount; i++ )
+    for ( sal_Int16 i = 0; i < nAttrCount; i++ )
     {
         const OUString& rAttrName = xAttrList->getNameByIndex( i );
         const OUString& rValue = xAttrList->getValueByIndex( i );
 
         OUString aLocalName;
-        sal_uInt16 nPrefix =
-            GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
-                                                            &aLocalName );
-        switch( rTokenMap.Get( nPrefix, aLocalName ) )
+        const sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
+        switch (rTokenMap.Get( nPrefix, aLocalName ))
         {
         case XML_TOK_TEXT_HYPERLINK_HREF:
-            pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
+            mpHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
             break;
         case XML_TOK_TEXT_HYPERLINK_NAME:
-            pHint->SetName( rValue );
+            mpHint->SetName( rValue );
             break;
         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
-            pHint->SetTargetFrameName( rValue );
+            mpHint->SetTargetFrameName( rValue );
             break;
         case XML_TOK_TEXT_HYPERLINK_SHOW:
             sShow = rValue;
             break;
         case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
-            pHint->SetStyleName( rValue );
+            mpHint->SetStyleName( rValue );
             break;
         case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
-            pHint->SetVisitedStyleName( rValue );
+            mpHint->SetVisitedStyleName( rValue );
             break;
         }
     }
 
-    if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() )
+    if( sShow.getLength() && !mpHint->GetTargetFrameName().getLength() )
     {
         if( IsXMLToken( sShow, XML_NEW ) )
-            pHint->SetTargetFrameName(
+            mpHint->SetTargetFrameName(
                     OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
         else if( IsXMLToken( sShow, XML_REPLACE ) )
-            pHint->SetTargetFrameName(
+            mpHint->SetTargetFrameName(
                     OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
     }
-    rHints.Insert( pHint, rHints.Count() );
+
+    if ( mpHint->GetHRef().isEmpty() )
+    {
+        // hyperlink without an URL is not imported.
+        delete mpHint;
+        mpHint = NULL;
+    }
+    else
+    {
+        mrHints.Insert( mpHint, mrHints.Count() );
+    }
 }
 
 XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
 {
-    if( pHint )
-        pHint->SetEnd( GetImport().GetTextImport()
+    if( mpHint != NULL )
+        mpHint->SetEnd( GetImport().GetTextImport()
                             ->GetCursorAsRange()->getStart() );
 }
 
@@ -444,7 +450,7 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
     {
         XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
             GetImport(), nPrefix, rLocalName);
-        pHint->SetEventsContext(pCtxt);
+        mpHint->SetEventsContext(pCtxt);
         return pCtxt;
     }
     else
@@ -455,13 +461,13 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
 
         return XMLImpSpanContext_Impl::CreateChildContext(
             GetImport(), nPrefix, rLocalName, xAttrList,
-            nToken, rHints, rIgnoreLeadingSpace );
+            nToken, mrHints, mrbIgnoreLeadingSpace );
     }
 }
 
 void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
 {
-    GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace );
+    GetImport().GetTextImport()->InsertString( rChars, mrbIgnoreLeadingSpace );
 }
 
 // ---------------------------------------------------------------------
@@ -1656,25 +1662,23 @@ SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
         // test for HyperLinkURL property. If present, insert link as
         // text property (StarWriter), else try to insert as text
         // field (StarCalc, StarDraw, ...)
-        Reference<beans::XPropertySet> xPropSet(
-            rImport.GetTextImport()->GetCursor(),
-            UNO_QUERY );
+        Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
 
-        const OUString sHyperLinkURL(
-            RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
+        static const OUString sHyperLinkURL( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkURL" ) );
 
-        if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL))
+        if ( xPropSet->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL ) )
         {
-            pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix,
-                                                        rLocalName, xAttrList,
-                                                        rHints,
-                                                        rIgnoreLeadingSpace );
+            pContext = new XMLImpHyperlinkContext_Impl(
+                    rImport,
+                    nPrefix,
+                    rLocalName,
+                    xAttrList,
+                    rHints,
+                    rIgnoreLeadingSpace );
         }
         else
         {
-            pContext = new XMLUrlFieldImportContext( rImport,
-                                              *rImport.GetTextImport().get(),
-                                                     nPrefix, rLocalName);
+            pContext = new XMLUrlFieldImportContext( rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName );
             //whitespace handling like other fields
             rIgnoreLeadingSpace = sal_False;
 


More information about the Libreoffice-commits mailing list