22#include <osl/endian.h>
29#include <com/sun/star/ucb/ContentCreationException.hpp>
30#include <com/sun/star/embed/XStorage.hpp>
31#include <unicode/ucsdet.h>
64 return "WordDocument";
80 std::shared_ptr<const SfxFilter> pFilter = aIter.
First();
83 if( pFilter->GetUserData() == rFormatNm )
85 pFilter = aIter.
Next();
88 if( pCnt || pFltCnt == &aCntSwWeb )
101 bRet = rStg->isStreamElement(
"content.xml" );
103 bRet = ( nStgFormatId != SotClipboardFormatId::NONE && ( rFilter.
GetFormat() == nStgFormatId ) );
105 catch (
const css::uno::Exception& )
117 nStgFormatId = SotClipboardFormatId::NONE;
120 ( nStgFormatId == SotClipboardFormatId::NONE || rFilter.
GetFormat() == nStgFormatId ) &&
135 StreamMode::STD_READ );
138 xRef->ReadUChar( nByte );
157 std::shared_ptr<const SfxFilter> pFilter = aIter.
First();
171 std::shared_ptr<const SfxFilter> pTemplateFilter;
174 uno::Reference<embed::XStorage>
const xStor = aMedium.
GetStorage();
179 if (pFilter->GetUserData().startsWith(
"C") &&
IsValidStgFilter(xStor, *pFilter ))
181 if (pFilter->IsOwnTemplateFormat())
184 pTemplateFilter = pFilter;
190 pFilter = aIter.
Next();
194 if ( pTemplateFilter )
195 pFilter = pTemplateFilter;
206 catch (
const css::ucb::ContentCreationException &)
214 if (pFilter->GetUserData().startsWith(
"C") &&
IsValidStgFilter(*xStg, *pFilter))
216 if (pFilter->IsOwnTemplateFormat())
219 pTemplateFilter = pFilter;
225 pFilter = aIter.
Next();
229 if ( pTemplateFilter )
230 pFilter = pTemplateFilter;
243 sal_Size nLen, nOrig;
247 rtl_TextEncoding eCharSet;
249 if (bRet && eCharSet != RTL_TEXTENCODING_DONTKNOW)
258 rtl_TextEncoding *pCharSet,
bool *pSwap,
LineEnd *pLineEnd,
bool *pBom)
261 rtl_TextEncoding eCharSet = RTL_TEXTENCODING_DONTKNOW;
271 eCharSet = RTL_TEXTENCODING_UTF8;
277 eCharSet = RTL_TEXTENCODING_UCS2;
284 eCharSet = RTL_TEXTENCODING_UCS2;
292 if (rLen >= 1 && eCharSet == RTL_TEXTENCODING_DONTKNOW)
294 UErrorCode uerr = U_ZERO_ERROR;
295 UCharsetDetector* ucd = ucsdet_open(&uerr);
296 ucsdet_setText(ucd, pBuf, rLen, &uerr);
297 if (
const UCharsetMatch*
match = ucsdet_detect(ucd, &uerr))
299 const char* pEncodingName = ucsdet_getName(
match, &uerr);
301 if (U_SUCCESS(uerr) && !strcmp(
"UTF-8", pEncodingName))
303 eCharSet = RTL_TEXTENCODING_UTF8;
305 else if (U_SUCCESS(uerr) && !strcmp(
"UTF-16BE", pEncodingName))
307 eCharSet = RTL_TEXTENCODING_UCS2;
310 else if (U_SUCCESS(uerr) && !strcmp(
"UTF-16LE", pEncodingName))
312 eCharSet = RTL_TEXTENCODING_UCS2;
314 else if (U_SUCCESS(uerr) && !strcmp(
"GB18030", pEncodingName))
316 eCharSet = RTL_TEXTENCODING_GB_18030;
323 bool bCR =
false, bLF =
false, bIsBareUnicode =
false;
325 if (eCharSet != RTL_TEXTENCODING_DONTKNOW)
327 std::unique_ptr<sal_Unicode[]> aWork(
new sal_Unicode[rLen+1]);
330 if (eCharSet != RTL_TEXTENCODING_UCS2)
333 rtl_TextToUnicodeConverter hConverter =
334 rtl_createTextToUnicodeConverter(eCharSet);
335 rtl_TextToUnicodeContext hContext =
336 rtl_createTextToUnicodeContext(hConverter);
340 nNewLen = rtl_convertTextToUnicode( hConverter, hContext, pBuf,
341 rLen, pNewBuf, nNewLen,
342 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT |
343 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
344 RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT), &nInfo, &nCntBytes);
346 rtl_destroyTextToUnicodeContext(hConverter, hContext);
347 rtl_destroyTextToUnicodeConverter(hConverter);
352 memcpy(pNewBuf, pBuf, rLen);
354 bool const bNativeLE =
true;
356 bool const bNativeLE =
false;
358 if (bLE != bNativeLE)
361 char* pF =
reinterpret_cast<char*
>(pNewBuf);
372 for (
sal_uLong nCnt = 0; nCnt < nNewLen; ++nCnt, ++pNewBuf)
389 for(
sal_uLong nCnt = 0; nCnt < rLen; ++nCnt, ++pBuf )
394 if( nCnt + 1 < rLen && !*(pBuf+1) )
396 bIsBareUnicode =
true;
422 *pCharSet = eCharSet;
426 *pLineEnd = eLineEnd;
430 return !bIsBareUnicode;
void SetSmartProtocol(INetProtocol eTheSmartScheme)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString const & GetName() const
std::shared_ptr< const SfxFilter > First()
std::shared_ptr< const SfxFilter > Next()
const OUString & GetUserData() const
bool IsAllowedAsTemplate() const
SotClipboardFormatId GetFormat() const
css::uno::Reference< css::embed::XStorage > GetStorage(bool bCreateTempFile=true)
bool IsContained(const OUString &rEleName) const
static SotClipboardFormatId GetFormatID(css::uno::Reference< css::embed::XStorage > const &xStorage)
tools::SvRef< SotStorageStream > OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
static bool IsStorageFile(OUString const &rFileName)
SotClipboardFormatId GetFormat()
std::size_t ReadBytes(void *pData, std::size_t nSize)
sal_uInt64 SeekRel(sal_Int64 nPos)
static std::shared_ptr< const SfxFilter > GetFileFilter(const OUString &rFileName)
Detect for the given file which filter should be used.
static bool IsDetectableText(const char *pBuf, sal_uLong &rLen, rtl_TextEncoding *pCharSet, bool *pSwap, LineEnd *pLineEnd, bool *pBom)
static OUString GetSubStorageName(const SfxFilter &rFltr)
static SW_DLLPUBLIC std::shared_ptr< const SfxFilter > GetFilterOfFormat(std::u16string_view rFormat, const SfxFilterContainer *pCnt=nullptr)
find for an internal format name the corresponding filter entry
static bool IsValidStgFilter(SotStorage &, const SfxFilter &)
static SW_DLLPUBLIC rtl_TextEncoding GetTextEncoding(SvStream &)
SwIoDetect aFilterDetect[]
static bool IsDocShellRegistered()
constexpr OUStringLiteral FILTER_WW8
WinWord 97 filter.
constexpr OUStringLiteral FILTER_TEXT_DLG
text filter with encoding dialog
constexpr OUStringLiteral sRtfWH
constexpr OUStringLiteral FILTER_RTF
RTF filter.
constexpr OUStringLiteral FILTER_XML
XML filter.
constexpr OUStringLiteral FILTER_BAS
StarBasic (identical to ANSI)
#define FILTER_XMLVW
XML filter.
constexpr OUStringLiteral sWW5
constexpr OUStringLiteral FILTER_DOCX
constexpr OUStringLiteral sSWRITERWEB
#define FILTER_XMLV
XML filter.
constexpr OUStringLiteral sWW6
constexpr OUStringLiteral sSWRITER
constexpr OUStringLiteral sHTML
constexpr OUStringLiteral FILTER_TEXT
text filter with default codeset
LineEnd GetSystemLineEnd()
bool match(const sal_Unicode *pWild, const sal_Unicode *pStr, const sal_Unicode cEscape)