diff options
Diffstat (limited to 'unotools')
29 files changed, 5676 insertions, 0 deletions
diff --git a/unotools/inc/unotools/charclass.hxx b/unotools/inc/unotools/charclass.hxx new file mode 100644 index 000000000000..1cd1b3da19ac --- /dev/null +++ b/unotools/inc/unotools/charclass.hxx @@ -0,0 +1,268 @@ +/************************************************************************* + * + * $RCSfile: charclass.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:52 $ + * + * 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_CHARCLASS_HXX +#define _UNOTOOLS_CHARCLASS_HXX + +#include <ctype.h> // isdigit(), isalpha() + +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif +#ifndef _SOLAR_H +#include <tools/solar.h> +#endif + +#ifndef _COM_SUN_STAR_LANG_KCHARACTERTYPE_HPP_ +#include <com/sun/star/lang/KCharacterType.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_KPARSETOKENS_HPP_ +#include <com/sun/star/lang/KParseTokens.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_KPARSETYPE_HPP_ +#include <com/sun/star/lang/KParseType.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_PARSERESULT_HPP_ +#include <com/sun/star/lang/ParseResult.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCHARACTERCLASSIFICATION_HPP_ +#include <com/sun/star/lang/XCharacterClassification.hpp> +#endif + +class String; +namespace com { namespace sun { namespace star { + namespace lang { + class XMultiServiceFactory; + } +}}} + +const sal_Int32 nCharClassAlphaType = + ::com::sun::star::lang::KCharacterType::UPPER | + ::com::sun::star::lang::KCharacterType::LOWER | + ::com::sun::star::lang::KCharacterType::TITLE_CASE; + +const sal_Int32 nCharClassAlphaTypeMask = + nCharClassAlphaType | + ::com::sun::star::lang::KCharacterType::PRINTABLE | + ::com::sun::star::lang::KCharacterType::BASE_FORM; + +const sal_Int32 nCharClassLetterType = + nCharClassAlphaType | + ::com::sun::star::lang::KCharacterType::LETTER; + +const sal_Int32 nCharClassLetterTypeMask = + nCharClassAlphaTypeMask | + ::com::sun::star::lang::KCharacterType::LETTER; + +class CharClass +{ + ::com::sun::star::lang::Locale aLocale; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XCharacterClassification > xCC; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xSMgr; + + // not implemented, prevent usage + CharClass( const CharClass& ); + CharClass& operator=( const CharClass& ); + + // instantiate component somehow + void getComponentInstance(); + +public: + /// Preferred ctor with service manager specified + CharClass( + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xSF, + const ::com::sun::star::lang::Locale& rLocale + ); + + /// Depricated ctor, tries to get a process service manager or to load the + /// library directly. + CharClass( + const ::com::sun::star::lang::Locale& rLocale + ); + + ~CharClass(); + + /// set a new Locale + void setLocale( const ::com::sun::star::lang::Locale& rLocale ); + + /// get current Locale + const ::com::sun::star::lang::Locale& getLocale() const { return aLocale; } + + + /// isdigit() on ascii values + static inline sal_Bool isAsciiDigit( sal_Unicode c ) + { return c < 128 ? (isdigit( (unsigned char) c ) != 0) : 0; } + + /// isalpha() on ascii values + static inline sal_Bool isAsciiAlpha( sal_Unicode c ) + { return c < 128 ? (isalpha( (unsigned char) c ) != 0) : 0; } + + /// isalnum() on ascii values + static inline sal_Bool isAsciiAlphaNumeric( sal_Unicode c ) + { return c < 128 ? (isalnum( (unsigned char) c ) != 0) : 0; } + + /// isdigit() on ascii values of entire string + static sal_Bool isAsciiNumeric( const String& rStr ); + + /// isalpha() on ascii values of entire string + static sal_Bool isAsciiAlpha( const String& rStr ); + + /// isalnum() on ascii values of entire string + static sal_Bool isAsciiAlphaNumeric( const String& rStr ); + + /// whether type is pure alpha or not, e.g. return of getStringType + static inline sal_Bool isAlphaType( sal_Int32 nType ) + { + return ((nType & nCharClassAlphaType) != 0) && + (nType & ~(nCharClassAlphaTypeMask) == 0); + } + + /// whether type is pure numeric or not, e.g. return of getStringType + static inline sal_Bool isNumericType( sal_Int32 nType ) + { + return ((nType & + ::com::sun::star::lang::KCharacterType::DIGIT) != 0) && + ((nType & ~(::com::sun::star::lang::KCharacterType::DIGIT | + ::com::sun::star::lang::KCharacterType::PRINTABLE)) == 0); + } + + /// whether type is pure alphanumeric or not, e.g. return of getStringType + static inline sal_Bool isAlphaNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassAlphaType | + ::com::sun::star::lang::KCharacterType::DIGIT)) != 0) && + ((nType & ~(nCharClassAlphaTypeMask | + ::com::sun::star::lang::KCharacterType::DIGIT)) == 0); + } + + /// whether type is pure letter or not, e.g. return of getStringType + static inline sal_Bool isLetterType( sal_Int32 nType ) + { + return ((nType & nCharClassLetterType) != 0) && + (nType & ~(nCharClassLetterTypeMask) == 0); + } + + /// whether type is pure letternumeric or not, e.g. return of getStringType + static inline sal_Bool isLetterNumericType( sal_Int32 nType ) + { + return ((nType & (nCharClassLetterType | + ::com::sun::star::lang::KCharacterType::DIGIT)) != 0) && + ((nType & ~(nCharClassLetterTypeMask | + ::com::sun::star::lang::KCharacterType::DIGIT)) == 0); + } + + + // Wrapper implementations of class CharacterClassification + + String toUpper( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + String toLower( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + String toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + + sal_Int16 getType( const String& rStr, xub_StrLen nPos ) const; + sal_Int16 getCharacterDirection( const String& rStr, xub_StrLen nPos ) const; + sal_Int16 getScript( const String& rStr, xub_StrLen nPos ) const; + sal_Int32 getCharacterType( const String& rStr, xub_StrLen nPos ) const; + sal_Int32 getStringType( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const; + + ::com::sun::star::lang::ParseResult parseAnyToken( + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const; + + ::com::sun::star::lang::ParseResult parsePredefinedToken( + sal_Int32 nTokenType, + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const; + + + // Functionality of class International methods + + sal_Bool isAlpha( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isLetter( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isDigit( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isAlphaNumeric( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isLetterNumeric( const String& rStr, xub_StrLen nPos ) const; + sal_Bool isAlpha( const String& rStr ) const; + sal_Bool isLetter( const String& rStr ) const; + sal_Bool isNumeric( const String& rStr ) const; + sal_Bool isAlphaNumeric( const String& rStr ) const; + sal_Bool isLetterNumeric( const String& rStr ) const; + + void toUpper( String& rStr ) const + { rStr = toUpper( rStr, 0, rStr.Len() ); } + void toLower( String& rStr ) const + { rStr = toLower( rStr, 0, rStr.Len() ); } + inline String upper( const String& rStr ) const + { return toUpper( rStr, 0, rStr.Len() ); } + inline String lower( const String& rStr ) const + { return toLower( rStr, 0, rStr.Len() ); } +}; + + + +#endif // _UNOTOOLS_CHARCLASS_HXX diff --git a/unotools/inc/unotools/configitem.hxx b/unotools/inc/unotools/configitem.hxx new file mode 100644 index 000000000000..827fa8558a9f --- /dev/null +++ b/unotools/inc/unotools/configitem.hxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * $RCSfile: configitem.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:52 $ + * + * 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 _UTL_CONFIGITEM_HXX_ +#define _UTL_CONFIGITEM_HXX_ + +#ifndef _SAL_TYPES_H_ +#include <sal/types.h> +#endif +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_H_ +#include <com/sun/star/uno/Sequence.h> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif +//----------------------------------------------------------------------------- +namespace com{ namespace sun{ namespace star{ + namespace uno{ + class Any; + } + namespace beans{ + class XMultiPropertySet; + struct PropertyValue; + } + namespace container{ + class XHierarchicalNameAccess; + } + namespace util{ + class XChangesListener; + } +}}} +//----------------------------------------------------------------------------- +namespace utl +{ + class ConfigChangeListener_Impl; + class ConfigManager; + class ConfigItem + { + friend class ConfigChangeListener_Impl; + + const rtl::OUString sSubTree; + com::sun::star::uno::Reference< com::sun::star::beans::XMultiPropertySet> + xMultPrSet; + com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> + xHierarchyAccess; + com::sun::star::uno::Reference< com::sun::star::util::XChangesListener > + xChangeLstnr; + utl::ConfigManager* pManager; + sal_Bool bIsModified : 1; // + sal_Bool bInPutValues : 1; //prevent notification of own change actions + sal_Bool bHasChangedProperties : 1; //call XChangesBatch::Commit() if any changes were notified + + ConfigItem();// + void RemoveListener(); + void CallNotify( + const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); + + protected: + ConfigItem(const rtl::OUString rSubTree); + + void SetModified() {bIsModified = sal_True;} + + com::sun::star::uno::Sequence< com::sun::star::uno::Any> + GetProperties(const com::sun::star::uno::Sequence< rtl::OUString >& rNames); + + sal_Bool PutProperties( + const com::sun::star::uno::Sequence< rtl::OUString >& rNames, + const com::sun::star::uno::Sequence< com::sun::star::uno::Any>& rValues); + + sal_Bool EnableNotification(com::sun::star::uno::Sequence< rtl::OUString >& rNames); + + //returns all members of a node + com::sun::star::uno::Sequence< rtl::OUString > + GetNodeNames(rtl::OUString& rNode); + // remove all members of a set + sal_Bool ClearNodeSet(rtl::OUString& rNode); + // change or add members to a set + sal_Bool SetSetProperties(rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); + // remove, change or add members of a set + sal_Bool ReplaceSetProperties(rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); + + public: + virtual ~ConfigItem(); + + /** is called from the ConfigManager before application ends of from the + PropertyChangeListener if the sub tree broadcasts changes. */ + virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); + + /** is called from the ConfigManager if it is destroyed before the ConfigItem. */ + void ReleaseConfigMgr(); + + const rtl::OUString& GetSubTreeName() const {return sSubTree;} + + sal_Bool IsModified() const {return bIsModified;} + + /** writes the changed values into the sub tree. Always called in the Dtor of the derived class. */ + virtual void Commit(); + + }; +}//namespace utl +#endif //_UTL_CONFIGITEM_HXX_ diff --git a/unotools/inc/unotools/configmgr.hxx b/unotools/inc/unotools/configmgr.hxx new file mode 100644 index 000000000000..1c65d68d9b47 --- /dev/null +++ b/unotools/inc/unotools/configmgr.hxx @@ -0,0 +1,113 @@ +/************************************************************************* + * + * $RCSfile: configmgr.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:52 $ + * + * 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 _UTL_CONFIGMGR_HXX_ +#define _UTL_CONFIGMGR_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_ +#include <com/sun/star/uno/Reference.h> +#endif +#ifndef _RTL_USTRING_ +#include <rtl/ustring> +#endif + +//----------------------------------------------------------------------------- +namespace com{ namespace sun{ namespace star{ + namespace lang{ + class XMultiServiceFactory; + } + namespace beans{ + class XMultiPropertySet; + } +}}} + +//----------------------------------------------------------------------------- +namespace utl +{ + struct ConfigMgr_Impl; + class ConfigItem; + class ConfigManager + { + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + xConfigurationProvider; + ConfigMgr_Impl* pMgrImpl; + + static ConfigManager* pConfigManager; + public: + ConfigManager(); + ~ConfigManager(); + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > + GetConfigurationProvider(); + + com::sun::star::uno::Reference< com::sun::star::beans::XMultiPropertySet> + AddConfigItem(utl::ConfigItem& rCfgItem); + + void RemoveConfigItem(utl::ConfigItem& rCfgItem); + + void StoreConfigItems(); + + static ConfigManager* GetConfigManager(); + static void RemoveConfigManager(); + static rtl::OUString GetConfigBaseURL(); + }; +}//namespace utl +#endif //_UTL_CONFIGMGR_HXX_ diff --git a/unotools/inc/unotools/datetime.hxx b/unotools/inc/unotools/datetime.hxx new file mode 100644 index 000000000000..b1c070ea145d --- /dev/null +++ b/unotools/inc/unotools/datetime.hxx @@ -0,0 +1,117 @@ +/************************************************************************* + * + * $RCSfile: datetime.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:52 $ + * + * 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): _______________________________________ + * + * + ************************************************************************/ + +//= conversions UNO3.TimeClass <-> Tools.TimeClass (Date/Time/DateTime) + +#ifndef _UNOTOOLS_DATETIME_HXX_ +#define _UNOTOOLS_DATETIME_HXX_ + +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/util/Time.hpp> +#include <com/sun/star/util/DateTime.hpp> + +class Date; +class Time; +class DateTime; + +//......................................................................... +namespace utl +{ +//......................................................................... + + namespace starutil = ::com::sun::star::util; + + //------------------------------------------------------------------------- + /** compare two DateTime's + */ + sal_Bool operator ==(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight); + inline sal_Bool operator !=(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight) + { return !(_rLeft == _rRight); } + + //------------------------------------------------------------------------- + /** compare two Date's + */ + sal_Bool operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRight); + inline sal_Bool operator !=(const starutil::Date& _rLeft, const starutil::Date& _rRight) + { return !(_rLeft == _rRight); } + + //------------------------------------------------------------------------- + /** compare two Time's + */ + sal_Bool operator ==(const starutil::Time& _rLeft, const starutil::Time& _rRight); + inline sal_Bool operator !=(const starutil::Time& _rLeft, const starutil::Time& _rRight) + { return !(_rLeft == _rRight); } + + void typeConvert(const Time& _rTime, starutil::Time& _rOut); + void typeConvert(const starutil::Time& _rTime, Time& _rOut); + + void typeConvert(const Date& _rDate, starutil::Date& _rOut); + void typeConvert(const starutil::Date& _rDate, Date& _rOut); + + void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut); + void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut); + +//......................................................................... +} // namespace utl +//......................................................................... + +#endif // _UNOTOOLS_DATETIME_HXX_ + diff --git a/unotools/inc/unotools/idhelper.hxx b/unotools/inc/unotools/idhelper.hxx new file mode 100644 index 000000000000..b757984eb6d4 --- /dev/null +++ b/unotools/inc/unotools/idhelper.hxx @@ -0,0 +1,269 @@ +/************************************************************************* + * + * $RCSfile: idhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:52 $ + * + * 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_ID_HELPER_HXX_ +#define _UNOTOOLS_ID_HELPER_HXX_ + +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XTYPEPROVIDER_HPP_ +#include <com/sun/star/lang/XTypeProvider.hpp> +#endif +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif +#ifndef _UTL_STLTYPES_HXX_ +#include <unotools/stl_types.hxx> +#endif +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +//......................................................................... +namespace utl +{ +//......................................................................... + +//========================================================================= +// to shorten some lines ... +typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > TypeSequence; + +// compare to Sequences of Types +struct TypeSequenceLess : public ::std::binary_function<TypeSequence, TypeSequence, bool> +{ +public: + inline bool operator() (const TypeSequence& lhs, const TypeSequence& rhs) const + { + sal_Int32 nLengthLeft = lhs.getLength(); + sal_Int32 nLengthRight = rhs.getLength(); + + // first check the two lengths + if (nLengthLeft < nLengthRight) + return sal_True; + if (nLengthLeft > nLengthRight) + return sal_False; + + // both sequences have the same length -> check the type names + const ::com::sun::star::uno::Type* pTypesLeft = lhs.getConstArray(); + const ::com::sun::star::uno::Type* pTypesRight = rhs.getConstArray(); + for (sal_Int32 i=0; i<nLengthLeft; ++i, ++pTypesLeft, ++pTypesRight) + { + sal_Int32 nTypeNameCompare = pTypesLeft->getTypeName().compareTo(pTypesRight->getTypeName()); + if (nTypeNameCompare < 0) + return sal_True; + if (nTypeNameCompare > 0) + return sal_False; + } + + // both sequences are equal ... + return sal_False; + } +}; + +// declare the map +DECLARE_STL_MAP ( TypeSequence, + ::cppu::OImplementationId, + TypeSequenceLess, + MapType2Id + ); + +//......................................................................... +} // namespace utl +//......................................................................... + +//========================================================================= +/** defines a helper class for implementing the XTypeProvider::getImplementationId. + it maps sequences of ::com::sun::star::uno::Type to implementation ids + (which means sequences of bytes).<BR> + As there is no possibility to determine the time where the id's are no longer + needed (e.g. because the last instance of the class using this mechanism died) + the helper is "refcounted", i.e. there are acquire and release methods. + To simplify this there is a class classname##Ref which you may want to + use as an member of your classes. + <BR><BR> + As we don't want a global helper class which handles implementation id's + of components from all over the office (supposing somebody want's to use this :) + this is only a define. Wherever you have a "closed" area (which is small enough + and large enough :), see below) where diffenrent components want to use an id helper, + define your own one with this macro.<BR> + The more classes use this helper, the later redundant map entries will be + cleared. The less classes use it, the earlier map entries which may have + been reused will be cleared. +*/ +#define DECLARE_IMPLEMENTATIONID_HELPER(_namespace, classname) \ +namespace _namespace { \ +class classname \ +{ \ + friend class classname##Ref; \ + \ + static sal_Int32 s_nReferenced; \ + static void* s_pMap; \ + \ + static ::osl::Mutex s_aMutex; \ + \ +public: \ + static void acquire(); \ + static void release(); \ + \ + static ::com::sun::star::uno::Sequence< sal_Int8 > getImplementationId( \ + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider >& _rxProvider); \ + \ + static ::com::sun::star::uno::Sequence< sal_Int8 > getImplementationId( \ + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _rTypes); \ + \ +private: \ + static void implCreateMap(); \ + \ + classname() { } \ +}; \ + \ +/*=======================================================================*/ \ +class classname##Ref \ +{ \ +public: \ + classname##Ref() { classname::acquire(); } \ + ~classname##Ref() { classname::release(); } \ +}; \ + \ +} /* _namespace */ \ + \ + +/************************************************************************* +************************************************************************** +*************************************************************************/ + +/** implement an id helper +*/ +#define IMPLEMENT_IMPLEMENTATIONID_HELPER(_namespace, classname) \ +namespace _namespace { \ + \ +/*=======================================================================*/ \ + \ +sal_Int32 classname::s_nReferenced(0); \ +void* classname::s_pMap = NULL; \ +::osl::Mutex classname::s_aMutex; \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::acquire() \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + ++s_nReferenced; \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::release() \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + if (!--s_nReferenced) \ + { \ + delete s_pMap; \ + s_pMap = NULL; \ + } \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId( \ + const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider >& _rxProvider) \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + if (_rxProvider.is()) \ + return getImplementationId(_rxProvider->getTypes()); \ + return ::com::sun::star::uno::Sequence< sal_Int8 >(); \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +::com::sun::star::uno::Sequence< sal_Int8 > classname::getImplementationId( \ + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _rTypes) \ +{ \ + ::osl::MutexGuard aGuard(s_aMutex); \ + DBG_ASSERT(s_nReferenced, \ + "classname::getImplementationId : you need to hold a reference to this class in order to use it !"); \ + /* give the calling class a member of type classname##Ref and all is fine .... */ \ + \ + implCreateMap(); \ + \ + ::utl::MapType2Id* pMap = reinterpret_cast< ::utl::MapType2Id *>(s_pMap); \ + \ + ::cppu::OImplementationId& rId = (*pMap)[_rTypes]; \ + /* this will create an entry for the given type sequence, if neccessary */ \ + \ + return rId.getImplementationId(); \ +} \ + \ +/*-----------------------------------------------------------------------*/ \ +void classname::implCreateMap() \ +{ \ + if (s_pMap) \ + return; \ + s_pMap = new ::utl::MapType2Id(); \ +} \ + \ + \ +} /* _namespace */ \ + \ + + +#endif // _UNOTOOLS_ID_HELPER_HXX_ + diff --git a/unotools/inc/unotools/processfactory.hxx b/unotools/inc/unotools/processfactory.hxx new file mode 100644 index 000000000000..5f67d473fd64 --- /dev/null +++ b/unotools/inc/unotools/processfactory.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * $RCSfile: processfactory.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:53 $ + * + * 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_PROCESSFACTORY_HXX_ +#define _UNOTOOLS_PROCESSFACTORY_HXX_ + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif + +namespace com { namespace sun { namespace star { namespace lang { + class XMultiServiceFactory; +} } } } + +namespace utl +{ + +/** + * This function set the process service factory. + * + * @author Juergen Schmidt + */ +void setProcessServiceFactory(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr); + +/** + * This function get the process service factory. If no service factory is set the function returns + * a null interface. + * + * @author Juergen Schmidt + */ +::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > getProcessServiceFactory(); + +} + +#endif // _UNOTOOLS_PROCESSFACTORY_HXX_ + diff --git a/unotools/inc/unotools/querydeep.hxx b/unotools/inc/unotools/querydeep.hxx new file mode 100644 index 000000000000..c5f76cff6935 --- /dev/null +++ b/unotools/inc/unotools/querydeep.hxx @@ -0,0 +1,526 @@ +/************************************************************************* + * + * $RCSfile: querydeep.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:53 $ + * + * 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_QUERYDEEPINTERFACE_HXX +#define _UNOTOOLS_QUERYDEEPINTERFACE_HXX + +#ifndef _COM_SUN_STAR_UNO_XINTERFACE_HPP_ +#include <com/sun/star/uno/XInterface.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_TYPE_HXX_ +#include <com/sun/star/uno/Type.hxx> +#endif + +/** */ //for docpp +namespace utl +{ + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interfaces types whether they are related by inheritance. + *<BR> + * @return true if rType is derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param rType a <type>Type</type> of an interface. + */ +sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type & rBaseType, + const ::com::sun::star::uno::Type & rType ); + +//-------------------------------------------------------------------------------------------------------- +/** + * Inspect interface types whether they are related by inheritance. + *<BR> + * @return true if p is of a type derived from rBaseType + * @param rBaseType a <type>Type</type> of an interface. + * @param p a pointer to an interface. + */ +template <class Interface> +inline sal_Bool isDerivedFrom( + const ::com::sun::star::uno::Type& rBaseType, + Interface* /*p*/) +{ + return isDerivedFrom( + rBaseType, + ::getCppuType(static_cast<const ::com::sun::star::uno::Reference<Interface> *>(0))); +} + +//-------------------------------------------------------------------------------------------------------- +// possible optimization ? +// Any aRet(::cppu::queryInterface(rType, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)); +// if (aRet.hasValue()) +// return aRet; + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + */ +template< class Interface1 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + */ +template< class Interface1, class Interface2 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + return ::com::sun::star::uno::Any( &p10, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + * @param p11 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10, + class Interface11 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10, + Interface11 * p11 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface11 > *>(0)))) + return ::com::sun::star::uno::Any( &p11, rType ); + else + return ::com::sun::star::uno::Any(); +} + +/** + * Inspect types and choose return proper interface. + *<BR> + * @param p1 a pointer to an interface. + * @param p2 a pointer to an interface. + * @param p3 a pointer to an interface. + * @param p4 a pointer to an interface. + * @param p5 a pointer to an interface. + * @param p6 a pointer to an interface. + * @param p7 a pointer to an interface. + * @param p8 a pointer to an interface. + * @param p9 a pointer to an interface. + * @param p10 a pointer to an interface. + * @param p11 a pointer to an interface. + * @param p12 a pointer to an interface. + */ +template< class Interface1, class Interface2, class Interface3, class Interface4, class Interface5, + class Interface6, class Interface7, class Interface8, class Interface9, class Interface10, + class Interface11, class Interface12 > +inline ::com::sun::star::uno::Any queryDeepInterface( + const ::com::sun::star::uno::Type & rType, + Interface1 * p1, Interface2 * p2, Interface3 * p3, Interface4 * p4, Interface5 * p5, + Interface6 * p6, Interface7 * p7, Interface8 * p8, Interface9 * p9, Interface10 * p10, + Interface11 * p11, Interface12 * p12 ) +{ + if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface1 > *>(0)))) + return ::com::sun::star::uno::Any( &p1, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface2 > *>(0)))) + return ::com::sun::star::uno::Any( &p2, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface3 > *>(0)))) + return ::com::sun::star::uno::Any( &p3, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface4 > *>(0)))) + return ::com::sun::star::uno::Any( &p4, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface5 > *>(0)))) + return ::com::sun::star::uno::Any( &p5, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface6 > *>(0)))) + return ::com::sun::star::uno::Any( &p6, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface7 > *>(0)))) + return ::com::sun::star::uno::Any( &p7, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface8 > *>(0)))) + return ::com::sun::star::uno::Any( &p8, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface9 > *>(0)))) + return ::com::sun::star::uno::Any( &p9, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface10 > *>(0)))) + return ::com::sun::star::uno::Any( &p10, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface11 > *>(0)))) + return ::com::sun::star::uno::Any( &p11, rType ); + else if (isDerivedFrom(rType, ::getCppuType(static_cast<const ::com::sun::star::uno::Reference< Interface12 > *>(0)))) + return ::com::sun::star::uno::Any( &p12, rType ); + else + return ::com::sun::star::uno::Any(); +} + +} // namespace utl + +#endif // _UNOTOOLS_QUERYDEEPINTERFACE_HXX + diff --git a/unotools/inc/unotools/regpathhelper.hxx b/unotools/inc/unotools/regpathhelper.hxx new file mode 100644 index 000000000000..33ce3eb2e28c --- /dev/null +++ b/unotools/inc/unotools/regpathhelper.hxx @@ -0,0 +1,107 @@ +/************************************************************************* + * + * $RCSfile: regpathhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:53 $ + * + * 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_REGPATHHELPER_HXX_ +#define _UNOTOOLS_REGPATHHELPER_HXX_ + +#ifndef _RTL_OUSTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +namespace utl +{ + +/** + * This function returns a path to the user registry file. + * Search for the user registry using the following rules: + * <dl> + * <dt> 1. (for further use) search in sversion.ini (.sversionrc) for an entry + * REGISTRY_VERSION_STRING (example: UserRegistry 5.0/505=test.rdb) in the section + * [Registry]. If found, then take this value instead of the name "user.rdb". + * <dt> 2. Search in the config directory of the user for a file "user.rdb". If + * found return the full path and name of the file. If not found, retry this + * step with a dot before ".user.rdb". + * <dt> 3. If not found a new user registry with name "user.rdb" will be created in the user + * config directory. + * </dl> + *<BR> + * @author Juergen Schmidt + */ +::rtl::OUString getPathToUserRegistry(); + +/** + * This function returns a path to the system registry file. + * The system registry will always be searched in the same directory of the + * executable. The name of the system registry is "applicat.rdb". If the system + * registry was not found, then the environment variable STAR_REGISTRY will be checked. + * If this variable was set, it must contain a full path to a valid system registry. + * Search for the user registry using the following rules: + * + *<BR> + * @author Juergen Schmidt + */ + +::rtl::OUString getPathToSystemRegistry(); + +} + +#endif + diff --git a/unotools/inc/unotools/servicehelper.hxx b/unotools/inc/unotools/servicehelper.hxx new file mode 100644 index 000000000000..735dccf58f51 --- /dev/null +++ b/unotools/inc/unotools/servicehelper.hxx @@ -0,0 +1,139 @@ +/************************************************************************* + * + * $RCSfile: servicehelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:53 $ + * + * 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 _UTL_SERVICEHELPER_HXX_ +#define _UTL_SERVICEHELPER_HXX_ + +/** the UNO3_GETIMPLEMENTATION_* macros implement a static helper function + that gives access to your implementation for a given interface reference, + if possible. + + Example: + MyClass* pClass = MyClass::getImplementation( xRef ); + + Usage: + Put a UNO3_GETIMPLEMENTATION_DECL( classname ) inside your class + definitian and UNO3_GETIMPLEMENTATION_IMPL( classname ) inside + your cxx file. Your class must inherit ::com::sun::star::uno::XUnoTunnel + and export it with queryInterface. Implementation of XUnoTunnel is + done by this macro. +*/ +#define UNO3_GETIMPLEMENTATION_DECL( classname ) \ + static const ::com::sun::star::uno::Sequence< sal_Int8 > & getUnoTunnelId() throw(); \ + static classname* getImplementation( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt ) throw(); \ + virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(::com::sun::star::uno::RuntimeException); + +#define UNO3_GETIMPLEMENTATION_BASE_IMPL( classname ) \ +const ::com::sun::star::uno::Sequence< sal_Int8 > & classname::getUnoTunnelId() throw() \ +{ \ + static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0; \ + if( !pSeq ) \ + { \ + ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); \ + if( !pSeq ) \ + { \ + static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); \ + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); \ + pSeq = &aSeq; \ + } \ + } \ + return *pSeq; \ +} \ +\ +classname* classname::getImplementation( uno::Reference< uno::XInterface > xInt ) throw() \ +{ \ + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xInt, ::com::sun::star::uno::UNO_QUERY ); \ + if( xUT.is() ) \ + return (classname*)xUT->getSomething( classname::getUnoTunnelId() ); \ + else \ + return NULL; \ +} + +#define UNO3_GETIMPLEMENTATION_IMPL( classname )\ +UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\ +sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException) \ +{ \ + if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), \ + rId.getConstArray(), 16 ) ) \ + { \ + return (sal_Int64)this; \ + } \ + return 0; \ +} + +#define UNO3_GETIMPLEMENTATION2_IMPL( classname, baseclass )\ +UNO3_GETIMPLEMENTATION_BASE_IMPL(classname)\ +sal_Int64 SAL_CALL classname::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException) \ +{ \ + if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), \ + rId.getConstArray(), 16 ) ) \ + { \ + return (sal_Int64)this; \ + } \ + else \ + { \ + return baseclass::getSomething( rId ); \ + } \ +} + + +#endif _UTL_SERVICEHELPER_HXX_ + diff --git a/unotools/inc/unotools/streamhelper.hxx b/unotools/inc/unotools/streamhelper.hxx new file mode 100644 index 000000000000..77f2503ccd4e --- /dev/null +++ b/unotools/inc/unotools/streamhelper.hxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * $RCSfile: streamhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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_STREAMHELPER_HXX_ +#define _UNOTOOLS_STREAMHELPER_HXX_ + +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XSEEKABLE_HPP_ +#include <com/sun/star/io/XSeekable.hpp> +#endif +#ifndef _OSL_MUTEX_HXX_ //autogen wg. ::osl::Mutex +#include <osl/mutex.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ +#include <cppuhelper/implbase2.hxx> +#endif +#ifndef _STREAM_HXX +#include <tools/stream.hxx> +#endif + +namespace utl +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +/** + * The helper implementation for a using input streams based on SvLockBytes. + * + * @author Dirk Grobler + * @since 00/28/03 + */ + typedef ::cppu::WeakImplHelper2<stario::XInputStream, stario::XSeekable> InputStreamHelper_Base; + // needed for some compilers +class OInputStreamHelper : public InputStreamHelper_Base +{ + ::osl::Mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt32 m_nActPos; + sal_Int32 m_nAvailable; // this is typically the chunk(buffer) size + +public: + OInputStreamHelper(const SvLockBytesRef& _xLockBytes, + sal_uInt32 _nAvailable, + sal_uInt32 _nPos = 0) + :m_xLockBytes(_xLockBytes) + ,m_nActPos(_nPos) + ,m_nAvailable(_nAvailable){} + +// staruno::XInterface + virtual void SAL_CALL acquire() throw (staruno::RuntimeException); + virtual void SAL_CALL release() throw (staruno::RuntimeException); + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes( staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available( ) throw(stario::NotConnectedException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL closeInput( ) throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException); + + virtual void SAL_CALL seek( sal_Int64 location ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getPosition( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int64 SAL_CALL getLength( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); +}; + +/** + * The helper implementation for a using output streams based on SvLockBytes. + * + * @author Dirk Grobler + * @since 00/28/03 + */ +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamHelper_Base; + // needed for some compilers +class OOutputStreamHelper : public OutputStreamHelper_Base +{ + ::osl::Mutex m_aMutex; + SvLockBytesRef m_xLockBytes; + sal_uInt32 m_nActPos; + +public: + OOutputStreamHelper(const SvLockBytesRef& _xLockBytes, sal_uInt32 _nPos = 0) + :m_xLockBytes(_xLockBytes) + ,m_nActPos(_nPos){} + +// staruno::XInterface + virtual void SAL_CALL acquire() throw (staruno::RuntimeException); + virtual void SAL_CALL release() throw (staruno::RuntimeException); + +// stario::XOutputStream + virtual void SAL_CALL writeBytes( const staruno::Sequence< sal_Int8 >& aData ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL flush( ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput( ) throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException); +}; + +} // namespace utl + + +#endif // _UNOTOOLS_STREAM_WRAPPER_HXX_ + diff --git a/unotools/inc/unotools/streamsection.hxx b/unotools/inc/unotools/streamsection.hxx new file mode 100644 index 000000000000..3229a5f8267d --- /dev/null +++ b/unotools/inc/unotools/streamsection.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * $RCSfile: streamsection.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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_STREAMSECTION_HXX_ +#define _UNOTOOLS_STREAMSECTION_HXX_ + +#ifndef _COM_SUN_STAR_IO_XMARKABLESTREAM_HPP_ +#include <com/sun/star/io/XMarkableStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XDATAINPUTSTREAM_HPP_ +#include <com/sun/star/io/XDataInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XDATAOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XDataOutputStream.hpp> +#endif + +namespace utl +{ + + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +/** implements handling for compatibly reading/writing data from/into an input/output stream. + data written in a block secured by this class should be readable by older versions which + use the same mechanism. + + @author Frank Schoenheit + @since 00/26/05 +*/ + +class OStreamSection +{ + staruno::Reference< stario::XMarkableStream > m_xMarkStream; + staruno::Reference< stario::XDataInputStream > m_xInStream; + staruno::Reference< stario::XDataOutputStream > m_xOutStream; + + sal_Int32 m_nBlockStart; + sal_Int32 m_nBlockLen; + +public: + /** starts reading of a "skippable" section of data within the given input stream<BR> + @param _rxInput the stream to read from. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + */ + OStreamSection(const staruno::Reference< stario::XDataInputStream >& _rxInput); + + /** starts writing of a "skippable" section of data into the given output stream + @param _rxOutput the stream the stream to write to. Must support the + <type scope="com::sun::star::io">XMarkableStream</type> interface + @param _nPresumedLength estimation for the length of the upcoming section. If greater 0, this + value will be written as section length and corrected (in the dtor) only if + needed. If you know how much bytes you are about to write, you may + want to use this param, saving some stream operations this way. + */ + OStreamSection(const staruno::Reference< stario::XDataOutputStream >& _rxOutput, sal_Int32 _nPresumedLength = 0); + + /** dtor. <BR>If constructed for writing, the section "opened" by this object will be "closed".<BR> + If constructed for reading, any remaining bytes 'til the end of the section will be skipped. + */ + ~OStreamSection(); +}; + +} // namespace utl + +#endif // _UNOTOOLS_STREAMSECTION_HXX_ + + diff --git a/unotools/inc/unotools/streamwrap.hxx b/unotools/inc/unotools/streamwrap.hxx new file mode 100644 index 000000000000..ff67671612a7 --- /dev/null +++ b/unotools/inc/unotools/streamwrap.hxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * $RCSfile: streamwrap.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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 _UTL_STREAM_WRAPPER_HXX_ +#define _UTL_STREAM_WRAPPER_HXX_ + +#ifndef _OSL_MUTEX_HXX_ //autogen wg. ::osl::Mutex +#include <osl/mutex.hxx> +#endif + +#ifndef _COM_SUN_STAR_IO_XOUTPUTSTREAM_HPP_ +#include <com/sun/star/io/XOutputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> +#endif + +#ifndef _UTL_UNO3_HXX_ +#include <unotools/uno3.hxx> +#endif + +class SvStream; + +namespace utl +{ + namespace stario = ::com::sun::star::io; + namespace staruno = ::com::sun::star::uno; + +//================================================================== +// FmUnoIOStream, +// stream zum schreiben un lesen von Daten, basieren auf svstream +//================================================================== + typedef ::cppu::WeakImplHelper1<stario::XInputStream> InputStreamWrapper_Base; + // needed for some compilers +class OInputStreamWrapper : public InputStreamWrapper_Base +{ + ::osl::Mutex m_aMutex; + SvStream* m_pSvStream; + sal_Bool m_bSvStreamOwner : 1; + +public: + OInputStreamWrapper(SvStream& _rStream); + OInputStreamWrapper(SvStream* pStream, sal_Bool bOwner=sal_False); + virtual ~OInputStreamWrapper(); + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OInputStreamWrapper, InputStreamWrapper_Base); + +// stario::XInputStream + virtual sal_Int32 SAL_CALL readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL skipBytes(sal_Int32 nBytesToSkip) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual sal_Int32 SAL_CALL available() throw(stario::NotConnectedException, staruno::RuntimeException); + virtual void SAL_CALL closeInput() throw(stario::NotConnectedException, staruno::RuntimeException); +}; + +//================================================================== +// FmUnoOutStream, +// Datensenke fuer SvStreams +//================================================================== +typedef ::cppu::WeakImplHelper1<stario::XOutputStream> OutputStreamWrapper_Base; + // needed for some compilers +class OOutputStreamWrapper : public OutputStreamWrapper_Base +{ + SvStream& rStream; + +public: + OOutputStreamWrapper(SvStream& _rStream) :rStream(_rStream) { } + +// UNO Anbindung + DECLARE_UNO3_AGG_DEFAULTS(OOutputStreamWrapper, OutputStreamWrapper_Base); + +// stario::XOutputStream + virtual void SAL_CALL writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL flush() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); + virtual void SAL_CALL closeOutput() throw(stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException); +}; + +} // namespace utl + + +#endif // _UTL_STREAM_WRAPPER_HXX_ + diff --git a/unotools/inc/unotools/unotunnelhelper.hxx b/unotools/inc/unotools/unotunnelhelper.hxx new file mode 100644 index 000000000000..31db05e8bdfc --- /dev/null +++ b/unotools/inc/unotools/unotunnelhelper.hxx @@ -0,0 +1,240 @@ +/************************************************************************* + * + * $RCSfile: unotunnelhelper.hxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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_UNOTUNNELHLP_HXX +#define _UNOTOOLS_UNOTUNNELHLP_HXX + +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_ +#include <com/sun/star/lang/XUnoTunnel.hpp> +#endif +#ifndef _RTL_UUID_H_ +#include <rtl/uuid.h> +#endif +#ifndef _RTL_MEMORY_H_ +#include <rtl/memory.h> +#endif + +#ifndef _CPPUHELPER_EXTRACT_HXX_ +#include <cppuhelper/extract.hxx> +#endif + +namespace utl +{ +namespace staruno = ::com::sun::star::uno; +namespace starlang = ::com::sun::star::lang; + +//----------------------------------------------------------------------------------------------------------- +// to use the following, define +// sal_Bool getTunneledImplementation(Classname*& pObjImpl, staruno::Reference<starlang::XUnoTunnel> const& xObj); + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Reference<starlang::XUnoTunnel> const& xTunnel) + throw(staruno::RuntimeException) +{ + if (xTunnel.is()) + return getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Reference<staruno::XInterface> const& xObj) + throw(staruno::RuntimeException) +{ + staruno::Reference<starlang::XUnoTunnel> xTunnel(xObj,staruno::UNO_QUERY); + if (xTunnel.is()) + return getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, staruno::Any const& aObj) + throw(staruno::RuntimeException) +{ + staruno::Reference<starlang::XUnoTunnel> xTunnel; + if (cppu::extractInterface(xTunnel, aObj)) + getTunneledImplementation(pImpl, xTunnel); + + pImpl = 0; + return sal_False; +} + +template <class Classname> +sal_Bool getImplementation(Classname*& pImpl, starlang::XUnoTunnel* pObj) + throw(staruno::RuntimeException) +{ + if (pObj) + { + staruno::Reference<starlang::XUnoTunnel> xTunnel(pObj); + return getTunneledImplementation(pImpl, xTunnel); + } + + pImpl = 0; + return sal_False; +} + +//----------------------------------------------------------------------------------------------------------- + +class UnoTunnelId +{ + sal_Int8 tunnelId[16]; +public: + UnoTunnelId(sal_Bool bUseMAC = sal_True) throw() + { + rtl_createUuid(reinterpret_cast<sal_uInt8*>(tunnelId),0,bUseMAC); + } + + staruno::Sequence<sal_Int8> getId() const throw(staruno::RuntimeException) + { + return staruno::Sequence<sal_Int8>(tunnelId, sizeof(tunnelId)); + } + + sal_Bool equalTo(staruno::Sequence<sal_Int8> const& rIdentifier) throw() + { + return rIdentifier.getLength() == sizeof(tunnelId) && + rtl_compareMemory(tunnelId, rIdentifier.getConstArray(), sizeof(tunnelId)) == 0; + } + + sal_Int8 const (&getIdBytes() const)[16] { return tunnelId; } +}; + +//----------------------------------------------------------------------------------------------------------- +template<class Classname> +class UnoTunnelImplBase +{ +protected: + Classname* ThisImplementation() throw() { return static_cast<Classname*>(this); } + + sal_Int64 makeUnoSomething() throw() + { + return reinterpret_cast<sal_Int64>(static_cast<void*>(ThisImplementation())); + } + + static Classname* extractUnoSomething(sal_Int64 nSomething) throw() + { + if (nSomething != sal_Int64()) + return static_cast<Classname*>(reinterpret_cast<void*>(nSomething)); + + return NULL; + } +#ifdef LINUX +public: +#endif + static Classname* + extractUnoSomething( + staruno::Reference<starlang::XUnoTunnel> const& xObj, + staruno::Sequence<sal_Int8> const& rMyTunnelId + ) + throw(staruno::RuntimeException) + { + return xObj.is() ? extractUnoSomething(xObj->getSomething(rMyTunnelId)) : NULL; + } +}; +//----------------------------------------------------------------------------------------------------------- + + +template<class Classname> +class UnoTunnelHelper : public UnoTunnelImplBase<Classname> +{ +protected: + static UnoTunnelId s_aTunnelId; + + sal_Int64 getSomething(staruno::Sequence<sal_Int8> const& rTunnelId) throw() + { + if (s_aTunnelId.equalTo(rTunnelId)) + return makeUnoSomething(); + else + return sal_Int64(); + } +public: + static staruno::Sequence<sal_Int8> getImplementationTunnelId() + throw(staruno::RuntimeException) + { + return s_aTunnelId.getId(); + } +#ifndef LINUX + friend sal_Bool getTunneledImplementation(Classname*& pImpl, staruno::Reference<starlang::XUnoTunnel> const& xObj) + throw(staruno::RuntimeException) + { + pImpl = UnoTunnelHelper<Classname>::UnoTunnelHelper<Classname>::extractUnoSomething( xObj, UnoTunnelHelper<Classname>::getImplementationTunnelId() ); + + return pImpl != 0; + } +#endif +}; +template<class Classname> +UnoTunnelId UnoTunnelHelper<Classname>::s_aTunnelId; + + +//----------------------------------------------------------------------------------------------------------- +} // namespace utl + +#endif // _UNOTOOLS_UNOTUNNELHLP_HXX + diff --git a/unotools/prj/d.lst b/unotools/prj/d.lst new file mode 100644 index 000000000000..9879e4356e37 --- /dev/null +++ b/unotools/prj/d.lst @@ -0,0 +1,11 @@ +..\%__SRC%\bin\*.dll %_DEST%\bin%_EXT%\*.dll +..\%__SRC%\lib\*.lib %_DEST%\lib%_EXT%\*.lib +..\%__SRC%\lib\*.so %_DEST%\lib%_EXT%\*.so +..\%__SRC%\lib\*.dylib %_DEST%\lib%_EXT%\*.dylib +..\%__SRC%\lib\*.sl %_DEST%\lib%_EXT%\*.sl +..\%__SRC%\bin\*.bin %_DEST%\bin%_EXT%\*.bin +..\%__SRC%\inc\*.bin %_DEST%\bin%_EXT%\*.bin + +mkdir: %_DEST%\inc%_EXT%\unotools +..\inc\unotools\*.mk %_DEST%\inc%_EXT%\unotools\*.mk +..\inc\unotools\*.hxx %_DEST%\inc%_EXT%\unotools\*.hxx diff --git a/unotools/source/config/configitem.cxx b/unotools/source/config/configitem.cxx new file mode 100644 index 000000000000..d4544d9753a5 --- /dev/null +++ b/unotools/source/config/configitem.cxx @@ -0,0 +1,623 @@ +/************************************************************************* + * + * $RCSfile: configitem.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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 _UTL_CONFIGITEM_HXX_ +#include "unotools/configitem.hxx" +#endif +#ifndef _UTL_CONFIGMGR_HXX_ +#include "unotools/configmgr.hxx" +#endif +#ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_ +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCHANGESLISTENER_HPP_ +#include <com/sun/star/util/XChangesListener.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_XCHANGESNOTIFIER_HPP_ +#include <com/sun/star/util/XChangesNotifier.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_ +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ +#include <com/sun/star/container/XNameContainer.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif + +#ifndef _COM_SUN_STAR_UTIL_XCHANGESBATCH_HPP_ +#include <com/sun/star/util/XChangesBatch.hpp> +#endif + +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif + +using namespace utl; +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; + +#ifndef _CPPUHELPER_IMPLBASE1_HXX_ +#include <cppuhelper/implbase1.hxx> // helper for implementations +#endif + +namespace utl{ + class ConfigChangeListener_Impl : public cppu::WeakImplHelper1 + < + com::sun::star::util::XChangesListener + > + { + ConfigItem* pParent; + public: + ConfigChangeListener_Impl(ConfigItem& rItem); + ~ConfigChangeListener_Impl(); + + //XChangesListener + virtual void SAL_CALL changesOccurred( const ChangesEvent& Event ) throw(RuntimeException); + + //XEventListener + virtual void SAL_CALL disposing( const EventObject& Source ) throw(RuntimeException); + + }; +} +/* -----------------------------29.08.00 16:34-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigChangeListener_Impl::ConfigChangeListener_Impl(ConfigItem& rItem) : + pParent(&rItem) +{ +} +/* -----------------------------29.08.00 16:34-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigChangeListener_Impl::~ConfigChangeListener_Impl() +{ +} +/* -----------------------------29.08.00 16:34-------------------------------- + + ---------------------------------------------------------------------------*/ + +void ConfigChangeListener_Impl::changesOccurred( const ChangesEvent& rEvent ) throw(RuntimeException) +{ + const ElementChange* pElementChanges = rEvent.Changes.getConstArray(); + + Sequence<OUString> aChangedNames(rEvent.Changes.getLength()); + OUString* pNames = aChangedNames.getArray(); + + const sal_Int32 nBaseTreeLen = ConfigManager::GetConfigBaseURL().getLength() + + pParent->GetSubTreeName().getLength() + 1; + for(int i = 0; i < aChangedNames.getLength(); i++) + { + pElementChanges[i].Accessor >>= pNames[i]; + DBG_ASSERT(nBaseTreeLen < pNames[i].getLength(),"property name incorrect"); + pNames[i] = pNames[i].copy(nBaseTreeLen); + } + pParent->CallNotify(aChangedNames); +} +/* -----------------------------29.08.00 16:34-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigChangeListener_Impl::disposing( const EventObject& Source ) throw(RuntimeException) +{ + DBG_ERROR("ConfigChangeListener_Impl::disposing") +} +/* -----------------------------29.08.00 12:50-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigItem::ConfigItem(const rtl::OUString rSubTree ) : + pManager(ConfigManager::GetConfigManager()), + sSubTree(rSubTree), + bIsModified(sal_False), + bInPutValues(sal_False), + bHasChangedProperties(sal_False) +{ + xMultPrSet = pManager->AddConfigItem(*this); + xHierarchyAccess = Reference<XHierarchicalNameAccess>(xMultPrSet, UNO_QUERY); +} +/* -----------------------------29.08.00 12:52-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigItem::~ConfigItem() +{ + if(pManager) + { + if(bHasChangedProperties && xMultPrSet.is()) + { + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + xBatch->commitChanges(); + } + RemoveListener(); + pManager->RemoveConfigItem(*this); + } +} +/* -----------------------------29.08.00 12:52-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigItem::Commit() +{ + DBG_ERROR("Base class called") +} +/* -----------------------------29.08.00 12:52-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigItem::ReleaseConfigMgr() +{ + if(bHasChangedProperties && xMultPrSet.is()) + { + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + xBatch->commitChanges(); + bHasChangedProperties = FALSE; + } + RemoveListener(); + DBG_ASSERT(pManager, "ConfigManager already released") + pManager = 0; +} +/* -----------------------------29.08.00 12:52-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigItem::CallNotify( const com::sun::star::uno::Sequence<rtl::OUString>& rPropertyNames ) +{ + if(!bInPutValues) + Notify(rPropertyNames); + else + bHasChangedProperties = TRUE; +} +/* -----------------------------29.08.00 12:52-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigItem::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& rPropertyNames) +{ + DBG_ERROR("Base class called") +} +/* -----------------------------29.08.00 15:10-------------------------------- + + ---------------------------------------------------------------------------*/ +Sequence< Any > ConfigItem::GetProperties(const Sequence< OUString >& rNames) +{ + Sequence< Any > aRet(rNames.getLength()); + const OUString* pNames = rNames.getConstArray(); + Any* pRet = aRet.getArray(); + if(xHierarchyAccess.is()) + { + for(int i = 0; i < rNames.getLength(); i++) + { + try + { + pRet[i] = xHierarchyAccess->getByHierarchicalName(pNames[i]); + } + #ifdef DBG_UTIL + catch(Exception& rEx) + { + ByteString sMsg("Exception from XHierarchicalNameAccess: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) + } +#else + catch(Exception&){} +#endif + } + } + return aRet; +} +/* -----------------------------29.08.00 17:28-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool ConfigItem::PutProperties( const Sequence< OUString >& rNames, + const Sequence< Any>& rValues) +{ + bInPutValues = sal_True; + Reference<XPropertySet> xPropSet(xMultPrSet, UNO_QUERY); + sal_Bool bRet = xHierarchyAccess.is() && xPropSet.is(); + if(bRet) + { + const OUString* pNames = rNames.getConstArray(); + const Any* pValues = rValues.getConstArray(); + for(int i = 0; i < rNames.getLength(); i++) + { + try + { + sal_Int32 nLastIndex = pNames[i].lastIndexOf( '/', pNames[i].getLength()); + + if(nLastIndex > 0) + { + OUString sNode = pNames[i].copy( 0, nLastIndex ); + OUString sProperty = pNames[i].copy( nLastIndex + 1, pNames[i].getLength() - nLastIndex - 1 ); + Any aNode = xHierarchyAccess->getByHierarchicalName(sNode); + Reference<XNameAccess> xNodeAcc; + aNode >>= xNodeAcc; + Reference<XNameReplace> xNodeReplace(xNodeAcc, UNO_QUERY); + if(xNodeReplace.is()) + { + xNodeReplace->replaceByName(sProperty, pValues[i]); + } + else + bRet = FALSE; + } + else //direct value + { + xPropSet->setPropertyValue(pNames[i], pValues[i]); + } + } +#ifdef DBG_UTIL + catch(Exception& rEx) + { + ByteString sMsg("Exception from PutProperties: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) + } +#else + catch(Exception&){} +#endif + } +#if SUPD<605 + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + xBatch->commitChanges(); + +#else + DBG_ERROR("does setPropertyValue work correctly now?") +#endif + } + + bInPutValues = sal_False; + return bRet; +} +/* -----------------------------29.08.00 16:19-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool ConfigItem::EnableNotification(com::sun::star::uno::Sequence< rtl::OUString >& rNames) +{ + Reference<XChangesNotifier> xChgNot(xMultPrSet, UNO_QUERY); + if(!xChgNot.is()) + return FALSE; + BOOL bRet = TRUE; + + try + { + xChangeLstnr = new ConfigChangeListener_Impl(*this); + xChgNot->addChangesListener( xChangeLstnr ); + } + catch(RuntimeException& ) + { + bRet = FALSE; + } + return bRet; +} +/* -----------------------------29.08.00 16:47-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigItem::RemoveListener() +{ + Reference<XChangesNotifier> xChgNot(xMultPrSet, UNO_QUERY); + if(xChgNot.is() && xChangeLstnr.is()) + { + try + { + xChgNot->removeChangesListener( xChangeLstnr ); + xMultPrSet = 0; + } + catch(Exception & ) + { + } + } +} +/* -----------------------------15.09.00 12:06-------------------------------- + + ---------------------------------------------------------------------------*/ +Sequence< OUString > ConfigItem::GetNodeNames(rtl::OUString& rNode) +{ + Sequence< OUString > aRet; + if(xHierarchyAccess.is()) + { + try + { + Any aNode = xHierarchyAccess->getByHierarchicalName(rNode); + Reference<XNameContainer> xCont; + aNode >>= xCont; + if(xCont.is()) + { + aRet = xCont->getElementNames(); + } + } +#ifdef DBG_UTIL + catch(Exception& rEx) + { + ByteString sMsg("Exception from GetNodeNames: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) + } +#else + catch(Exception&){} +#endif + } + return aRet; +} +/* -----------------------------15.09.00 15:52-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool ConfigItem::ClearNodeSet(OUString& rNode) +{ + sal_Bool bRet; + if(xHierarchyAccess.is()) + { + try + { + Any aNode = xHierarchyAccess->getByHierarchicalName(rNode); + Reference<XNameContainer> xCont; + aNode >>= xCont; + if(!xCont.is()) + return sal_False; + Sequence< OUString > aNames = xCont->getElementNames(); + const OUString* pNames = aNames.getConstArray(); + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + for(sal_Int32 i = 0; i < aNames.getLength(); i++) + { + xCont->removeByName(pNames[i]); + xBatch->commitChanges(); + } + } + catch(Exception& rEx) + { +#ifdef DBG_UTIL + ByteString sMsg("Exception from GetNodeNames: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) +#endif + bRet = FALSE; + } + } + return bRet; +} +/* -----------------------------15.09.00 15:52-------------------------------- + add or change properties + ---------------------------------------------------------------------------*/ +sal_Bool ConfigItem::SetSetProperties( + OUString& rNode, Sequence< PropertyValue > rValues) +{ + sal_Bool bRet; + if(xHierarchyAccess.is()) + { + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + try + { + Any aNode = xHierarchyAccess->getByHierarchicalName(rNode); + Reference<XNameContainer> xCont; + aNode >>= xCont; + if(!xCont.is()) + return sal_False; + const PropertyValue* pProperties = rValues.getConstArray(); + Sequence< OUString > aSubNodeNames(rValues.getLength()); + OUString* pSubNodeNames = aSubNodeNames.getArray(); + sal_Int32 nNodeLength = rNode.getLength() + 1; + OUString sLastSubNode; + sal_Int32 nSubIndex = 0; + + for(sal_Int32 i = 0; i < rValues.getLength(); i++) + { + OUString sSubNode = pProperties[i].Name.copy(nNodeLength); + sSubNode = sSubNode.copy(0, sSubNode.indexOf('/')); + if(sLastSubNode != sSubNode) + { + pSubNodeNames[nSubIndex++] = sSubNode; + } + sLastSubNode = sSubNode; + } + aSubNodeNames.realloc(nSubIndex); + pSubNodeNames = aSubNodeNames.getArray(); + + Reference<XSingleServiceFactory> xFac(xCont, UNO_QUERY); + for(sal_Int32 j = 0; j < nSubIndex; j++) + { + if(!xCont->hasByName(pSubNodeNames[j])) + { + //create if not available + if(!xFac.is()) + return FALSE; + Reference<XInterface> xInst = xFac->createInstance(); + Any aVal; aVal <<= xInst; + xCont->insertByName(pSubNodeNames[j], aVal); + //node changes must be commited before values can be changed + xBatch->commitChanges(); + } + //set values + } + Sequence< OUString > aSetNames(rValues.getLength()); + OUString* pSetNames = aSetNames.getArray(); + Sequence< Any> aSetValues(rValues.getLength()); + Any* pSetValues = aSetValues.getArray(); + for(sal_Int32 k = 0; k < rValues.getLength(); k++) + { + pSetNames[k] = pProperties[k].Name; + pSetValues[k] = pProperties[k].Value; + } + + xBatch->commitChanges(); + bRet = PutProperties(aSetNames, aSetValues); + + } + catch(Exception& rEx) + { +#ifdef DBG_UTIL + ByteString sMsg("Exception from GetNodeNames: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) +#endif + bRet = FALSE; + } + } + return bRet; +} +/* -----------------------------15.09.00 15:52-------------------------------- + + ---------------------------------------------------------------------------*/ +sal_Bool ConfigItem::ReplaceSetProperties( + OUString& rNode, Sequence< PropertyValue > rValues) +{ + sal_Bool bRet; + if(xHierarchyAccess.is()) + { + Reference<XChangesBatch> xBatch(xMultPrSet, UNO_QUERY); + try + { + Any aNode = xHierarchyAccess->getByHierarchicalName(rNode); + Reference<XNameContainer> xCont; + aNode >>= xCont; + if(!xCont.is()) + return sal_False; + const PropertyValue* pProperties = rValues.getConstArray(); + //remove unknown members first + + Sequence< OUString > aSubNodeNames(rValues.getLength()); + OUString* pSubNodeNames = aSubNodeNames.getArray(); + sal_Int32 nNodeLength = rNode.getLength() + 1; + OUString sLastSubNode; + sal_Int32 nSubIndex = 0; + + for(sal_Int32 i = 0; i < rValues.getLength(); i++) + { + OUString sSubNode = pProperties[i].Name.copy(nNodeLength); + sSubNode = sSubNode.copy(0, sSubNode.indexOf('/')); + if(sLastSubNode != sSubNode) + { + pSubNodeNames[nSubIndex++] = sSubNode; + } + sLastSubNode = sSubNode; + } + aSubNodeNames.realloc(nSubIndex); + pSubNodeNames = aSubNodeNames.getArray(); + + Sequence<OUString> aContainerSubNodes = xCont->getElementNames(); + const OUString* pContainerSubNodes = aContainerSubNodes.getConstArray(); + for(sal_Int32 nContSub = 0; nContSub < aContainerSubNodes.getLength(); nContSub++) + { + sal_Bool bFound = sal_False; + for(sal_Int32 j = 0; j < nSubIndex; j++) + if(pSubNodeNames[j] == pContainerSubNodes[nContSub]) + { + bFound = sal_True; + break; + } + if(!bFound) + { + xCont->removeByName(pContainerSubNodes[nContSub]); + //node changes must be commited before values can be changed + xBatch->commitChanges(); + } + } + + Reference<XSingleServiceFactory> xFac(xCont, UNO_QUERY); + for(sal_Int32 j = 0; j < nSubIndex; j++) + { + if(!xCont->hasByName(pSubNodeNames[j])) + { + //create if not available + if(!xFac.is()) + return FALSE; + Reference<XInterface> xInst = xFac->createInstance(); + Any aVal; aVal <<= xInst; + xCont->insertByName(pSubNodeNames[j], aVal); + //node changes must be commited before values can be changed + xBatch->commitChanges(); + } + //set values + } + Sequence< OUString > aSetNames(rValues.getLength()); + OUString* pSetNames = aSetNames.getArray(); + Sequence< Any> aSetValues(rValues.getLength()); + Any* pSetValues = aSetValues.getArray(); + for(sal_Int32 k = 0; k < rValues.getLength(); k++) + { + pSetNames[k] = pProperties[k].Name; + pSetValues[k] = pProperties[k].Value; + } + + //node changes must be commited before values can be changed + xBatch->commitChanges(); + bRet = PutProperties(aSetNames, aSetValues); + + } + catch(Exception& rEx) + { +#ifdef DBG_UTIL + ByteString sMsg("Exception from GetNodeNames: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) +#endif + bRet = FALSE; + } + } + return bRet; +} + + + diff --git a/unotools/source/config/configmgr.cxx b/unotools/source/config/configmgr.cxx new file mode 100644 index 000000000000..de24bfa59791 --- /dev/null +++ b/unotools/source/config/configmgr.cxx @@ -0,0 +1,268 @@ +/************************************************************************* + * + * $RCSfile: configmgr.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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 _UTL_CONFIGMGR_HXX_ +#include "unotools/configmgr.hxx" +#endif +#ifndef _UTL_CONFIGITEM_HXX_ +#include "unotools/configitem.hxx" +#endif +#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_ +#include <unotools/processfactory.hxx> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XMULTIPROPERTYSET_HPP_ +#include <com/sun/star/beans/XMultiPropertySet.hpp> +#endif +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif + +#include <list> + +//----------------------------------------------------------------------------- + +using namespace utl; +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; + +#define C2U(cChar) OUString::createFromAscii(cChar) +//----------------------------------------------------------------------------- +const char* cConfigBaseURL = "/org.openoffice."; +//const char* cConfigBaseURL = "/com.sun.star."; +const char* cAccessSrvc = "com.sun.star.configuration.ConfigurationUpdateAccess"; + +//----------------------------------------------------------------------------- +struct ConfigItemListEntry_Impl +{ + ConfigItem* pConfigItem; + + ConfigItemListEntry_Impl(ConfigItem* pItem ) : + pConfigItem(pItem){} +}; +typedef std::list<ConfigItemListEntry_Impl> ConfigItemList; +struct utl::ConfigMgr_Impl +{ + ConfigItemList aItemList; +}; + +/* -----------------------------28.08.00 15:35-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigManager::ConfigManager() : + pMgrImpl(new utl::ConfigMgr_Impl) +{ +} +/* -----------------------------28.08.00 15:35-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigManager::~ConfigManager() +{ + //check list content -> should be empty! + DBG_ASSERT(pMgrImpl->aItemList.empty(), "some ConfigItems are still alive") + if(!pMgrImpl->aItemList.empty()) + { + ConfigItemList::iterator aListIter; + for(aListIter = pMgrImpl->aItemList.begin(); aListIter != pMgrImpl->aItemList.end(); ++aListIter) + { + ConfigItemListEntry_Impl& rEntry = *aListIter; + rEntry.pConfigItem->ReleaseConfigMgr(); + } + pMgrImpl->aItemList.erase(pMgrImpl->aItemList.begin(), pMgrImpl->aItemList.end()); + } + delete pMgrImpl; + +} +/* -----------------------------28.08.00 16:17-------------------------------- + + ---------------------------------------------------------------------------*/ +Reference< XMultiServiceFactory > ConfigManager::GetConfigurationProvider() +{ + if(!xConfigurationProvider.is()) + { + Reference< XMultiServiceFactory > xMSF = ::utl::getProcessServiceFactory(); + xConfigurationProvider = Reference< XMultiServiceFactory > + (xMSF->createInstance( + C2U("com.sun.star.configuration.ConfigurationProvider")), + UNO_QUERY); + } + return xConfigurationProvider; +} +/* -----------------------------29.08.00 12:35-------------------------------- + + ---------------------------------------------------------------------------*/ +Reference< XMultiPropertySet> ConfigManager::AddConfigItem(utl::ConfigItem& rCfgItem) +{ + ConfigItemList::iterator aListIter = pMgrImpl->aItemList.begin(); +#ifdef DBG_UTIL + for(aListIter = pMgrImpl->aItemList.begin(); aListIter != pMgrImpl->aItemList.end(); ++aListIter) + { + ConfigItemListEntry_Impl& rEntry = *aListIter; + if(rEntry.pConfigItem == &rCfgItem) + DBG_ERROR("AddConfigItem: already inserted!") + } +#endif + OUString sPath = C2U(cConfigBaseURL); + sPath += rCfgItem.GetSubTreeName(); + Sequence< Any > aArgs(1); + aArgs[0] <<= sPath; + + Reference< XMultiServiceFactory > xCfgProvider = GetConfigurationProvider(); + Reference< XInterface > xIFace; + try + { + xIFace = xCfgProvider->createInstanceWithArguments( + C2U(cAccessSrvc), + aArgs); + pMgrImpl->aItemList.insert(aListIter, ConfigItemListEntry_Impl(&rCfgItem)); +#ifdef DEBUG + Reference<XNameAccess> xNA(xIFace, UNO_QUERY); + Sequence<OUString> aNames = xNA->getElementNames(); + const OUString* pNames = aNames.getConstArray(); +#endif + } +#ifdef DBG_UTIL + catch(Exception& rEx) + { + ByteString sMsg("CreateInstance exception: "); + sMsg += ByteString(String(rEx.Message), RTL_TEXTENCODING_ASCII_US); + DBG_ERROR(sMsg.GetBuffer()) + } +#else + catch(Exception&){} +#endif + return Reference<XMultiPropertySet>(xIFace, UNO_QUERY); +} +/* -----------------------------29.08.00 12:35-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigManager::RemoveConfigItem(utl::ConfigItem& rCfgItem) +{ + DBG_ASSERT(!pMgrImpl->aItemList.empty(), "no ConfigItems available") + ConfigItemList::iterator aListIter = pMgrImpl->aItemList.begin(); + for(aListIter = pMgrImpl->aItemList.begin(); aListIter != pMgrImpl->aItemList.end(); ++aListIter) + { + ConfigItemListEntry_Impl& rEntry = *aListIter; + if(rEntry.pConfigItem == &rCfgItem) + { + pMgrImpl->aItemList.erase(aListIter); + break; + } + } +} +/* -----------------------------30.08.00 15:04-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigManager::StoreConfigItems() +{ + if(!pMgrImpl->aItemList.empty()) + { + ConfigItemList::iterator aListIter = pMgrImpl->aItemList.begin(); + for(aListIter = pMgrImpl->aItemList.begin(); aListIter != pMgrImpl->aItemList.end(); ++aListIter) + { + ConfigItemListEntry_Impl& rEntry = *aListIter; + if(rEntry.pConfigItem->IsModified()) + rEntry.pConfigItem->Commit(); + } + } +} +ConfigManager* ConfigManager::pConfigManager = 0; +/* -----------------------------07.09.00 11:06-------------------------------- + + ---------------------------------------------------------------------------*/ +ConfigManager* ConfigManager::GetConfigManager() +{ + if(!pConfigManager) + { + pConfigManager = new ConfigManager(); + } + return pConfigManager; +} +/* -----------------------------07.09.00 11:06-------------------------------- + + ---------------------------------------------------------------------------*/ +void ConfigManager::RemoveConfigManager() +{ + if(pConfigManager) + { + delete pConfigManager; + pConfigManager = 0; + } +} +/* -----------------------------08.09.00 13:22-------------------------------- + + ---------------------------------------------------------------------------*/ +rtl::OUString ConfigManager::GetConfigBaseURL() +{ + return C2U(cConfigBaseURL); +} + diff --git a/unotools/source/config/makefile.mk b/unotools/source/config/makefile.mk new file mode 100644 index 000000000000..30f5f4c7872b --- /dev/null +++ b/unotools/source/config/makefile.mk @@ -0,0 +1,103 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=config + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + +#UNOTYPES= +#.INCLUDE : $(PRJINC)$/unotools$/unotools.mk + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +#UNOTYPES+= \ +# com.sun.star.container.XEnumeration \ + + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/configitem.obj \ + $(SLO)$/configmgr.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/i18n/charclass.cxx b/unotools/source/i18n/charclass.cxx new file mode 100644 index 000000000000..c9c68d04da8d --- /dev/null +++ b/unotools/source/i18n/charclass.cxx @@ -0,0 +1,575 @@ +/************************************************************************* + * + * $RCSfile: charclass.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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/charclass.hxx> + +#ifndef _STRING_HXX +#include <tools/string.hxx> +#endif +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +#ifndef _UNOTOOLS_COMPONENTFACTORY_HXX_ +#include <unotools/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 CHARCLASS_LIBRARYNAME "int" +#define CHARCLASS_SERVICENAME "com.sun.star.lang.CharacterClassification" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; + + +CharClass::CharClass( + const Reference< XMultiServiceFactory > & xSF, + const Locale& rLocale + ) + : + xSMgr( xSF ) +{ + setLocale( rLocale ); + if ( xSMgr.is() ) + { + try + { + xCC = Reference< XCharacterClassification > ( xSMgr->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CHARCLASS_SERVICENAME ) ) ), + uno::UNO_QUERY ); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "CharClass ctor: Exception caught!" ); + } + } + else + { // try to get an instance somehow + getComponentInstance(); + } +} + + +CharClass::CharClass( + const ::com::sun::star::lang::Locale& rLocale ) +{ + setLocale( rLocale ); + getComponentInstance(); +} + + +CharClass::~CharClass() +{ +} + + +void CharClass::getComponentInstance() +{ + try + { + // CharClass may be needed by "small tools" like the Setup + // => maybe no service manager => loadLibComponentFactory + Reference < XInterface > xI = ::utl::getComponentInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LLCF_LIBNAME( CHARCLASS_LIBRARYNAME ) ) ), + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( CHARCLASS_SERVICENAME ) ) ); + if ( xI.is() ) + { + Any x = xI->queryInterface( ::getCppuType((const Reference< XCharacterClassification >*)0) ); + x >>= xCC; + } + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getComponentInstance: Exception caught!" ); + } +} + + +void CharClass::setLocale( const ::com::sun::star::lang::Locale& rLocale ) +{ + aLocale.Language = rLocale.Language; + aLocale.Country = rLocale.Country; + aLocale.Variant = rLocale.Variant; +} + + +// static +sal_Bool CharClass::isAsciiNumeric( const String& rStr ) +{ + if ( !rStr.Len() ) + return sal_False; + register const sal_Unicode* p = rStr.GetBuffer(); + register const sal_Unicode* const pStop = p + rStr.Len(); + do + { + if ( !isAsciiDigit( *p ) ) + return sal_False; + } while ( ++p < pStop ); + return sal_True; +} + + +// static +sal_Bool CharClass::isAsciiAlpha( const String& rStr ) +{ + if ( !rStr.Len() ) + return sal_False; + register const sal_Unicode* p = rStr.GetBuffer(); + register const sal_Unicode* const pStop = p + rStr.Len(); + do + { + if ( !isAsciiAlpha( *p ) ) + return sal_False; + } while ( ++p < pStop ); + return sal_True; +} + + +// static +sal_Bool CharClass::isAsciiAlphaNumeric( const String& rStr ) +{ + if ( !rStr.Len() ) + return sal_False; + register const sal_Unicode* p = rStr.GetBuffer(); + register const sal_Unicode* const pStop = p + rStr.Len(); + do + { + if ( !isAsciiAlphaNumeric( *p ) ) + return sal_False; + } while ( ++p < pStop ); + return sal_True; +} + + +sal_Bool CharClass::isAlpha( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return (xCC->getCharacterType( rStr, nPos, aLocale ) & + nCharClassAlphaType) != 0; + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isAlpha: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isAlpha( const String& rStr ) const +{ + try + { + if ( xCC.is() ) + return isAlphaType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) ); + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isAlpha: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isLetter( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return (xCC->getCharacterType( rStr, nPos, aLocale ) & + nCharClassLetterType) != 0; + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isLetter: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isLetter( const String& rStr ) const +{ + try + { + if ( xCC.is() ) + return isLetterType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) ); + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isLetter: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isDigit( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return (xCC->getCharacterType( rStr, nPos, aLocale ) & + KCharacterType::DIGIT) != 0; + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isDigit: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isNumeric( const String& rStr ) const +{ + try + { + if ( xCC.is() ) + return isNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) ); + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isNumeric: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isAlphaNumeric( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return (xCC->getCharacterType( rStr, nPos, aLocale ) & + (nCharClassAlphaType | KCharacterType::DIGIT)) != 0; + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isAlphaNumeric: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isAlphaNumeric( const String& rStr ) const +{ + try + { + if ( xCC.is() ) + return isAlphaNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) ); + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isAlphaNumeric: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isLetterNumeric( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return (xCC->getCharacterType( rStr, nPos, aLocale ) & + (nCharClassLetterType | KCharacterType::DIGIT)) != 0; + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isLetterNumeric: Exception caught!" ); + return sal_False; + } +} + + +sal_Bool CharClass::isLetterNumeric( const String& rStr ) const +{ + try + { + if ( xCC.is() ) + return isLetterNumericType( xCC->getStringType( rStr, 0, rStr.Len(), aLocale ) ); + else + return sal_False; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "isLetterNumeric: Exception caught!" ); + return sal_False; + } +} + + +String CharClass::toUpper( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const +{ + try + { + if ( xCC.is() ) + return xCC->toUpper( rStr, nPos, nCount, aLocale ); + else + return rStr.Copy( nPos, nCount ); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "toUpper: Exception caught!" ); + return rStr.Copy( nPos, nCount ); + } +} + + +String CharClass::toLower( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const +{ + try + { + if ( xCC.is() ) + return xCC->toLower( rStr, nPos, nCount, aLocale ); + else + return rStr.Copy( nPos, nCount ); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "toLower: Exception caught!" ); + return rStr.Copy( nPos, nCount ); + } +} + + +String CharClass::toTitle( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const +{ + try + { + if ( xCC.is() ) + return xCC->toTitle( rStr, nPos, nCount, aLocale ); + else + return rStr.Copy( nPos, nCount ); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "toTitle: Exception caught!" ); + return rStr.Copy( nPos, nCount ); + } +} + + +sal_Int16 CharClass::getType( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return xCC->getType( rStr, nPos ); + else + return 0; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getType: Exception caught!" ); + return 0; + } +} + + +sal_Int16 CharClass::getCharacterDirection( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return xCC->getCharacterDirection( rStr, nPos ); + else + return 0; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getCharacterDirection: Exception caught!" ); + return 0; + } +} + + +sal_Int16 CharClass::getScript( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return xCC->getScript( rStr, nPos ); + else + return 0; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getScript: Exception caught!" ); + return 0; + } +} + + +sal_Int32 CharClass::getCharacterType( const String& rStr, xub_StrLen nPos ) const +{ + try + { + if ( xCC.is() ) + return xCC->getCharacterType( rStr, nPos, aLocale ); + else + return 0; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getCharacterType: Exception caught!" ); + return 0; + } +} + + +sal_Int32 CharClass::getStringType( const String& rStr, xub_StrLen nPos, xub_StrLen nCount ) const +{ + try + { + if ( xCC.is() ) + return xCC->getStringType( rStr, nPos, nCount, aLocale ); + else + return 0; + } + catch ( Exception& ) + { + DBG_ERRORFILE( "getStringType: Exception caught!" ); + return 0; + } +} + + +::com::sun::star::lang::ParseResult CharClass::parseAnyToken( + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const +{ + try + { + if ( xCC.is() ) + return xCC->parseAnyToken( rStr, nPos, aLocale, + nStartCharFlags, userDefinedCharactersStart, + nContCharFlags, userDefinedCharactersCont ); + else + return ParseResult(); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "parseAnyToken: Exception caught!" ); + return ParseResult(); + } +} + + +::com::sun::star::lang::ParseResult CharClass::parsePredefinedToken( + sal_Int32 nTokenType, + const String& rStr, + sal_Int32 nPos, + sal_Int32 nStartCharFlags, + const String& userDefinedCharactersStart, + sal_Int32 nContCharFlags, + const String& userDefinedCharactersCont ) const +{ + try + { + if ( xCC.is() ) + return xCC->parsePredefinedToken( nTokenType, rStr, nPos, aLocale, + nStartCharFlags, userDefinedCharactersStart, + nContCharFlags, userDefinedCharactersCont ); + else + return ParseResult(); + } + catch ( Exception& ) + { + DBG_ERRORFILE( "parsePredefinedToken: Exception caught!" ); + return ParseResult(); + } +} + + + diff --git a/unotools/source/i18n/makefile.mk b/unotools/source/i18n/makefile.mk new file mode 100644 index 000000000000..373c83d063de --- /dev/null +++ b/unotools/source/i18n/makefile.mk @@ -0,0 +1,102 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=i18n + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + +#UNOTYPES= +#.INCLUDE : $(PRJINC)$/unotools$/unotools.mk + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +#UNOTYPES+= \ +# com.sun.star.lang.XCharacterClassification + + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/charclass.obj + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/misc/datetime.cxx b/unotools/source/misc/datetime.cxx new file mode 100644 index 000000000000..c756c6cb2442 --- /dev/null +++ b/unotools/source/misc/datetime.cxx @@ -0,0 +1,162 @@ +/************************************************************************* + * + * $RCSfile: datetime.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ + * + * 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_DATETIME_HXX_ +#include <unotools/datetime.hxx> +#endif + +#ifndef _DATE_HXX +#include <tools/date.hxx> +#endif +#ifndef _TOOLS_TIME_HXX +#include <tools/time.hxx> +#endif +#ifndef _DATETIME_HXX +#include <tools/datetime.hxx> +#endif + +//......................................................................... +namespace utl +{ +//......................................................................... + +//------------------------------------------------------------------ +void typeConvert(const Time& _rTime, starutil::Time& _rOut) +{ + _rOut.Hours = _rTime.GetHour(); + _rOut.Minutes = _rTime.GetMin(); + _rOut.Seconds = _rTime.GetSec(); + _rOut.HundredthSeconds = _rTime.Get100Sec(); +} + +//------------------------------------------------------------------ +void typeConvert(const starutil::Time& _rTime, Time& _rOut) +{ + _rOut = Time(_rTime.Hours, _rTime.Minutes, _rTime.Seconds, _rTime.HundredthSeconds); +} + +//------------------------------------------------------------------ +void typeConvert(const Date& _rDate, starutil::Date& _rOut) +{ + _rOut.Day = _rDate.GetDay(); + _rOut.Month = _rDate.GetMonth(); + _rOut.Year = _rDate.GetYear(); +} + +//------------------------------------------------------------------ +void typeConvert(const starutil::Date& _rDate, Date& _rOut) +{ + _rOut = Date(_rDate.Day, _rDate.Month, _rDate.Year); +} + +//------------------------------------------------------------------ +void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut) +{ + _rOut.Year = _rDateTime.GetYear(); + _rOut.Month = _rDateTime.GetMonth(); + _rOut.Day = _rDateTime.GetDay(); + _rOut.Hours = _rDateTime.GetHour(); + _rOut.Minutes = _rDateTime.GetMin(); + _rOut.Seconds = _rDateTime.GetSec(); + _rOut.HundredthSeconds = _rDateTime.Get100Sec(); +} + +//------------------------------------------------------------------ +void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut) +{ + Date aDate(_rDateTime.Day, _rDateTime.Month, _rDateTime.Year); + Time aTime(_rDateTime.Hours, _rDateTime.Minutes, _rDateTime.Seconds, _rDateTime.HundredthSeconds); + _rOut = DateTime(aDate, aTime); +} + +//------------------------------------------------------------------------- +sal_Bool operator ==(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight) +{ + return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + ( _rLeft.Seconds == _rRight.Seconds) && + ( _rLeft.Minutes == _rRight.Minutes) && + ( _rLeft.Hours == _rRight.Hours) && + ( _rLeft.Day == _rRight.Day) && + ( _rLeft.Month == _rRight.Month) && + ( _rLeft.Year == _rRight.Year) ; +} + +//------------------------------------------------------------------------- +sal_Bool operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRight) +{ + return ( _rLeft.Day == _rRight.Day) && + ( _rLeft.Month == _rRight.Month) && + ( _rLeft.Year == _rRight.Year) ; +} + +//------------------------------------------------------------------------- +sal_Bool operator ==(const starutil::Time& _rLeft, const starutil::Time& _rRight) +{ + return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + ( _rLeft.Seconds == _rRight.Seconds) && + ( _rLeft.Minutes == _rRight.Minutes) && + ( _rLeft.Hours == _rRight.Hours) ; +} + +//......................................................................... +} // namespace utl +//......................................................................... + diff --git a/unotools/source/misc/makefile.mk b/unotools/source/misc/makefile.mk new file mode 100644 index 000000000000..474d193111e4 --- /dev/null +++ b/unotools/source/misc/makefile.mk @@ -0,0 +1,112 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:54 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=misc + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + +#UNOTYPES= +#.INCLUDE : $(PRJINC)$/unotools$/unotools.mk + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +#UNOTYPES+= \ +# com.sun.star.util.XNumberFormatTypes \ +# com.sun.star.awt.FontDescriptor \ +# com.sun.star.awt.FontUnderline \ +# com.sun.star.awt.FontStrikeout \ +# com.sun.star.awt.FontSlant \ + + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/types.obj \ + $(SLO)$/datetime.obj \ + $(SLO)$/numbers.obj \ + $(SLO)$/guarding.obj \ + $(SLO)$/sequence.obj \ + $(SLO)$/querydeep.obj \ + $(SLO)$/regpathhelper.obj \ + + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/processfactory/componentfactory.cxx b/unotools/source/processfactory/componentfactory.cxx new file mode 100644 index 000000000000..98c648d48d12 --- /dev/null +++ b/unotools/source/processfactory/componentfactory.cxx @@ -0,0 +1,224 @@ +/************************************************************************* + * + * $RCSfile: componentfactory.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ + * + * 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/componentfactory.hxx> +#include <unotools/processfactory.hxx> + +#ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_REGISTRY_XREGISTRYKEY_HDL_ +#include <com/sun/star/registry/XRegistryKey.hpp> +#endif + +#include <cppuhelper/factory.hxx> + +#include <uno/environment.h> +#include <uno/mapping.hxx> + +#include <rtl/ustring.hxx> +#include <osl/module.h> + + +#pragma hdrstop + + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; +using namespace ::rtl; + + +namespace utl +{ + +Reference< XInterface > getComponentInstance( + const OUString & rLibraryName, + const OUString & rImplementationName + ) +{ + Reference< XInterface > xI; + Reference< XMultiServiceFactory > xMSF = ::utl::getProcessServiceFactory(); + if ( xMSF.is() ) + xI = xMSF->createInstance( rImplementationName ); + if( !xI.is() ) + { + Reference< XSingleServiceFactory > xSSF = + loadLibComponentFactory( rLibraryName, rImplementationName, + Reference< XMultiServiceFactory >(), Reference< XRegistryKey >() ); + xI = xSSF->createInstance(); + } + return xI; +} + + +Reference< XSingleServiceFactory > loadLibComponentFactory( + const OUString & rLibName, + const OUString & rImplName, + const Reference< XMultiServiceFactory > & xSF, + const Reference< XRegistryKey > & xKey + ) +{ + Reference< XSingleServiceFactory > xRet; + + oslModule lib = osl_loadModule( rLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL ); + if (lib) + { + void * pSym; + + // ========================= LATEST VERSION ========================= + OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) ); + if (pSym = osl_getSymbol( lib, aGetEnvName.pData )) + { + uno_Environment * pCurrentEnv = 0; + uno_Environment * pEnv = 0; + const sal_Char * pEnvTypeName = 0; + (*((component_getImplementationEnvironmentFunc)pSym))( &pEnvTypeName, &pEnv ); + + sal_Bool bNeedsMapping = + (pEnv || 0 != rtl_str_compare( pEnvTypeName, CPPU_CURRENT_LANGUAGE_BINDING_NAME )); + + OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) ); + + if (bNeedsMapping) + { + if (! pEnv) + uno_getEnvironment( &pEnv, aEnvTypeName.pData, 0 ); + if (pEnv) + { + OUString aCppEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_getEnvironment( &pCurrentEnv, aCppEnvTypeName.pData, 0 ); + if (pCurrentEnv) + bNeedsMapping = (pEnv != pCurrentEnv); + } + } + + OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) ); + if (pSym = osl_getSymbol( lib, aGetFactoryName.pData )) + { + OString aImplName( OUStringToOString( rImplName, RTL_TEXTENCODING_ASCII_US ) ); + + if (bNeedsMapping) + { + if (pEnv && pCurrentEnv) + { + Mapping aCurrent2Env( pCurrentEnv, pEnv ); + Mapping aEnv2Current( pEnv, pCurrentEnv ); + + if (aCurrent2Env.is() && aEnv2Current.is()) + { + void * pSMgr = aCurrent2Env.mapInterface( + xSF.get(), ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ) ); + void * pKey = aCurrent2Env.mapInterface( + xKey.get(), ::getCppuType( (const Reference< XRegistryKey > *)0 ) ); + + void * pSSF = (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), pSMgr, pKey ); + + if (pKey) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pKey ); + if (pSMgr) + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSMgr ); + + if (pSSF) + { + aEnv2Current.mapInterface( + reinterpret_cast< void ** >( &xRet ), + pSSF, ::getCppuType( (const Reference< XSingleServiceFactory > *)0 ) ); + (*pEnv->pExtEnv->releaseInterface)( pEnv->pExtEnv, pSSF ); + } + } + } + } + else + { + XSingleServiceFactory * pRet = (XSingleServiceFactory *) + (*((component_getFactoryFunc)pSym))( + aImplName.getStr(), xSF.get(), xKey.get() ); + if (pRet) + { + xRet = pRet; + pRet->release(); + } + } + } + + if (pEnv) + (*pEnv->release)( pEnv ); + if (pCurrentEnv) + (*pCurrentEnv->release)( pCurrentEnv ); + } + + + if (! xRet.is()) + osl_unloadModule( lib ); + } + + return xRet; +} + +} // namespace utl diff --git a/unotools/source/processfactory/makefile.mk b/unotools/source/processfactory/makefile.mk new file mode 100644 index 000000000000..a0e4baf2567b --- /dev/null +++ b/unotools/source/processfactory/makefile.mk @@ -0,0 +1,97 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=procfact + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +#UNOTYPES+= \ +# com.sun.star.uno.TypeClass \ +# com.sun.star.lang.XMultiServiceFactory + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/processfactory.obj \ + $(SLO)$/componentfactory.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/processfactory/processfactory.cxx b/unotools/source/processfactory/processfactory.cxx new file mode 100644 index 000000000000..42ca1ae1f25d --- /dev/null +++ b/unotools/source/processfactory/processfactory.cxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * $RCSfile: processfactory.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ + * + * 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 _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_ +#include <unotools/processfactory.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace osl; + +namespace utl +{ + +/* + This function preserves only that the xProcessFactory variable will not be create when + the library is loaded. +*/ +Reference< XMultiServiceFactory > localProcessFactory( const Reference< XMultiServiceFactory >& xSMgr, sal_Bool bSet ) +{ + Guard< Mutex > aGuard( Mutex::getGlobalMutex() ); + + static Reference< XMultiServiceFactory > xProcessFactory; + if ( bSet ) + { + xProcessFactory = xSMgr; + } + + return xProcessFactory; +} + + +void setProcessServiceFactory(const Reference< XMultiServiceFactory >& xSMgr) +{ + localProcessFactory( xSMgr, sal_True ); +} + +Reference< XMultiServiceFactory > getProcessServiceFactory() +{ + return localProcessFactory( Reference< XMultiServiceFactory >(), sal_False ); +} + +} // namesapce utl + diff --git a/unotools/source/property/makefile.mk b/unotools/source/property/makefile.mk new file mode 100644 index 000000000000..88de50a1b134 --- /dev/null +++ b/unotools/source/property/makefile.mk @@ -0,0 +1,103 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=property + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + +#UNOTYPES= +#.INCLUDE : $(PRJINC)$/unotools$/unotools.mk + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +#UNOTYPES+= \ + + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/property.obj \ + $(SLO)$/propmultiplex.obj \ + $(SLO)$/propstate.obj \ + $(SLO)$/propagg.obj \ + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/streaming/makefile.mk b/unotools/source/streaming/makefile.mk new file mode 100644 index 000000000000..7b9fbcb8d21a --- /dev/null +++ b/unotools/source/streaming/makefile.mk @@ -0,0 +1,106 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. +PRJINC=..$/..$/inc +PRJNAME=unotools +TARGET=streaming + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings common for the whole project ----- + +#UNOTYPES= +#.INCLUDE : $(PRJINC)$/unotools$/unotools.mk + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +# --- Types ------------------------------------- + + +#UNOUCRDEP=$(SOLARBINDIR)$/applicat.rdb +#UNOUCRRDB=$(SOLARBINDIR)$/applicat.rdb + +#UNOUCROUT=$(OUT)$/inc +#INCPRE+=$(UNOUCROUT) + +# --- Types ------------------------------------- + +#UNOTYPES+= \ +# com.sun.star.awt.FontDescriptor \ + + +# --- Files ------------------------------------- + +SLOFILES= $(SLO)$/basicio.obj \ + $(SLO)$/streamsection.obj \ + $(SLO)$/streamhelper.obj \ + $(SLO)$/streamwrap.obj \ + $(SLO)$/seqstream.obj \ + $(SLO)$/oslfile2streamwrap.obj + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/unotools/source/streaming/streamhelper.cxx b/unotools/source/streaming/streamhelper.cxx new file mode 100644 index 000000000000..ebbdd783ff21 --- /dev/null +++ b/unotools/source/streaming/streamhelper.cxx @@ -0,0 +1,234 @@ +/************************************************************************* + * + * $RCSfile: streamhelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ + * + * 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/streamhelper.hxx> +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +namespace utl +{ + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamHelper::acquire() throw (staruno::RuntimeException) +{ + InputStreamHelper_Base::acquire(); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamHelper::release() throw (staruno::RuntimeException) +{ + InputStreamHelper_Base::release(); +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamHelper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + ::osl::MutexGuard aGuard( m_aMutex ); + aData.realloc(nBytesToRead); + + sal_uInt32 nRead; + ErrCode nError = m_xLockBytes->ReadAt(m_nActPos, (void*)aData.getArray(), nBytesToRead, &nRead); + m_nActPos += nRead; + + if (nError != ERRCODE_NONE) + throw stario::IOException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + // adjust sequence if data read is lower than the desired data + if (nRead < (sal_uInt32)nBytesToRead) + aData.realloc( nRead ); + + return nRead; +} + +void SAL_CALL OInputStreamHelper::seek( sal_Int64 location ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + m_nActPos = location; +} + +sal_Int64 SAL_CALL OInputStreamHelper::getPosition( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + return m_nActPos; +} + +sal_Int64 SAL_CALL OInputStreamHelper::getLength( ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) +{ + if (!m_xLockBytes.Is()) + return 0; + + ::osl::MutexGuard aGuard( m_aMutex ); + SvLockBytesStat aStat; + m_xLockBytes->Stat( &aStat, SVSTATFLAG_DEFAULT ); + m_nActPos = aStat.nSize; + return m_nActPos; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamHelper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, + sal_Int32 nMaxBytesToRead) + throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + // read all data desired + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamHelper::skipBytes(sal_Int32 nBytesToSkip) + throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nBytesToSkip < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_nActPos += nBytesToSkip; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamHelper::available() + throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + return m_nAvailable; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamHelper::closeInput() + throw (stario::NotConnectedException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_xLockBytes = NULL; +} + +/*************************************************************************/ +//------------------------------------------------------------------------------ +void SAL_CALL OOutputStreamHelper::acquire() throw (staruno::RuntimeException) +{ + OutputStreamHelper_Base::acquire(); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OOutputStreamHelper::release() throw (staruno::RuntimeException) +{ + OutputStreamHelper_Base::release(); +} +// stario::XOutputStream +//------------------------------------------------------------------------------ +void SAL_CALL OOutputStreamHelper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) + throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + ULONG nWritten; + ErrCode nError = m_xLockBytes->WriteAt( m_nActPos, aData.getConstArray(), aData.getLength(), &nWritten ); + m_nActPos += nWritten; + + if (nError != ERRCODE_NONE || + nWritten != aData.getLength()) + { + throw stario::IOException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + } +} + +//------------------------------------------------------------------ +void SAL_CALL OOutputStreamHelper::flush() + throw (stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + ErrCode nError = m_xLockBytes->Flush(); + if (nError != ERRCODE_NONE) + throw stario::IOException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); +} + +//------------------------------------------------------------------ +void SAL_CALL OOutputStreamHelper::closeOutput( ) + throw(stario::NotConnectedException, stario::BufferSizeExceededException, stario::IOException, staruno::RuntimeException) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_xLockBytes.Is()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_xLockBytes = NULL; +} + +} // namespace utl + + diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx new file mode 100644 index 000000000000..399e78e328e1 --- /dev/null +++ b/unotools/source/streaming/streamwrap.cxx @@ -0,0 +1,231 @@ +/************************************************************************* + * + * $RCSfile: streamwrap.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ + * + * 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 _UTL_STREAM_WRAPPER_HXX_ +#include <unotools/streamwrap.hxx> +#endif + +#ifndef _STREAM_HXX //autogen +#include <tools/stream.hxx> +#endif +#ifndef _TOOLS_DEBUG_HXX +#include <tools/debug.hxx> +#endif + +namespace utl +{ + +DBG_NAME(OInputStreamWrapper) +//------------------------------------------------------------------ +OInputStreamWrapper::OInputStreamWrapper( SvStream& _rStream ) + :m_pSvStream(&_rStream) + ,m_bSvStreamOwner(sal_False) +{ + DBG_CTOR(OInputStreamWrapper,NULL); + +} + +//------------------------------------------------------------------ +OInputStreamWrapper::OInputStreamWrapper( SvStream* pStream, sal_Bool bOwner ) + :m_pSvStream( pStream ) + ,m_bSvStreamOwner( bOwner ) +{ + DBG_CTOR(OInputStreamWrapper,NULL); + +} + +//------------------------------------------------------------------ +OInputStreamWrapper::~OInputStreamWrapper() +{ + if( m_bSvStreamOwner ) + delete m_pSvStream; + + DBG_DTOR(OInputStreamWrapper,NULL); +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead) + throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pSvStream) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + ::osl::MutexGuard aGuard( m_aMutex ); + + aData.realloc(nBytesToRead); + + sal_uInt32 nRead = m_pSvStream->Read((void*)aData.getArray(), nBytesToRead); + if (m_pSvStream->SvStream::GetError() != ERRCODE_NONE) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + // Wenn gelesene Zeichen < MaxLength, staruno::Sequence anpassen + if (nRead < (sal_uInt32)nBytesToRead) + aData.realloc( nRead ); + + return nRead; +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamWrapper::readSomeBytes(staruno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + if (!m_pSvStream) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (nMaxBytesToRead < 0) + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + if (m_pSvStream->IsEof()) + { + aData.realloc(0); + return 0; + } + else + return readBytes(aData, nMaxBytesToRead); +} + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamWrapper::skipBytes(sal_Int32 nBytesToSkip) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pSvStream) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + +#ifdef DBG_UTIL + sal_uInt32 nCurrentPos = m_pSvStream->Tell(); +#endif + + m_pSvStream->SeekRel(nBytesToSkip); + if (m_pSvStream->SvStream::GetError() != ERRCODE_NONE) + { + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + } + +#ifdef DBG_UTIL + nCurrentPos = m_pSvStream->Tell(); +#endif +} + +//------------------------------------------------------------------------------ +sal_Int32 SAL_CALL OInputStreamWrapper::available() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + ::osl::MutexGuard aGuard( m_aMutex ); + if (!m_pSvStream) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + sal_uInt32 nPos = m_pSvStream->Tell(); + if (m_pSvStream->SvStream::GetError()) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + m_pSvStream->Seek(STREAM_SEEK_TO_END); + if (m_pSvStream->SvStream::GetError()) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + + sal_Int32 nAvailable = (sal_Int32)m_pSvStream->Tell() - nPos; + m_pSvStream->Seek(nPos); + if (m_pSvStream->SvStream::GetError()) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + return nAvailable; +} + +//------------------------------------------------------------------------------ +void SAL_CALL OInputStreamWrapper::closeInput() throw( stario::NotConnectedException, staruno::RuntimeException ) +{ + if (!m_pSvStream) + throw stario::NotConnectedException(::rtl::OUString(), static_cast<staruno::XWeak*>(this)); + + if (m_bSvStreamOwner) + delete m_pSvStream; + + m_pSvStream = NULL; +} + +/*************************************************************************/ +// stario::XOutputStream +//------------------------------------------------------------------------------ +void SAL_CALL OOutputStreamWrapper::writeBytes(const staruno::Sequence< sal_Int8 >& aData) throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + sal_uInt32 nWritten = rStream.Write(aData.getConstArray(),aData.getLength()); + ErrCode err = rStream.GetError(); + if (err != ERRCODE_NONE || nWritten != aData.getLength()) + { + throw stario::BufferSizeExceededException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); + } +} + +//------------------------------------------------------------------ +void SAL_CALL OOutputStreamWrapper::flush() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ + rStream.Flush(); + if (rStream.GetError() != ERRCODE_NONE) + throw stario::NotConnectedException(::rtl::OUString(),static_cast<staruno::XWeak*>(this)); +} + +//------------------------------------------------------------------ +void SAL_CALL OOutputStreamWrapper::closeOutput() throw( stario::NotConnectedException, stario::BufferSizeExceededException, staruno::RuntimeException ) +{ +} + +} // namespace utl + + diff --git a/unotools/util/makefile.mk b/unotools/util/makefile.mk new file mode 100644 index 000000000000..c3b5ff7702fa --- /dev/null +++ b/unotools/util/makefile.mk @@ -0,0 +1,149 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:55 $ +# +# 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): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=.. +PRJNAME=unotools +TARGET=utl +TARGETTYPE=CUI +USE_LDUMP2=TRUE + +USE_DEFFILE=TRUE + +# --- Settings ---------------------------------- + +.INCLUDE : settings.mk + +LDUMP=ldump2.exe + +# --- Library ----------------------------------- + +LIB1TARGET=$(SLB)$/untools.lib +LIB1FILES=\ + $(SLB)$/i18n.lib \ + $(SLB)$/misc.lib \ + $(SLB)$/property.lib \ + $(SLB)$/streaming.lib \ + $(SLB)$/database.lib \ + $(SLB)$/evtattmgr.lib \ + $(SLB)$/config.lib \ + $(SLB)$/container.lib \ + $(SLB)$/procfact.lib + +# NETBSD: somewhere we have to instantiate the static data members. +# NETBSD-1.2.1 doesn't know about weak symbols so the default mechanism for GCC won't work. +# SCO and MACOSX: the linker does know about weak symbols, but we can't ignore multiple defined symbols +.IF "$(OS)"=="NETBSD" || "$(OS)"=="SCO" || "$(OS)$(COM)"=="OS2GCC" || "$(OS)"=="MACOSX" +LIB1OBJFILES+=$(OBJ)$/staticmb.obj +.ENDIF + +SHL1TARGET=$(TARGET)$(UPD)$(DLLPOSTFIX) + +SHL1IMPLIB=iutl + +SHL1STDLIBS= \ + $(SALLIB) \ + $(OSLLIB) \ + $(VOSLIB) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(TOOLSLIB) + +SHL1LIBS=$(LIB1TARGET) +SHL1DEF=$(MISC)$/$(SHL1TARGET).def +DEF1EXPORTFILE=$(TARGET).dxp + +SHL1DEPN=$(LIB1TARGET) + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + +# === .def file ========================================================== +# --- W32 ---------------------------------------------------------------- + +.IF "$(GUI)" == "WNT" + +$(MISC)$/$(SHL1TARGET).def: $(MISC)$/$(SHL1TARGET).flt makefile.mk + @echo ------------------------------ + @echo Making: $@ + @echo LIBRARY $(SHL1TARGET) >$@ + @echo DESCRIPTION 'UTL' >>$@ + @echo DATA READWRITE NONSHARED >>$@ + @echo EXPORTS >>$@ + $(LIBMGR) -EXTRACT:/ /OUT:$(TARGET).exp $(LIB1TARGET) + @$(LDUMP) -E20 -F$(MISC)$/$(SHL1TARGET).flt $(TARGET).exp >>$@ + +-del $(TARGET).exp + +.ENDIF + + +# --- Allgemein ---------------------------------------------------------- + +# --- Filter-Datei --- + +$(MISC)$/$(SHL1TARGET).flt: makefile.mk + @echo ------------------------------ + @echo Making: $@ + @echo CLEAR_THE_FILE > $@ + @echo _TI >> $@ + @echo _real >> $@ + |