Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / globalx.cxx
blob15e484ad5ee36e9c1134ba3c33b9e0d34f0f7d47
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "callform.hxx"
21 #include "global.hxx"
22 #include <tools/urlobj.hxx>
23 #include <ucbhelper/content.hxx>
24 #include <unotools/localfilehelper.hxx>
26 #include <unotools/pathoptions.hxx>
28 #include <com/sun/star/sdbc/XResultSet.hpp>
29 #include <com/sun/star/sdbc/XRow.hpp>
30 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
31 #include <com/sun/star/ucb/XContentAccess.hpp>
33 #include <com/sun/star/i18n/OrdinalSuffix.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <comphelper/processfactory.hxx>
36 #include <comphelper/string.hxx>
37 #include <unotools/localedatawrapper.hxx>
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::ucb;
45 void ScGlobal::InitAddIns()
47 // multi paths separated by semicolons
48 SvtPathOptions aPathOpt;
49 OUString aMultiPath = aPathOpt.GetAddinPath();
50 if (aMultiPath.isEmpty())
51 return;
53 sal_Int32 nTokens = comphelper::string::getTokenCount(aMultiPath, ';');
54 for (sal_Int32 j = 0; j < nTokens; ++j)
56 OUString aPath = comphelper::string::getToken(aMultiPath, j, ';');
57 if (aPath.isEmpty())
58 continue;
60 // use LocalFileHelper to convert the path to a URL that always points
61 // to the file on the server
62 OUString aUrl;
63 if ( utl::LocalFileHelper::ConvertPhysicalNameToURL( aPath, aUrl ) )
64 aPath = aUrl;
66 INetURLObject aObj;
67 aObj.SetSmartURL( aPath );
68 aObj.setFinalSlash();
69 try
71 ::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::NO_DECODE),
72 Reference< XCommandEnvironment >(),
73 comphelper::getProcessComponentContext() );
74 Reference< sdbc::XResultSet > xResultSet;
75 Sequence< OUString > aProps;
76 try
78 xResultSet = aCnt.createCursor(
79 aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
81 catch ( Exception& )
83 // ucb may throw different exceptions on failure now
84 // no assertion if AddIn directory doesn't exist
87 if ( xResultSet.is() )
89 Reference< sdbc::XRow > xRow( xResultSet, UNO_QUERY );
90 Reference< XContentAccess >
91 xContentAccess( xResultSet, UNO_QUERY );
92 try
94 if ( xResultSet->first() )
98 OUString aId = xContentAccess->queryContentIdentifierString();
99 InitExternalFunc( aId );
101 while ( xResultSet->next() );
104 catch ( Exception& )
106 OSL_FAIL( "ResultSetException caught!" );
110 catch ( Exception& )
112 OSL_FAIL( "Exception caught!" );
114 catch ( ... )
116 OSL_FAIL( "unexpected exception caught!" );
122 OUString ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
126 if (!xOrdinalSuffix.is())
128 xOrdinalSuffix = i18n::OrdinalSuffix::create( ::comphelper::getProcessComponentContext() );
130 uno::Sequence< OUString > aSuffixes = xOrdinalSuffix->getOrdinalSuffix( nNumber,
131 ScGlobal::pLocaleData->getLanguageTag().getLocale());
132 if ( aSuffixes.getLength() > 0 )
133 return aSuffixes[0];
134 else
135 return OUString();
137 catch ( Exception& )
139 OSL_FAIL( "GetOrdinalSuffix: exception caught during init" );
141 return OUString();
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */