23#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
24#include <com/sun/star/linguistic2/ConversionPropertyType.hpp>
25#include <com/sun/star/lang/Locale.hpp>
26#include <com/sun/star/uno/Reference.h>
27#include <com/sun/star/document/XFilter.hpp>
28#include <com/sun/star/beans/PropertyValue.hpp>
53 if (nConversionType == ConversionDictionaryType::HANGUL_HANJA)
55 else if (nConversionType == ConversionDictionaryType::SCHINESE_TCHINESE)
64 nRes = ConversionDictionaryType::HANGUL_HANJA;
66 nRes = ConversionDictionaryType::SCHINESE_TCHINESE;
72class ConvDicXMLImportContext :
88 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
92class ConvDicXMLDictionaryContext_Impl :
93 public ConvDicXMLImportContext
96 sal_Int16 nConversionType;
100 ConvDicXMLImportContext( rImport ),
106 virtual void SAL_CALL startFastElement( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs )
override;
107 virtual css::uno::Reference<XFastContextHandler> SAL_CALL createFastChildContext(
108 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
112class ConvDicXMLEntryTextContext_Impl :
113 public ConvDicXMLImportContext
119 ConvDicXMLImportContext( rImport )
124 virtual void SAL_CALL startFastElement( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs )
override;
125 virtual css::uno::Reference<XFastContextHandler> SAL_CALL createFastChildContext(
126 sal_Int32 Element,
const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
override;
128 const OUString & GetLeftText()
const {
return aLeftText; }
132class ConvDicXMLRightTextContext_Impl :
133 public ConvDicXMLImportContext
136 ConvDicXMLEntryTextContext_Impl &rEntryContext;
139 ConvDicXMLRightTextContext_Impl(
141 ConvDicXMLEntryTextContext_Impl &rParentContext ) :
142 ConvDicXMLImportContext( rImport ),
143 rEntryContext( rParentContext )
148 virtual void SAL_CALL endFastElement( sal_Int32 nElement )
override;
149 virtual void SAL_CALL characters(
const OUString &rChars )
override;
166css::uno::Reference<XFastContextHandler> ConvDicXMLImportContext::createFastChildContext(
168 const css::uno::Reference< css::xml::sax::XFastAttributeList > & )
171 return new ConvDicXMLDictionaryContext_Impl( GetConvDicImport() );
176void ConvDicXMLDictionaryContext_Impl::startFastElement( sal_Int32 ,
177 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttrList )
181 switch (aIter.getToken())
193 GetConvDicImport().SetLanguage( nLanguage );
194 GetConvDicImport().SetConversionType( nConversionType );
198css::uno::Reference<XFastContextHandler> ConvDicXMLDictionaryContext_Impl::createFastChildContext(
200 const css::uno::Reference< css::xml::sax::XFastAttributeList > & )
203 return new ConvDicXMLEntryTextContext_Impl( GetConvDicImport() );
207css::uno::Reference<XFastContextHandler> ConvDicXMLEntryTextContext_Impl::createFastChildContext(
209 const css::uno::Reference< css::xml::sax::XFastAttributeList > & )
212 return new ConvDicXMLRightTextContext_Impl( GetConvDicImport(), *
this );
216void ConvDicXMLEntryTextContext_Impl::startFastElement(
218 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttrList )
222 switch (aIter.getToken())
225 aLeftText = aIter.toString();
234void ConvDicXMLRightTextContext_Impl::characters(
const OUString &rChars )
236 aRightText += rChars;
239void ConvDicXMLRightTextContext_Impl::endFastElement( sal_Int32 )
241 ConvDic *pDic = GetConvDicImport().GetDic();
243 pDic->
AddEntry( rEntryContext.GetLeftText(), aRightText );
249 uno::Reference< document::XExporter > xExporter(
this );
250 uno::Reference< document::XFilter > xFilter( xExporter, UNO_QUERY );
251 xFilter->filter( {} );
291 std::set<OUString> aKeySet;
293 aKeySet.insert( elem.first );
295 for (
const OUString& aLeftText : aKeySet)
300 sal_Int16 nPropertyType = -1;
303 nPropertyType = (*aIt2).second;
304 DBG_ASSERT( nPropertyType,
"property-type not found" );
305 if (nPropertyType == -1)
306 nPropertyType = ConversionPropertyType::NOT_DEFINED;
310 "entry" ,
true,
true );
312 std::pair< ConvMap::iterator, ConvMap::iterator > aRange =
314 for (
auto aIt = aRange.first; aIt != aRange.second; ++aIt)
316 DBG_ASSERT( aLeftText == (*aIt).first,
"key <-> entry mismatch" );
317 OUString aRightText( (*aIt).second );
319 "right-text" ,
true,
false );
328 pDic ( pConvDic ), nLanguage(
LANGUAGE_NONE), nConversionType(-1)
335 const css::uno::Reference< css::xml::sax::XFastAttributeList > & )
338 return new ConvDicXMLDictionaryContext_Impl( *
this );
ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=::xmloff::token::XML_TOKEN_INVALID) override
void ExportContent_() override
ConvDicXMLImport(ConvDic *pConvDic)
! see comment for pDic member
virtual SvXMLImportContext * CreateFastContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
sal_Int16 nConversionType
std::unique_ptr< PropTypeMap > pConvPropType
void AddEntry(const OUString &rLeftText, const OUString &rRightText)
static OUString convertToBcp47(LanguageType nLangID)
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
void Characters(const OUString &rChars)
SvXMLNamespaceMap & GetNamespaceMap_()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
SvXMLImport & GetImport()
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
constexpr OUStringLiteral CONV_TYPE_SCHINESE_TCHINESE
constexpr OUStringLiteral CONV_TYPE_HANGUL_HANJA
static sal_Int16 GetConversionTypeFromText(std::u16string_view rText)
static OUString ConversionTypeToText(sal_Int16 nConversionType)
constexpr OUStringLiteral XML_NAMESPACE_TCD_STRING
@ TEXT_CONVERSION_DICTIONARY
#define DBG_ASSERT(sCon, aError)
Reference< XComponentContext > getProcessComponentContext()
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
constexpr sal_uInt16 XML_NAMESPACE_TCD
constexpr OStringLiteral XML_LANG