File: | comphelper/source/misc/numbers.cxx |
Location: | line 61, column 60 |
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 | #include <comphelper/numbers.hxx> |
21 | #include <osl/diagnose.h> |
22 | #include <com/sun/star/util/NumberFormat.hpp> |
23 | #include <com/sun/star/util/XNumberFormatTypes.hpp> |
24 | #include <com/sun/star/beans/XPropertySet.hpp> |
25 | #include <com/sun/star/lang/Locale.hpp> |
26 | |
27 | //......................................................................... |
28 | namespace comphelper |
29 | { |
30 | //......................................................................... |
31 | |
32 | namespace starbeans = ::com::sun::star::beans; |
33 | namespace starlang = ::com::sun::star::lang; |
34 | |
35 | //------------------------------------------------------------------------------ |
36 | sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey) |
37 | { |
38 | sal_Int16 nReturn(starutil::NumberFormat::UNDEFINED); |
39 | if (xFormats.is()) |
40 | { |
41 | try |
42 | { |
43 | staruno::Reference<starbeans::XPropertySet> xFormat(xFormats->getByKey(nKey)); |
44 | if (xFormat.is()) |
45 | xFormat->getPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Type" )(&("Type")[0]), ((sal_Int32)((sizeof ("Type") / sizeof (( "Type")[0]))-1)), (((rtl_TextEncoding) 11)))) >>= nReturn; |
46 | } |
47 | catch(...) |
48 | { |
49 | OSL_TRACE("getNumberFormatType : invalid key! (maybe created with another formatter ?)")do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "49" ": "), "getNumberFormatType : invalid key! (maybe created with another formatter ?)" ); } } while (false); |
50 | } |
51 | } |
52 | return nReturn; |
53 | } |
54 | |
55 | //------------------------------------------------------------------------------ |
56 | sal_Int16 getNumberFormatType(const staruno::Reference<starutil::XNumberFormatter>& xFormatter, sal_Int32 nKey) |
57 | { |
58 | OSL_ENSURE(xFormatter.is(), "getNumberFormatType : the formatter isn't valid !")do { if (true && (!(xFormatter.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "58" ": "), "%s", "getNumberFormatType : the formatter isn't valid !" ); } } while (false); |
59 | staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter->getNumberFormatsSupplier()); |
60 | OSL_ENSURE(xSupplier.is(), "getNumberFormatType : the formatter doesn't implement a supplier !")do { if (true && (!(xSupplier.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "60" ": "), "%s", "getNumberFormatType : the formatter doesn't implement a supplier !" ); } } while (false); |
61 | staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier->getNumberFormats()); |
Called C++ object pointer is null | |
62 | return getNumberFormatType(xFormats, nKey); |
63 | } |
64 | |
65 | //------------------------------------------------------------------------------ |
66 | staruno::Any getNumberFormatDecimals(const staruno::Reference<starutil::XNumberFormats>& xFormats, sal_Int32 nKey) |
67 | { |
68 | if (xFormats.is()) |
69 | { |
70 | try |
71 | { |
72 | staruno::Reference<starbeans::XPropertySet> xFormat( xFormats->getByKey(nKey)); |
73 | if (xFormat.is()) |
74 | { |
75 | static ::rtl::OUString PROPERTY_DECIMALS( RTL_CONSTASCII_USTRINGPARAM( "Decimals" )(&("Decimals")[0]), ((sal_Int32)((sizeof ("Decimals") / sizeof (("Decimals")[0]))-1)), (((rtl_TextEncoding) 11))); |
76 | return xFormat->getPropertyValue(PROPERTY_DECIMALS); |
77 | } |
78 | } |
79 | catch(...) |
80 | { |
81 | OSL_TRACE("getNumberFormatDecimals : invalid key! (may be created with another formatter ?)")do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "81" ": "), "getNumberFormatDecimals : invalid key! (may be created with another formatter ?)" ); } } while (false); |
82 | } |
83 | } |
84 | return staruno::makeAny((sal_Int16)0); |
85 | } |
86 | |
87 | |
88 | //------------------------------------------------------------------------------ |
89 | sal_Int32 getStandardFormat( |
90 | const staruno::Reference<starutil::XNumberFormatter>& xFormatter, |
91 | sal_Int16 nType, |
92 | const starlang::Locale& _rLocale) |
93 | { |
94 | staruno::Reference<starutil::XNumberFormatsSupplier> xSupplier( xFormatter.is() ? xFormatter->getNumberFormatsSupplier() : staruno::Reference<starutil::XNumberFormatsSupplier>(NULL__null)); |
95 | staruno::Reference<starutil::XNumberFormats> xFormats( xSupplier.is() ? xSupplier->getNumberFormats() : staruno::Reference<starutil::XNumberFormats>(NULL__null)); |
96 | staruno::Reference<starutil::XNumberFormatTypes> xTypes(xFormats, staruno::UNO_QUERY); |
97 | OSL_ENSURE(xTypes.is(), "getStandardFormat : no format types !")do { if (true && (!(xTypes.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "97" ": "), "%s", "getStandardFormat : no format types !" ); } } while (false); |
98 | |
99 | return xTypes.is() ? xTypes->getStandardFormat(nType, _rLocale) : 0; |
100 | } |
101 | |
102 | //------------------------------------------------------------------------------ |
103 | using namespace ::com::sun::star::uno; |
104 | using namespace ::com::sun::star::util; |
105 | using namespace ::com::sun::star::beans; |
106 | |
107 | //------------------------------------------------------------------------------ |
108 | Any getNumberFormatProperty( const Reference< XNumberFormatter >& _rxFormatter, sal_Int32 _nKey, const rtl::OUString& _rPropertyName ) |
109 | { |
110 | Any aReturn; |
111 | |
112 | OSL_ENSURE( _rxFormatter.is() && !_rPropertyName.isEmpty(), "getNumberFormatProperty: invalid arguments!" )do { if (true && (!(_rxFormatter.is() && !_rPropertyName .isEmpty()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "112" ": "), "%s", "getNumberFormatProperty: invalid arguments!" ); } } while (false); |
113 | try |
114 | { |
115 | Reference< XNumberFormatsSupplier > xSupplier; |
116 | Reference< XNumberFormats > xFormats; |
117 | Reference< XPropertySet > xFormatProperties; |
118 | |
119 | if ( _rxFormatter.is() ) |
120 | xSupplier = _rxFormatter->getNumberFormatsSupplier(); |
121 | if ( xSupplier.is() ) |
122 | xFormats = xSupplier->getNumberFormats(); |
123 | if ( xFormats.is() ) |
124 | xFormatProperties = xFormats->getByKey( _nKey ); |
125 | |
126 | if ( xFormatProperties.is() ) |
127 | aReturn = xFormatProperties->getPropertyValue( _rPropertyName ); |
128 | } |
129 | catch( const Exception& ) |
130 | { |
131 | OSL_FAIL( "::getNumberFormatProperty: caught an exception (did you create the key with another formatter?)!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/numbers.cxx" ":" "131" ": "), "%s", "::getNumberFormatProperty: caught an exception (did you create the key with another formatter?)!" ); } } while (false); |
132 | } |
133 | |
134 | return aReturn; |
135 | } |
136 | |
137 | //......................................................................... |
138 | } // namespace comphelper |
139 | //......................................................................... |
140 | |
141 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |