1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <string.h> 29*cdf0e10cSrcweir #include <unistd.h> 30*cdf0e10cSrcweir #include <sys/types.h> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <osl/time.h> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <osl/diagnose.h> 35*cdf0e10cSrcweir #include <osl/doublecheckedlocking.h> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChange.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/beans/PropertySetInfoChangeEvent.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/ucb/ContentInfoAttribute.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/ucb/InsertCommandArgument.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkConnectException.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkGeneralException.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkReadException.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkResolveNameException.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveNetworkWriteException.hpp> 55*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp> 56*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 57*cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp> 58*cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp> 59*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandInfo.hpp> 60*cdf0e10cSrcweir #include <com/sun/star/ucb/XPersistentPropertySet.hpp> 61*cdf0e10cSrcweir #include <com/sun/star/ucb/MissingInputStreamException.hpp> 62*cdf0e10cSrcweir #include <com/sun/star/ucb/MissingPropertiesException.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedCommandException.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> 65*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedNameClashException.hpp> 66*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedOpenModeException.hpp> 68*cdf0e10cSrcweir #include <com/sun/star/ucb/NameClashException.hpp> 69*cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp> 70*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentCreator.hpp> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #include <ucbhelper/contentidentifier.hxx> 73*cdf0e10cSrcweir #include <ucbhelper/propertyvalueset.hxx> 74*cdf0e10cSrcweir #include <ucbhelper/interactionrequest.hxx> 75*cdf0e10cSrcweir #include <ucbhelper/cancelcommandexecution.hxx> 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir #include <osl/conditn.hxx> 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir #include "gio_content.hxx" 80*cdf0e10cSrcweir #include "gio_provider.hxx" 81*cdf0e10cSrcweir #include "gio_resultset.hxx" 82*cdf0e10cSrcweir #include "gio_inputstream.hxx" 83*cdf0e10cSrcweir #include "gio_outputstream.hxx" 84*cdf0e10cSrcweir #include "gio_mount.hxx" 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir #include <stdio.h> 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir using namespace com::sun::star; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir namespace gio 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir Content::Content( 94*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 95*cdf0e10cSrcweir ContentProvider* pProvider, 96*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier) 97*cdf0e10cSrcweir throw ( ucb::ContentCreationException ) 98*cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 99*cdf0e10cSrcweir m_pProvider( pProvider ), mpFile (NULL), mpInfo( NULL ), mbTransient(false) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir #ifdef DEBUG 102*cdf0e10cSrcweir fprintf(stderr, "New Content ('%s')\n", rtl::OUStringToOString(m_xIdentifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr()); 103*cdf0e10cSrcweir #endif 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir Content::Content( 107*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rxSMgr, 108*cdf0e10cSrcweir ContentProvider* pProvider, 109*cdf0e10cSrcweir const uno::Reference< ucb::XContentIdentifier >& Identifier, 110*cdf0e10cSrcweir sal_Bool bIsFolder) 111*cdf0e10cSrcweir throw ( ucb::ContentCreationException ) 112*cdf0e10cSrcweir : ContentImplHelper( rxSMgr, pProvider, Identifier ), 113*cdf0e10cSrcweir m_pProvider( pProvider ), mpFile (NULL), mpInfo( NULL ), mbTransient(true) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir #ifdef DEBUG 116*cdf0e10cSrcweir fprintf(stderr, "Create Content ('%s')\n", rtl::OUStringToOString(m_xIdentifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr()); 117*cdf0e10cSrcweir #endif 118*cdf0e10cSrcweir mpInfo = g_file_info_new(); 119*cdf0e10cSrcweir g_file_info_set_file_type(mpInfo, bIsFolder ? G_FILE_TYPE_DIRECTORY : G_FILE_TYPE_REGULAR); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir Content::~Content() 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir if (mpInfo) g_object_unref(mpInfo); 125*cdf0e10cSrcweir if (mpFile) g_object_unref(mpFile); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir rtl::OUString Content::getParentURL() 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir rtl::OUString sURL; 131*cdf0e10cSrcweir if (GFile* pFile = g_file_get_parent(getGFile())) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir char* pPath = g_file_get_uri(pFile); 134*cdf0e10cSrcweir g_object_unref(pFile); 135*cdf0e10cSrcweir sURL = rtl::OUString::createFromAscii(pPath); 136*cdf0e10cSrcweir g_free(pPath); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir return sURL; 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) 142*cdf0e10cSrcweir throw( uno::RuntimeException ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir //TODO 145*cdf0e10cSrcweir //stick a map from each CommandId to a new GCancellable and propogate 146*cdf0e10cSrcweir //it throughout the g_file_* calls 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getContentType() throw( uno::RuntimeException ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir return isFolder(uno::Reference< ucb::XCommandEnvironment >()) 152*cdf0e10cSrcweir ? rtl::OUString::createFromAscii( GIO_FOLDER_TYPE ) 153*cdf0e10cSrcweir : rtl::OUString::createFromAscii( GIO_FILE_TYPE ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir #define EXCEPT(aExcept) \ 157*cdf0e10cSrcweir do { \ 158*cdf0e10cSrcweir if (bThrow) throw aExcept;\ 159*cdf0e10cSrcweir aRet = uno::makeAny( aExcept );\ 160*cdf0e10cSrcweir } while(0) 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir uno::Any convertToException(GError *pError, const uno::Reference< uno::XInterface >& rContext, bool bThrow) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir uno::Any aRet; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir gint eCode = pError->code; 167*cdf0e10cSrcweir rtl::OUString sMessage(pError->message, strlen(pError->message), RTL_TEXTENCODING_UTF8); 168*cdf0e10cSrcweir g_error_free(pError); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir rtl::OUString sName; 171*cdf0e10cSrcweir rtl::OUString sHost; 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 174*cdf0e10cSrcweir aArgs[ 0 ] <<= sName; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir switch (eCode) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir case G_IO_ERROR_FAILED: 179*cdf0e10cSrcweir { io::IOException aExcept(sMessage, rContext); 180*cdf0e10cSrcweir EXCEPT(aExcept); } 181*cdf0e10cSrcweir break; 182*cdf0e10cSrcweir case G_IO_ERROR_NOT_MOUNTED: 183*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 184*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NOT_EXISTING_PATH, aArgs); 185*cdf0e10cSrcweir EXCEPT(aExcept); } 186*cdf0e10cSrcweir break; 187*cdf0e10cSrcweir case G_IO_ERROR_NOT_FOUND: 188*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 189*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NOT_EXISTING, aArgs); 190*cdf0e10cSrcweir EXCEPT(aExcept); } 191*cdf0e10cSrcweir break; 192*cdf0e10cSrcweir case G_IO_ERROR_EXISTS: 193*cdf0e10cSrcweir { ucb::NameClashException aExcept(sMessage, rContext, 194*cdf0e10cSrcweir task::InteractionClassification_ERROR, sName); 195*cdf0e10cSrcweir EXCEPT(aExcept); } 196*cdf0e10cSrcweir break; 197*cdf0e10cSrcweir case G_IO_ERROR_INVALID_ARGUMENT: 198*cdf0e10cSrcweir { lang::IllegalArgumentException aExcept(sMessage, rContext, -1 ); 199*cdf0e10cSrcweir EXCEPT(aExcept); } 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir case G_IO_ERROR_PERMISSION_DENIED: 202*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 203*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_ACCESS_DENIED, aArgs); 204*cdf0e10cSrcweir EXCEPT(aExcept); } 205*cdf0e10cSrcweir break; 206*cdf0e10cSrcweir case G_IO_ERROR_IS_DIRECTORY: 207*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 208*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NO_FILE, aArgs); 209*cdf0e10cSrcweir EXCEPT(aExcept); } 210*cdf0e10cSrcweir break; 211*cdf0e10cSrcweir case G_IO_ERROR_NOT_REGULAR_FILE: 212*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 213*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NO_FILE, aArgs); 214*cdf0e10cSrcweir EXCEPT(aExcept); } 215*cdf0e10cSrcweir break; 216*cdf0e10cSrcweir case G_IO_ERROR_NOT_DIRECTORY: 217*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 218*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NO_DIRECTORY, aArgs); 219*cdf0e10cSrcweir EXCEPT(aExcept); } 220*cdf0e10cSrcweir break; 221*cdf0e10cSrcweir case G_IO_ERROR_FILENAME_TOO_LONG: 222*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 223*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NAME_TOO_LONG, aArgs); 224*cdf0e10cSrcweir EXCEPT(aExcept); } 225*cdf0e10cSrcweir break; 226*cdf0e10cSrcweir case G_IO_ERROR_PENDING: 227*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 228*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_PENDING, aArgs); 229*cdf0e10cSrcweir EXCEPT(aExcept); } 230*cdf0e10cSrcweir break; 231*cdf0e10cSrcweir case G_IO_ERROR_CLOSED: 232*cdf0e10cSrcweir case G_IO_ERROR_CANCELLED: 233*cdf0e10cSrcweir case G_IO_ERROR_TOO_MANY_LINKS: 234*cdf0e10cSrcweir case G_IO_ERROR_WRONG_ETAG: 235*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 236*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_GENERAL, aArgs); 237*cdf0e10cSrcweir EXCEPT(aExcept); } 238*cdf0e10cSrcweir break; 239*cdf0e10cSrcweir case G_IO_ERROR_NOT_SUPPORTED: 240*cdf0e10cSrcweir case G_IO_ERROR_CANT_CREATE_BACKUP: 241*cdf0e10cSrcweir case G_IO_ERROR_WOULD_MERGE: 242*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 243*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_NOT_SUPPORTED, aArgs); 244*cdf0e10cSrcweir EXCEPT(aExcept); } 245*cdf0e10cSrcweir break; 246*cdf0e10cSrcweir case G_IO_ERROR_NO_SPACE: 247*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 248*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_OUT_OF_DISK_SPACE, aArgs); 249*cdf0e10cSrcweir EXCEPT(aExcept); } 250*cdf0e10cSrcweir break; 251*cdf0e10cSrcweir case G_IO_ERROR_INVALID_FILENAME: 252*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 253*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_INVALID_CHARACTER, aArgs); 254*cdf0e10cSrcweir EXCEPT(aExcept); } 255*cdf0e10cSrcweir break; 256*cdf0e10cSrcweir case G_IO_ERROR_READ_ONLY: 257*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 258*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_WRITE_PROTECTED, aArgs); 259*cdf0e10cSrcweir EXCEPT(aExcept); } 260*cdf0e10cSrcweir break; 261*cdf0e10cSrcweir case G_IO_ERROR_TIMED_OUT: 262*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 263*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_DEVICE_NOT_READY, aArgs); 264*cdf0e10cSrcweir EXCEPT(aExcept); } 265*cdf0e10cSrcweir break; 266*cdf0e10cSrcweir case G_IO_ERROR_WOULD_RECURSE: 267*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 268*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_RECURSIVE, aArgs); 269*cdf0e10cSrcweir EXCEPT(aExcept); } 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir case G_IO_ERROR_BUSY: 272*cdf0e10cSrcweir case G_IO_ERROR_WOULD_BLOCK: 273*cdf0e10cSrcweir { ucb::InteractiveAugmentedIOException aExcept(sMessage, rContext, 274*cdf0e10cSrcweir task::InteractionClassification_ERROR, ucb::IOErrorCode_LOCKING_VIOLATION, aArgs); 275*cdf0e10cSrcweir EXCEPT(aExcept); } 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir case G_IO_ERROR_HOST_NOT_FOUND: 278*cdf0e10cSrcweir { ucb::InteractiveNetworkResolveNameException aExcept(sMessage, rContext, 279*cdf0e10cSrcweir task::InteractionClassification_ERROR, sHost); 280*cdf0e10cSrcweir EXCEPT(aExcept);} 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir default: 283*cdf0e10cSrcweir case G_IO_ERROR_ALREADY_MOUNTED: 284*cdf0e10cSrcweir case G_IO_ERROR_NOT_EMPTY: 285*cdf0e10cSrcweir case G_IO_ERROR_NOT_SYMBOLIC_LINK: 286*cdf0e10cSrcweir case G_IO_ERROR_NOT_MOUNTABLE_FILE: 287*cdf0e10cSrcweir case G_IO_ERROR_FAILED_HANDLED: 288*cdf0e10cSrcweir { ucb::InteractiveNetworkGeneralException aExcept(sMessage, rContext, 289*cdf0e10cSrcweir task::InteractionClassification_ERROR); 290*cdf0e10cSrcweir EXCEPT(aExcept);} 291*cdf0e10cSrcweir break; 292*cdf0e10cSrcweir } 293*cdf0e10cSrcweir return aRet; 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir uno::Any Content::mapGIOError( GError *pError ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir if (!pError) 299*cdf0e10cSrcweir return getBadArgExcept(); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir return convertToException(pError, static_cast< cppu::OWeakObject * >(this), false); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir uno::Any Content::getBadArgExcept() 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir return uno::makeAny( lang::IllegalArgumentException( 307*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Wrong argument type!" ), 308*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), -1) ); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir class MountOperation 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir GMainLoop *mpLoop; 314*cdf0e10cSrcweir GMountOperation *mpAuthentication; 315*cdf0e10cSrcweir GError *mpError; 316*cdf0e10cSrcweir static void Completed(GObject *source, GAsyncResult *res, gpointer user_data); 317*cdf0e10cSrcweir public: 318*cdf0e10cSrcweir MountOperation(const uno::Reference< ucb::XCommandEnvironment >& xEnv); 319*cdf0e10cSrcweir ~MountOperation(); 320*cdf0e10cSrcweir GError *Mount(GFile *pFile); 321*cdf0e10cSrcweir }; 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir MountOperation::MountOperation(const uno::Reference< ucb::XCommandEnvironment >& xEnv) : mpError(NULL) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir mpLoop = g_main_loop_new(NULL, FALSE); 326*cdf0e10cSrcweir mpAuthentication = ooo_mount_operation_new(xEnv); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void MountOperation::Completed(GObject *source, GAsyncResult *res, gpointer user_data) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir MountOperation *pThis = (MountOperation*)user_data; 332*cdf0e10cSrcweir g_file_mount_enclosing_volume_finish(G_FILE(source), res, &(pThis->mpError)); 333*cdf0e10cSrcweir g_main_loop_quit(pThis->mpLoop); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir GError *MountOperation::Mount(GFile *pFile) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir g_file_mount_enclosing_volume(pFile, G_MOUNT_MOUNT_NONE, mpAuthentication, NULL, MountOperation::Completed, this); 339*cdf0e10cSrcweir g_main_loop_run(mpLoop); 340*cdf0e10cSrcweir return mpError; 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir MountOperation::~MountOperation() 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir g_object_unref(mpAuthentication); 346*cdf0e10cSrcweir g_main_loop_unref(mpLoop); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir GFileInfo* Content::getGFileInfo(const uno::Reference< ucb::XCommandEnvironment >& xEnv, GError **ppError) 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir /*If we don't have it already, and we're not a "pre-creation" content then query for the info"*/ 352*cdf0e10cSrcweir if (!mpInfo && !mbTransient) 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir if (!(mpInfo = g_file_query_info(getGFile(), "*", G_FILE_QUERY_INFO_NONE, NULL, ppError))) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir //Try and mount if unmounted 357*cdf0e10cSrcweir if (ppError && (*ppError)->code == G_IO_ERROR_NOT_MOUNTED) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir g_error_free(*ppError); 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir MountOperation aMounter(xEnv); 362*cdf0e10cSrcweir *ppError = aMounter.Mount(getGFile()); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir //No Mount error, reattempt query 365*cdf0e10cSrcweir if (!*ppError) 366*cdf0e10cSrcweir mpInfo = g_file_query_info(getGFile(), "*", G_FILE_QUERY_INFO_NONE, NULL, ppError); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir return mpInfo; 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir GFile* Content::getGFile() 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir if (!mpFile) 376*cdf0e10cSrcweir mpFile = g_file_new_for_uri(rtl::OUStringToOString(m_xIdentifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr()); 377*cdf0e10cSrcweir return mpFile; 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir bool Content::isFolder(const uno::Reference< ucb::XCommandEnvironment >& xEnv) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir GFileInfo *pInfo = getGFileInfo(xEnv); 383*cdf0e10cSrcweir return pInfo && (g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir static util::DateTime getDateFromUnix (time_t t) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir TimeValue tv; 389*cdf0e10cSrcweir tv.Nanosec = 0; 390*cdf0e10cSrcweir tv.Seconds = t; 391*cdf0e10cSrcweir oslDateTime dt; 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir if ( osl_getDateTimeFromTimeValue( &tv, &dt ) ) 394*cdf0e10cSrcweir return util::DateTime( 0, dt.Seconds, dt.Minutes, dt.Hours, 395*cdf0e10cSrcweir dt.Day, dt.Month, dt.Year); 396*cdf0e10cSrcweir else 397*cdf0e10cSrcweir return util::DateTime(); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValuesFromGFileInfo(GFileInfo *pInfo, 401*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr, 402*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv, 403*cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( rSMgr ); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir sal_Int32 nProps; 408*cdf0e10cSrcweir const beans::Property* pProps; 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir nProps = rProperties.getLength(); 411*cdf0e10cSrcweir pProps = rProperties.getConstArray(); 412*cdf0e10cSrcweir 413*cdf0e10cSrcweir for( sal_Int32 n = 0; n < nProps; ++n ) 414*cdf0e10cSrcweir { 415*cdf0e10cSrcweir const beans::Property& rProp = pProps[ n ]; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir if (g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE)) 420*cdf0e10cSrcweir xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_REGULAR || 421*cdf0e10cSrcweir g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_UNKNOWN ) ); 422*cdf0e10cSrcweir else 423*cdf0e10cSrcweir xRow->appendVoid( rProp ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) ) 428*cdf0e10cSrcweir xRow->appendBoolean( rProp, ( g_file_info_get_file_type( pInfo ) == G_FILE_TYPE_DIRECTORY )); 429*cdf0e10cSrcweir else 430*cdf0e10cSrcweir xRow->appendVoid( rProp ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir if (g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME)) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir const char *pName = g_file_info_get_display_name(pInfo); 437*cdf0e10cSrcweir xRow->appendString( rProp, rtl::OUString(pName, strlen(pName), RTL_TEXTENCODING_UTF8) ); 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir else 440*cdf0e10cSrcweir xRow->appendVoid( rProp ); 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsReadOnly" ) ) ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ) ) 445*cdf0e10cSrcweir xRow->appendBoolean( rProp, !g_file_info_get_attribute_boolean( pInfo, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) ); 446*cdf0e10cSrcweir else 447*cdf0e10cSrcweir xRow->appendVoid( rProp ); 448*cdf0e10cSrcweir } 449*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateCreated" ) ) ) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CREATED ) ) 452*cdf0e10cSrcweir xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CREATED)) ); 453*cdf0e10cSrcweir else 454*cdf0e10cSrcweir xRow->appendVoid( rProp ); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateModified" ) ) ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED ) ) 459*cdf0e10cSrcweir xRow->appendTimestamp( rProp, getDateFromUnix(g_file_info_get_attribute_uint64(pInfo, G_FILE_ATTRIBUTE_TIME_CHANGED)) ); 460*cdf0e10cSrcweir else 461*cdf0e10cSrcweir xRow->appendVoid( rProp ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_SIZE) ) 466*cdf0e10cSrcweir xRow->appendLong( rProp, ( g_file_info_get_size( pInfo ) )); 467*cdf0e10cSrcweir else 468*cdf0e10cSrcweir xRow->appendVoid( rProp ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsVolume" ) ) ) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir //What do we use this for ? 473*cdf0e10cSrcweir xRow->appendBoolean( rProp, sal_False ); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsCompactDisc" ) ) ) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT ) ) 478*cdf0e10cSrcweir xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT) ); 479*cdf0e10cSrcweir else 480*cdf0e10cSrcweir xRow->appendVoid( rProp ); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRemoveable" ) ) ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) ) 485*cdf0e10cSrcweir xRow->appendBoolean( rProp, g_file_info_get_attribute_boolean(pInfo, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT ) ); 486*cdf0e10cSrcweir else 487*cdf0e10cSrcweir xRow->appendVoid( rProp ); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsFloppy" ) ) ) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir xRow->appendBoolean( rProp, sal_False ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsHidden" ) ) ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir if( g_file_info_has_attribute( pInfo, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) ) 496*cdf0e10cSrcweir xRow->appendBoolean( rProp, ( g_file_info_get_is_hidden ( pInfo ) ) ); 497*cdf0e10cSrcweir else 498*cdf0e10cSrcweir xRow->appendVoid( rProp ); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir else if (rProp.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir xRow->appendObject( rProp, uno::makeAny( queryCreatableContentsInfo( xEnv ) ) ); 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir #ifdef DEBUG 505*cdf0e10cSrcweir else 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir fprintf(stderr, "Looking for unsupported property %s\n", 508*cdf0e10cSrcweir rtl::OUStringToOString(rProp.Name, RTL_TEXTENCODING_UTF8).getStr()); 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir #endif 511*cdf0e10cSrcweir } 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir return uno::Reference< sdbc::XRow >( xRow.get() ); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir uno::Reference< sdbc::XRow > Content::getPropertyValues( 517*cdf0e10cSrcweir const uno::Sequence< beans::Property >& rProperties, 518*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 519*cdf0e10cSrcweir { 520*cdf0e10cSrcweir GError *pError = NULL; 521*cdf0e10cSrcweir GFileInfo *pInfo = getGFileInfo(xEnv, &pError); 522*cdf0e10cSrcweir if (!pInfo) 523*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir return getPropertyValuesFromGFileInfo(pInfo, m_xSMgr, xEnv, rProperties); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir static lang::IllegalAccessException 529*cdf0e10cSrcweir getReadOnlyException( const uno::Reference< uno::XInterface >& rContext ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir return lang::IllegalAccessException ( rtl::OUString::createFromAscii( "Property is read-only!" ), rContext ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir void Content::queryChildren( ContentRefList& rChildren ) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir // Obtain a list with a snapshot of all currently instanciated contents 537*cdf0e10cSrcweir // from provider and extract the contents which are direct children 538*cdf0e10cSrcweir // of this content. 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir ucbhelper::ContentRefList aAllContents; 541*cdf0e10cSrcweir m_xProvider->queryExistingContents( aAllContents ); 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 544*cdf0e10cSrcweir sal_Int32 nURLPos = aURL.lastIndexOf( '/' ); 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir if ( nURLPos != ( aURL.getLength() - 1 ) ) 547*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir sal_Int32 nLen = aURL.getLength(); 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir ucbhelper::ContentRefList::const_iterator it = aAllContents.begin(); 552*cdf0e10cSrcweir ucbhelper::ContentRefList::const_iterator end = aAllContents.end(); 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir while ( it != end ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir ucbhelper::ContentImplHelperRef xChild = (*it); 557*cdf0e10cSrcweir rtl::OUString aChildURL = xChild->getIdentifier()->getContentIdentifier(); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // Is aURL a prefix of aChildURL? 560*cdf0e10cSrcweir if ( ( aChildURL.getLength() > nLen ) && ( aChildURL.compareTo( aURL, nLen ) == 0 ) ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir sal_Int32 nPos = nLen; 563*cdf0e10cSrcweir nPos = aChildURL.indexOf( '/', nPos ); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir if ( ( nPos == -1 ) || ( nPos == ( aChildURL.getLength() - 1 ) ) ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir // No further slashes / only a final slash. It's a child! 568*cdf0e10cSrcweir rChildren.push_back( ::gio::Content::ContentRef (static_cast< ::gio::Content * >(xChild.get() ) ) ); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir ++it; 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir sal_Bool Content::exchangeIdentity( const uno::Reference< ucb::XContentIdentifier >& xNewId ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir if ( !xNewId.is() ) 578*cdf0e10cSrcweir return sal_False; 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir if ( mbTransient ) 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir m_xIdentifier = xNewId; 585*cdf0e10cSrcweir return sal_False; 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir rtl::OUString aOldURL = m_xIdentifier->getContentIdentifier(); 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir // Exchange own identitity. 591*cdf0e10cSrcweir if ( exchange( xNewId ) ) 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir // Process instanciated children... 594*cdf0e10cSrcweir ContentRefList aChildren; 595*cdf0e10cSrcweir queryChildren( aChildren ); 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 598*cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir while ( it != end ) 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir ContentRef xChild = (*it); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir // Create new content identifier for the child... 605*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xOldChildId = xChild->getIdentifier(); 606*cdf0e10cSrcweir rtl::OUString aOldChildURL = xOldChildId->getContentIdentifier(); 607*cdf0e10cSrcweir rtl::OUString aNewChildURL = aOldChildURL.replaceAt( 608*cdf0e10cSrcweir 0, aOldURL.getLength(), xNewId->getContentIdentifier() ); 609*cdf0e10cSrcweir 610*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewChildId 611*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewChildURL ); 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir if ( !xChild->exchangeIdentity( xNewChildId ) ) 614*cdf0e10cSrcweir return sal_False; 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir ++it; 617*cdf0e10cSrcweir } 618*cdf0e10cSrcweir return sal_True; 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir return sal_False; 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir uno::Sequence< uno::Any > Content::setPropertyValues( 625*cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& rValues, 626*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 627*cdf0e10cSrcweir { 628*cdf0e10cSrcweir GError *pError=NULL; 629*cdf0e10cSrcweir GFileInfo *pNewInfo=NULL; 630*cdf0e10cSrcweir GFileInfo *pInfo = getGFileInfo(xEnv, &pError); 631*cdf0e10cSrcweir if (pInfo) 632*cdf0e10cSrcweir pNewInfo = g_file_info_dup(pInfo); 633*cdf0e10cSrcweir else 634*cdf0e10cSrcweir { 635*cdf0e10cSrcweir if (!mbTransient) 636*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 637*cdf0e10cSrcweir else 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir if (pError) 640*cdf0e10cSrcweir g_error_free(pError); 641*cdf0e10cSrcweir pNewInfo = g_file_info_new(); 642*cdf0e10cSrcweir } 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir sal_Int32 nCount = rValues.getLength(); 646*cdf0e10cSrcweir 647*cdf0e10cSrcweir beans::PropertyChangeEvent aEvent; 648*cdf0e10cSrcweir aEvent.Source = static_cast< cppu::OWeakObject * >( this ); 649*cdf0e10cSrcweir aEvent.Further = sal_False; 650*cdf0e10cSrcweir aEvent.PropertyHandle = -1; 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir sal_Int32 nChanged = 0, nTitlePos = -1; 653*cdf0e10cSrcweir const char *newName = NULL; 654*cdf0e10cSrcweir uno::Sequence< beans::PropertyChangeEvent > aChanges(nCount); 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir uno::Sequence< uno::Any > aRet( nCount ); 657*cdf0e10cSrcweir const beans::PropertyValue* pValues = rValues.getConstArray(); 658*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir const beans::PropertyValue& rValue = pValues[ n ]; 661*cdf0e10cSrcweir #ifdef DEBUG 662*cdf0e10cSrcweir g_warning("Set prop '%s'", rtl::OUStringToOString(rValue.Name, RTL_TEXTENCODING_UTF8).getStr()); 663*cdf0e10cSrcweir #endif 664*cdf0e10cSrcweir if ( rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) || 665*cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) || 666*cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) || 667*cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) || 668*cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) || 669*cdf0e10cSrcweir rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir aRet[ n ] <<= getReadOnlyException( static_cast< cppu::OWeakObject * >(this) ); 672*cdf0e10cSrcweir } 673*cdf0e10cSrcweir else if ( rValue.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Title" ) ) ) 674*cdf0e10cSrcweir { 675*cdf0e10cSrcweir rtl::OUString aNewTitle; 676*cdf0e10cSrcweir if (!( rValue.Value >>= aNewTitle )) 677*cdf0e10cSrcweir { 678*cdf0e10cSrcweir aRet[ n ] <<= beans::IllegalTypeException 679*cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Property value has wrong type!" ), 680*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 681*cdf0e10cSrcweir continue; 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir if ( aNewTitle.getLength() <= 0 ) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir aRet[ n ] <<= lang::IllegalArgumentException 687*cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Empty title not allowed!" ), 688*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ), -1 ); 689*cdf0e10cSrcweir continue; 690*cdf0e10cSrcweir 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir 693*cdf0e10cSrcweir rtl::OString sNewTitle = OUStringToOString(aNewTitle, RTL_TEXTENCODING_UTF8); 694*cdf0e10cSrcweir newName = sNewTitle.getStr(); 695*cdf0e10cSrcweir const char *oldName = g_file_info_get_name( pInfo); 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir if (!newName || !oldName || strcmp(newName, oldName)) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir #ifdef DEBUG 700*cdf0e10cSrcweir g_warning ("Set new name to '%s'", newName); 701*cdf0e10cSrcweir #endif 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir aEvent.PropertyName = rtl::OUString::createFromAscii( "Title" ); 704*cdf0e10cSrcweir if (oldName) 705*cdf0e10cSrcweir aEvent.OldValue = uno::makeAny(rtl::OUString(oldName, strlen(oldName), RTL_TEXTENCODING_UTF8)); 706*cdf0e10cSrcweir aEvent.NewValue = uno::makeAny(aNewTitle); 707*cdf0e10cSrcweir aChanges.getArray()[ nChanged ] = aEvent; 708*cdf0e10cSrcweir nTitlePos = nChanged++; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir g_file_info_set_name(pNewInfo, newName); 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir else 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir #ifdef DEBUG 716*cdf0e10cSrcweir fprintf(stderr, "Unknown property %s\n", rtl::OUStringToOString(rValue.Name, RTL_TEXTENCODING_UTF8).getStr()); 717*cdf0e10cSrcweir #endif 718*cdf0e10cSrcweir aRet[ n ] <<= getReadOnlyException( static_cast< cppu::OWeakObject * >(this) ); 719*cdf0e10cSrcweir //TODO 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir if (nChanged) 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir bool bOk = true; 726*cdf0e10cSrcweir if (!mbTransient) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir if ((bOk = doSetFileInfo(pNewInfo))) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir for (sal_Int32 i = 0; i < nChanged; ++i) 731*cdf0e10cSrcweir aRet[ i ] <<= getBadArgExcept(); 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir } 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir if (bOk) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir if (nTitlePos > -1) 738*cdf0e10cSrcweir { 739*cdf0e10cSrcweir rtl::OUString aNewURL = getParentURL(); 740*cdf0e10cSrcweir aNewURL += rtl::OUString( newName, strlen(newName), RTL_TEXTENCODING_UTF8 ); 741*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xNewId 742*cdf0e10cSrcweir = new ::ucbhelper::ContentIdentifier( m_xSMgr, aNewURL ); 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir if (!exchangeIdentity( xNewId ) ) 745*cdf0e10cSrcweir { 746*cdf0e10cSrcweir aRet[ nTitlePos ] <<= uno::Exception 747*cdf0e10cSrcweir ( rtl::OUString::createFromAscii( "Exchange failed!" ), 748*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ); 749*cdf0e10cSrcweir } 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir if (!mbTransient) //Discard and refetch 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir g_object_unref(mpInfo); 755*cdf0e10cSrcweir mpInfo = NULL; 756*cdf0e10cSrcweir } 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir if (mpInfo) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir g_file_info_copy_into(pNewInfo, mpInfo); 761*cdf0e10cSrcweir g_object_unref(pNewInfo); 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir else 764*cdf0e10cSrcweir mpInfo = pNewInfo; 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir if (mpFile) //Discard and refetch 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir g_object_unref(mpFile); 769*cdf0e10cSrcweir mpFile = NULL; 770*cdf0e10cSrcweir } 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir aChanges.realloc( nChanged ); 774*cdf0e10cSrcweir notifyPropertiesChange( aChanges ); 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir return aRet; 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir bool Content::doSetFileInfo(GFileInfo *pNewInfo) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir g_assert (!mbTransient); 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir bool bOk = true; 785*cdf0e10cSrcweir GFile *pFile = getGFile(); 786*cdf0e10cSrcweir if(!g_file_set_attributes_from_info(pFile, pNewInfo, G_FILE_QUERY_INFO_NONE, NULL, NULL)) 787*cdf0e10cSrcweir bOk = false; 788*cdf0e10cSrcweir return bOk; 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir const int TRANSFER_BUFFER_SIZE = 65536; 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir void Content::copyData( uno::Reference< io::XInputStream > xIn, 794*cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut ) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir uno::Sequence< sal_Int8 > theData( TRANSFER_BUFFER_SIZE ); 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir g_return_if_fail( xIn.is() && xOut.is() ); 799*cdf0e10cSrcweir 800*cdf0e10cSrcweir while ( xIn->readBytes( theData, TRANSFER_BUFFER_SIZE ) > 0 ) 801*cdf0e10cSrcweir xOut->writeBytes( theData ); 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir xOut->closeOutput(); 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir sal_Bool Content::feedSink( uno::Reference< uno::XInterface > xSink, 807*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& /*xEnv*/ ) 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir if ( !xSink.is() ) 810*cdf0e10cSrcweir return sal_False; 811*cdf0e10cSrcweir 812*cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOut = uno::Reference< io::XOutputStream >(xSink, uno::UNO_QUERY ); 813*cdf0e10cSrcweir uno::Reference< io::XActiveDataSink > xDataSink = uno::Reference< io::XActiveDataSink >(xSink, uno::UNO_QUERY ); 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir if ( !xOut.is() && !xDataSink.is() ) 816*cdf0e10cSrcweir return sal_False; 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir GError *pError=NULL; 819*cdf0e10cSrcweir GFileInputStream *pStream = g_file_read(getGFile(), NULL, &pError); 820*cdf0e10cSrcweir if (!pStream) 821*cdf0e10cSrcweir convertToException(pError, static_cast< cppu::OWeakObject * >(this)); 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir uno::Reference< io::XInputStream > xIn = new ::gio::InputStream(pStream); 824*cdf0e10cSrcweir if ( !xIn.is() ) 825*cdf0e10cSrcweir return sal_False; 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir if ( xOut.is() ) 828*cdf0e10cSrcweir copyData( xIn, xOut ); 829*cdf0e10cSrcweir 830*cdf0e10cSrcweir if ( xDataSink.is() ) 831*cdf0e10cSrcweir xDataSink->setInputStream( xIn ); 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir return sal_True; 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir uno::Any Content::open(const ucb::OpenCommandArgument2 & rOpenCommand, 837*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & xEnv ) 838*cdf0e10cSrcweir throw( uno::Exception ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir bool bIsFolder = isFolder(xEnv); 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir if (!g_file_query_exists(getGFile(), NULL)) 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 1 ); 845*cdf0e10cSrcweir aArgs[ 0 ] <<= m_xIdentifier->getContentIdentifier(); 846*cdf0e10cSrcweir uno::Any aErr = uno::makeAny( 847*cdf0e10cSrcweir ucb::InteractiveAugmentedIOException(rtl::OUString(), static_cast< cppu::OWeakObject * >( this ), 848*cdf0e10cSrcweir task::InteractionClassification_ERROR, 849*cdf0e10cSrcweir bIsFolder ? ucb::IOErrorCode_NOT_EXISTING_PATH : ucb::IOErrorCode_NOT_EXISTING, aArgs) 850*cdf0e10cSrcweir ); 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(aErr, xEnv); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir uno::Any aRet; 856*cdf0e10cSrcweir 857*cdf0e10cSrcweir sal_Bool bOpenFolder = ( 858*cdf0e10cSrcweir ( rOpenCommand.Mode == ucb::OpenMode::ALL ) || 859*cdf0e10cSrcweir ( rOpenCommand.Mode == ucb::OpenMode::FOLDERS ) || 860*cdf0e10cSrcweir ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENTS ) 861*cdf0e10cSrcweir ); 862*cdf0e10cSrcweir 863*cdf0e10cSrcweir if ( bOpenFolder && bIsFolder ) 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir uno::Reference< ucb::XDynamicResultSet > xSet 866*cdf0e10cSrcweir = new DynamicResultSet(m_xSMgr, this, rOpenCommand, xEnv ); 867*cdf0e10cSrcweir aRet <<= xSet; 868*cdf0e10cSrcweir } 869*cdf0e10cSrcweir else if ( rOpenCommand.Sink.is() ) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir if ( 872*cdf0e10cSrcweir ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) || 873*cdf0e10cSrcweir ( rOpenCommand.Mode == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) 874*cdf0e10cSrcweir ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 877*cdf0e10cSrcweir uno::makeAny ( ucb::UnsupportedOpenModeException 878*cdf0e10cSrcweir ( rtl::OUString(), static_cast< cppu::OWeakObject * >( this ), 879*cdf0e10cSrcweir sal_Int16( rOpenCommand.Mode ) ) ), 880*cdf0e10cSrcweir xEnv ); 881*cdf0e10cSrcweir } 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir if ( !feedSink( rOpenCommand.Sink, xEnv ) ) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir // Note: rOpenCommand.Sink may contain an XStream 886*cdf0e10cSrcweir // implementation. Support for this type of 887*cdf0e10cSrcweir // sink is optional... 888*cdf0e10cSrcweir #ifdef DEBUG 889*cdf0e10cSrcweir g_warning ("Failed to load data from '%s'", 890*cdf0e10cSrcweir rtl::OUStringToOString(m_xIdentifier->getContentIdentifier(), RTL_TEXTENCODING_UTF8).getStr()); 891*cdf0e10cSrcweir #endif 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( 894*cdf0e10cSrcweir uno::makeAny (ucb::UnsupportedDataSinkException 895*cdf0e10cSrcweir ( rtl::OUString(), static_cast< cppu::OWeakObject * >( this ), 896*cdf0e10cSrcweir rOpenCommand.Sink ) ), 897*cdf0e10cSrcweir xEnv ); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir } 900*cdf0e10cSrcweir else 901*cdf0e10cSrcweir g_warning ("Open falling through ..."); 902*cdf0e10cSrcweir return aRet; 903*cdf0e10cSrcweir } 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir uno::Any SAL_CALL Content::execute( 906*cdf0e10cSrcweir const ucb::Command& aCommand, 907*cdf0e10cSrcweir sal_Int32 /*CommandId*/, 908*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 909*cdf0e10cSrcweir throw( uno::Exception, 910*cdf0e10cSrcweir ucb::CommandAbortedException, 911*cdf0e10cSrcweir uno::RuntimeException ) 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir #ifdef DEBUG 914*cdf0e10cSrcweir fprintf(stderr, "Content::execute %s\n", rtl::OUStringToOString(aCommand.Name, RTL_TEXTENCODING_UTF8).getStr()); 915*cdf0e10cSrcweir #endif 916*cdf0e10cSrcweir uno::Any aRet; 917*cdf0e10cSrcweir 918*cdf0e10cSrcweir if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) )) 919*cdf0e10cSrcweir { 920*cdf0e10cSrcweir uno::Sequence< beans::Property > Properties; 921*cdf0e10cSrcweir if ( !( aCommand.Argument >>= Properties ) ) 922*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 923*cdf0e10cSrcweir aRet <<= getPropertyValues( Properties, xEnv ); 924*cdf0e10cSrcweir } 925*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) )) 926*cdf0e10cSrcweir aRet <<= getPropertySetInfo( xEnv, sal_False ); 927*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) )) 928*cdf0e10cSrcweir aRet <<= getCommandInfo( xEnv, sal_False ); 929*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "open" ) )) 930*cdf0e10cSrcweir { 931*cdf0e10cSrcweir ucb::OpenCommandArgument2 aOpenCommand; 932*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aOpenCommand ) ) 933*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 934*cdf0e10cSrcweir aRet = open( aOpenCommand, xEnv ); 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "transfer" ) )) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir ucb::TransferInfo transferArgs; 939*cdf0e10cSrcweir if ( !( aCommand.Argument >>= transferArgs ) ) 940*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 941*cdf0e10cSrcweir transfer( transferArgs, xEnv ); 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) )) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aProperties; 946*cdf0e10cSrcweir if ( !( aCommand.Argument >>= aProperties ) || !aProperties.getLength() ) 947*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 948*cdf0e10cSrcweir aRet <<= setPropertyValues( aProperties, xEnv ); 949*cdf0e10cSrcweir } 950*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "createNewContent" ) ) 951*cdf0e10cSrcweir && isFolder( xEnv ) ) 952*cdf0e10cSrcweir { 953*cdf0e10cSrcweir ucb::ContentInfo arg; 954*cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) ) 955*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 956*cdf0e10cSrcweir aRet <<= createNewContent( arg ); 957*cdf0e10cSrcweir } 958*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "insert" ) )) 959*cdf0e10cSrcweir { 960*cdf0e10cSrcweir ucb::InsertCommandArgument arg; 961*cdf0e10cSrcweir if ( !( aCommand.Argument >>= arg ) ) 962*cdf0e10cSrcweir ucbhelper::cancelCommandExecution ( getBadArgExcept (), xEnv ); 963*cdf0e10cSrcweir insert( arg.Data, arg.ReplaceExisting, xEnv ); 964*cdf0e10cSrcweir } 965*cdf0e10cSrcweir else if (aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "delete" ) )) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir sal_Bool bDeletePhysical = sal_False; 968*cdf0e10cSrcweir aCommand.Argument >>= bDeletePhysical; 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir //If no delete physical, try and trashcan it, if that doesn't work go 971*cdf0e10cSrcweir //ahead and try and delete it anyway 972*cdf0e10cSrcweir if (!bDeletePhysical && !g_file_trash(getGFile(), NULL, NULL)) 973*cdf0e10cSrcweir bDeletePhysical = true; 974*cdf0e10cSrcweir 975*cdf0e10cSrcweir if (bDeletePhysical) 976*cdf0e10cSrcweir { 977*cdf0e10cSrcweir GError *pError = NULL; 978*cdf0e10cSrcweir if (!g_file_delete( getGFile(), NULL, &pError)) 979*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 980*cdf0e10cSrcweir } 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir destroy( bDeletePhysical ); 983*cdf0e10cSrcweir } 984*cdf0e10cSrcweir else 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir #ifdef DEBUG 987*cdf0e10cSrcweir fprintf(stderr, "UNKNOWN COMMAND\n"); 988*cdf0e10cSrcweir //TODO 989*cdf0e10cSrcweir #endif 990*cdf0e10cSrcweir 991*cdf0e10cSrcweir ucbhelper::cancelCommandExecution 992*cdf0e10cSrcweir ( uno::makeAny( ucb::UnsupportedCommandException 993*cdf0e10cSrcweir ( rtl::OUString(), 994*cdf0e10cSrcweir static_cast< cppu::OWeakObject * >( this ) ) ), 995*cdf0e10cSrcweir xEnv ); 996*cdf0e10cSrcweir } 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir return aRet; 999*cdf0e10cSrcweir } 1000*cdf0e10cSrcweir 1001*cdf0e10cSrcweir void Content::destroy( sal_Bool bDeletePhysical ) 1002*cdf0e10cSrcweir throw( uno::Exception ) 1003*cdf0e10cSrcweir { 1004*cdf0e10cSrcweir uno::Reference< ucb::XContent > xThis = this; 1005*cdf0e10cSrcweir 1006*cdf0e10cSrcweir deleted(); 1007*cdf0e10cSrcweir 1008*cdf0e10cSrcweir ::gio::Content::ContentRefList aChildren; 1009*cdf0e10cSrcweir queryChildren( aChildren ); 1010*cdf0e10cSrcweir 1011*cdf0e10cSrcweir ContentRefList::const_iterator it = aChildren.begin(); 1012*cdf0e10cSrcweir ContentRefList::const_iterator end = aChildren.end(); 1013*cdf0e10cSrcweir 1014*cdf0e10cSrcweir while ( it != end ) 1015*cdf0e10cSrcweir { 1016*cdf0e10cSrcweir (*it)->destroy( bDeletePhysical ); 1017*cdf0e10cSrcweir ++it; 1018*cdf0e10cSrcweir } 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir void Content::insert(const uno::Reference< io::XInputStream > &xInputStream, 1022*cdf0e10cSrcweir sal_Bool bReplaceExisting, const uno::Reference< ucb::XCommandEnvironment > &xEnv ) 1023*cdf0e10cSrcweir throw( uno::Exception ) 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir GError *pError = NULL; 1026*cdf0e10cSrcweir GFileInfo *pInfo = getGFileInfo(xEnv); 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir if ( g_file_info_has_attribute(pInfo, G_FILE_ATTRIBUTE_STANDARD_TYPE) && 1029*cdf0e10cSrcweir g_file_info_get_file_type(pInfo) == G_FILE_TYPE_DIRECTORY ) 1030*cdf0e10cSrcweir { 1031*cdf0e10cSrcweir #ifdef DEBUG 1032*cdf0e10cSrcweir g_warning ("Make directory"); 1033*cdf0e10cSrcweir #endif 1034*cdf0e10cSrcweir if( !g_file_make_directory( getGFile(), NULL, &pError)) 1035*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 1036*cdf0e10cSrcweir return; 1037*cdf0e10cSrcweir } 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir if ( !xInputStream.is() ) 1040*cdf0e10cSrcweir { 1041*cdf0e10cSrcweir ucbhelper::cancelCommandExecution( uno::makeAny 1042*cdf0e10cSrcweir ( ucb::MissingInputStreamException 1043*cdf0e10cSrcweir ( rtl::OUString(), static_cast< cppu::OWeakObject * >( this ) ) ), 1044*cdf0e10cSrcweir xEnv ); 1045*cdf0e10cSrcweir } 1046*cdf0e10cSrcweir 1047*cdf0e10cSrcweir GFileOutputStream* pOutStream = NULL; 1048*cdf0e10cSrcweir if ( bReplaceExisting ) 1049*cdf0e10cSrcweir { 1050*cdf0e10cSrcweir if (!(pOutStream = g_file_replace(getGFile(), NULL, false, G_FILE_CREATE_PRIVATE, NULL, &pError))) 1051*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 1052*cdf0e10cSrcweir } 1053*cdf0e10cSrcweir else 1054*cdf0e10cSrcweir { 1055*cdf0e10cSrcweir if (!(pOutStream = g_file_create (getGFile(), G_FILE_CREATE_PRIVATE, NULL, &pError))) 1056*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 1057*cdf0e10cSrcweir } 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir uno::Reference < io::XOutputStream > xOutput = new ::gio::OutputStream(pOutStream); 1060*cdf0e10cSrcweir copyData( xInputStream, xOutput ); 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir if (mbTransient) 1063*cdf0e10cSrcweir { 1064*cdf0e10cSrcweir mbTransient = sal_False; 1065*cdf0e10cSrcweir inserted(); 1066*cdf0e10cSrcweir } 1067*cdf0e10cSrcweir } 1068*cdf0e10cSrcweir 1069*cdf0e10cSrcweir void Content::transfer( const ucb::TransferInfo& aTransferInfo, const uno::Reference< ucb::XCommandEnvironment >& xEnv ) 1070*cdf0e10cSrcweir throw( uno::Exception ) 1071*cdf0e10cSrcweir { 1072*cdf0e10cSrcweir rtl::OUString sDest = m_xIdentifier->getContentIdentifier(); 1073*cdf0e10cSrcweir if (aTransferInfo.NewTitle.getLength()) 1074*cdf0e10cSrcweir sDest += aTransferInfo.NewTitle; 1075*cdf0e10cSrcweir else 1076*cdf0e10cSrcweir sDest += rtl::OUString::createFromAscii(g_file_get_basename(getGFile())); 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir GFile *pDest = g_file_new_for_uri(rtl::OUStringToOString(sDest, RTL_TEXTENCODING_UTF8).getStr()); 1079*cdf0e10cSrcweir GFile *pSource = g_file_new_for_uri(rtl::OUStringToOString(aTransferInfo.SourceURL, RTL_TEXTENCODING_UTF8).getStr()); 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir gboolean bSuccess = false; 1082*cdf0e10cSrcweir GError *pError = NULL; 1083*cdf0e10cSrcweir if (aTransferInfo.MoveData) 1084*cdf0e10cSrcweir bSuccess = g_file_move(pSource, pDest, G_FILE_COPY_OVERWRITE, NULL, NULL, 0, &pError); 1085*cdf0e10cSrcweir else 1086*cdf0e10cSrcweir bSuccess = g_file_copy(pSource, pDest, G_FILE_COPY_OVERWRITE, NULL, NULL, 0, &pError); 1087*cdf0e10cSrcweir g_object_unref(pSource); 1088*cdf0e10cSrcweir g_object_unref(pDest); 1089*cdf0e10cSrcweir if (!bSuccess) 1090*cdf0e10cSrcweir ucbhelper::cancelCommandExecution(mapGIOError(pError), xEnv); 1091*cdf0e10cSrcweir } 1092*cdf0e10cSrcweir 1093*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > Content::queryCreatableContentsInfo( 1094*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment >& xEnv) 1095*cdf0e10cSrcweir throw( uno::RuntimeException ) 1096*cdf0e10cSrcweir { 1097*cdf0e10cSrcweir if ( isFolder( xEnv ) ) 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > seq(2); 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir // Minimum set of props we really need 1102*cdf0e10cSrcweir uno::Sequence< beans::Property > props( 1 ); 1103*cdf0e10cSrcweir props[0] = beans::Property( 1104*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ), 1105*cdf0e10cSrcweir -1, 1106*cdf0e10cSrcweir getCppuType( static_cast< rtl::OUString* >( 0 ) ), 1107*cdf0e10cSrcweir beans::PropertyAttribute::MAYBEVOID | beans::PropertyAttribute::BOUND ); 1108*cdf0e10cSrcweir 1109*cdf0e10cSrcweir // file 1110*cdf0e10cSrcweir seq[0].Type = rtl::OUString::createFromAscii( GIO_FILE_TYPE ); 1111*cdf0e10cSrcweir seq[0].Attributes = ( ucb::ContentInfoAttribute::INSERT_WITH_INPUTSTREAM | 1112*cdf0e10cSrcweir ucb::ContentInfoAttribute::KIND_DOCUMENT ); 1113*cdf0e10cSrcweir seq[0].Properties = props; 1114*cdf0e10cSrcweir 1115*cdf0e10cSrcweir // folder 1116*cdf0e10cSrcweir seq[1].Type = rtl::OUString::createFromAscii( GIO_FOLDER_TYPE ); 1117*cdf0e10cSrcweir seq[1].Attributes = ucb::ContentInfoAttribute::KIND_FOLDER; 1118*cdf0e10cSrcweir seq[1].Properties = props; 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir return seq; 1121*cdf0e10cSrcweir } 1122*cdf0e10cSrcweir else 1123*cdf0e10cSrcweir { 1124*cdf0e10cSrcweir return uno::Sequence< ucb::ContentInfo >(); 1125*cdf0e10cSrcweir } 1126*cdf0e10cSrcweir } 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir uno::Sequence< ucb::ContentInfo > SAL_CALL Content::queryCreatableContentsInfo() 1129*cdf0e10cSrcweir throw( uno::RuntimeException ) 1130*cdf0e10cSrcweir { 1131*cdf0e10cSrcweir return queryCreatableContentsInfo( uno::Reference< ucb::XCommandEnvironment >() ); 1132*cdf0e10cSrcweir } 1133*cdf0e10cSrcweir 1134*cdf0e10cSrcweir uno::Reference< ucb::XContent > 1135*cdf0e10cSrcweir SAL_CALL Content::createNewContent( const ucb::ContentInfo& Info ) 1136*cdf0e10cSrcweir throw( uno::RuntimeException ) 1137*cdf0e10cSrcweir { 1138*cdf0e10cSrcweir bool create_document; 1139*cdf0e10cSrcweir const char *name; 1140*cdf0e10cSrcweir 1141*cdf0e10cSrcweir if ( Info.Type.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( GIO_FILE_TYPE ) ) ) 1142*cdf0e10cSrcweir create_document = true; 1143*cdf0e10cSrcweir else if ( Info.Type.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( GIO_FOLDER_TYPE ) ) ) 1144*cdf0e10cSrcweir create_document = false; 1145*cdf0e10cSrcweir else 1146*cdf0e10cSrcweir { 1147*cdf0e10cSrcweir #ifdef DEBUG 1148*cdf0e10cSrcweir g_warning( "Failed to create new content '%s'", rtl::OUStringToOString(Info.Type, 1149*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr() ); 1150*cdf0e10cSrcweir #endif 1151*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 1152*cdf0e10cSrcweir } 1153*cdf0e10cSrcweir 1154*cdf0e10cSrcweir #ifdef DEBUG 1155*cdf0e10cSrcweir g_warning( "createNewContent (%d)", (int) create_document ); 1156*cdf0e10cSrcweir #endif 1157*cdf0e10cSrcweir 1158*cdf0e10cSrcweir rtl::OUString aURL = m_xIdentifier->getContentIdentifier(); 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) 1161*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( "/" ); 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir name = create_document ? "[New_Content]" : "[New_Collection]"; 1164*cdf0e10cSrcweir aURL += rtl::OUString::createFromAscii( name ); 1165*cdf0e10cSrcweir 1166*cdf0e10cSrcweir uno::Reference< ucb::XContentIdentifier > xId(new ::ucbhelper::ContentIdentifier(m_xSMgr, aURL)); 1167*cdf0e10cSrcweir 1168*cdf0e10cSrcweir try 1169*cdf0e10cSrcweir { 1170*cdf0e10cSrcweir return new ::gio::Content( m_xSMgr, m_pProvider, xId, !create_document ); 1171*cdf0e10cSrcweir } catch ( ucb::ContentCreationException & ) 1172*cdf0e10cSrcweir { 1173*cdf0e10cSrcweir return uno::Reference< ucb::XContent >(); 1174*cdf0e10cSrcweir } 1175*cdf0e10cSrcweir } 1176*cdf0e10cSrcweir 1177*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Content::getTypes() 1178*cdf0e10cSrcweir throw( uno::RuntimeException ) 1179*cdf0e10cSrcweir { 1180*cdf0e10cSrcweir if ( isFolder( uno::Reference< ucb::XCommandEnvironment >() ) ) 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir static cppu::OTypeCollection aFolderCollection 1183*cdf0e10cSrcweir (CPPU_TYPE_REF( lang::XTypeProvider ), 1184*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 1185*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 1186*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 1187*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 1188*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 1189*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 1190*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 1191*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 1192*cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ), 1193*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContentCreator ) ); 1194*cdf0e10cSrcweir return aFolderCollection.getTypes(); 1195*cdf0e10cSrcweir } 1196*cdf0e10cSrcweir else 1197*cdf0e10cSrcweir { 1198*cdf0e10cSrcweir static cppu::OTypeCollection aFileCollection 1199*cdf0e10cSrcweir (CPPU_TYPE_REF( lang::XTypeProvider ), 1200*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XServiceInfo ), 1201*cdf0e10cSrcweir CPPU_TYPE_REF( lang::XComponent ), 1202*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XContent ), 1203*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandProcessor ), 1204*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), 1205*cdf0e10cSrcweir CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), 1206*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertyContainer ), 1207*cdf0e10cSrcweir CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), 1208*cdf0e10cSrcweir CPPU_TYPE_REF( container::XChild ) ); 1209*cdf0e10cSrcweir 1210*cdf0e10cSrcweir return aFileCollection.getTypes(); 1211*cdf0e10cSrcweir } 1212*cdf0e10cSrcweir } 1213*cdf0e10cSrcweir 1214*cdf0e10cSrcweir uno::Sequence< beans::Property > Content::getProperties( 1215*cdf0e10cSrcweir const uno::Reference< ucb::XCommandEnvironment > & /*xEnv*/ ) 1216*cdf0e10cSrcweir { 1217*cdf0e10cSrcweir static const beans::Property aGenericProperties[] = 1218*cdf0e10cSrcweir { 1219*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsDocument" ) ), 1220*cdf0e10cSrcweir -1, getCppuBooleanType(), 1221*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1222*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsFolder" ) ), 1223*cdf0e10cSrcweir -1, getCppuBooleanType(), 1224*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1225*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), 1226*cdf0e10cSrcweir -1, getCppuType( static_cast< const rtl::OUString * >( 0 ) ), 1227*cdf0e10cSrcweir beans::PropertyAttribute::BOUND ), 1228*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ), 1229*cdf0e10cSrcweir -1, getCppuBooleanType(), 1230*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1231*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateCreated" ) ), 1232*cdf0e10cSrcweir -1, getCppuType( static_cast< const util::DateTime * >( 0 ) ), 1233*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1234*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DateModified" ) ), 1235*cdf0e10cSrcweir -1, getCppuType( static_cast< const util::DateTime * >( 0 ) ), 1236*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1237*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Size" ) ), 1238*cdf0e10cSrcweir -1, getCppuType( static_cast< const sal_Int64 * >( 0 ) ), 1239*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1240*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVolume" ) ), 1241*cdf0e10cSrcweir -1, getCppuBooleanType(), 1242*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1243*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsCompactDisc" ) ), 1244*cdf0e10cSrcweir -1, getCppuBooleanType(), 1245*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1246*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsRemoveable" ) ), 1247*cdf0e10cSrcweir -1, getCppuBooleanType(), 1248*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1249*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ), 1250*cdf0e10cSrcweir -1, getCppuBooleanType(), 1251*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ), 1252*cdf0e10cSrcweir beans::Property( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CreatableContentsInfo" ) ), 1253*cdf0e10cSrcweir -1, getCppuType( static_cast< const uno::Sequence< ucb::ContentInfo > * >( 0 ) ), 1254*cdf0e10cSrcweir beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY ) 1255*cdf0e10cSrcweir }; 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir const int nProps = sizeof (aGenericProperties) / sizeof (aGenericProperties[0]); 1258*cdf0e10cSrcweir return uno::Sequence< beans::Property > ( aGenericProperties, nProps ); 1259*cdf0e10cSrcweir } 1260*cdf0e10cSrcweir 1261*cdf0e10cSrcweir uno::Sequence< ucb::CommandInfo > Content::getCommands( const uno::Reference< ucb::XCommandEnvironment > & xEnv) 1262*cdf0e10cSrcweir { 1263*cdf0e10cSrcweir static ucb::CommandInfo aCommandInfoTable[] = 1264*cdf0e10cSrcweir { 1265*cdf0e10cSrcweir // Required commands 1266*cdf0e10cSrcweir ucb::CommandInfo 1267*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getCommandInfo" ) ), 1268*cdf0e10cSrcweir -1, getCppuVoidType() ), 1269*cdf0e10cSrcweir ucb::CommandInfo 1270*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertySetInfo" ) ), 1271*cdf0e10cSrcweir -1, getCppuVoidType() ), 1272*cdf0e10cSrcweir ucb::CommandInfo 1273*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getPropertyValues" ) ), 1274*cdf0e10cSrcweir -1, getCppuType( static_cast<uno::Sequence< beans::Property > * >( 0 ) ) ), 1275*cdf0e10cSrcweir ucb::CommandInfo 1276*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "setPropertyValues" ) ), 1277*cdf0e10cSrcweir -1, getCppuType( static_cast<uno::Sequence< beans::PropertyValue > * >( 0 ) ) ), 1278*cdf0e10cSrcweir 1279*cdf0e10cSrcweir // Optional standard commands 1280*cdf0e10cSrcweir ucb::CommandInfo 1281*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "delete" ) ), 1282*cdf0e10cSrcweir -1, getCppuBooleanType() ), 1283*cdf0e10cSrcweir ucb::CommandInfo 1284*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), 1285*cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::InsertCommandArgument * >( 0 ) ) ), 1286*cdf0e10cSrcweir ucb::CommandInfo 1287*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "open" ) ), 1288*cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::OpenCommandArgument2 * >( 0 ) ) ), 1289*cdf0e10cSrcweir 1290*cdf0e10cSrcweir // Folder Only, omitted if not a folder 1291*cdf0e10cSrcweir ucb::CommandInfo 1292*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "transfer" ) ), 1293*cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::TransferInfo * >( 0 ) ) ), 1294*cdf0e10cSrcweir ucb::CommandInfo 1295*cdf0e10cSrcweir ( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "createNewContent" ) ), 1296*cdf0e10cSrcweir -1, getCppuType( static_cast<ucb::ContentInfo * >( 0 ) ) ) 1297*cdf0e10cSrcweir }; 1298*cdf0e10cSrcweir 1299*cdf0e10cSrcweir const int nProps = sizeof (aCommandInfoTable) / sizeof (aCommandInfoTable[0]); 1300*cdf0e10cSrcweir return uno::Sequence< ucb::CommandInfo >(aCommandInfoTable, isFolder(xEnv) ? nProps : nProps - 2); 1301*cdf0e10cSrcweir } 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir XTYPEPROVIDER_COMMON_IMPL( Content ); 1304*cdf0e10cSrcweir 1305*cdf0e10cSrcweir void SAL_CALL Content::acquire() throw() 1306*cdf0e10cSrcweir { 1307*cdf0e10cSrcweir ContentImplHelper::acquire(); 1308*cdf0e10cSrcweir } 1309*cdf0e10cSrcweir 1310*cdf0e10cSrcweir void SAL_CALL Content::release() throw() 1311*cdf0e10cSrcweir { 1312*cdf0e10cSrcweir ContentImplHelper::release(); 1313*cdf0e10cSrcweir } 1314*cdf0e10cSrcweir 1315*cdf0e10cSrcweir uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType ) throw ( uno::RuntimeException ) 1316*cdf0e10cSrcweir { 1317*cdf0e10cSrcweir uno::Any aRet = cppu::queryInterface( rType, static_cast< ucb::XContentCreator * >( this ) ); 1318*cdf0e10cSrcweir return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface(rType); 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir rtl::OUString SAL_CALL Content::getImplementationName() throw( uno::RuntimeException ) 1322*cdf0e10cSrcweir { 1323*cdf0e10cSrcweir return rtl::OUString::createFromAscii("com.sun.star.comp.GIOContent" ); 1324*cdf0e10cSrcweir } 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames() 1327*cdf0e10cSrcweir throw( uno::RuntimeException ) 1328*cdf0e10cSrcweir { 1329*cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSNS( 1 ); 1330*cdf0e10cSrcweir aSNS.getArray()[ 0 ] = rtl::OUString::createFromAscii("com.sun.star.ucb.GIOContent" ); 1331*cdf0e10cSrcweir return aSNS; 1332*cdf0e10cSrcweir } 1333*cdf0e10cSrcweir 1334*cdf0e10cSrcweir } 1335