1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28 #include "callform.hxx"
29 #include "global.hxx"
30 #include <tools/urlobj.hxx>
31 #include <ucbhelper/contentbroker.hxx>
32 #include <ucbhelper/content.hxx>
33 #include <unotools/localfilehelper.hxx>
34
35 #include <tools/debug.hxx>
36 #include <unotools/pathoptions.hxx>
37
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <com/sun/star/sdbc/XRow.hpp>
40 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
41 #include <com/sun/star/ucb/XContentAccess.hpp>
42
43 #include <com/sun/star/i18n/XOrdinalSuffix.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <unotools/localedatawrapper.hxx>
47
48
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::ucb;
52
53
54 // static
InitAddIns()55 void ScGlobal::InitAddIns()
56 {
57 // multi paths separated by semicolons
58 SvtPathOptions aPathOpt;
59 String aMultiPath = aPathOpt.GetAddinPath();
60 if ( aMultiPath.Len() > 0 )
61 {
62 xub_StrLen nTokens = aMultiPath.GetTokenCount( ';' );
63 xub_StrLen nIndex = 0;
64 for ( xub_StrLen j=0; j<nTokens; j++ )
65 {
66 String aPath( aMultiPath.GetToken( 0, ';', nIndex ) );
67 if ( aPath.Len() > 0 )
68 {
69 // use LocalFileHelper to convert the path to a URL that always points
70 // to the file on the server
71 String aUrl;
72 if ( utl::LocalFileHelper::ConvertPhysicalNameToURL( aPath, aUrl ) )
73 aPath = aUrl;
74
75 INetURLObject aObj;
76 aObj.SetSmartURL( aPath );
77 aObj.setFinalSlash();
78 try
79 {
80 ::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::NO_DECODE),
81 Reference< XCommandEnvironment > () );
82 Reference< sdbc::XResultSet > xResultSet;
83 Sequence< rtl::OUString > aProps;
84 try
85 {
86 xResultSet = aCnt.createCursor(
87 aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
88 }
89 catch ( Exception& )
90 {
91 // ucb may throw different exceptions on failure now
92 // no assertion if AddIn directory doesn't exist
93 }
94
95 if ( xResultSet.is() )
96 {
97 Reference< sdbc::XRow > xRow( xResultSet, UNO_QUERY );
98 Reference< XContentAccess >
99 xContentAccess( xResultSet, UNO_QUERY );
100 try
101 {
102 if ( xResultSet->first() )
103 {
104 do
105 {
106 rtl::OUString aId( xContentAccess->queryContentIdentifierString() );
107 InitExternalFunc( aId );
108 }
109 while ( xResultSet->next() );
110 }
111 }
112 catch ( Exception& )
113 {
114 DBG_ERRORFILE( "ResultSetException caught!" );
115 }
116 }
117 }
118 catch ( Exception& )
119 {
120 DBG_ERRORFILE( "Exception caught!" );
121 }
122 catch ( ... )
123 {
124
125 DBG_ERRORFILE( "unexpected exception caught!" );
126 }
127 }
128 }
129 }
130 }
131
132
133 // static
GetOrdinalSuffix(sal_Int32 nNumber)134 String ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
135 {
136 if (!xOrdinalSuffix.is())
137 {
138 try
139 {
140 Reference< lang::XMultiServiceFactory > xServiceManager =
141 ::comphelper::getProcessServiceFactory();
142 Reference< XInterface > xInterface =
143 xServiceManager->createInstance(
144 ::rtl::OUString::createFromAscii("com.sun.star.i18n.OrdinalSuffix"));
145 if (xInterface.is())
146 xOrdinalSuffix = Reference< i18n::XOrdinalSuffix >( xInterface, UNO_QUERY);
147 }
148 catch ( Exception& )
149 {
150 DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during init" );
151 }
152 }
153 DBG_ASSERT( xOrdinalSuffix.is(), "GetOrdinalSuffix: createInstance failed");
154 if (xOrdinalSuffix.is())
155 {
156 try
157 {
158 return xOrdinalSuffix->getOrdinalSuffix( nNumber,
159 ScGlobal::pLocaleData->getLocale());
160 }
161 catch ( Exception& )
162 {
163 DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during getOrdinalSuffix" );
164 }
165 }
166 return String();
167 }
168