1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _LINGUISTIC_CONVDICXML_HXX_
25 #define _LINGUISTIC_CONVDICXML_HXX_
26 
27 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
28 #include <com/sun/star/util/XFlushable.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
31 #include <xmloff/xmlexp.hxx>
32 #include <xmloff/xmlimp.hxx>
33 #include <cppuhelper/implbase3.hxx>
34 #include <cppuhelper/interfacecontainer.h>
35 #include <tools/string.hxx>
36 #include <rtl/ustring.hxx>
37 #include "linguistic/misc.hxx"
38 #include "defs.hxx"
39 
40 
41 class ConvDic;
42 
43 ///////////////////////////////////////////////////////////////////////////
44 
45 class ConvDicXMLExport : public SvXMLExport
46 {
47     ConvDic     &rDic;
48     sal_Bool    bSuccess;
49 
50 protected:
51     //void ExportNodes(const SmNode *pIn, int nLevel);
52 
53 public:
ConvDicXMLExport(ConvDic & rConvDic,const rtl::OUString & rFileName,com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> & rHandler)54     ConvDicXMLExport( ConvDic &rConvDic,
55         const rtl::OUString &rFileName,
56         com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > &rHandler) :
57         SvXMLExport ( utl::getProcessServiceFactory(), rFileName, rHandler ),
58         rDic        ( rConvDic ),
59         bSuccess    ( sal_False )
60     {
61     }
~ConvDicXMLExport()62     virtual ~ConvDicXMLExport()
63     {
64     }
65 
66     // XServiceInfo (override parent method)
67     ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
68 
69     // SvXMLExport
_ExportAutoStyles()70     void _ExportAutoStyles()    {}
_ExportMasterStyles()71     void _ExportMasterStyles()  {}
72     void _ExportContent();
73     sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum eClass );
74 
75     sal_Bool    Export();
76 };
77 
78 
79 class ConvDicXMLImport : public SvXMLImport
80 {
81     ConvDic        *pDic;       // conversion dictionary to be used
82                                 // if != NULL: whole file will be read and
83                                 //   all entries will be added to the dictionary
84                                 // if == NULL: no entries will be added
85                                 //   but the language and conversion type will
86                                 //   still be determined!
87 
88     sal_Int16           nLanguage;          // language of the dictionary
89     sal_Int16       nConversionType;    // conversion type the dictionary is used for
90     sal_Bool        bSuccess;
91 
92 public:
93 
94     //!!  see comment for pDic member
ConvDicXMLImport(ConvDic * pConvDic,const rtl::OUString)95     ConvDicXMLImport( ConvDic *pConvDic, const rtl::OUString /*&rFileName*/ ) :
96         SvXMLImport ( utl::getProcessServiceFactory(), IMPORT_ALL ),
97         pDic        ( pConvDic )
98     {
99         nLanguage       = LANGUAGE_NONE;
100         nConversionType = -1;
101         bSuccess        = sal_False;
102     }
103 
~ConvDicXMLImport()104     virtual ~ConvDicXMLImport() throw ()
105     {
106     }
107 
108     // XServiceInfo (override parent method)
109     ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
110 
111     virtual void SAL_CALL startDocument(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
112     virtual void SAL_CALL endDocument(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
113 
114     virtual SvXMLImportContext * CreateContext(
115         sal_uInt16 nPrefix, const rtl::OUString &rLocalName,
116         const com::sun::star::uno::Reference < com::sun::star::xml::sax::XAttributeList > &rxAttrList );
117 
GetDic()118     ConvDic *   GetDic()                    { return pDic; }
GetLanguage() const119     sal_Int16       GetLanguage() const         { return nLanguage; }
GetConversionType() const120     sal_Int16   GetConversionType() const   { return nConversionType; }
GetSuccess() const121     sal_Bool    GetSuccess() const          { return bSuccess; }
122 
SetLanguage(sal_Int16 nLang)123     void        SetLanguage( sal_Int16 nLang )              { nLanguage = nLang; }
SetConversionType(sal_Int16 nType)124     void        SetConversionType( sal_Int16 nType )    { nConversionType = nType; }
125 };
126 
127 ///////////////////////////////////////////////////////////////////////////
128 
129 #endif
130 
131