update dev300-m58
[ooovba.git] / sc / source / core / data / globalx.cxx
blobbdc0afda4222b552995a3abb71acf046b98a0078
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: globalx.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include "callform.hxx"
36 #include "global.hxx"
37 #include <tools/urlobj.hxx>
38 #include <ucbhelper/contentbroker.hxx>
39 #include <ucbhelper/content.hxx>
40 #include <unotools/localfilehelper.hxx>
42 #include <tools/debug.hxx>
43 #include <svtools/pathoptions.hxx>
45 #include <com/sun/star/sdbc/XResultSet.hpp>
46 #include <com/sun/star/sdbc/XRow.hpp>
47 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
48 #include <com/sun/star/ucb/XContentAccess.hpp>
50 #include <com/sun/star/i18n/XOrdinalSuffix.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <comphelper/processfactory.hxx>
53 #include <unotools/localedatawrapper.hxx>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::ucb;
61 // static
62 void ScGlobal::InitAddIns()
64 // multi paths separated by semicolons
65 SvtPathOptions aPathOpt;
66 String aMultiPath = aPathOpt.GetAddinPath();
67 if ( aMultiPath.Len() > 0 )
69 xub_StrLen nTokens = aMultiPath.GetTokenCount( ';' );
70 xub_StrLen nIndex = 0;
71 for ( xub_StrLen j=0; j<nTokens; j++ )
73 String aPath( aMultiPath.GetToken( 0, ';', nIndex ) );
74 if ( aPath.Len() > 0 )
76 // use LocalFileHelper to convert the path to a URL that always points
77 // to the file on the server
78 String aUrl;
79 if ( utl::LocalFileHelper::ConvertPhysicalNameToURL( aPath, aUrl ) )
80 aPath = aUrl;
82 INetURLObject aObj;
83 aObj.SetSmartURL( aPath );
84 aObj.setFinalSlash();
85 try
87 ::ucbhelper::Content aCnt( aObj.GetMainURL(INetURLObject::NO_DECODE),
88 Reference< XCommandEnvironment > () );
89 Reference< sdbc::XResultSet > xResultSet;
90 Sequence< rtl::OUString > aProps;
91 try
93 xResultSet = aCnt.createCursor(
94 aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY );
96 catch ( Exception& )
98 // ucb may throw different exceptions on failure now
99 // no assertion if AddIn directory doesn't exist
102 if ( xResultSet.is() )
104 Reference< sdbc::XRow > xRow( xResultSet, UNO_QUERY );
105 Reference< XContentAccess >
106 xContentAccess( xResultSet, UNO_QUERY );
109 if ( xResultSet->first() )
113 rtl::OUString aId( xContentAccess->queryContentIdentifierString() );
114 InitExternalFunc( aId );
116 while ( xResultSet->next() );
119 catch ( Exception& )
121 DBG_ERRORFILE( "ResultSetException catched!" );
125 catch ( Exception& )
127 DBG_ERRORFILE( "Exception catched!" );
129 catch ( ... )
132 DBG_ERRORFILE( "unexpected exception caught!" );
140 // static
141 String ScGlobal::GetOrdinalSuffix( sal_Int32 nNumber)
143 if (!xOrdinalSuffix.is())
147 Reference< lang::XMultiServiceFactory > xServiceManager =
148 ::comphelper::getProcessServiceFactory();
149 Reference< XInterface > xInterface =
150 xServiceManager->createInstance(
151 ::rtl::OUString::createFromAscii("com.sun.star.i18n.OrdinalSuffix"));
152 if (xInterface.is())
153 xOrdinalSuffix = Reference< i18n::XOrdinalSuffix >( xInterface, UNO_QUERY);
155 catch ( Exception& )
157 DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during init" );
160 DBG_ASSERT( xOrdinalSuffix.is(), "GetOrdinalSuffix: createInstance failed");
161 if (xOrdinalSuffix.is())
165 return xOrdinalSuffix->getOrdinalSuffix( nNumber,
166 ScGlobal::pLocaleData->getLocale());
168 catch ( Exception& )
170 DBG_ERRORFILE( "GetOrdinalSuffix: exception caught during getOrdinalSuffix" );
173 return String();