LibreOffice Module uui (master) 1
iahndl-ioexceptions.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <com/sun/star/beans/PropertyValue.hpp>
21#include <com/sun/star/task/XInteractionRequest.hpp>
22#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
24
25#include <ids.hxx>
26
27#include "iahndl.hxx"
28
29using namespace com::sun::star;
30
31namespace {
32
33template<class T>
34bool
35getRequestArgument(uno::Sequence< uno::Any > const & rArguments,
36 std::u16string_view rKey,
37 T * pValue)
38{
39 for (const auto& rArgument : rArguments)
40 {
41 beans::PropertyValue aProperty;
42 if ((rArgument >>= aProperty) && aProperty.Name == rKey)
43 {
44 T aValue;
45 if (aProperty.Value >>= aValue)
46 {
47 if (pValue)
48 *pValue = aValue;
49 return true;
50 }
51 }
52 }
53 return false;
54}
55
56bool
57getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
58 OUString * pValue)
59{
60 if (!getRequestArgument(rArguments, u"Uri", pValue))
61 return false;
62 // Use the resource name only for file URLs, to avoid confusion:
63 if (pValue && comphelper::isFileUrl(*pValue))
64 getRequestArgument(rArguments, u"ResourceName", pValue);
65 return true;
66}
67
68} // namespace
69
70bool
72 uno::Reference< task::XInteractionRequest > const & rRequest,
73 bool bObtainErrorStringOnly,
74 bool & bHasErrorString,
75 OUString & rErrorString)
76{
77 uno::Any aAnyRequest(rRequest->getRequest());
78 bHasErrorString = false;
79
80 ucb::InteractiveIOException aIoException;
81 if (aAnyRequest >>= aIoException)
82 {
83 uno::Sequence< uno::Any > aRequestArguments;
84 ucb::InteractiveAugmentedIOException aAugmentedIoException;
85 if (aAnyRequest >>= aAugmentedIoException)
86 aRequestArguments = aAugmentedIoException.Arguments;
87
88 ErrCode nErrorCode;
89 std::vector< OUString > aArguments;
90 static ErrCode const
91 aErrorCode[sal_Int32(ucb::IOErrorCode_WRONG_VERSION) + 1][2]
92 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
94 // ACCESS_DENIED
96 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
99 // CANT_CREATE
101 // CANT_READ
103 // CANT_SEEK
105 // CANT_TELL
107 // CANT_WRITE
109 // CURRENT_DIRECTORY
111 // DEVICE_NOT_READY
113 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
116 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
118 // INVALID_CHARACTER
120 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
122 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
124 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
126 // IS_WILDCARD
128 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
130 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
132 // NAME_TOO_LONG
134 // NOT_EXISTING
136 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
138 // NOT_SUPPORTED
140 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
142 // NO_FILE
144 // OUT_OF_DISK_SPACE
147 // OUT_OF_FILE_HANDLES
149 // OUT_OF_MEMORY
152 // RECURSIVE
155 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
157 // WRONG_FORMAT
159 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
160 switch (aIoException.Code)
161 {
162 case ucb::IOErrorCode_CANT_CREATE:
163 {
164 OUString aArgFolder;
165 if (getRequestArgument(aRequestArguments, u"Folder", &aArgFolder))
166 {
167 OUString aArgUri;
168 if (getResourceNameRequestArgument(aRequestArguments,
169 &aArgUri))
170 {
171 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
172 aArguments.reserve(2);
173 aArguments.push_back(aArgUri);
174 aArguments.push_back(aArgFolder);
175 }
176 else
177 {
179 aArguments.push_back(aArgFolder);
180 }
181 }
182 else
183 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
184 break;
185 }
186
187 case ucb::IOErrorCode_DEVICE_NOT_READY:
188 {
189 OUString aArgUri;
190 if (getResourceNameRequestArgument(aRequestArguments,
191 &aArgUri))
192 {
193 OUString aResourceType;
194 getRequestArgument(aRequestArguments, u"ResourceType", &aResourceType);
195 bool bRemovable = false;
196 getRequestArgument(aRequestArguments, u"Removable", &bRemovable);
197 nErrorCode = aResourceType == "volume"
198 ? (bRemovable
201 : (bRemovable
204 aArguments.push_back(aArgUri);
205 }
206 else
207 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
208 break;
209 }
210
211 case ucb::IOErrorCode_DIFFERENT_DEVICES:
212 {
213 OUString aArgVolume;
214 OUString aArgOtherVolume;
215 if (getRequestArgument(aRequestArguments, u"Volume", &aArgVolume)
216 && getRequestArgument(aRequestArguments, u"OtherVolume",
217 &aArgOtherVolume))
218 {
219 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][1];
220 aArguments.reserve(2);
221 aArguments.push_back(aArgVolume);
222 aArguments.push_back(aArgOtherVolume);
223 }
224 else
225 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
226 break;
227 }
228
229 case ucb::IOErrorCode_NOT_EXISTING:
230 {
231 OUString aArgUri;
232 if (getResourceNameRequestArgument(aRequestArguments,
233 &aArgUri))
234 {
235 OUString aResourceType;
236 getRequestArgument(aRequestArguments, u"ResourceType",
237 &aResourceType);
238 nErrorCode = aResourceType == "volume"
240 : (aResourceType == "folder"
243 aArguments.push_back(aArgUri);
244 }
245 else
246 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
247 break;
248 }
249
250 default:
251 {
252 OUString aArgUri;
253 if (getResourceNameRequestArgument(aRequestArguments,
254 &aArgUri))
255 {
256 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][1];
257 aArguments.push_back(aArgUri);
258 }
259 else
260 nErrorCode = aErrorCode[static_cast<sal_Int32>(aIoException.Code)][0];
261 break;
262 }
263 }
264
265 handleErrorHandlerRequest(aIoException.Classification,
266 nErrorCode,
268 rRequest->getContinuations(),
269 bObtainErrorStringOnly,
270 bHasErrorString,
271 rErrorString);
272 return true;
273 }
274 return false;
275}
276
277/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void handleErrorHandlerRequest(css::task::InteractionClassification eClassification, ErrCode nErrorCode, std::vector< OUString > const &rArguments, css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > const &rContinuations, bool bObtainErrorStringOnly, bool &bHasErrorString, OUString &rErrorString)
bool handleInteractiveIOException(css::uno::Reference< css::task::XInteractionRequest > const &rRequest, bool bObtainErrorStringOnly, bool &bHasErrorString, OUString &rErrorString)
float u
#define ERRCODE_IO_INVALIDLENGTH
#define ERRCODE_IO_BADCRC
#define ERRCODE_IO_ACCESSDENIED
#define ERRCODE_IO_MISPLACEDCHAR
#define ERRCODE_IO_CANTTELL
#define ERRCODE_IO_OUTOFSPACE
#define ERRCODE_IO_INVALIDDEVICE
#define ERRCODE_IO_CURRENTDIR
#define ERRCODE_IO_NOTADIRECTORY
#define ERRCODE_IO_ABORT
#define ERRCODE_IO_CANTREAD
#define ERRCODE_IO_CANTCREATE
#define ERRCODE_IO_LOCKVIOLATION
#define ERRCODE_IO_GENERAL
#define ERRCODE_IO_NOTSAMEDEVICE
#define ERRCODE_IO_PENDING
#define ERRCODE_IO_WRONGVERSION
#define ERRCODE_IO_CANTSEEK
#define ERRCODE_IO_DEVICENOTREADY
#define ERRCODE_IO_NOTEXISTSPATH
#define ERRCODE_IO_CANTWRITE
#define ERRCODE_IO_WRONGFORMAT
#define ERRCODE_IO_NOTEXISTS
#define ERRCODE_IO_RECURSIVE
#define ERRCODE_IO_ALREADYEXISTS
#define ERRCODE_IO_INVALIDCHAR
#define ERRCODE_IO_NOTSUPPORTED
#define ERRCODE_IO_UNKNOWN
#define ERRCODE_IO_WRITEPROTECTED
#define ERRCODE_IO_INVALIDACCESS
#define ERRCODE_IO_OUTOFMEMORY
#define ERRCODE_IO_NAMETOOLONG
#define ERRCODE_IO_TOOMANYOPENFILES
#define ERRCODE_IO_NOTAFILE
#define ERRCODE_IO_ISWILDCARD
#define ERRCODE_IO_INVALIDPARAMETER
#define ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
Definition: ids.hxx:70
#define ERRCODE_UUI_IO_NAMETOOLONG
Definition: ids.hxx:45
#define ERRCODE_UUI_IO_NOTREADY_REMOVABLE
Definition: ids.hxx:69
#define ERRCODE_UUI_IO_BADCRC
Definition: ids.hxx:27
#define ERRCODE_UUI_IO_CANTREAD
Definition: ids.hxx:29
#define ERRCODE_UUI_IO_NOTEXISTS_FOLDER
Definition: ids.hxx:61
#define ERRCODE_UUI_IO_NOTADIRECTORY
Definition: ids.hxx:49
#define ERRCODE_UUI_IO_CANTWRITE
Definition: ids.hxx:32
#define ERRCODE_UUI_IO_NOTREADY_VOLUME
Definition: ids.hxx:68
#define ERRCODE_UUI_IO_OUTOFMEMORY
Definition: ids.hxx:53
#define ERRCODE_UUI_IO_WRONGFORMAT
Definition: ids.hxx:58
#define ERRCODE_UUI_IO_CANTSEEK
Definition: ids.hxx:30
#define ERRCODE_UUI_IO_NOTREADY
Definition: ids.hxx:34
#define ERRCODE_UUI_IO_CANTCREATE
Definition: ids.hxx:28
#define ERRCODE_UUI_IO_RECURSIVE
Definition: ids.hxx:55
#define ERRCODE_UUI_IO_INVALIDPARAMETER
Definition: ids.hxx:41
#define ERRCODE_UUI_IO_NOTEXISTSPATH
Definition: ids.hxx:47
#define ERRCODE_UUI_IO_PENDING
Definition: ids.hxx:54
#define ERRCODE_UUI_IO_OUTOFSPACE
Definition: ids.hxx:51
#define ERRCODE_UUI_IO_MISPLACEDCHAR
Definition: ids.hxx:44
#define ERRCODE_UUI_IO_WRITEPROTECTED
Definition: ids.hxx:57
#define ERRCODE_UUI_IO_NOTEXISTS_VOLUME
Definition: ids.hxx:60
#define ERRCODE_UUI_IO_INVALIDACCESS
Definition: ids.hxx:37
#define ERRCODE_UUI_IO_UNKNOWN
Definition: ids.hxx:56
#define ERRCODE_UUI_IO_INVALIDCHAR
Definition: ids.hxx:38
#define ERRCODE_UUI_IO_NOTEXISTS
Definition: ids.hxx:46
#define ERRCODE_UUI_IO_WRONGVERSION
Definition: ids.hxx:59
#define ERRCODE_UUI_IO_CANTCREATE_NONAME
Definition: ids.hxx:72
#define ERRCODE_UUI_IO_NOTAFILE
Definition: ids.hxx:50
#define ERRCODE_UUI_IO_TOOMANYOPENFILES
Definition: ids.hxx:52
#define ERRCODE_UUI_IO_CANTTELL
Definition: ids.hxx:31
#define ERRCODE_UUI_IO_LOCKVIOLATION
Definition: ids.hxx:43
#define ERRCODE_UUI_IO_ACCESSDENIED
Definition: ids.hxx:25
#define ERRCODE_UUI_IO_GENERAL
Definition: ids.hxx:36
#define ERRCODE_UUI_IO_ABORT
Definition: ids.hxx:24
#define ERRCODE_UUI_IO_NOTSUPPORTED
Definition: ids.hxx:48
#define ERRCODE_UUI_IO_NOTSAMEDEVICE
Definition: ids.hxx:35
#define ERRCODE_UUI_IO_CURRENTDIR
Definition: ids.hxx:33
#define ERRCODE_UUI_IO_INVALIDDEVICE
Definition: ids.hxx:39
#define ERRCODE_UUI_IO_INVALIDLENGTH
Definition: ids.hxx:40
#define ERRCODE_UUI_IO_ISWILDCARD
Definition: ids.hxx:42
#define ERRCODE_UUI_IO_ALREADYEXISTS
Definition: ids.hxx:26
Sequence< PropertyValue > aArguments
COMPHELPER_DLLPUBLIC bool isFileUrl(std::u16string_view url)