21#include <com/sun/star/io/XInputStream.hpp>
22#include <com/sun/star/uno/XComponentContext.hpp>
23#include <com/sun/star/container/XNameAccess.hpp>
24#include <com/sun/star/beans/PropertyState.hpp>
39OUString supportedByType( std::u16string_view clipBoardFormat, std::u16string_view resultString,
const OUString& checkType)
44 std::u16string_view tryStr = clipBoardFormat.substr(8);
45 if (resultString.find(tryStr) != std::u16string_view::npos)
53bool IsMediaTypeXML(
const OUString& mediaType )
55 if (!mediaType.isEmpty())
57 OUString
sType, sSubType;
59 && sType ==
"application")
62 if (sSubType ==
"xml")
65 if (sSubType.endsWith(
"+xml"))
80 css::uno::Reference< css::io::XInputStream > xInStream;
81 const PropertyValue * pValue =
aArguments.getConstArray();
83 OUString resultString;
89 if ( pValue[
i].
Name ==
"TypeName" )
93 else if ( pValue[
i].
Name ==
"URL" )
95 pValue[
i].Value >>= sUrl;
97 else if ( pValue[
i].
Name ==
"InputStream" )
99 pValue[
i].Value >>= xInStream ;
117 pInStream->StartReadingUnicodeText( RTL_TEXTENCODING_DONTKNOW );
118 sal_uInt64
const nUniPos = pInStream->Tell();
120 const sal_uInt16 nSize = 4000;
121 bool bTryUtf16 =
false;
125 sal_uInt16 nHeader = 0;
126 pInStream->ReadUInt16( nHeader );
127 if ( nHeader == 0x003C )
129 else if ( nHeader == 0x3C00 )
132 pInStream->SetEndian( pInStream->GetEndian() == SvStreamEndian::LITTLE ? SvStreamEndian::BIG : SvStreamEndian::LITTLE );
137 if ( nUniPos == 3 || ( nUniPos == 0 && !bTryUtf16 ) )
140 resultString = OUString(str.getStr(), str.getLength(),
141 RTL_TEXTENCODING_ASCII_US,
142 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT|RTL_TEXTTOUNICODE_FLAGS_INVALID_DEFAULT);
144 else if ( nUniPos == 2 || bTryUtf16 )
147 if ( !resultString.startsWith(
"<?xml" ) )
178 sal_Int32 new_nlength=0;
180 while ((
i <
nLength) && (sTypeName.isEmpty()))
182 Any elem = xTypeCont->getByName(myTypes[
i]);
184 new_nlength = lProps.getLength();
186 while (j < new_nlength && (sTypeName.isEmpty()))
189 lProps[j].Value >>=tmpStr;
190 if ( lProps[j].
Name ==
"ClipboardFormat" && !tmpStr.isEmpty() )
192 sTypeName = supportedByType(tmpStr,resultString, myTypes[
i]);
204 if (!sTypeName.isEmpty())
209 aArguments.getArray()[location].Name =
"TypeName";
211 aArguments.getArray()[location].Value <<=sTypeName;
225 return "com.sun.star.comp.filters.XMLFilterDetect";
235 return {
"com.sun.star.document.ExtendedTypeDetection" };
238extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
240 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
constexpr OUStringLiteral sMediaType
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Reference< css::uno::XComponentContext > mxCtx
virtual OUString SAL_CALL getImplementationName() override
virtual OUString SAL_CALL detect(css::uno::Sequence< css::beans::PropertyValue > &lDescriptor) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
css::uno::Any getPropertyValue(const OUString &rPropertyName)
css::uno::Reference< css::io::XInputStream > openStream()
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
#define TOOLS_WARN_EXCEPTION(area, stream)
Sequence< PropertyValue > aArguments
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
void checkType(rtl::Reference< TypeManager > const &manager, OUString const &name, std::set< OUString > &interfaceTypes, std::set< OUString > &serviceTypes, AttributeInfo &properties)
TOOLS_DLLPUBLIC OString read_uInt8s_ToOString(SvStream &rStrm, std::size_t nUnits)
TOOLS_DLLPUBLIC OUString read_uInt16s_ToOUString(SvStream &rStrm, std::size_t nUnits)
#define STREAM_SEEK_TO_BEGIN
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_XMLFilterDetect_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)