xref: /aoo41x/main/sc/source/core/data/globalx.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 #include "callform.hxx"
33 #include "global.hxx"
34 #include <tools/urlobj.hxx>
35 #include <ucbhelper/contentbroker.hxx>
36 #include <ucbhelper/content.hxx>
37 #include <unotools/localfilehelper.hxx>
38 
39 #include <tools/debug.hxx>
40 #include <unotools/pathoptions.hxx>
41 
42 #include <com/sun/star/sdbc/XResultSet.hpp>
43 #include <com/sun/star/sdbc/XRow.hpp>
44 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
45 #include <com/sun/star/ucb/XContentAccess.hpp>
46 
47 #include <com/sun/star/i18n/XOrdinalSuffix.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <comphelper/processfactory.hxx>
50 #include <unotools/localedatawrapper.hxx>
51 
52 
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::ucb;
56 
57 
58 // static
59 void ScGlobal::InitAddIns()
60 {
61 	// multi paths separated by semicolons
62 	SvtPathOptions aPathOpt;
63 	String aMultiPath = aPathOpt.GetAddinPath();
64 	if ( aMultiPath.Len() > 0 )
65 	{
66 		xub_StrLen nTokens = aMultiPath.GetTokenCount( ';' );
67 		xub_StrLen nIndex = 0;
68 		for ( xub_StrLen j=0; j<nTokens; j++ )
69 		{
70 			String aPath( aMultiPath.GetToken( 0, ';', nIndex ) );
71 			if ( aPath.Len() > 0 )
72 			{
73 				//	use LocalFileHelper to convert the path to a URL that always points
74 				//	to the file on the server
75 				String aUrl;
76 				if ( utl::LocalFileHelper::ConvertPhysicalNameToURL( aPath, aUrl ) )
77 					aPath = aUrl;
78 
79 				INetURLObject aObj;
80 				aObj.SetSmartURL( aPath );
81 				aObj.setFinalSlash();
82 				try
83 				{
84 					::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::NO_DECODE),
85 						Reference< XCommandEnvironment > () );
86 					Reference< sdbc::XResultSet > xResultSet;
87 					Sequence< rtl::OUString > aProps;
88 					try
89 					{
90 						xResultSet = aCnt.createCursor(
91 							aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
92 					}
93 					catch ( Exception& )
94 					{
95 						// ucb may throw different exceptions on failure now
96 						// no assertion if AddIn directory doesn't exist
97 					}
98 
99     				if ( xResultSet.is() )
100     				{
101 						Reference< sdbc::XRow > xRow( xResultSet, UNO_QUERY );
102 						Reference< XContentAccess >
103 							xContentAccess( xResultSet, UNO_QUERY );
104 						try
105 						{
106 							if ( xResultSet->first() )
107 							{
108 								do
109 								{
110 									rtl::OUString aId( xContentAccess->queryContentIdentifierString() );
111 									InitExternalFunc( aId );
112 								}
113 								while ( xResultSet->next() );
114 							}
115 						}
116     					catch ( Exception& )
117     					{
118         					DBG_ERRORFILE( "ResultSetException catched!" );
119     					}
120     				}
121 				}
122 				catch ( Exception& )
123 				{
124     				DBG_ERRORFILE( "Exception catched!" );
125 				}
126 				catch ( ... )
127 				{
128 
129 					DBG_ERRORFILE( "unexpected exception caught!" );
130 				}
131 			}
132 		}
133 	}
134 }
135 
136 
137 // static
138 String ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
139 {
140     if (!xOrdinalSuffix.is())
141     {
142         try
143         {
144             Reference< lang::XMultiServiceFactory > xServiceManager =
145                 ::comphelper::getProcessServiceFactory();
146             Reference< XInterface > xInterface =
147                 xServiceManager->createInstance(
148                     ::rtl::OUString::createFromAscii("com.sun.star.i18n.OrdinalSuffix"));
149             if  (xInterface.is())
150                 xOrdinalSuffix = Reference< i18n::XOrdinalSuffix >( xInterface, UNO_QUERY);
151         }
152         catch ( Exception& )
153         {
154             DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during init" );
155         }
156     }
157     DBG_ASSERT( xOrdinalSuffix.is(), "GetOrdinalSuffix: createInstance failed");
158     if (xOrdinalSuffix.is())
159     {
160         try
161         {
162             return xOrdinalSuffix->getOrdinalSuffix( nNumber,
163                     ScGlobal::pLocaleData->getLocale());
164         }
165         catch ( Exception& )
166         {
167             DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during getOrdinalSuffix" );
168         }
169     }
170     return String();
171 }
172