1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_LINGUISTIC_SOURCE_CONVDICXML_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_CONVDICXML_HXX
22 
23 #include <com/sun/star/util/MeasureUnit.hpp>
24 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
25 #include <com/sun/star/xml/sax/FastToken.hpp>
26 #include <comphelper/processfactory.hxx>
27 #include <xmloff/xmlexp.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <rtl/ustring.hxx>
32 
33 
34 class ConvDic;
35 using namespace css::xml::sax;
36 using namespace ::xmloff::token;
37 
38 
39 class ConvDicXMLExport : public SvXMLExport
40 {
41     ConvDic     &rDic;
42     bool    bSuccess;
43 
44 public:
ConvDicXMLExport(ConvDic & rConvDic,const OUString & rFileName,css::uno::Reference<css::xml::sax::XDocumentHandler> const & rHandler)45     ConvDicXMLExport( ConvDic &rConvDic,
46         const OUString &rFileName,
47         css::uno::Reference< css::xml::sax::XDocumentHandler > const &rHandler) :
48         SvXMLExport ( comphelper::getProcessComponentContext(), "com.sun.star.lingu2.ConvDicXMLExport", rFileName,
49                       css::util::MeasureUnit::CM, rHandler ),
50         rDic        ( rConvDic ),
51         bSuccess    ( false )
52     {
53     }
54 
55     // SvXMLExport
ExportAutoStyles_()56     void ExportAutoStyles_() override    {}
ExportMasterStyles_()57     void ExportMasterStyles_() override  {}
58     void ExportContent_() override;
59     ErrCode exportDoc( enum ::xmloff::token::XMLTokenEnum eClass = ::xmloff::token::XML_TOKEN_INVALID ) override;
60 
61     bool    Export();
62 };
63 
64 
65 enum ConvDicXMLToken : sal_Int32
66 {
67     TEXT_CONVERSION_DICTIONARY = FastToken::NAMESPACE | XML_NAMESPACE_TCD | XML_BLOCK_LIST,
68     RIGHT_TEXT = FastToken::NAMESPACE | XML_NAMESPACE_TCD | XML_RIGHT_TEXT,
69     ENTRY = FastToken::NAMESPACE | XML_NAMESPACE_TCD | XML_ENTRY,
70 };
71 
72 class ConvDicXMLImport : public SvXMLImport
73 {
74     ConvDic        *pDic;       // conversion dictionary to be used
75                                 // if != NULL: whole file will be read and
76                                 //   all entries will be added to the dictionary
77                                 // if == NULL: no entries will be added
78                                 //   but the language and conversion type will
79                                 //   still be determined!
80 
81     LanguageType    nLanguage;          // language of the dictionary
82     sal_Int16       nConversionType;    // conversion type the dictionary is used for
83 
84 public:
85 
86     //!!  see comment for pDic member
87     explicit ConvDicXMLImport( ConvDic *pConvDic );
88 
GetDic()89     ConvDic *    GetDic()                    { return pDic; }
GetLanguage() const90     LanguageType GetLanguage() const         { return nLanguage; }
GetConversionType() const91     sal_Int16    GetConversionType() const   { return nConversionType; }
92 
SetLanguage(LanguageType nLang)93     void         SetLanguage( LanguageType nLang )              { nLanguage = nLang; }
SetConversionType(sal_Int16 nType)94     void         SetConversionType( sal_Int16 nType )    { nConversionType = nType; }
95 
96 private:
97     virtual SvXMLImportContext *CreateFastContext( sal_Int32 Element,
98         const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
99 };
100 
101 
102 #endif
103 
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
105