xref: /aoo41x/main/sc/source/core/data/globalx.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew 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 
95cdf0e10cSrcweir     				if ( xResultSet.is() )
96cdf0e10cSrcweir     				{
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 						}
112cdf0e10cSrcweir     					catch ( Exception& )
113cdf0e10cSrcweir     					{
114cdf0e10cSrcweir         					DBG_ERRORFILE( "ResultSetException catched!" );
115cdf0e10cSrcweir     					}
116cdf0e10cSrcweir     				}
117cdf0e10cSrcweir 				}
118cdf0e10cSrcweir 				catch ( Exception& )
119cdf0e10cSrcweir 				{
120cdf0e10cSrcweir     				DBG_ERRORFILE( "Exception catched!" );
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 {
136cdf0e10cSrcweir     if (!xOrdinalSuffix.is())
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         try
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             Reference< lang::XMultiServiceFactory > xServiceManager =
141cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory();
142cdf0e10cSrcweir             Reference< XInterface > xInterface =
143cdf0e10cSrcweir                 xServiceManager->createInstance(
144cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("com.sun.star.i18n.OrdinalSuffix"));
145cdf0e10cSrcweir             if  (xInterface.is())
146cdf0e10cSrcweir                 xOrdinalSuffix = Reference< i18n::XOrdinalSuffix >( xInterface, UNO_QUERY);
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir         catch ( Exception& )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during init" );
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     DBG_ASSERT( xOrdinalSuffix.is(), "GetOrdinalSuffix: createInstance failed");
154cdf0e10cSrcweir     if (xOrdinalSuffix.is())
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         try
157cdf0e10cSrcweir         {
158cdf0e10cSrcweir             return xOrdinalSuffix->getOrdinalSuffix( nNumber,
159cdf0e10cSrcweir                     ScGlobal::pLocaleData->getLocale());
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir         catch ( Exception& )
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during getOrdinalSuffix" );
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir     return String();
167cdf0e10cSrcweir }
168