xref: /trunk/main/linguistic/source/convdicxml.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _LINGUISTIC_CONVDICXML_HXX_
29 #define _LINGUISTIC_CONVDICXML_HXX_
30 
31 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
32 #include <com/sun/star/util/XFlushable.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 #include <xmloff/xmlexp.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <cppuhelper/implbase3.hxx>
38 #include <cppuhelper/interfacecontainer.h>
39 #include <tools/string.hxx>
40 #include <rtl/ustring.hxx>
41 #include "linguistic/misc.hxx"
42 #include "defs.hxx"
43 
44 
45 class ConvDic;
46 
47 ///////////////////////////////////////////////////////////////////////////
48 
49 class ConvDicXMLExport : public SvXMLExport
50 {
51     ConvDic     &rDic;
52     sal_Bool    bSuccess;
53 
54 protected:
55     //void ExportNodes(const SmNode *pIn, int nLevel);
56 
57 public:
58     ConvDicXMLExport( ConvDic &rConvDic,
59         const rtl::OUString &rFileName,
60         com::sun::star::uno::Reference< com::sun::star::xml::sax::XDocumentHandler > &rHandler) :
61         SvXMLExport ( utl::getProcessServiceFactory(), rFileName, rHandler ),
62         rDic        ( rConvDic ),
63         bSuccess    ( sal_False )
64     {
65     }
66     virtual ~ConvDicXMLExport()
67     {
68     }
69 
70     // XServiceInfo (override parent method)
71     ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
72 
73     // SvXMLExport
74     void _ExportAutoStyles()    {}
75     void _ExportMasterStyles()  {}
76     void _ExportContent();
77     sal_uInt32 exportDoc( enum ::xmloff::token::XMLTokenEnum eClass );
78 
79     sal_Bool    Export();
80 };
81 
82 
83 class ConvDicXMLImport : public SvXMLImport
84 {
85     ConvDic        *pDic;       // conversion dictionary to be used
86                                 // if != NULL: whole file will be read and
87                                 //   all entries will be added to the dictionary
88                                 // if == NULL: no entries will be added
89                                 //   but the language and conversion type will
90                                 //   still be determined!
91 
92     sal_Int16           nLanguage;          // language of the dictionary
93     sal_Int16       nConversionType;    // conversion type the dictionary is used for
94     sal_Bool        bSuccess;
95 
96 public:
97 
98     //!!  see comment for pDic member
99     ConvDicXMLImport( ConvDic *pConvDic, const rtl::OUString /*&rFileName*/ ) :
100         SvXMLImport ( utl::getProcessServiceFactory(), IMPORT_ALL ),
101         pDic        ( pConvDic )
102     {
103         nLanguage       = LANGUAGE_NONE;
104         nConversionType = -1;
105         bSuccess        = sal_False;
106     }
107 
108     virtual ~ConvDicXMLImport() throw ()
109     {
110     }
111 
112     // XServiceInfo (override parent method)
113     ::rtl::OUString SAL_CALL getImplementationName() throw( ::com::sun::star::uno::RuntimeException );
114 
115     virtual void SAL_CALL startDocument(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
116     virtual void SAL_CALL endDocument(void) throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
117 
118     virtual SvXMLImportContext * CreateContext(
119         sal_uInt16 nPrefix, const rtl::OUString &rLocalName,
120         const com::sun::star::uno::Reference < com::sun::star::xml::sax::XAttributeList > &rxAttrList );
121 
122     ConvDic *   GetDic()                    { return pDic; }
123     sal_Int16       GetLanguage() const         { return nLanguage; }
124     sal_Int16   GetConversionType() const   { return nConversionType; }
125     sal_Bool    GetSuccess() const          { return bSuccess; }
126 
127     void        SetLanguage( sal_Int16 nLang )              { nLanguage = nLang; }
128     void        SetConversionType( sal_Int16 nType )    { nConversionType = nType; }
129 };
130 
131 ///////////////////////////////////////////////////////////////////////////
132 
133 #endif
134 
135