xref: /aoo41x/main/linguistic/source/convdic.hxx (revision 63ce064a)
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 #ifndef _LINGUISTIC_CONVDIC_HXX_
24 #define _LINGUISTIC_CONVDIC_HXX_
25 
26 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
27 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
28 #include <com/sun/star/util/XFlushable.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <cppuhelper/implbase4.hxx>
31 #include <cppuhelper/interfacecontainer.h>
32 #include <tools/string.hxx>
33 
34 #include <hash_map>
35 #include <set>
36 #include <memory>
37 #include "linguistic/misc.hxx"
38 #include "defs.hxx"
39 
40 // text conversion dictionary extension
41 #define CONV_DIC_EXT            "tcd"
42 #define CONV_DIC_DOT_EXT        ".tcd"
43 
44 #define SN_CONV_DICTIONARY      "com.sun.star.linguistic2.ConversionDictionary"
45 
46 
47 class SvStream;
48 
49 ///////////////////////////////////////////////////////////////////////////
50 
51 sal_Bool    IsConvDic( const String &rFileURL, sal_Int16 &nLang, sal_Int16 &nConvType );
52 
53 ///////////////////////////////////////////////////////////////////////////
54 
55 struct StrLT
56 {
operator ()StrLT57     bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
58     {
59         return rTxt1 < rTxt2;
60     }
61 };
62 
63 struct StrEQ
64 {
operator ()StrEQ65     bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
66     {
67         return rTxt1 == rTxt2;
68     }
69 };
70 
71 typedef std::hash_multimap< const rtl::OUString, rtl::OUString,
72                        const rtl::OUStringHash, StrEQ > ConvMap;
73 
74 typedef std::set< rtl::OUString, StrLT > ConvMapKeySet;
75 
76 typedef std::hash_multimap< const rtl::OUString, sal_Int16,
77                        rtl::OUStringHash, StrEQ > PropTypeMap;
78 
79 ///////////////////////////////////////////////////////////////////////////
80 
81 class ConvDic :
82     public ::cppu::WeakImplHelper4
83 	<
84         ::com::sun::star::linguistic2::XConversionDictionary,
85         ::com::sun::star::linguistic2::XConversionPropertyType,
86         ::com::sun::star::util::XFlushable,
87         ::com::sun::star::lang::XServiceInfo
88 	>
89 {
90     friend class ConvDicXMLExport;
91 
92 protected:
93 
94     ::cppu::OInterfaceContainerHelper       aFlushListeners;
95 
96     ConvMap                         aFromLeft;
97     std::auto_ptr< ConvMap >        pFromRight;     // only available for bidirectional conversion dictionaries
98 
99     std::auto_ptr< PropTypeMap >    pConvPropType;
100 
101     String          aMainURL;   // URL to file
102     rtl::OUString   aName;
103     sal_Int16           nLanguage;
104     sal_Int16       nConversionType;
105     sal_Int16       nMaxLeftCharCount;
106     sal_Int16       nMaxRightCharCount;
107     sal_Bool            bMaxCharCountIsValid;
108     sal_Bool            bNeedEntries;
109     sal_Bool            bIsModified;
110     sal_Bool            bIsActive;
111     sal_Bool            bIsReadonly;
112 
113 	// disallow copy-constructor and assignment-operator for now
114     ConvDic(const ConvDic &);
115     ConvDic & operator = (const ConvDic &);
116 
117     ConvMap::iterator   GetEntry( ConvMap &rMap, const rtl::OUString &rFirstText, const rtl::OUString &rSecondText );
118     void    Load();
119     void    Save();
120 
121 public:
122     ConvDic( const String &rName,
123              sal_Int16 nLanguage,
124              sal_Int16 nConversionType,
125              sal_Bool bBiDirectional,
126              const String &rMainURL);
127     virtual ~ConvDic();
128 
129     // XConversionDictionary
130     virtual ::rtl::OUString SAL_CALL getName(  ) throw (::com::sun::star::uno::RuntimeException);
131     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale(  ) throw (::com::sun::star::uno::RuntimeException);
132     virtual sal_Int16 SAL_CALL getConversionType(  ) throw (::com::sun::star::uno::RuntimeException);
133     virtual void SAL_CALL setActive( sal_Bool bActivate ) throw (::com::sun::star::uno::RuntimeException);
134     virtual sal_Bool SAL_CALL isActive(  ) throw (::com::sun::star::uno::RuntimeException);
135     virtual void SAL_CALL clear(  ) throw (::com::sun::star::uno::RuntimeException);
136     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, ::com::sun::star::linguistic2::ConversionDirection eDirection, sal_Int32 nTextConversionOptions ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
137     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getConversionEntries( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
138     virtual void SAL_CALL addEntry( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
139     virtual void SAL_CALL removeEntry( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
140     virtual sal_Int16 SAL_CALL getMaxCharCount( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
141 
142     // XConversionPropertyType
143     virtual void SAL_CALL setPropertyType( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText, ::sal_Int16 nPropertyType ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
144     virtual ::sal_Int16 SAL_CALL getPropertyType( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
145 
146     // XFlushable
147     virtual void SAL_CALL flush(  ) throw (::com::sun::star::uno::RuntimeException);
148     virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
149     virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
150 
151     // XServiceInfo
152     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
153     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
154     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
155 
156 
157     static inline ::rtl::OUString
158         getImplementationName_Static() throw();
159     static com::sun::star::uno::Sequence< ::rtl::OUString >
160         getSupportedServiceNames_Static() throw();
161 
162     sal_Bool    HasEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
163     void    AddEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
164     void    RemoveEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
165 };
166 
getImplementationName_Static()167 inline ::rtl::OUString ConvDic::getImplementationName_Static() throw()
168 {
169     return A2OU( "com.sun.star.lingu2.ConvDic" );
170 }
171 
172 ///////////////////////////////////////////////////////////////////////////
173 
174 #endif
175 
176