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