1*63ce064aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63ce064aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63ce064aSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63ce064aSAndrew Rist * distributed with this work for additional information
6*63ce064aSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63ce064aSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63ce064aSAndrew Rist * "License"); you may not use this file except in compliance
9*63ce064aSAndrew Rist * with the License. You may obtain a copy of the License at
10*63ce064aSAndrew Rist *
11*63ce064aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*63ce064aSAndrew Rist *
13*63ce064aSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63ce064aSAndrew Rist * software distributed under the License is distributed on an
15*63ce064aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63ce064aSAndrew Rist * KIND, either express or implied. See the License for the
17*63ce064aSAndrew Rist * specific language governing permissions and limitations
18*63ce064aSAndrew Rist * under the License.
19*63ce064aSAndrew Rist *
20*63ce064aSAndrew Rist *************************************************************/
21*63ce064aSAndrew Rist
22*63ce064aSAndrew Rist
23cdf0e10cSrcweir #ifndef _LINGUISTIC_CONVDIC_HXX_
24cdf0e10cSrcweir #define _LINGUISTIC_CONVDIC_HXX_
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
27cdf0e10cSrcweir #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
28cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
30cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
31cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h>
32cdf0e10cSrcweir #include <tools/string.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <hash_map>
35cdf0e10cSrcweir #include <set>
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir #include "linguistic/misc.hxx"
38cdf0e10cSrcweir #include "defs.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir // text conversion dictionary extension
41cdf0e10cSrcweir #define CONV_DIC_EXT "tcd"
42cdf0e10cSrcweir #define CONV_DIC_DOT_EXT ".tcd"
43cdf0e10cSrcweir
44cdf0e10cSrcweir #define SN_CONV_DICTIONARY "com.sun.star.linguistic2.ConversionDictionary"
45cdf0e10cSrcweir
46cdf0e10cSrcweir
47cdf0e10cSrcweir class SvStream;
48cdf0e10cSrcweir
49cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
50cdf0e10cSrcweir
51cdf0e10cSrcweir sal_Bool IsConvDic( const String &rFileURL, sal_Int16 &nLang, sal_Int16 &nConvType );
52cdf0e10cSrcweir
53cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
54cdf0e10cSrcweir
55cdf0e10cSrcweir struct StrLT
56cdf0e10cSrcweir {
operator ()StrLT57cdf0e10cSrcweir bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
58cdf0e10cSrcweir {
59cdf0e10cSrcweir return rTxt1 < rTxt2;
60cdf0e10cSrcweir }
61cdf0e10cSrcweir };
62cdf0e10cSrcweir
63cdf0e10cSrcweir struct StrEQ
64cdf0e10cSrcweir {
operator ()StrEQ65cdf0e10cSrcweir bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return rTxt1 == rTxt2;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir };
70cdf0e10cSrcweir
71cdf0e10cSrcweir typedef std::hash_multimap< const rtl::OUString, rtl::OUString,
72cdf0e10cSrcweir const rtl::OUStringHash, StrEQ > ConvMap;
73cdf0e10cSrcweir
74cdf0e10cSrcweir typedef std::set< rtl::OUString, StrLT > ConvMapKeySet;
75cdf0e10cSrcweir
76cdf0e10cSrcweir typedef std::hash_multimap< const rtl::OUString, sal_Int16,
77cdf0e10cSrcweir rtl::OUStringHash, StrEQ > PropTypeMap;
78cdf0e10cSrcweir
79cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
80cdf0e10cSrcweir
81cdf0e10cSrcweir class ConvDic :
82cdf0e10cSrcweir public ::cppu::WeakImplHelper4
83cdf0e10cSrcweir <
84cdf0e10cSrcweir ::com::sun::star::linguistic2::XConversionDictionary,
85cdf0e10cSrcweir ::com::sun::star::linguistic2::XConversionPropertyType,
86cdf0e10cSrcweir ::com::sun::star::util::XFlushable,
87cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo
88cdf0e10cSrcweir >
89cdf0e10cSrcweir {
90cdf0e10cSrcweir friend class ConvDicXMLExport;
91cdf0e10cSrcweir
92cdf0e10cSrcweir protected:
93cdf0e10cSrcweir
94cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper aFlushListeners;
95cdf0e10cSrcweir
96cdf0e10cSrcweir ConvMap aFromLeft;
97cdf0e10cSrcweir std::auto_ptr< ConvMap > pFromRight; // only available for bidirectional conversion dictionaries
98cdf0e10cSrcweir
99cdf0e10cSrcweir std::auto_ptr< PropTypeMap > pConvPropType;
100cdf0e10cSrcweir
101cdf0e10cSrcweir String aMainURL; // URL to file
102cdf0e10cSrcweir rtl::OUString aName;
103cdf0e10cSrcweir sal_Int16 nLanguage;
104cdf0e10cSrcweir sal_Int16 nConversionType;
105cdf0e10cSrcweir sal_Int16 nMaxLeftCharCount;
106cdf0e10cSrcweir sal_Int16 nMaxRightCharCount;
107cdf0e10cSrcweir sal_Bool bMaxCharCountIsValid;
108cdf0e10cSrcweir sal_Bool bNeedEntries;
109cdf0e10cSrcweir sal_Bool bIsModified;
110cdf0e10cSrcweir sal_Bool bIsActive;
111cdf0e10cSrcweir sal_Bool bIsReadonly;
112cdf0e10cSrcweir
113cdf0e10cSrcweir // disallow copy-constructor and assignment-operator for now
114cdf0e10cSrcweir ConvDic(const ConvDic &);
115cdf0e10cSrcweir ConvDic & operator = (const ConvDic &);
116cdf0e10cSrcweir
117cdf0e10cSrcweir ConvMap::iterator GetEntry( ConvMap &rMap, const rtl::OUString &rFirstText, const rtl::OUString &rSecondText );
118cdf0e10cSrcweir void Load();
119cdf0e10cSrcweir void Save();
120cdf0e10cSrcweir
121cdf0e10cSrcweir public:
122cdf0e10cSrcweir ConvDic( const String &rName,
123cdf0e10cSrcweir sal_Int16 nLanguage,
124cdf0e10cSrcweir sal_Int16 nConversionType,
125cdf0e10cSrcweir sal_Bool bBiDirectional,
126cdf0e10cSrcweir const String &rMainURL);
127cdf0e10cSrcweir virtual ~ConvDic();
128cdf0e10cSrcweir
129cdf0e10cSrcweir // XConversionDictionary
130cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getName( ) throw (::com::sun::star::uno::RuntimeException);
131cdf0e10cSrcweir virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::uno::RuntimeException);
132cdf0e10cSrcweir virtual sal_Int16 SAL_CALL getConversionType( ) throw (::com::sun::star::uno::RuntimeException);
133cdf0e10cSrcweir virtual void SAL_CALL setActive( sal_Bool bActivate ) throw (::com::sun::star::uno::RuntimeException);
134cdf0e10cSrcweir virtual sal_Bool SAL_CALL isActive( ) throw (::com::sun::star::uno::RuntimeException);
135cdf0e10cSrcweir virtual void SAL_CALL clear( ) throw (::com::sun::star::uno::RuntimeException);
136cdf0e10cSrcweir 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);
137cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getConversionEntries( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
138cdf0e10cSrcweir 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);
139cdf0e10cSrcweir virtual void SAL_CALL removeEntry( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
140cdf0e10cSrcweir virtual sal_Int16 SAL_CALL getMaxCharCount( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
141cdf0e10cSrcweir
142cdf0e10cSrcweir // XConversionPropertyType
143cdf0e10cSrcweir 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);
144cdf0e10cSrcweir 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);
145cdf0e10cSrcweir
146cdf0e10cSrcweir // XFlushable
147cdf0e10cSrcweir virtual void SAL_CALL flush( ) throw (::com::sun::star::uno::RuntimeException);
148cdf0e10cSrcweir virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
149cdf0e10cSrcweir virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
150cdf0e10cSrcweir
151cdf0e10cSrcweir // XServiceInfo
152cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
153cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
154cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
155cdf0e10cSrcweir
156cdf0e10cSrcweir
157cdf0e10cSrcweir static inline ::rtl::OUString
158cdf0e10cSrcweir getImplementationName_Static() throw();
159cdf0e10cSrcweir static com::sun::star::uno::Sequence< ::rtl::OUString >
160cdf0e10cSrcweir getSupportedServiceNames_Static() throw();
161cdf0e10cSrcweir
162cdf0e10cSrcweir sal_Bool HasEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
163cdf0e10cSrcweir void AddEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
164cdf0e10cSrcweir void RemoveEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
165cdf0e10cSrcweir };
166cdf0e10cSrcweir
getImplementationName_Static()167cdf0e10cSrcweir inline ::rtl::OUString ConvDic::getImplementationName_Static() throw()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir return A2OU( "com.sun.star.lingu2.ConvDic" );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
173cdf0e10cSrcweir
174cdf0e10cSrcweir #endif
175cdf0e10cSrcweir
176