1*859212d1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*859212d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*859212d1SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*859212d1SAndrew Rist * distributed with this work for additional information 6*859212d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*859212d1SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*859212d1SAndrew Rist * "License"); you may not use this file except in compliance 9*859212d1SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*859212d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*859212d1SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*859212d1SAndrew Rist * software distributed under the License is distributed on an 15*859212d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*859212d1SAndrew Rist * KIND, either express or implied. See the License for the 17*859212d1SAndrew Rist * specific language governing permissions and limitations 18*859212d1SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*859212d1SAndrew Rist *************************************************************/ 21*859212d1SAndrew Rist 22*859212d1SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp" 25cdf0e10cSrcweir #include "com/sun/star/task/XInteractionRequest.hpp" 26cdf0e10cSrcweir #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "ids.hrc" 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "iahndl.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace com::sun::star; 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace { 35cdf0e10cSrcweir 36cdf0e10cSrcweir bool 37cdf0e10cSrcweir getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments, 38cdf0e10cSrcweir rtl::OUString const & rKey, 39cdf0e10cSrcweir rtl::OUString * pValue) 40cdf0e10cSrcweir SAL_THROW(()) 41cdf0e10cSrcweir { 42cdf0e10cSrcweir for (sal_Int32 i = 0; i < rArguments.getLength(); ++i) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir beans::PropertyValue aProperty; 45cdf0e10cSrcweir if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey) 46cdf0e10cSrcweir { 47cdf0e10cSrcweir rtl::OUString aValue; 48cdf0e10cSrcweir if (aProperty.Value >>= aValue) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir if (pValue) 51cdf0e10cSrcweir *pValue = aValue; 52cdf0e10cSrcweir return true; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir } 55cdf0e10cSrcweir } 56cdf0e10cSrcweir return false; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir 59cdf0e10cSrcweir bool 60cdf0e10cSrcweir getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments, 61cdf0e10cSrcweir rtl::OUString const & rKey, 62cdf0e10cSrcweir bool * pValue) 63cdf0e10cSrcweir SAL_THROW(()) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir for (sal_Int32 i = 0; i < rArguments.getLength(); ++i) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir beans::PropertyValue aProperty; 68cdf0e10cSrcweir if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir sal_Bool bValue = sal_Bool(); 71cdf0e10cSrcweir if (aProperty.Value >>= bValue) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir if (pValue) 74cdf0e10cSrcweir *pValue = bValue; 75cdf0e10cSrcweir return true; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir } 79cdf0e10cSrcweir return false; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir bool 83cdf0e10cSrcweir getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments, 84cdf0e10cSrcweir rtl::OUString * pValue) 85cdf0e10cSrcweir SAL_THROW(()) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir if (!getStringRequestArgument(rArguments, 88cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 89cdf0e10cSrcweir "Uri")), 90cdf0e10cSrcweir pValue)) 91cdf0e10cSrcweir return false; 92cdf0e10cSrcweir // Use the resource name only for file URLs, to avoid confusion: 93cdf0e10cSrcweir //TODO! work with ucp locality concept instead of hardcoded "file"? 94cdf0e10cSrcweir if (pValue 95cdf0e10cSrcweir && pValue->matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM( 96cdf0e10cSrcweir "file:"))) 97cdf0e10cSrcweir getStringRequestArgument(rArguments, 98cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 99cdf0e10cSrcweir "ResourceName")), 100cdf0e10cSrcweir pValue); 101cdf0e10cSrcweir return true; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir } // namespace 105cdf0e10cSrcweir 106cdf0e10cSrcweir bool 107cdf0e10cSrcweir UUIInteractionHelper::handleInteractiveIOException( 108cdf0e10cSrcweir uno::Reference< task::XInteractionRequest > const & rRequest, 109cdf0e10cSrcweir bool bObtainErrorStringOnly, 110cdf0e10cSrcweir bool & bHasErrorString, 111cdf0e10cSrcweir rtl::OUString & rErrorString) 112cdf0e10cSrcweir SAL_THROW((uno::RuntimeException)) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir uno::Any aAnyRequest(rRequest->getRequest()); 115cdf0e10cSrcweir bHasErrorString = false; 116cdf0e10cSrcweir 117cdf0e10cSrcweir ucb::InteractiveIOException aIoException; 118cdf0e10cSrcweir if (aAnyRequest >>= aIoException) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir uno::Sequence< uno::Any > aRequestArguments; 121cdf0e10cSrcweir ucb::InteractiveAugmentedIOException aAugmentedIoException; 122cdf0e10cSrcweir if (aAnyRequest >>= aAugmentedIoException) 123cdf0e10cSrcweir aRequestArguments = aAugmentedIoException.Arguments; 124cdf0e10cSrcweir 125cdf0e10cSrcweir ErrCode nErrorCode; 126cdf0e10cSrcweir std::vector< rtl::OUString > aArguments; 127cdf0e10cSrcweir static ErrCode const 128cdf0e10cSrcweir aErrorCode[ucb::IOErrorCode_WRONG_VERSION + 1][2] 129cdf0e10cSrcweir = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT 130cdf0e10cSrcweir { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED }, 131cdf0e10cSrcweir // ACCESS_DENIED 132cdf0e10cSrcweir { ERRCODE_IO_ALREADYEXISTS, 133cdf0e10cSrcweir ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING 134cdf0e10cSrcweir { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC 135cdf0e10cSrcweir { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE }, 136cdf0e10cSrcweir // CANT_CREATE 137cdf0e10cSrcweir { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD }, 138cdf0e10cSrcweir // CANT_READ 139cdf0e10cSrcweir { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK }, 140cdf0e10cSrcweir // CANT_SEEK 141cdf0e10cSrcweir { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL }, 142cdf0e10cSrcweir // CANT_TELL 143cdf0e10cSrcweir { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE }, 144cdf0e10cSrcweir // CANT_WRITE 145cdf0e10cSrcweir { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR }, 146cdf0e10cSrcweir // CURRENT_DIRECTORY 147cdf0e10cSrcweir { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY }, 148cdf0e10cSrcweir // DEVICE_NOT_READY 149cdf0e10cSrcweir { ERRCODE_IO_NOTSAMEDEVICE, 150cdf0e10cSrcweir ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES 151cdf0e10cSrcweir { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL 152cdf0e10cSrcweir { ERRCODE_IO_INVALIDACCESS, 153cdf0e10cSrcweir ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS 154cdf0e10cSrcweir { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR }, 155cdf0e10cSrcweir // INVALID_CHARACTER 156cdf0e10cSrcweir { ERRCODE_IO_INVALIDDEVICE, 157cdf0e10cSrcweir ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE 158cdf0e10cSrcweir { ERRCODE_IO_INVALIDLENGTH, 159cdf0e10cSrcweir ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH 160cdf0e10cSrcweir { ERRCODE_IO_INVALIDPARAMETER, 161cdf0e10cSrcweir ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER 162cdf0e10cSrcweir { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD }, 163cdf0e10cSrcweir // IS_WILDCARD 164cdf0e10cSrcweir { ERRCODE_IO_LOCKVIOLATION, 165cdf0e10cSrcweir ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION 166cdf0e10cSrcweir { ERRCODE_IO_MISPLACEDCHAR, 167cdf0e10cSrcweir ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER 168cdf0e10cSrcweir { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG }, 169cdf0e10cSrcweir // NAME_TOO_LONG 170cdf0e10cSrcweir { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS }, 171cdf0e10cSrcweir // NOT_EXISTING 172cdf0e10cSrcweir { ERRCODE_IO_NOTEXISTSPATH, 173cdf0e10cSrcweir ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH 174cdf0e10cSrcweir { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED }, 175cdf0e10cSrcweir // NOT_SUPPORTED 176cdf0e10cSrcweir { ERRCODE_IO_NOTADIRECTORY, 177cdf0e10cSrcweir ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY 178cdf0e10cSrcweir { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE }, 179cdf0e10cSrcweir // NO_FILE 180cdf0e10cSrcweir { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE }, 181cdf0e10cSrcweir // OUT_OF_DISK_SPACE 182cdf0e10cSrcweir { ERRCODE_IO_TOOMANYOPENFILES, 183cdf0e10cSrcweir ERRCODE_UUI_IO_TOOMANYOPENFILES }, 184cdf0e10cSrcweir // OUT_OF_FILE_HANDLES 185cdf0e10cSrcweir { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY }, 186cdf0e10cSrcweir // OUT_OF_MEMORY 187cdf0e10cSrcweir { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING 188cdf0e10cSrcweir { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE }, 189cdf0e10cSrcweir // RECURSIVE 190cdf0e10cSrcweir { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN 191cdf0e10cSrcweir { ERRCODE_IO_WRITEPROTECTED, 192cdf0e10cSrcweir ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED 193cdf0e10cSrcweir { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT }, 194cdf0e10cSrcweir // WRONG_FORMAT 195cdf0e10cSrcweir { ERRCODE_IO_WRONGVERSION, 196cdf0e10cSrcweir ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION 197cdf0e10cSrcweir switch (aIoException.Code) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir case ucb::IOErrorCode_CANT_CREATE: 200cdf0e10cSrcweir { 201cdf0e10cSrcweir rtl::OUString aArgFolder; 202cdf0e10cSrcweir if (getStringRequestArgument( 203cdf0e10cSrcweir aRequestArguments, 204cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 205cdf0e10cSrcweir "Folder")), 206cdf0e10cSrcweir &aArgFolder)) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir rtl::OUString aArgUri; 209cdf0e10cSrcweir if (getResourceNameRequestArgument(aRequestArguments, 210cdf0e10cSrcweir &aArgUri)) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir nErrorCode = ERRCODE_UUI_IO_CANTCREATE; 213cdf0e10cSrcweir aArguments.reserve(2); 214cdf0e10cSrcweir aArguments.push_back(aArgUri); 215cdf0e10cSrcweir aArguments.push_back(aArgFolder); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir else 218cdf0e10cSrcweir { 219cdf0e10cSrcweir nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME; 220cdf0e10cSrcweir aArguments.push_back(aArgFolder); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir } 223cdf0e10cSrcweir else 224cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][0]; 225cdf0e10cSrcweir break; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir 228cdf0e10cSrcweir case ucb::IOErrorCode_DEVICE_NOT_READY: 229cdf0e10cSrcweir { 230cdf0e10cSrcweir rtl::OUString aArgUri; 231cdf0e10cSrcweir if (getResourceNameRequestArgument(aRequestArguments, 232cdf0e10cSrcweir &aArgUri)) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir rtl::OUString aResourceType; 235cdf0e10cSrcweir getStringRequestArgument( 236cdf0e10cSrcweir aRequestArguments, 237cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 238cdf0e10cSrcweir "ResourceType")), 239cdf0e10cSrcweir &aResourceType); 240cdf0e10cSrcweir bool bRemovable = false; 241cdf0e10cSrcweir getBoolRequestArgument(aRequestArguments, 242cdf0e10cSrcweir rtl::OUString( 243cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 244cdf0e10cSrcweir "Removable")), 245cdf0e10cSrcweir &bRemovable); 246cdf0e10cSrcweir nErrorCode 247cdf0e10cSrcweir = aResourceType.equalsAsciiL( 248cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("volume")) 249cdf0e10cSrcweir ? (bRemovable 250cdf0e10cSrcweir ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE 251cdf0e10cSrcweir : ERRCODE_UUI_IO_NOTREADY_VOLUME) 252cdf0e10cSrcweir : (bRemovable 253cdf0e10cSrcweir ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE 254cdf0e10cSrcweir : ERRCODE_UUI_IO_NOTREADY); 255cdf0e10cSrcweir aArguments.push_back(aArgUri); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir else 258cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][0]; 259cdf0e10cSrcweir break; 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir case ucb::IOErrorCode_DIFFERENT_DEVICES: 263cdf0e10cSrcweir { 264cdf0e10cSrcweir rtl::OUString aArgVolume; 265cdf0e10cSrcweir rtl::OUString aArgOtherVolume; 266cdf0e10cSrcweir if (getStringRequestArgument( 267cdf0e10cSrcweir aRequestArguments, 268cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 269cdf0e10cSrcweir "Volume")), 270cdf0e10cSrcweir &aArgVolume) 271cdf0e10cSrcweir && getStringRequestArgument( 272cdf0e10cSrcweir aRequestArguments, 273cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 274cdf0e10cSrcweir "OtherVolume")), 275cdf0e10cSrcweir &aArgOtherVolume)) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][1]; 278cdf0e10cSrcweir aArguments.reserve(2); 279cdf0e10cSrcweir aArguments.push_back(aArgVolume); 280cdf0e10cSrcweir aArguments.push_back(aArgOtherVolume); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir else 283cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][0]; 284cdf0e10cSrcweir break; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir case ucb::IOErrorCode_NOT_EXISTING: 288cdf0e10cSrcweir { 289cdf0e10cSrcweir rtl::OUString aArgUri; 290cdf0e10cSrcweir if (getResourceNameRequestArgument(aRequestArguments, 291cdf0e10cSrcweir &aArgUri)) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir rtl::OUString aResourceType; 294cdf0e10cSrcweir getStringRequestArgument( 295cdf0e10cSrcweir aRequestArguments, 296cdf0e10cSrcweir rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 297cdf0e10cSrcweir "ResourceType")), 298cdf0e10cSrcweir &aResourceType); 299cdf0e10cSrcweir nErrorCode 300cdf0e10cSrcweir = aResourceType.equalsAsciiL( 301cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("volume")) 302cdf0e10cSrcweir ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME 303cdf0e10cSrcweir : (aResourceType.equalsAsciiL( 304cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("folder")) 305cdf0e10cSrcweir ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER 306cdf0e10cSrcweir : ERRCODE_UUI_IO_NOTEXISTS); 307cdf0e10cSrcweir aArguments.push_back(aArgUri); 308cdf0e10cSrcweir } 309cdf0e10cSrcweir else 310cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][0]; 311cdf0e10cSrcweir break; 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir default: 315cdf0e10cSrcweir { 316cdf0e10cSrcweir rtl::OUString aArgUri; 317cdf0e10cSrcweir if (getResourceNameRequestArgument(aRequestArguments, 318cdf0e10cSrcweir &aArgUri)) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][1]; 321cdf0e10cSrcweir aArguments.push_back(aArgUri); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir else 324cdf0e10cSrcweir nErrorCode = aErrorCode[aIoException.Code][0]; 325cdf0e10cSrcweir break; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir 329cdf0e10cSrcweir handleErrorHandlerRequest(aIoException.Classification, 330cdf0e10cSrcweir nErrorCode, 331cdf0e10cSrcweir aArguments, 332cdf0e10cSrcweir rRequest->getContinuations(), 333cdf0e10cSrcweir bObtainErrorStringOnly, 334cdf0e10cSrcweir bHasErrorString, 335cdf0e10cSrcweir rErrorString); 336cdf0e10cSrcweir return true; 337cdf0e10cSrcweir } 338cdf0e10cSrcweir return false; 339cdf0e10cSrcweir } 340