1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: provconf.cxx,v $
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_ucbhelper.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
40 #ifndef _UCBHELPER_PROVCONF_HXX_
41 #include <provconf.hxx>
43 #include <osl/diagnose.h>
44 #include <rtl/ustrbuf.hxx>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
47 #include <com/sun/star/container/XNameAccess.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 using namespace com::sun::star
;
52 //=========================================================================
54 #define CONFIG_CONTENTPROVIDERS_KEY \
55 "/org.openoffice.ucb.Configuration/ContentProviders"
57 //=========================================================================
61 void makeAndAppendXMLName(
62 rtl::OUStringBuffer
& rBuffer
, const rtl::OUString
& rIn
)
64 sal_Int32 nCount
= rIn
.getLength();
65 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
67 const sal_Unicode c
= rIn
.getStr()[ n
];
71 rBuffer
.appendAscii( "&" );
75 rBuffer
.appendAscii( """ );
79 rBuffer
.appendAscii( "'" );
83 rBuffer
.appendAscii( "<" );
87 rBuffer
.appendAscii( ">" );
97 //=========================================================================
98 bool getContentProviderData(
99 const uno::Reference
< lang::XMultiServiceFactory
> & rServiceMgr
,
100 const rtl::OUString
& rKey1
,
101 const rtl::OUString
& rKey2
,
102 ContentProviderDataList
& rListToFill
)
104 if ( !rServiceMgr
.is() || !rKey1
.getLength() || !rKey2
.getLength() )
107 "getContentProviderData - Invalid argument!" );
113 uno::Reference
< lang::XMultiServiceFactory
> xConfigProv(
114 rServiceMgr
->createInstance(
115 rtl::OUString::createFromAscii(
116 "com.sun.star.configuration.ConfigurationProvider" ) ),
119 if ( !xConfigProv
.is() )
122 "getContentProviderData - No config provider!" );
126 rtl::OUStringBuffer aFullPath
;
127 aFullPath
.appendAscii( CONFIG_CONTENTPROVIDERS_KEY
"/['" );
128 makeAndAppendXMLName( aFullPath
, rKey1
);
129 aFullPath
.appendAscii( "']/SecondaryKeys/['" );
130 makeAndAppendXMLName( aFullPath
, rKey2
);
131 aFullPath
.appendAscii( "']/ProviderData" );
133 uno::Sequence
< uno::Any
> aArguments( 1 );
134 beans::PropertyValue aProperty
;
136 = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
137 aProperty
.Value
<<= aFullPath
.makeStringAndClear();
138 aArguments
[ 0 ] <<= aProperty
;
140 uno::Reference
< uno::XInterface
> xInterface(
141 xConfigProv
->createInstanceWithArguments(
142 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
143 "com.sun.star.configuration.ConfigurationAccess" ) ),
146 if ( !xInterface
.is() )
149 "getContentProviderData - No config access!" );
153 uno::Reference
< container::XNameAccess
> xNameAccess(
154 xInterface
, uno::UNO_QUERY
);
156 if ( !xNameAccess
.is() )
159 "getContentProviderData - No XNameAccess!" );
163 uno::Sequence
< rtl::OUString
> aElems
= xNameAccess
->getElementNames();
164 const rtl::OUString
* pElems
= aElems
.getConstArray();
165 sal_Int32 nCount
= aElems
.getLength();
169 uno::Reference
< container::XHierarchicalNameAccess
>
170 xHierNameAccess( xInterface
, uno::UNO_QUERY
);
172 if ( !xHierNameAccess
.is() )
175 "getContentProviderData - "
176 "No XHierarchicalNameAccess!" );
180 // Iterate over children.
181 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
183 rtl::OUStringBuffer aElemBuffer
;
184 aElemBuffer
.appendAscii( "['" );
185 makeAndAppendXMLName( aElemBuffer
, pElems
[ n
] );
189 ContentProviderData aInfo
;
191 // Obtain service name.
192 rtl::OUStringBuffer aKeyBuffer
= aElemBuffer
;
193 aKeyBuffer
.appendAscii( "']/ServiceName" );
195 rtl::OUString aValue
;
196 if ( !( xHierNameAccess
->getByHierarchicalName(
197 aKeyBuffer
.makeStringAndClear() ) >>= aValue
) )
200 "getContentProviderData - "
201 "Error getting item value!" );
205 aInfo
.ServiceName
= aValue
;
207 // Obtain URL Template.
208 aKeyBuffer
= aElemBuffer
;
209 aKeyBuffer
.appendAscii( "']/URLTemplate" );
211 if ( !( xHierNameAccess
->getByHierarchicalName(
212 aKeyBuffer
.makeStringAndClear() ) >>= aValue
) )
215 "getContentProviderData - "
216 "Error getting item value!" );
220 aInfo
.URLTemplate
= aValue
;
223 aKeyBuffer
= aElemBuffer
;
224 aKeyBuffer
.appendAscii( "']/Arguments" );
226 if ( !( xHierNameAccess
->getByHierarchicalName(
227 aKeyBuffer
.makeStringAndClear() ) >>= aValue
) )
230 "getContentProviderData - "
231 "Error getting item value!" );
235 aInfo
.Arguments
= aValue
;
237 // Append info to list.
238 rListToFill
.push_back( aInfo
);
240 catch ( container::NoSuchElementException
& )
242 // getByHierarchicalName
245 "getContentProviderData - "
246 "caught NoSuchElementException!" );
251 catch ( uno::RuntimeException
& )
254 "getContentProviderData - caught RuntimeException!" );
257 catch ( uno::Exception
& )
259 // createInstance, createInstanceWithArguments
262 "getContentProviderData - caught Exception!" );