25#include <com/sun/star/deployment/PackageInformationProvider.hpp>
26#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
33#include <rtl/ustrbuf.hxx>
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::UNO_QUERY_THROW;
47 using ::com::sun::star::uno::UNO_SET_THROW;
48 using ::com::sun::star::uno::Exception;
49 using ::com::sun::star::uno::Sequence;
50 using ::com::sun::star::uno::XComponentContext;
51 using ::com::sun::star::ucb::XContent;
52 using ::com::sun::star::ucb::XContentIdentifier;
53 using ::com::sun::star::sdbc::XRow;
54 using ::com::sun::star::ucb::IllegalIdentifierException;
55 using ::com::sun::star::deployment::PackageInformationProvider;
56 using ::com::sun::star::deployment::XPackageInformationProvider;
57 using ::com::sun::star::sdbc::XResultSet;
64 OUString lcl_compose( std::u16string_view i_rBaseURL,
const OUString& i_rRelativeURL )
68 OUStringBuffer aComposer( i_rBaseURL );
70 aComposer.append(
'/' );
71 aComposer.append( i_rRelativeURL );
72 return aComposer.makeStringAndClear();
88 void DataSupplier::fetchData()
92 const Reference< XPackageInformationProvider > xPackageInfo = PackageInformationProvider::get(
m_xContext );
94 const OUString sContentIdentifier(
m_xContent->getIdentifier()->getContentIdentifier() );
96 switch (
m_xContent->getExtensionContentType() )
100 const Sequence< Sequence< OUString > > aExtensionInfo( xPackageInfo->getExtensionList() );
101 for (
auto const & extInfo : aExtensionInfo )
103 if ( !extInfo.hasElements() )
105 SAL_WARN(
"ucb.ucp.ext",
"illegal extension info" );
109 const OUString& rLocalId = extInfo[0];
111 aEntry.
sId = ContentProvider::getRootURL() + Content::encodeIdentifier( rLocalId ) +
"/";
112 m_aResults.push_back( aEntry );
119 const OUString sPackageLocation(
m_xContent->getPhysicalURL() );
123 Sequence< OUString > aPropertyNames {
"Title" };
125 const Reference< XResultSet > xFolderContent( aWrappedContent.
createCursor( aPropertyNames ), UNO_SET_THROW );
126 const Reference< XRow > xContentRow( xFolderContent, UNO_QUERY_THROW );
127 while ( xFolderContent->next() )
130 aEntry.
sId = lcl_compose( sContentIdentifier, xContentRow->getString( 1 ) );
131 m_aResults.push_back( aEntry );
136 OSL_FAIL(
"DataSupplier::fetchData: unimplemented content type!" );
147 DataSupplier::~DataSupplier()
152 OUString DataSupplier::queryContentIdentifierString( sal_uInt32 i_nIndex )
154 std::unique_lock aGuard(
m_aMutex );
156 if ( i_nIndex < m_aResults.size() )
158 const OUString
sId = m_aResults[ i_nIndex ].sId;
159 if ( !
sId.isEmpty() )
163 OSL_FAIL(
"DataSupplier::queryContentIdentifierString: illegal index, or illegal result entry id!" );
168 Reference< XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 i_nIndex )
170 std::unique_lock aGuard(
m_aMutex );
172 if ( i_nIndex < m_aResults.size() )
174 Reference< XContentIdentifier > xId( m_aResults[ i_nIndex ].xId );
179 OUString
sId = queryContentIdentifierString( i_nIndex );
180 if ( !
sId.isEmpty() )
182 Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier(
sId );
183 m_aResults[ i_nIndex ].xId = xId;
187 return Reference< XContentIdentifier >();
191 Reference< XContent > DataSupplier::queryContent( sal_uInt32 i_nIndex )
193 std::unique_lock aGuard(
m_aMutex );
194 ENSURE_OR_RETURN( i_nIndex < m_aResults.size(),
"illegal index!",
nullptr );
201 Reference< XContentIdentifier > xId( queryContentIdentifier( i_nIndex ) );
206 Reference< XContent > xContent(
m_xContent->getProvider()->queryContent( xId ) );
207 pContent.set(
dynamic_cast< Content*
>( xContent.get() ) );
208 OSL_ENSURE( pContent.is() || !xContent.is(),
"DataSupplier::queryContent: invalid content implementation!" );
209 m_aResults[ i_nIndex ].pContent = pContent;
213 catch (
const IllegalIdentifierException& )
219 return Reference< XContent >();
223 bool DataSupplier::getResult( sal_uInt32 i_nIndex )
225 std::unique_lock aGuard(
m_aMutex );
228 return m_aResults.size() > i_nIndex;
232 sal_uInt32 DataSupplier::totalCount()
234 std::unique_lock aGuard(
m_aMutex );
235 return m_aResults.size();
239 sal_uInt32 DataSupplier::currentCount()
241 return m_aResults.size();
245 bool DataSupplier::isCountFinal()
251 Reference< XRow > DataSupplier::queryPropertyValues( sal_uInt32 i_nIndex )
253 std::unique_lock aGuard(
m_aMutex );
254 ENSURE_OR_RETURN( i_nIndex < m_aResults.size(),
"DataSupplier::queryPropertyValues: illegal index!",
nullptr );
256 Reference< XRow > xRow = m_aResults[ i_nIndex ].xRow;
260 ENSURE_OR_RETURN( queryContent( i_nIndex ).is(),
"could not retrieve the content",
nullptr );
262 switch (
m_xContent->getExtensionContentType() )
266 const OUString& rId( m_aResults[ i_nIndex ].
sId );
267 const OUString sRootURL( ContentProvider::getRootURL() );
268 OUString sTitle = Content::decodeIdentifier( rId.copy( sRootURL.getLength() ) );
269 if ( sTitle.endsWith(
"/") )
270 sTitle = sTitle.copy( 0, sTitle.getLength() - 1 );
271 xRow = Content::getArtificialNodePropertyValues(
m_xContext, getResultSet()->getProperties(), sTitle );
278 xRow = m_aResults[ i_nIndex ].pContent->getPropertyValues(
279 getResultSet()->getProperties(), getResultSet()->
getEnvironment() );
283 OSL_FAIL(
"DataSupplier::queryPropertyValues: unhandled case!" );
287 m_aResults[ i_nIndex ].xRow = xRow;
292 void DataSupplier::releasePropertyValues( sal_uInt32 i_nIndex )
294 std::unique_lock aGuard(
m_aMutex );
296 if ( i_nIndex < m_aResults.size() )
297 m_aResults[ i_nIndex ].xRow.clear();
301 void DataSupplier::close()
306 void DataSupplier::validate()
uno::Reference< ucb::XContent > m_xContent
Reference< XComponentContext > m_xContext
DataSupplier(const css::uno::Reference< css::uno::XComponentContext > &rxContext, rtl::Reference< Content > xContent)
css::uno::Reference< css::sdbc::XResultSet > createCursor(const css::uno::Sequence< OUString > &rPropertyNames, ResultSetInclude eMode=INCLUDE_FOLDERS_AND_DOCUMENTS)
#define ENSURE_OR_RETURN(c, m, r)
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
css::uno::Environment getEnvironment(OUString const &name, std::u16string_view implementation)
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept