diff options
author | jp <jp@openoffice.org> | 2000-12-21 08:26:35 +0000 |
---|---|---|
committer | jp <jp@openoffice.org> | 2000-12-21 08:26:35 +0000 |
commit | dddf730f98da0192e7dceca2b4c78be70e5aa651 (patch) | |
tree | e93ebf732058fb1f273c975dcdb1e7ccfd07b70a /unotools | |
parent | 57e3a219de554b26f5d75762ba351b5729365018 (diff) |
wrapper for the I18N transliteration
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/transliterationwrapper.hxx | 121 | ||||
-rw-r--r-- | unotools/source/i18n/makefile.mk | 5 | ||||
-rw-r--r-- | unotools/source/i18n/transliterationwrapper.cxx | 184 |
3 files changed, 308 insertions, 2 deletions
diff --git a/unotools/inc/unotools/transliterationwrapper.hxx b/unotools/inc/unotools/transliterationwrapper.hxx new file mode 100644 index 000000000000..4b8ee04dc84e --- /dev/null +++ b/unotools/inc/unotools/transliterationwrapper.hxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * $RCSfile: transliterationwrapper.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jp $ $Date: 2000-12-21 09:25:32 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX +#define _UNOTOOLS_TRANSLITERATIONWRAPPER_HXX + +#ifndef _SOLAR_H +#include <tools/solar.h> +#endif +#ifndef _COM_SUN_STAR_I18N_XTRANSLITERATION_HPP_ +#include <com/sun/star/i18n/XTransliteration.hpp> +#endif + +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + +namespace utl +{ + +class TransliterationWrapper +{ + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + ::com::sun::star::uno::Reference< + ::com::sun::star::i18n::XTransliteration > xTrans; + ::com::sun::star::lang::Locale aLocale; + sal_uInt32 nType; + sal_uInt16 nLanguage; + sal_Bool bFirstCall; + + // not implemented, prevent usage + TransliterationWrapper( const TransliterationWrapper& ); + TransliterationWrapper& operator=( const TransliterationWrapper& ); + +public: + TransliterationWrapper( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & xSF, + sal_uInt32 nType ); + + ~TransliterationWrapper(); + + // get current Locale / Language + const ::com::sun::star::lang::Locale& getLocale() const { return aLocale;} + sal_uInt16 getLanguage() const { return nLanguage; } + + sal_uInt32 getType() const { return nType; } + + sal_Bool needLanguageForTheMode() const; + + // Wrapper implementations of class Transliteration + String transliterate( const String& rStr, sal_uInt16 nLanguage, + xub_StrLen nStart, xub_StrLen nEnd, + ::com::sun::star::uno::Sequence <long>* pOffset ); +}; + +// ............................................................................ +} // namespace utl +// ............................................................................ + +#endif diff --git a/unotools/source/i18n/makefile.mk b/unotools/source/i18n/makefile.mk index 50fbfded686b..bf5144a7700c 100644 --- a/unotools/source/i18n/makefile.mk +++ b/unotools/source/i18n/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.5 $ +# $Revision: 1.6 $ # -# last change: $Author: er $ $Date: 2000-11-18 19:23:59 $ +# last change: $Author: jp $ $Date: 2000-12-21 09:26:35 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -100,6 +100,7 @@ SLOFILES= \ $(SLO)$/calendarwrapper.obj \ $(SLO)$/localedatawrapper.obj \ $(SLO)$/numberformatcodewrapper.obj \ + $(SLO)$/transliterationwrapper.obj \ $(SLO)$/textsearch.obj # NETBSD: somewhere we have to instantiate the static data members. diff --git a/unotools/source/i18n/transliterationwrapper.cxx b/unotools/source/i18n/transliterationwrapper.cxx new file mode 100644 index 000000000000..b08e32f33ac4 --- /dev/null +++ b/unotools/source/i18n/transliterationwrapper.cxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * $RCSfile: transliterationwrapper.cxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: jp $ $Date: 2000-12-21 09:26:08 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#include <unotools/transliterationwrapper.hxx> + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif +#ifndef _ISOLANG_HXX +#include <tools/isolang.hxx> +#endif +#ifndef _COMPHELPER_COMPONENTFACTORY_HXX_ +#include <comphelper/componentfactory.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#pragma hdrstop + + +#define _LIBRARYNAME "int" +#define _SERVICENAME "com.sun.star.util.Transliteration" + +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::i18n; +using namespace ::com::sun::star::uno; +using namespace ::utl; + +TransliterationWrapper::TransliterationWrapper( + const Reference< XMultiServiceFactory > & xSF, + sal_uInt32 nTyp ) + : xSMgr( xSF ), nType( nTyp ), nLanguage( 0 ), bFirstCall( sal_True ) +{ + if( xSMgr.is() ) + { + try { + xTrans = Reference< XTransliteration > ( xSMgr->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( _SERVICENAME ) ) ), + UNO_QUERY ); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "TransliterationWrapper: Exception caught!" ); + } + } + else + { // try to get an instance somehow + DBG_ERRORFILE( "TransliterationWrapper: no service manager, trying own" ); + try + { + Reference< XInterface > xI = ::comphelper::getComponentInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + LLCF_LIBNAME( _LIBRARYNAME ) ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + _SERVICENAME ) ) ); + if ( xI.is() ) + { + Any x = xI->queryInterface( + ::getCppuType((const Reference< XTransliteration>*)0) ); + x >>= xTrans ; + } + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); + } + } + DBG_ASSERT( xTrans .is(), "TransliterationWrapper: no Transliteraion avaible" ); +} + + +TransliterationWrapper::~TransliterationWrapper() +{ +} + + +String TransliterationWrapper::transliterate( + const String& rStr, sal_uInt16 nLang, + xub_StrLen nStart, xub_StrLen nLen, + Sequence <long>* pOffset ) +{ + String sRet; + try + { + sal_Bool bLoad = bFirstCall; + bFirstCall = sal_False; + + if( nLanguage != nLang ) + { + nLanguage = nLang; + String aLangStr, aCtryStr; + if( LANGUAGE_NONE == nLanguage ) + nLanguage = LANGUAGE_SYSTEM; + ConvertLanguageToIsoNames( nLanguage, aLangStr, aCtryStr ); + aLocale.Language = aLangStr; + aLocale.Country = aCtryStr; + if( !bLoad ) + bLoad = needLanguageForTheMode(); + } + if( bLoad ) + xTrans->loadModule( (TransliterationModules)nType, aLocale ); + + Sequence <long> aOffset; + if( !pOffset ) + pOffset = &aOffset; + + sRet = xTrans->transliterate( rStr, nStart, nLen, *pOffset ); + } + catch( Exception& ) + { + DBG_ERRORFILE( "transliterate: Exception caught!" ); + } + return sRet; +} + +sal_Bool TransliterationWrapper::needLanguageForTheMode() const +{ + return TransliterationModules_UPPERCASE_LOWERCASE == nType || + TransliterationModules_LOWERCASE_UPPERCASE == nType || + TransliterationModules_IGNORE_CASE == nType; +} + |