Kaydet (Commit) 40e043ca authored tarafından Michael Stahl's avatar Michael Stahl

sw: remove more dead code from SwIoSystem::GetFileFilter()

Change-Id: I53cadf01246faf3c4b54ee360db19bde2dcb98cc
üst 3ec25899
...@@ -102,8 +102,6 @@ public: ...@@ -102,8 +102,6 @@ public:
static bool IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen, static bool IsDetectableText( const sal_Char* pBuf, sal_uLong &rLen,
rtl_TextEncoding *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false ); rtl_TextEncoding *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0, bool bEncodedFilter = false );
static const SfxFilter* GetTextFilter( const sal_Char* pBuf, sal_uLong nLen );
static const OUString GetSubStorageName( const SfxFilter& rFltr ); static const OUString GetSubStorageName( const SfxFilter& rFltr );
}; };
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <unotools/moduleoptions.hxx> #include <unotools/moduleoptions.hxx>
using namespace ::com::sun::star;
static bool IsDocShellRegistered() static bool IsDocShellRegistered()
{ {
return SvtModuleOptions().IsWriter(); return SvtModuleOptions().IsWriter();
...@@ -210,7 +213,6 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) ...@@ -210,7 +213,6 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
if ( !pFilter ) if ( !pFilter )
return 0; return 0;
::boost::scoped_ptr<SfxMedium> pMedium;
if (SotStorage::IsStorageFile(rFileName)) if (SotStorage::IsStorageFile(rFileName))
{ {
// package storage or OLEStorage based format // package storage or OLEStorage based format
...@@ -218,25 +220,24 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) ...@@ -218,25 +220,24 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
INetURLObject aObj; INetURLObject aObj;
aObj.SetSmartProtocol( INET_PROT_FILE ); aObj.SetSmartProtocol( INET_PROT_FILE );
aObj.SetSmartURL( rFileName ); aObj.SetSmartURL( rFileName );
pMedium.reset(new SfxMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ)); SfxMedium aMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ);
// templates should not get precedence over "normal" filters (#i35508, #i33168) // templates should not get precedence over "normal" filters (#i35508, #i33168)
const SfxFilter* pTemplateFilter = 0; const SfxFilter* pTemplateFilter = 0;
const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName(""); if (aMedium.IsStorage())
assert(!pOldFilter);
bool bLookForTemplate = pOldFilter && pOldFilter->IsOwnTemplateFormat();
if ( pMedium->IsStorage() )
{ {
com::sun::star::uno::Reference < com::sun::star::embed::XStorage > xStor = pMedium->GetStorage(); uno::Reference<embed::XStorage> const xStor = aMedium.GetStorage();
if ( xStor.is() ) if ( xStor.is() )
{ {
while ( pFilter ) while ( pFilter )
{ {
if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( xStor, *pFilter ) ) if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( xStor, *pFilter ) )
{ {
if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate ) if (pFilter->IsOwnTemplateFormat())
{
// found template filter; maybe there's a "normal" one also // found template filter; maybe there's a "normal" one also
pTemplateFilter = pFilter; pTemplateFilter = pFilter;
}
else else
return pFilter; return pFilter;
} }
...@@ -253,7 +254,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) ...@@ -253,7 +254,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
{ {
try try
{ {
SvStream* pStream = pMedium->GetInStream(); SvStream *const pStream = aMedium.GetInStream();
if ( pStream && SotStorage::IsStorageFile(pStream) ) if ( pStream && SotStorage::IsStorageFile(pStream) )
xStg = new SotStorage( pStream, false ); xStg = new SotStorage( pStream, false );
} }
...@@ -267,9 +268,11 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) ...@@ -267,9 +268,11 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
{ {
if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( *xStg, *pFilter ) ) if( 'C' == pFilter->GetUserData()[0] && IsValidStgFilter( *xStg, *pFilter ) )
{ {
if ( pFilter->IsOwnTemplateFormat() && !bLookForTemplate ) if (pFilter->IsOwnTemplateFormat())
{
// found template filter; maybe there's a "normal" one also // found template filter; maybe there's a "normal" one also
pTemplateFilter = pFilter; pTemplateFilter = pFilter;
}
else else
return pFilter; return pFilter;
} }
...@@ -287,42 +290,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) ...@@ -287,42 +290,7 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName)
return pFilter; return pFilter;
} }
sal_Char aBuffer[4098]; return SwIoSystem::GetFilterOfFormat(OUString::createFromAscii(FILTER_TEXT), 0);
const sal_uLong nMaxRead = sizeof(aBuffer) - 2;
sal_uLong nBytesRead = 0;
if (pMedium)
{
SvStream* pIStrm = pMedium->GetInStream();
if( !pIStrm || SVSTREAM_OK != pIStrm->GetError() )
return 0;
sal_uLong nCurrPos = pIStrm->Tell();
nBytesRead = pIStrm->Read(aBuffer, nMaxRead);
pIStrm->Seek( nCurrPos );
}
TerminateBuffer(aBuffer, nBytesRead, sizeof(aBuffer));
{
for( sal_uInt16 n = 0; n < MAXFILTER; ++n )
{
OUString sNm(aFilterDetect[n].IsReader(aBuffer, nBytesRead));
const SfxFilter* pFilterTmp =
sNm.isEmpty() ? 0 : SwIoSystem::GetFilterOfFormat(sNm, pFCntnr);
if (pFilterTmp)
{
return pFilterTmp;
}
}
}
// no filter recognized so far; thus check "WORD 4 WORD" Filter
if( !rFileName.isEmpty() )
{
if( pMedium )
pMedium->CloseInStream();
}
return SwIoSystem::GetTextFilter( aBuffer, nBytesRead);
} }
bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen, bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen,
...@@ -464,11 +432,4 @@ bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen, ...@@ -464,11 +432,4 @@ bool SwIoSystem::IsDetectableText(const sal_Char* pBuf, sal_uLong &rLen,
return bEncodedFilter || (!bIsBareUnicode && eSysLE == eLineEnd); return bEncodedFilter || (!bIsBareUnicode && eSysLE == eLineEnd);
} }
const SfxFilter* SwIoSystem::GetTextFilter( const sal_Char* pBuf, sal_uLong nLen)
{
bool bAuto = IsDetectableText(pBuf, nLen);
const sal_Char* pNm = bAuto ? FILTER_TEXT : FILTER_TEXT_DLG;
return SwIoSystem::GetFilterOfFormat( OUString::createFromAscii(pNm), 0 );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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