1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/task/InteractionHandler.hpp>
26 #include <com/sun/star/ucb/CommandAbortedException.hpp>
27 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
28 #include <com/sun/star/ucb/NameClash.hpp>
29 #include <com/sun/star/ucb/NumberedSortingInfo.hpp>
30 #include <com/sun/star/ucb/TransferInfo.hpp>
31 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
32 #include <com/sun/star/ucb/XCommandInfo.hpp>
33 #include <com/sun/star/ucb/XContentAccess.hpp>
34 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
35 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
36 #include <com/sun/star/util/DateTime.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <unotools/localedatawrapper.hxx>
39 #include <rtl/strbuf.hxx>
41 #include <tools/debug.hxx>
42 #include <tools/urlobj.hxx>
43 #include <tools/datetime.hxx>
44 #include <vcl/svapp.hxx>
45 #include <ucbhelper/content.hxx>
46 #include <ucbhelper/commandenvironment.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <osl/file.hxx>
51 using namespace com::sun::star
;
52 using namespace comphelper
;
58 std::vector
<OUString
> SfxContentHelper::GetResultSet( const OUString
& rURL
)
60 vector
<OUString
> aList
;
63 ::ucbhelper::Content
aCnt( rURL
, uno::Reference
< ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
64 uno::Reference
< sdbc::XResultSet
> xResultSet
;
65 uno::Reference
< ucb::XDynamicResultSet
> xDynResultSet
;
66 uno::Sequence
< OUString
> aProps(3);
67 OUString
* pProps
= aProps
.getArray();
69 pProps
[1] = "ContentType";
70 pProps
[2] = "IsFolder";
74 xDynResultSet
= aCnt
.createDynamicCursor( aProps
, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS
);
75 if ( xDynResultSet
.is() )
76 xResultSet
= xDynResultSet
->getStaticResultSet();
78 catch( const ucb::CommandAbortedException
& )
80 SAL_WARN( "sfx.bastyp", "GetResultSet: CommandAbortedException" );
82 catch( const uno::Exception
& )
84 SAL_WARN( "sfx.bastyp", "GetResultSet: Any other exception" );
88 if ( xResultSet
.is() )
90 uno::Reference
< sdbc::XRow
> xRow( xResultSet
, uno::UNO_QUERY
);
91 uno::Reference
< ucb::XContentAccess
> xContentAccess( xResultSet
, uno::UNO_QUERY
);
95 while ( xResultSet
->next() )
97 OUString
aTitle( xRow
->getString(1) );
98 OUString
aType( xRow
->getString(2) );
99 OUString aRow
= aTitle
;
103 aRow
+= xContentAccess
->queryContentIdentifierString();
104 aList
.push_back( OUString( aRow
) );
107 catch( const ucb::CommandAbortedException
& )
109 SAL_WARN( "sfx.bastyp", "XContentAccess::next(): CommandAbortedException" );
111 catch( const uno::Exception
& )
113 SAL_WARN( "sfx.bastyp", "XContentAccess::next(): Any other exception" );
117 catch( const uno::Exception
& e
)
119 SAL_WARN( "sfx.bastyp", "GetResultSet: Any other exception: " << e
.Message
);
127 std::vector
< OUString
> SfxContentHelper::GetHelpTreeViewContents( const OUString
& rURL
)
129 vector
< OUString
> aProperties
;
132 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
133 uno::Reference
< task::XInteractionHandler
> xInteractionHandler(
134 task::InteractionHandler::createWithParent(xContext
, 0), uno::UNO_QUERY_THROW
);
136 ::ucbhelper::Content
aCnt( rURL
, new ::ucbhelper::CommandEnvironment( xInteractionHandler
, uno::Reference
< ucb::XProgressHandler
>() ), comphelper::getProcessComponentContext() );
137 uno::Reference
< sdbc::XResultSet
> xResultSet
;
138 uno::Sequence
< OUString
> aProps(2);
139 OUString
* pProps
= aProps
.getArray();
141 pProps
[1] = "IsFolder";
145 uno::Reference
< ucb::XDynamicResultSet
> xDynResultSet
;
146 xDynResultSet
= aCnt
.createDynamicCursor( aProps
, ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS
);
147 if ( xDynResultSet
.is() )
148 xResultSet
= xDynResultSet
->getStaticResultSet();
150 catch( const ucb::CommandAbortedException
& )
153 catch( const uno::Exception
& )
157 if ( xResultSet
.is() )
159 uno::Reference
< sdbc::XRow
> xRow( xResultSet
, uno::UNO_QUERY
);
160 uno::Reference
< ucb::XContentAccess
> xContentAccess( xResultSet
, uno::UNO_QUERY
);
164 while ( xResultSet
->next() )
166 OUString
aTitle( xRow
->getString(1) );
167 bool bFolder
= xRow
->getBoolean(2);
168 OUString aRow
= aTitle
;
170 aRow
+= xContentAccess
->queryContentIdentifierString();
172 aRow
+= bFolder
? OUString("1") : OUString("0");
173 aProperties
.push_back( aRow
);
176 catch( const ucb::CommandAbortedException
& )
179 catch( const uno::Exception
& )
184 catch( const uno::Exception
& )
193 OUString
SfxContentHelper::GetActiveHelpString( const OUString
& rURL
)
198 uno::Reference
< uno::XComponentContext
> xContext
= ::comphelper::getProcessComponentContext();
199 uno::Reference
< task::XInteractionHandler
> xInteractionHandler(
200 task::InteractionHandler::createWithParent(xContext
, 0), uno::UNO_QUERY_THROW
);
201 ::ucbhelper::Content
aCnt( rURL
, new ::ucbhelper::CommandEnvironment( xInteractionHandler
, uno::Reference
< ucb::XProgressHandler
>() ), comphelper::getProcessComponentContext() );
202 // open the "active help" stream
203 uno::Reference
< io::XInputStream
> xStream
= aCnt
.openStream();
204 // and convert it to a String
205 uno::Sequence
< sal_Int8
> lData
;
206 sal_Int32 nRead
= xStream
->readBytes( lData
, 1024 );
209 OString
sOldString( reinterpret_cast<char const *>(lData
.getConstArray()), nRead
);
210 OUString sString
= OStringToOUString( sOldString
, RTL_TEXTENCODING_UTF8
);
211 aRet
.append( sString
);
213 nRead
= xStream
->readBytes( lData
, 1024 );
216 catch( const uno::Exception
& )
220 return aRet
.makeStringAndClear();
225 bool SfxContentHelper::IsHelpErrorDocument( const OUString
& rURL
)
230 ::ucbhelper::Content
aCnt( INetURLObject( rURL
).GetMainURL( INetURLObject::NO_DECODE
),
231 uno::Reference
< ucb::XCommandEnvironment
>(),
232 comphelper::getProcessComponentContext() );
233 if ( !( aCnt
.getPropertyValue( "IsErrorDocument" ) >>= bRet
) )
235 SAL_WARN( "sfx.bastyp", "Property 'IsErrorDocument' is missing" );
238 catch( const uno::Exception
& )
247 sal_Int64
SfxContentHelper::GetSize( const OUString
& rContent
)
250 INetURLObject
aObj( rContent
);
251 DBG_ASSERT( aObj
.GetProtocol() != INetProtocol::NotValid
, "Invalid URL!" );
254 ::ucbhelper::Content
aCnt( aObj
.GetMainURL( INetURLObject::NO_DECODE
), uno::Reference
< ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
255 aCnt
.getPropertyValue( "Size" ) >>= nSize
;
257 catch( const ucb::CommandAbortedException
& )
259 SAL_WARN( "sfx.bastyp", "CommandAbortedException" );
261 catch( const uno::Exception
& )
263 SAL_WARN( "sfx.bastyp", "Any other exception" );
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */