12#include <boost/make_shared.hpp>
14#include <com/sun/star/beans/PropertyAttribute.hpp>
15#include <com/sun/star/beans/PropertyValue.hpp>
16#include <com/sun/star/beans/XPropertySetInfo.hpp>
17#include <com/sun/star/lang/IllegalArgumentException.hpp>
18#include <com/sun/star/ucb/XCommandInfo.hpp>
19#include <com/sun/star/ucb/XDynamicResultSet.hpp>
21#include <com/sun/star/xml/crypto/XDigestContext.hpp>
22#include <com/sun/star/xml/crypto/DigestID.hpp>
23#include <com/sun/star/xml/crypto/NSSInitializer.hpp>
26#include <config_oauth2.h>
44#define OUSTR_TO_STDSTR(s) std::string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ) )
45#define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
52 ContentProvider *pProvider,
const uno::Reference< ucb::XContentIdentifier >& Identifier,
53 std::vector< libcmis::RepositoryPtr > && aRepos )
54 : ContentImplHelper( rxContext, pProvider,
Identifier ),
55 m_pProvider( pProvider ),
57 m_aRepositories(
std::move(aRepos) )
61 SAL_INFO(
"ucb.ucp.cmis",
"RepoContent::RepoContent() " << sURL );
74 return uno::Any( lang::IllegalArgumentException(
75 "Wrong argument type!",
80 const uno::Sequence< beans::Property >& rProperties,
81 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
85 for(
const beans::Property& rProp : rProperties )
89 if ( rProp.Name ==
"IsDocument" )
91 xRow->appendBoolean( rProp,
false );
93 else if ( rProp.Name ==
"IsFolder" )
95 xRow->appendBoolean( rProp,
true );
97 else if ( rProp.Name ==
"Title" )
101 else if ( rProp.Name ==
"IsReadOnly" )
103 xRow->appendBoolean( rProp,
true );
107 xRow->appendVoid( rProp );
108 SAL_INFO(
"ucb.ucp.cmis",
"Looking for unsupported property " << rProp.Name );
111 catch (
const libcmis::Exception&)
113 xRow->appendVoid( rProp );
125 uno::Reference< css::xml::crypto::XNSSInitializer >
126 xNSSInitializer = css::xml::crypto::NSSInitializer::create(
m_xContext );
128 uno::Reference< css::xml::crypto::XDigestContext > xDigestContext(
129 xNSSInitializer->getDigestContext( css::xml::crypto::DigestID::SHA256,
130 uno::Sequence< beans::NamedValue >() ),
131 uno::UNO_SET_THROW );
139 OUString sProxy = rProxy.
aName;
140 if ( rProxy.
nPort > 0 )
141 sProxy +=
":" + OUString::number( rProxy.
nPort );
142 libcmis::SessionFactory::setProxySettings(
OUSTR_TO_STDSTR( sProxy ), std::string(), std::string(), std::string() );
148 libcmis::CertValidationHandlerPtr certHandler(
150 libcmis::SessionFactory::setCertificateValidationHandler( certHandler );
159 bool bIsDone =
false;
168 libcmis::OAuth2DataPtr oauth2Data;
172 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
173 GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
174 GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
175 GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET );
178 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
179 ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL,
180 ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
181 ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET );
185 oauth2Data = boost::make_shared<libcmis::OAuth2Data>(
186 ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
187 ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
188 ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET );
191 std::unique_ptr<libcmis::Session> session(libcmis::SessionFactory::createSession(
193 rUsername, rPassword,
"",
false, oauth2Data ));
196 ucb::IOErrorCode_INVALID_DEVICE,
197 uno::Sequence< uno::Any >( 0 ),
203 catch (
const libcmis::Exception& e )
205 SAL_INFO(
"ucb.ucp.cmis",
"Error getting repositories: " << e.what() );
207 if ( e.getType() !=
"permissionDenied" )
210 ucb::IOErrorCode_INVALID_DEVICE,
211 uno::Sequence< uno::Any >( 0 ),
220 ucb::IOErrorCode_ABORT,
221 uno::Sequence< uno::Any >( 0 ),
223 "Authentication cancelled" );
233 libcmis::RepositoryPtr repo;
238 [&](
const libcmis::RepositoryPtr& rRepo) { return STD_TO_OUSTR(rRepo->getId()) == m_sRepositoryId; });
248 const uno::Reference< ucb::XCommandEnvironment > & )
250 static const beans::Property aGenericProperties[] =
252 beans::Property(
"IsDocument",
254 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
255 beans::Property(
"IsFolder",
257 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
258 beans::Property(
"Title",
260 beans::PropertyAttribute::BOUND ),
261 beans::Property(
"IsReadOnly",
263 beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ),
267 return uno::Sequence< beans::Property > ( aGenericProperties, nProps );
271 const uno::Reference< ucb::XCommandEnvironment > & )
273 static const ucb::CommandInfo aCommandInfoTable[] =
280 (
"getPropertySetInfo",
283 (
"getPropertyValues",
284 -1,
cppu::UnoType<uno::Sequence< beans::Property >>::get() ),
286 (
"setPropertyValues",
287 -1,
cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get() ),
296 return uno::Sequence< ucb::CommandInfo >(aCommandInfoTable, nProps );
301 SAL_INFO(
"ucb.ucp.cmis",
"RepoContent::getParentURL()" );
312 return "com.sun.star.comp.CmisRepoContent";
317 return {
"com.sun.star.ucb.Content" };
326 const ucb::Command& aCommand,
328 const uno::Reference< ucb::XCommandEnvironment >& xEnv )
334 if (
aCommand.Name ==
"getPropertyValues" )
341 else if (
aCommand.Name ==
"getPropertySetInfo" )
343 else if (
aCommand.Name ==
"getCommandInfo" )
347 ucb::OpenCommandArgument2 aOpenCommand;
348 if ( !(
aCommand.Argument >>= aOpenCommand ) )
350 const ucb::OpenCommandArgument2& rOpenCommand = aOpenCommand;
353 uno::Reference< ucb::XDynamicResultSet > xSet
359 SAL_INFO(
"ucb.ucp.cmis",
"Command not allowed" );
367 SAL_INFO(
"ucb.ucp.cmis",
"TODO - RepoContent::abort()" );
384 return s_aFolderCollection.
getTypes();
389 std::vector< uno::Reference< ucb::XContent > >
result;
392 SAL_INFO(
"ucb.ucp.cmis",
"RepoContent::getChildren" );
404 result.push_back( xContent );
411 OUString sEncodedBinding = rtl::Uri::encode(
413 rtl_UriCharClassRelSegment,
414 rtl_UriEncodeKeepEscapes,
415 RTL_TEXTENCODING_UTF8 );
416 sUrl =
"vnd.libreoffice.cmis://" + sEncodedBinding;
421 result.push_back( xContent );
sal_uInt32 GetPort() const
static OUString GetScheme(INetProtocol eTheScheme)
OUString GetHost(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
bool authenticationQuery(std::string &username, std::string &password) override
static void setXEnv(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
static char * copyWebAuthCodeFallback(const char *url, const char *, const char *)
virtual css::uno::Sequence< css::beans::Property > getProperties(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
virtual std::vector< css::uno::Reference< css::ucb::XContent > > getChildren() override
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties, const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
RepoContent(const css::uno::Reference< css::uno::XComponentContext > &rxContext, ContentProvider *pProvider, const css::uno::Reference< css::ucb::XContentIdentifier > &Identifier, std::vector< libcmis::RepositoryPtr > &&aRepos=std::vector< libcmis::RepositoryPtr >())
virtual css::uno::Any SAL_CALL execute(const css::ucb::Command &aCommand, sal_Int32 CommandId, const css::uno::Reference< css::ucb::XCommandEnvironment > &Environment) override
virtual OUString SAL_CALL getImplementationName() override
ContentProvider * m_pProvider
virtual css::uno::Sequence< css::ucb::CommandInfo > getCommands(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv) override
std::vector< libcmis::RepositoryPtr > m_aRepositories
void getRepositories(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
css::uno::Any getBadArgExcept()
virtual void SAL_CALL abort(sal_Int32 CommandId) override
virtual ~RepoContent() override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
libcmis::RepositoryPtr getRepository(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv)
virtual OUString getParentURL() override
virtual OUString SAL_CALL getContentType() override
const OUString & getPassword() const
const OUString & getUsername() const
void setObjectPath(const OUString &sPath)
const OUString & getObjectPath() const
const OUString & getBindingUrl() const
OUString asString() const
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
css::uno::Reference< css::ucb::XCommandInfo > getCommandInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo(const css::uno::Reference< css::ucb::XCommandEnvironment > &xEnv, bool bCache=true)
css::uno::Reference< css::ucb::XContentIdentifier > m_xIdentifier
css::uno::Reference< css::uno::XComponentContext > m_xContext
InternetProxyServer getProxy(const OUString &rProtocol, const OUString &rHost, sal_Int32 nPort) const
#define OUSTR_TO_STDSTR(s)
#define STD_TO_OUSTR(str)
#define SAL_INFO(area, stream)
#define SAL_N_ELEMENTS(arr)
XTYPEPROVIDER_COMMON_IMPL(Content)
constexpr OUStringLiteral CMIS_REPO_TYPE
void cancelCommandExecution(const uno::Any &rException, const uno::Reference< ucb::XCommandEnvironment > &xEnv)