Commits

Ingrid Halama  committed 47203f3

chart50: #i113950# ODF: don't export text:id with bad value

  • Participants
  • Parent commits 4bf1484

Comments (0)

Files changed (4)

File xmloff/source/chart/SchXMLExport.cxx

         {
             mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_STRING );
             SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
-            // write the original range name as id into the local table
-            // to allow a correct re-association when copying via clipboard
-            if( !bHasOwnData && aColumnDescriptions_RangeIter != aColumnDescriptions_RangeEnd )
-            {
-                if ((*aColumnDescriptions_RangeIter).getLength())
-                {
-                    mrExport.AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
-                        *aColumnDescriptions_RangeIter);
-                }
-                ++aColumnDescriptions_RangeIter;
-            }
             exportText( *aIt );
             if( nC < nComplexCount )
                 lcl_exportComplexLabel( rComplexColumnDescriptions[nC++], mrExport );
+            if( !bHasOwnData && aColumnDescriptions_RangeIter != aColumnDescriptions_RangeEnd )
+            {
+                // remind the original range to allow a correct re-association when copying via clipboard
+                if ((*aColumnDescriptions_RangeIter).getLength())
+                    SchXMLTools::exportRangeToSomewhere( mrExport, *aColumnDescriptions_RangeIter );
+                ++aColumnDescriptions_RangeIter;
+            }
         }
         OSL_ASSERT( bHasOwnData || aColumnDescriptions_RangeIter == aColumnDescriptions_RangeEnd );
     } // closing row and header-rows elements
                 SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
                 if( aRowDescriptionsIter != aData.aRowDescriptions.end())
                 {
-                    // write the original range name as id into the local table
-                    // to allow a correct re-association when copying via clipboard
-                    if( !bHasOwnData && aRowDescriptions_RangeIter != aRowDescriptions_RangeEnd )
-                    {
-                        mrExport.AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
-                            *aRowDescriptions_RangeIter++);
-                    }
                     exportText( *aRowDescriptionsIter );
                     ++aRowDescriptionsIter;
                     if( nC < nComplexCount )
                         lcl_exportComplexLabel( rComplexRowDescriptions[nC++], mrExport );
+                    if( !bHasOwnData && aRowDescriptions_RangeIter != aRowDescriptions_RangeEnd )
+                    {
+                        // remind the original range to allow a correct re-association when copying via clipboard
+                        SchXMLTools::exportRangeToSomewhere( mrExport, *aRowDescriptions_RangeIter++ );
+                    }
                 }
             }
 
                 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE_TYPE, XML_FLOAT );
                 mrExport.AddAttribute( XML_NAMESPACE_OFFICE, XML_VALUE, msString );
                 SvXMLElementExport aCell( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_CELL, sal_True, sal_True );
-                // write the original range name as id into the local table to
-                // allow a correct re-association when copying via clipboard
+                exportText( msString, false ); // do not convert tabs and lfs
                 if( ( !bHasOwnData && aDataRangeIter != aDataRangeEndIter ) &&
-                    ( mbRowSourceColumns || (aColIt == aRowIt->begin())) )
+                    ( mbRowSourceColumns || (aColIt == aRowIt->begin()) ) )
                 {
+                    // remind the original range to allow a correct re-association when copying via clipboard
                     if ((*aDataRangeIter).getLength())
-                    {
-                        mrExport.AddAttributeIdLegacy(XML_NAMESPACE_TEXT,
-                            *aDataRangeIter);
-                    }
+                        SchXMLTools::exportRangeToSomewhere( mrExport, *aDataRangeIter );
                     ++aDataRangeIter;
                 }
-                exportText( msString, false ); // do not convert tabs and lfs
             }
         }
     }

File xmloff/source/chart/SchXMLTableContext.cxx

 #include "SchXMLImport.hxx"
 #include "SchXMLTools.hxx"
 #include "transporttypes.hxx"
+#include "XMLStringBufferImportContext.hxx"
 #include <tools/debug.hxx>
 #include <rtl/math.hxx>
 #include "xmlnmspe.hxx"
 	return pContext;
 }
 
+//---------------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------------
+
+class SchXMLRangeSomewhereContext : public SvXMLImportContext
+{
+//#i113950# previously the range was exported to attribute text:id,
+//but that attribute does not allow arbitrary strings anymore
+//so we need to find an alternative to save that range info for copy/paste scenario ...
+//-> use description at an empty group element for now
+
+private:
+	::rtl::OUString& mrRangeString;
+    ::rtl::OUStringBuffer maRangeStringBuffer;
+
+public:
+	SchXMLRangeSomewhereContext( SvXMLImport& rImport,
+							const ::rtl::OUString& rLocalName,
+							::rtl::OUString& rRangeString );
+	virtual ~SchXMLRangeSomewhereContext();
+	
+	virtual SvXMLImportContext* CreateChildContext(
+		USHORT nPrefix,
+		const ::rtl::OUString& rLocalName,
+		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
+    virtual void EndElement();
+};
+
+//---------------------------------------------------------------------------------------------------
+//---------------------------------------------------------------------------------------------------
 
 // ========================================
 // classes for cells and their content
         pContext = new SchXMLTextListContext( GetImport(), rLocalName, *rCell.pComplexString );
         mbReadText = sal_False;//don't apply text from <text:p>
 	}
-	// <text:p> element - read text and range-id
+	// <text:p> element - read text (and range from text:id old version)
 	else if( nPrefix == XML_NAMESPACE_TEXT && IsXMLToken( rLocalName, XML_P ) )
 	{
         pContext = new SchXMLParagraphContext( GetImport(), rLocalName, maCellContent, &maRangeId );
 	}
+    // <draw:g> element - read range
+    else if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_G ) )
+	{
+        //#i113950# previously the range was exported to attribute text:id, but that attribute does not allow arbitrary strings anymore
+        //so we need to find an alternative to save that range info for copy/paste scenario ... -> use description at an empty group element for now
+        pContext = new SchXMLRangeSomewhereContext( GetImport(), rLocalName, maRangeId );
+	}
 	else
 	{
 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     }
 }
 
+//---------------------------------------------------------------------------------------------------
+
+SchXMLRangeSomewhereContext::SchXMLRangeSomewhereContext( SvXMLImport& rImport,
+												const OUString& rLocalName,
+												OUString& rRangeString ) :
+		SvXMLImportContext( rImport, XML_NAMESPACE_TEXT, rLocalName ),
+		mrRangeString( rRangeString )
+{
+}
+
+SchXMLRangeSomewhereContext::~SchXMLRangeSomewhereContext()
+{
+}
+
+SvXMLImportContext* SchXMLRangeSomewhereContext::CreateChildContext(
+    USHORT nPrefix,
+    const OUString& rLocalName,
+    const uno::Reference< xml::sax::XAttributeList >& )
+{
+    if( XML_NAMESPACE_SVG == nPrefix && IsXMLToken( rLocalName, XML_DESC ) )
+	{
+		return new XMLStringBufferImportContext(
+			GetImport(), nPrefix, rLocalName, maRangeStringBuffer );
+	}
+	return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
+}
+
+void SchXMLRangeSomewhereContext::EndElement()
+{
+    mrRangeString = maRangeStringBuffer.makeStringAndClear();
+}

File xmloff/source/chart/SchXMLTools.cxx

     }
 }
 
+void exportRangeToSomewhere( SvXMLExport& rExport, const ::rtl::OUString& rValue )
+{
+    //with issue #i366# and CWS chart20 ranges for error bars were introduced
+    //to keep them during copy paste from calc to impress for example it
+    //was necessary to introduce a mapping between the used ranges within calc and the data written to the local table
+    //this is why we write this ranges here
+
+    //#i113950# first the range was exported to attribute text:id, but that attribute does not allow arbitrary strings anymore within ODF 1.2
+    //as an alternative the range info is now saved into the description at an empty group element (not very nice, but ODF conform)
+
+    const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
+    if( nCurrentODFVersion == SvtSaveOptions::ODFVER_010 || nCurrentODFVersion == SvtSaveOptions::ODFVER_011 )
+        return;//svg:desc is not allowed at draw:g in ODF1.0; but as the ranges for error bars are anyhow not allowed within ODF1.0 nor ODF1.1 we do not need the information
+    
+    SvXMLElementExport aEmptyShapeGroup( rExport, XML_NAMESPACE_DRAW,
+                              ::xmloff::token::GetXMLToken( ::xmloff::token::XML_G ),
+                              sal_True, sal_False );
+    SvXMLElementExport aDescription( rExport, XML_NAMESPACE_SVG,
+                              ::xmloff::token::GetXMLToken( ::xmloff::token::XML_DESC ),
+                              sal_True, sal_False );
+    rExport.GetDocHandler()->characters( rValue );
+}
+
 Reference< chart2::XRegressionCurve > getRegressionCurve(
     const Reference< chart2::XDataSeries > & xDataSeries )
 {

File xmloff/source/chart/SchXMLTools.hxx

 
     void exportText( SvXMLExport& rExport, const ::rtl::OUString& rText, bool bConvertTabsLFs );
 
+    void exportRangeToSomewhere( SvXMLExport& rExport, const ::rtl::OUString& rValue );
+
     /** returns the properties of the equation of the first regression curve
         that is no mean-value line
      */