Bug Summary

File:comphelper/source/misc/documentinfo.cxx
Location:line 122, column 26
Description:Called C++ object pointer is null

Annotated Source Code

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/documentinfo.hxx"
22#include "comphelper/namedvaluecollection.hxx"
23
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
26#include <com/sun/star/document/XDocumentProperties.hpp>
27#include <com/sun/star/frame/XStorable.hpp>
28#include <com/sun/star/frame/XTitle.hpp>
29
30#include <cppuhelper/exc_hlp.hxx>
31
32#include <osl/diagnose.h>
33#include <osl/thread.h>
34
35#include <boost/current_function.hpp>
36
37//........................................................................
38namespace comphelper {
39//........................................................................
40
41 /** === begin UNO using === **/
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::UNO_QUERY;
44 using ::com::sun::star::uno::UNO_QUERY_THROW;
45 using ::com::sun::star::uno::Exception;
46 using ::com::sun::star::uno::RuntimeException;
47 using ::com::sun::star::frame::XModel;
48 using ::com::sun::star::frame::XTitle;
49 using ::com::sun::star::frame::XController;
50 using ::com::sun::star::beans::XPropertySet;
51 using ::com::sun::star::document::XDocumentPropertiesSupplier;
52 using ::com::sun::star::document::XDocumentProperties;
53 using ::com::sun::star::frame::XStorable;
54 using ::com::sun::star::beans::XPropertySetInfo;
55 using ::com::sun::star::frame::XTitle;
56 using ::com::sun::star::uno::XInterface;
57 using ::com::sun::star::frame::XFrame;
58 /** === end UNO using === **/
59
60 //====================================================================
61 //= helper
62 //====================================================================
63 namespace
64 {
65 ::rtl::OUString lcl_getTitle( const Reference< XInterface >& _rxComponent )
66 {
67 Reference< XTitle > xTitle( _rxComponent, UNO_QUERY );
68 if ( xTitle.is() )
69 return xTitle->getTitle();
70 return ::rtl::OUString();
71 }
72 }
73
74 //====================================================================
75 //= DocumentInfo
76 //====================================================================
77 //--------------------------------------------------------------------
78 ::rtl::OUString DocumentInfo::getDocumentTitle( const Reference< XModel >& _rxDocument )
79 {
80 ::rtl::OUString sTitle;
81
82 if ( !_rxDocument.is() )
1
Taking false branch
83 return sTitle;
84
85 ::rtl::OUString sDocURL;
86 try
87 {
88 // 1. ask the model and the controller for their XTitle::getTitle
89 sTitle = lcl_getTitle( _rxDocument );
90 if ( !sTitle.isEmpty() )
2
Taking false branch
91 return sTitle;
92
93 Reference< XController > xController( _rxDocument->getCurrentController() );
94 sTitle = lcl_getTitle( xController );
95 if ( !sTitle.isEmpty() )
3
Taking false branch
96 return sTitle;
97
98 // work around a problem with embedded objects, which sometimes return
99 // private:object as URL
100 sDocURL = _rxDocument->getURL();
101 if ( sDocURL.matchAsciiL( "private:", 8 ) )
4
Taking false branch
102 sDocURL = ::rtl::OUString();
103
104 // 2. if the document is not saved, yet, check the frame title
105 if ( sDocURL.isEmpty() )
5
Taking false branch
106 {
107 Reference< XFrame > xFrame;
108 if ( xController.is() )
109 xFrame.set( xController->getFrame() );
110 sTitle = lcl_getTitle( xFrame );
111 if ( !sTitle.isEmpty() )
112 return sTitle;
113 }
114
115 // 3. try the UNO DocumentInfo
116 Reference< XDocumentPropertiesSupplier > xDPS( _rxDocument, UNO_QUERY );
117 if ( xDPS.is() )
6
Taking true branch
118 {
119 Reference< XDocumentProperties > xDocProps (
120 xDPS->getDocumentProperties(), UNO_QUERY_THROW );
121 OSL_ENSURE(xDocProps.is(), "no DocumentProperties")do { if (true && (!(xDocProps.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/documentinfo.cxx"
":" "121" ": "), "%s", "no DocumentProperties"); } } while (
false)
;
122 sTitle = xDocProps->getTitle();
7
Called C++ object pointer is null
123 if ( !sTitle.isEmpty() )
124 return sTitle;
125 }
126
127 // 4. try model arguments
128 NamedValueCollection aModelArgs( _rxDocument->getArgs() );
129 sTitle = aModelArgs.getOrDefault( "Title", sTitle );
130 if ( !sTitle.isEmpty() )
131 return sTitle;
132
133 // 5. try the last segment of the document URL
134 // this formerly was an INetURLObject::getName( LAST_SEGMENT, true, DECODE_WITH_CHARSET ),
135 // but since we moved this code to comphelper, we do not have access to an INetURLObject anymore
136 // This heuristics here should be sufficient - finally, we will get an UNO title API in a not
137 // too distant future (hopefully), then this complete class is superfluous)
138 if ( sDocURL.isEmpty() )
139 {
140 Reference< XStorable > xDocStorable( _rxDocument, UNO_QUERY_THROW );
141 sDocURL = xDocStorable->getLocation();
142 }
143 sal_Int32 nLastSepPos = sDocURL.lastIndexOf( '/' );
144 if ( ( nLastSepPos != -1 ) && ( nLastSepPos == sDocURL.getLength() - 1 ) )
145 {
146 sDocURL = sDocURL.copy( 0, nLastSepPos );
147 nLastSepPos = sDocURL.lastIndexOf( '/' );
148 }
149 sTitle = sDocURL.copy( nLastSepPos + 1 );
150
151 if ( !sTitle.isEmpty() )
152 return sTitle;
153
154 // 5.
155 // <-- #i88104# (05-16-08) TKR: use the new XTitle Interface to get the Title -->
156
157 Reference< XTitle > xTitle( _rxDocument, UNO_QUERY );
158 if ( xTitle.is() )
159 {
160 if ( !xTitle->getTitle().isEmpty() )
161 return xTitle->getTitle();
162 }
163 }
164 catch ( const Exception& )
165 {
166 ::com::sun::star::uno::Any caught( ::cppu::getCaughtException() );
167 ::rtl::OString sMessage( "caught an exception!" );
168 sMessage += "\ntype : ";
169 sMessage += ::rtl::OString( caught.getValueTypeName().getStr(), caught.getValueTypeName().getLength(), osl_getThreadTextEncoding() );
170 sMessage += "\nmessage: ";
171 ::com::sun::star::uno::Exception exception;
172 caught >>= exception;
173 sMessage += ::rtl::OString( exception.Message.getStr(), exception.Message.getLength(), osl_getThreadTextEncoding() );
174 sMessage += "\nin function:\n";
175 sMessage += BOOST_CURRENT_FUNCTION__PRETTY_FUNCTION__;
176 sMessage += "\n";
177 OSL_FAIL( sMessage.getStr() )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/comphelper/source/misc/documentinfo.cxx"
":" "177" ": "), "%s", sMessage.getStr()); } } while (false)
;
178 }
179
180 return sTitle;
181 }
182
183//........................................................................
184} // namespace comphelper
185//........................................................................
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */