File: | comphelper/source/compare/AnyCompareFactory.cxx |
Location: | line 60, column 9 |
Description: | Called C++ object pointer is null |
1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||
2 | /* | |||
3 | * This file is part of the LibreOffice project. | |||
4 | * | |||
5 | * This Source Code Form is subject to the terms of the Mozilla Public | |||
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this | |||
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |||
8 | * | |||
9 | * This file incorporates work covered by the following license notice: | |||
10 | * | |||
11 | * Licensed to the Apache Software Foundation (ASF) under one or more | |||
12 | * contributor license agreements. See the NOTICE file distributed | |||
13 | * with this work for additional information regarding copyright | |||
14 | * ownership. The ASF licenses this file to you under the Apache | |||
15 | * License, Version 2.0 (the "License"); you may not use this file | |||
16 | * except in compliance with the License. You may obtain a copy of | |||
17 | * the License at http://www.apache.org/licenses/LICENSE-2.0 . | |||
18 | */ | |||
19 | ||||
20 | ||||
21 | #include "comphelper_module.hxx" | |||
22 | ||||
23 | #include <com/sun/star/ucb/XAnyCompareFactory.hpp> | |||
24 | #include <com/sun/star/i18n/XCollator.hpp> | |||
25 | #include <com/sun/star/lang/Locale.hpp> | |||
26 | #include <com/sun/star/uno/Sequence.h> | |||
27 | #include <com/sun/star/beans/PropertyValue.hpp> | |||
28 | #include <cppuhelper/implbase3.hxx> | |||
29 | #include <cppuhelper/implbase1.hxx> | |||
30 | #include <com/sun/star/lang/XServiceInfo.hpp> | |||
31 | #include <com/sun/star/lang/XInitialization.hpp> | |||
32 | #include <com/sun/star/lang/IllegalArgumentException.hpp> | |||
33 | #include <com/sun/star/lang/XMultiComponentFactory.hpp> | |||
34 | #include <comphelper/stl_types.hxx> | |||
35 | #include <map> | |||
36 | ||||
37 | ||||
38 | using namespace com::sun::star::uno; | |||
39 | using namespace com::sun::star::ucb; | |||
40 | using namespace com::sun::star::lang; | |||
41 | using namespace com::sun::star::i18n; | |||
42 | ||||
43 | using ::rtl::OUString; | |||
44 | ||||
45 | //============================================================================= | |||
46 | ||||
47 | class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare > | |||
48 | { | |||
49 | Reference< XCollator > m_rCollator; | |||
50 | ||||
51 | public: | |||
52 | AnyCompare( Reference< XComponentContext > xContext, const Locale& rLocale ) throw() | |||
53 | { | |||
54 | Reference< XMultiComponentFactory > xFactory = xContext->getServiceManager(); | |||
55 | if ( xFactory.is() ) | |||
| ||||
56 | { | |||
57 | m_rCollator = Reference< XCollator >( | |||
58 | xFactory->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.i18n.Collator" )(&("com.sun.star.i18n.Collator")[0]), ((sal_Int32)((sizeof ("com.sun.star.i18n.Collator") / sizeof (("com.sun.star.i18n.Collator" )[0]))-1)), (((rtl_TextEncoding) 11))), xContext ), | |||
59 | UNO_QUERY ); | |||
60 | m_rCollator->loadDefaultCollator( rLocale, | |||
| ||||
61 | 0 ); //??? | |||
62 | } | |||
63 | ||||
64 | } | |||
65 | ||||
66 | virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException); | |||
67 | }; | |||
68 | ||||
69 | //============================================================================= | |||
70 | ||||
71 | class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo > | |||
72 | { | |||
73 | Reference< XAnyCompare > m_rAnyCompare; | |||
74 | Reference< XComponentContext > m_rContext; | |||
75 | Locale m_Locale; | |||
76 | ||||
77 | public: | |||
78 | AnyCompareFactory( Reference< XComponentContext > xContext ) : m_rContext( xContext ) | |||
79 | {} | |||
80 | ||||
81 | // XAnyCompareFactory | |||
82 | virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException); | |||
83 | ||||
84 | // XInitialization | |||
85 | virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) | |||
86 | throw ( Exception, RuntimeException ); | |||
87 | ||||
88 | // XServiceInfo | |||
89 | virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException); | |||
90 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException); | |||
91 | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException); | |||
92 | ||||
93 | // XServiceInfo - static versions (used for component registration) | |||
94 | static ::rtl::OUString SAL_CALL getImplementationName_static(); | |||
95 | static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); | |||
96 | static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& ); | |||
97 | }; | |||
98 | ||||
99 | //=========================================================================================== | |||
100 | ||||
101 | sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException) | |||
102 | { | |||
103 | sal_Int16 aResult = 0; | |||
104 | ||||
105 | if( m_rCollator.is() ) | |||
106 | { | |||
107 | OUString aStr1; | |||
108 | OUString aStr2; | |||
109 | ||||
110 | any1 >>= aStr1; | |||
111 | any2 >>= aStr2; | |||
112 | ||||
113 | aResult = ( sal_Int16 )m_rCollator->compareString( aStr1, aStr2 ); | |||
114 | } | |||
115 | ||||
116 | return aResult; | |||
117 | } | |||
118 | ||||
119 | //=========================================================================================== | |||
120 | ||||
121 | Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException) | |||
122 | { | |||
123 | // for now only OUString properties compare is implemented | |||
124 | // so no check for the property name is done | |||
125 | ||||
126 | if( aPropertyName == "Title" ) | |||
127 | return m_rAnyCompare; | |||
128 | ||||
129 | return Reference< XAnyCompare >(); | |||
130 | } | |||
131 | ||||
132 | void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) | |||
133 | { | |||
134 | if( aArguments.getLength() ) | |||
135 | { | |||
136 | if( aArguments[0] >>= m_Locale ) | |||
137 | { | |||
138 | m_rAnyCompare = new AnyCompare( m_rContext, m_Locale ); | |||
139 | return; | |||
140 | } | |||
141 | } | |||
142 | ||||
143 | } | |||
144 | ||||
145 | OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException ) | |||
146 | { | |||
147 | return getImplementationName_static(); | |||
148 | } | |||
149 | ||||
150 | OUString SAL_CALL AnyCompareFactory::getImplementationName_static( ) | |||
151 | { | |||
152 | return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AnyCompareFactory" )(&("AnyCompareFactory")[0]), ((sal_Int32)((sizeof ("AnyCompareFactory" ) / sizeof (("AnyCompareFactory")[0]))-1)), (((rtl_TextEncoding ) 11)) ); | |||
153 | } | |||
154 | ||||
155 | sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException) | |||
156 | { | |||
157 | rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" )(&("com.sun.star.ucb.AnyCompareFactory")[0]), ((sal_Int32 )((sizeof ("com.sun.star.ucb.AnyCompareFactory") / sizeof (("com.sun.star.ucb.AnyCompareFactory" )[0]))-1)), (((rtl_TextEncoding) 11)) ); | |||
158 | return aServiceName == ServiceName; | |||
159 | } | |||
160 | ||||
161 | Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException) | |||
162 | { | |||
163 | return getSupportedServiceNames_static(); | |||
164 | } | |||
165 | ||||
166 | Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames_static( ) | |||
167 | { | |||
168 | const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" )(&("com.sun.star.ucb.AnyCompareFactory")[0]), ((sal_Int32 )((sizeof ("com.sun.star.ucb.AnyCompareFactory") / sizeof (("com.sun.star.ucb.AnyCompareFactory" )[0]))-1)), (((rtl_TextEncoding) 11)) ); | |||
169 | const Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); | |||
170 | return aSeq; | |||
171 | } | |||
172 | ||||
173 | Reference< XInterface > SAL_CALL AnyCompareFactory::Create( | |||
174 | const Reference< XComponentContext >& rxContext ) | |||
175 | { | |||
176 | return (cppu::OWeakObject*)new AnyCompareFactory( rxContext ); | |||
177 | } | |||
178 | ||||
179 | void createRegistryInfo_AnyCompareFactory() | |||
180 | { | |||
181 | static ::comphelper::module::OAutoRegistration< AnyCompareFactory > aAutoRegistration; | |||
182 | } | |||
183 | ||||
184 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |