update dev300-m58
[ooovba.git] / linguistic / source / convdic.hxx
blob649262ab393ea41c8ed0921b82483d3c5e535f82
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: convdic.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _LINGUISTIC_CONVDIC_HXX_
31 #define _LINGUISTIC_CONVDIC_HXX_
33 #include <com/sun/star/linguistic2/XConversionDictionary.hpp>
34 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp>
35 #include <com/sun/star/util/XFlushable.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <cppuhelper/implbase4.hxx>
38 #include <cppuhelper/interfacecontainer.h>
39 #include <tools/string.hxx>
41 #include <hash_map>
42 #include <set>
43 #include <memory>
44 #include "misc.hxx"
45 #include "defs.hxx"
47 // text conversion dictionary extension
48 #define CONV_DIC_EXT "tcd"
49 #define CONV_DIC_DOT_EXT ".tcd"
51 #define SN_CONV_DICTIONARY "com.sun.star.linguistic2.ConversionDictionary"
54 class SvStream;
56 ///////////////////////////////////////////////////////////////////////////
58 BOOL IsConvDic( const String &rFileURL, INT16 &nLang, sal_Int16 &nConvType );
60 ///////////////////////////////////////////////////////////////////////////
62 struct StrLT
64 bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
66 return rTxt1 < rTxt2;
70 struct StrEQ
72 bool operator()( const rtl::OUString &rTxt1, const rtl::OUString &rTxt2 ) const
74 return rTxt1 == rTxt2;
78 typedef std::hash_multimap< const rtl::OUString, rtl::OUString,
79 const rtl::OUStringHash, StrEQ > ConvMap;
81 typedef std::set< rtl::OUString, StrLT > ConvMapKeySet;
83 typedef std::hash_multimap< const rtl::OUString, sal_Int16,
84 rtl::OUStringHash, StrEQ > PropTypeMap;
86 ///////////////////////////////////////////////////////////////////////////
88 class ConvDic :
89 public ::cppu::WeakImplHelper4
91 ::com::sun::star::linguistic2::XConversionDictionary,
92 ::com::sun::star::linguistic2::XConversionPropertyType,
93 ::com::sun::star::util::XFlushable,
94 ::com::sun::star::lang::XServiceInfo
97 friend class ConvDicXMLExport;
99 protected:
101 ::cppu::OInterfaceContainerHelper aFlushListeners;
103 ConvMap aFromLeft;
104 std::auto_ptr< ConvMap > pFromRight; // only available for bidirectional conversion dictionaries
106 std::auto_ptr< PropTypeMap > pConvPropType;
108 String aMainURL; // URL to file
109 rtl::OUString aName;
110 INT16 nLanguage;
111 sal_Int16 nConversionType;
112 sal_Int16 nMaxLeftCharCount;
113 sal_Int16 nMaxRightCharCount;
114 BOOL bMaxCharCountIsValid;
115 BOOL bNeedEntries;
116 BOOL bIsModified;
117 BOOL bIsActive;
118 BOOL bIsReadonly;
120 // disallow copy-constructor and assignment-operator for now
121 ConvDic(const ConvDic &);
122 ConvDic & operator = (const ConvDic &);
124 ConvMap::iterator GetEntry( ConvMap &rMap, const rtl::OUString &rFirstText, const rtl::OUString &rSecondText );
125 void Load();
126 void Save();
128 public:
129 ConvDic( const String &rName,
130 INT16 nLanguage,
131 sal_Int16 nConversionType,
132 BOOL bBiDirectional,
133 const String &rMainURL);
134 virtual ~ConvDic();
136 // XConversionDictionary
137 virtual ::rtl::OUString SAL_CALL getName( ) throw (::com::sun::star::uno::RuntimeException);
138 virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::uno::RuntimeException);
139 virtual sal_Int16 SAL_CALL getConversionType( ) throw (::com::sun::star::uno::RuntimeException);
140 virtual void SAL_CALL setActive( sal_Bool bActivate ) throw (::com::sun::star::uno::RuntimeException);
141 virtual sal_Bool SAL_CALL isActive( ) throw (::com::sun::star::uno::RuntimeException);
142 virtual void SAL_CALL clear( ) throw (::com::sun::star::uno::RuntimeException);
143 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);
144 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getConversionEntries( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
145 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);
146 virtual void SAL_CALL removeEntry( const ::rtl::OUString& aLeftText, const ::rtl::OUString& aRightText ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);
147 virtual sal_Int16 SAL_CALL getMaxCharCount( ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);
149 // XConversionPropertyType
150 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);
151 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);
153 // XFlushable
154 virtual void SAL_CALL flush( ) throw (::com::sun::star::uno::RuntimeException);
155 virtual void SAL_CALL addFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
156 virtual void SAL_CALL removeFlushListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushListener >& l ) throw (::com::sun::star::uno::RuntimeException);
158 // XServiceInfo
159 virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException);
160 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
161 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException);
164 static inline ::rtl::OUString
165 getImplementationName_Static() throw();
166 static com::sun::star::uno::Sequence< ::rtl::OUString >
167 getSupportedServiceNames_Static() throw();
169 BOOL HasEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
170 void AddEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
171 void RemoveEntry( const rtl::OUString &rLeftText, const rtl::OUString &rRightText );
174 inline ::rtl::OUString ConvDic::getImplementationName_Static() throw()
176 return A2OU( "com.sun.star.lingu2.ConvDic" );
179 ///////////////////////////////////////////////////////////////////////////
181 #endif