Commits

Anonymous committed 94204ee

calc67: #i117735# use calc FormatDetector for XLS again, handle Excel 2003 XML directly in XLS detection

  • Participants
  • Parent commits 5d2aa93

Comments (0)

Files changed (9)

File filter/source/config/fragments/types/calc_MS_Excel_40.xcu

 	<node oor:name="calc_MS_Excel_40" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xls xlw xlc xlm</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_40_VorlageTemplate.xcu

 	<node oor:name="calc_MS_Excel_40_VorlageTemplate" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xlt</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_5095.xcu

 	<node oor:name="calc_MS_Excel_5095" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_5095_VorlageTemplate.xcu

 	<node oor:name="calc_MS_Excel_5095_VorlageTemplate" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xlt</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_95.xcu

 	<node oor:name="calc_MS_Excel_95" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_95_VorlageTemplate.xcu

 	<node oor:name="calc_MS_Excel_95_VorlageTemplate" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xlt</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_97.xcu

 	<node oor:name="calc_MS_Excel_97" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File filter/source/config/fragments/types/calc_MS_Excel_97_VorlageTemplate.xcu

 	<node oor:name="calc_MS_Excel_97_VorlageTemplate" oor:op="replace" >
-		<prop oor:name="DetectService"><value>com.sun.star.comp.oox.xls.BiffDetector</value></prop>
+		<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop>
 		<prop oor:name="URLPattern"/>
 		<prop oor:name="Extensions"><value>xlt</value></prop>
 		<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>

File sc/source/ui/unoobj/scdetect.cxx

 static const sal_Char __FAR_DATA pFilterEx95Temp[]	= "MS Excel 95 Vorlage/Template";
 static const sal_Char __FAR_DATA pFilterExcel97[]	= "MS Excel 97";
 static const sal_Char __FAR_DATA pFilterEx97Temp[]	= "MS Excel 97 Vorlage/Template";
+static const sal_Char __FAR_DATA pFilterExcelXML[]  = "MS Excel 2003 XML";
 static const sal_Char __FAR_DATA pFilterDBase[]		= "dBase";
 static const sal_Char __FAR_DATA pFilterDif[]		= "DIF";
 static const sal_Char __FAR_DATA pFilterSylk[]		= "SYLK";
 	return nMask != 0;
 }
 
+static const SfxFilter* lcl_DetectExcelXML( SvStream& rStream, SfxFilterMatcher& rMatcher )
+{
+    const SfxFilter* pFound = NULL;
+    rStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+    const size_t nBufSize = 4000;
+    sal_uInt8 aBuffer[ nBufSize ];
+    sal_uLong nBytesRead = rStream.Read( aBuffer, nBufSize );
+    sal_uLong nXMLStart = 0;
+
+    // Skip UTF-8 BOM if present.
+    // No need to handle UTF-16 etc (also rejected in XMLFilterDetect).
+    if ( nBytesRead >= 3 && aBuffer[0] == 0xEF && aBuffer[1] == 0xBB && aBuffer[2] == 0xBF )
+        nXMLStart = 3;
+
+    if ( nBytesRead >= nXMLStart + 5 && rtl_compareMemory( aBuffer+nXMLStart, "<?xml", 5 ) == 0 )
+    {
+        // Be consistent with XMLFilterDetect service: Check for presence of "Workbook" in XML file.
+
+        rtl::OString aTryStr( "Workbook" );
+        rtl::OString aFileString(reinterpret_cast<const sal_Char*>(aBuffer), nBytesRead);
+
+        if (aFileString.indexOf(aTryStr) >= 0)
+            pFound = rMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterExcelXML) );
+    }
+
+    return pFound;
+}
+
 static sal_Bool lcl_MayBeDBase( SvStream& rStream )
 {
     // Look for dbf marker, see connectivity/source/inc/dbase/DTable.hxx
                                 }
                                 else if ( bIsXLS && bMaybeText )
                                 {
-                                    pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterAscii) );
+                                    // Detect Excel 2003 XML here only if XLS was preselected.
+                                    // The configured detection for Excel 2003 XML is still in XMLFilterDetect.
+                                    pFilter = lcl_DetectExcelXML( rStr, aMatcher );
+                                    if (!pFilter)
+                                        pFilter = aMatcher.GetFilter4FilterName( String::CreateFromAscii(pFilterAscii) );
                                     bFakeXLS = true;
                                 }
                                 else if ( aHeader.CompareTo( "{\\rtf", 5 ) == COMPARE_EQUAL )