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