Kaydet (Commit) fed4f580 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Use the new excel format detector for all binary excel types.

But I have yet to implement the detection of Excel 4.0...

Separating detection services like this will make the overall type
detection process a little more reliable. It's actually not a good
idea to use a single type detection service for a multitude of file
format types...

Change-Id: I2914c179ac939a031b84e8d37de891a5043851e6
üst ff59007a
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_40" oor:op="replace" > <node oor:name="calc_MS_Excel_40" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xls xlw xlc xlm</value></prop> <prop oor:name="Extensions"><value>xls xlw xlc xlm</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_40_VorlageTemplate" oor:op="replace" > <node oor:name="calc_MS_Excel_40_VorlageTemplate" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xlt</value></prop> <prop oor:name="Extensions"><value>xlt</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_5095" oor:op="replace" > <node oor:name="calc_MS_Excel_5095" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop> <prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_5095_VorlageTemplate" oor:op="replace" > <node oor:name="calc_MS_Excel_5095_VorlageTemplate" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xlt</value></prop> <prop oor:name="Extensions"><value>xlt</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_95" oor:op="replace" > <node oor:name="calc_MS_Excel_95" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop> <prop oor:name="Extensions"><value>xls xlc xlm xlw</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_95_VorlageTemplate" oor:op="replace" > <node oor:name="calc_MS_Excel_95_VorlageTemplate" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xlt</value></prop> <prop oor:name="Extensions"><value>xlt</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_97" oor:op="replace" > <node oor:name="calc_MS_Excel_97" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xls xlc xlm xlw xlk</value></prop> <prop oor:name="Extensions"><value>xls xlc xlm xlw xlk</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
--> -->
<node oor:name="calc_MS_Excel_97_VorlageTemplate" oor:op="replace" > <node oor:name="calc_MS_Excel_97_VorlageTemplate" oor:op="replace" >
<prop oor:name="DetectService"><value>com.sun.star.comp.calc.FormatDetector</value></prop> <prop oor:name="DetectService"><value>com.sun.star.comp.calc.ExcelBiffFormatDetector</value></prop>
<prop oor:name="URLPattern"/> <prop oor:name="URLPattern"/>
<prop oor:name="Extensions"><value>xlt</value></prop> <prop oor:name="Extensions"><value>xlt</value></prop>
<prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop> <prop oor:name="MediaType"><value>application/vnd.ms-excel</value></prop>
......
...@@ -9,7 +9,19 @@ ...@@ -9,7 +9,19 @@
#include "exceldetect.hxx" #include "exceldetect.hxx"
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/ucb/XContent.hpp>
#include "svl/itemset.hxx"
#include "svl/eitem.hxx"
#include "sfx2/app.hxx"
#include "sfx2/docfile.hxx"
#include "sfx2/sfxsids.hrc"
#include "comphelper/mediadescriptor.hxx"
#include "sot/storage.hxx"
using namespace com::sun::star; using namespace com::sun::star;
using comphelper::MediaDescriptor;
ScExcelBiffDetect::ScExcelBiffDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ ) {} ScExcelBiffDetect::ScExcelBiffDetect( const uno::Reference<uno::XComponentContext>& /*xContext*/ ) {}
ScExcelBiffDetect::~ScExcelBiffDetect() {} ScExcelBiffDetect::~ScExcelBiffDetect() {}
...@@ -36,9 +48,95 @@ uno::Sequence<OUString> ScExcelBiffDetect::getSupportedServiceNames() throw (uno ...@@ -36,9 +48,95 @@ uno::Sequence<OUString> ScExcelBiffDetect::getSupportedServiceNames() throw (uno
return impl_getStaticSupportedServiceNames(); return impl_getStaticSupportedServiceNames();
} }
namespace {
bool hasStream(const uno::Reference<io::XInputStream>& xInStream, const OUString& rName)
{
SfxMedium aMedium;
aMedium.UseInteractionHandler(true);
aMedium.setStreamToLoadFrom(xInStream, true);
SvStream* pStream = aMedium.GetInStream();
if (!pStream)
return false;
pStream->Seek(STREAM_SEEK_TO_END);
sal_Size nSize = pStream->Tell();
pStream->Seek(0);
if (!nSize)
// 0-size stream. Failed.
return false;
SotStorageRef xStorage = new SotStorage(pStream, false);
if (!xStorage.Is() || xStorage->GetError())
return false;
return xStorage->IsStream(rName);
}
bool isTemplate(const OUString& rType)
{
return rType.indexOf("_VorlageTemplate") != -1;
}
}
OUString ScExcelBiffDetect::detect( uno::Sequence<beans::PropertyValue>& lDescriptor ) OUString ScExcelBiffDetect::detect( uno::Sequence<beans::PropertyValue>& lDescriptor )
throw (uno::RuntimeException) throw (uno::RuntimeException)
{ {
MediaDescriptor aMediaDesc(lDescriptor);
OUString aType;
aMediaDesc[MediaDescriptor::PROP_TYPENAME()] >>= aType;
if (aType.isEmpty())
// Type is not given. We can't proceed.
return OUString();
aMediaDesc.addInputStream();
uno::Reference<io::XInputStream> xInStream(aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY);
if (!xInStream.is())
// No input stream.
return OUString();
if (aType == "calc_MS_Excel_97" || aType == "calc_MS_Excel_97_VorlageTemplate")
{
// See if this stream is a Excel 97/XP/2003 (BIFF8) stream.
if (!hasStream(xInStream, "Workbook"))
// BIFF8 is expected to contain a stream named "Workbook".
return OUString();
aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 97 Vorlage/Template") : OUString("MS Excel 97");
return aType;
}
if (aType == "calc_MS_Excel_95" || aType == "calc_MS_Excel_95_VorlageTemplate")
{
// See if this stream is a Excel 95 (BIFF5) stream.
if (!hasStream(xInStream, "Book"))
return OUString();
aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 95 Vorlage/Template") : OUString("MS Excel 95");
return aType;
}
if (aType == "calc_MS_Excel_5095" || aType == "calc_MS_Excel_5095_VorlageTemplate")
{
// See if this stream is a Excel 5.0/95 stream.
if (!hasStream(xInStream, "Book"))
return OUString();
aMediaDesc[MediaDescriptor::PROP_FILTERNAME()] <<= isTemplate(aType) ? OUString("MS Excel 5.0/95 Vorlage/Template") : OUString("MS Excel 5.0/95");
return aType;
}
if (aType == "calc_MS_Excel_40" || aType == "calc_MS_Excel_40_VorlageTemplate")
{
// See if this stream is a Excel 4.0 stream.
// TODO: Implement this.
return OUString();
}
// failed!
return OUString(); return OUString();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment