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 <callform.hxx>
21 #include <global.hxx>
22 #include <osl/diagnose.h>
23 #include <osl/file.hxx>
24 #include <tools/urlobj.hxx>
25 #include <tools/diagnose_ex.h>
26 #include <ucbhelper/content.hxx>
27 
28 #include <unotools/pathoptions.hxx>
29 
30 #include <com/sun/star/sdbc/XResultSet.hpp>
31 #include <com/sun/star/ucb/XContentAccess.hpp>
32 
33 #include <com/sun/star/i18n/OrdinalSuffix.hpp>
34 #include <comphelper/processfactory.hxx>
35 #include <unotools/configmgr.hxx>
36 #include <unotools/localedatawrapper.hxx>
37 
38 namespace com::sun::star::ucb { class XCommandEnvironment; }
39 
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::ucb;
43 
InitAddIns()44 void ScGlobal::InitAddIns()
45 {
46     if (utl::ConfigManager::IsFuzzing())
47         return;
48 
49     // multi paths separated by semicolons
50     SvtPathOptions aPathOpt;
51     const OUString& aMultiPath = aPathOpt.GetAddinPath();
52     if (aMultiPath.isEmpty())
53         return;
54 
55     sal_Int32 nIdx {0};
56     do
57     {
58         OUString aPath = aMultiPath.getToken(0, ';', nIdx);
59         if (aPath.isEmpty())
60             continue;
61 
62         OUString aUrl;
63         if ( osl::FileBase::getFileURLFromSystemPath( aPath, aUrl ) == osl::FileBase::E_None )
64             aPath = aUrl;
65 
66         INetURLObject aObj;
67         aObj.SetSmartURL( aPath );
68         aObj.setFinalSlash();
69         try
70         {
71             ::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::DecodeMechanism::NONE),
72                 Reference< XCommandEnvironment >(),
73                 comphelper::getProcessComponentContext() );
74             Reference< sdbc::XResultSet > xResultSet;
75             Sequence< OUString > aProps;
76             try
77             {
78                 xResultSet = aCnt.createCursor(
79                     aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
80             }
81             catch ( Exception& )
82             {
83                 // ucb may throw different exceptions on failure now
84                 // no assertion if AddIn directory doesn't exist
85             }
86 
87             if ( xResultSet.is() )
88             {
89                 Reference< XContentAccess > xContentAccess( xResultSet, UNO_QUERY );
90                 try
91                 {
92                     if ( xResultSet->first() )
93                     {
94                         do
95                         {
96                             OUString aId = xContentAccess->queryContentIdentifierString();
97                             InitExternalFunc( aId );
98                         }
99                         while ( xResultSet->next() );
100                     }
101                 }
102                 catch ( Exception& )
103                 {
104                     TOOLS_WARN_EXCEPTION( "sc", "" );
105                 }
106             }
107         }
108         catch ( Exception& )
109         {
110             TOOLS_WARN_EXCEPTION( "sc", "" );
111         }
112         catch ( ... )
113         {
114             OSL_FAIL( "unexpected exception caught!" );
115         }
116     }
117     while (nIdx>0);
118 }
119 
GetOrdinalSuffix(sal_Int32 nNumber)120 OUString ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
121 {
122     try
123     {
124         if (!xOrdinalSuffix.is())
125         {
126             xOrdinalSuffix = i18n::OrdinalSuffix::create( ::comphelper::getProcessComponentContext() );
127         }
128         uno::Sequence< OUString > aSuffixes = xOrdinalSuffix->getOrdinalSuffix( nNumber,
129                 ScGlobal::getLocaleDataPtr()->getLanguageTag().getLocale());
130         if ( aSuffixes.hasElements() )
131             return aSuffixes[0];
132         else
133             return OUString();
134     }
135     catch ( Exception& )
136     {
137         TOOLS_WARN_EXCEPTION( "sc", "GetOrdinalSuffix: exception caught during init" );
138     }
139     return OUString();
140 }
141 
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
143