1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/PropertyValue.hpp>
21 #include <com/sun/star/task/XInteractionRequest.hpp>
22 #include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
23 #include <comphelper/fileurl.hxx>
29 using namespace com::sun::star
;
34 getStringRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
35 OUString
const & rKey
,
38 for (sal_Int32 i
= 0; i
< rArguments
.getLength(); ++i
)
40 beans::PropertyValue aProperty
;
41 if ((rArguments
[i
] >>= aProperty
) && aProperty
.Name
== rKey
)
44 if (aProperty
.Value
>>= aValue
)
56 getBoolRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
57 OUString
const & rKey
,
60 for (sal_Int32 i
= 0; i
< rArguments
.getLength(); ++i
)
62 beans::PropertyValue aProperty
;
63 if ((rArguments
[i
] >>= aProperty
) && aProperty
.Name
== rKey
)
66 if (aProperty
.Value
>>= bValue
)
78 getResourceNameRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
81 if (!getStringRequestArgument(rArguments
, "Uri", pValue
))
83 // Use the resource name only for file URLs, to avoid confusion:
84 if (pValue
&& comphelper::isFileUrl(*pValue
))
85 getStringRequestArgument(rArguments
, "ResourceName", pValue
);
92 UUIInteractionHelper::handleInteractiveIOException(
93 uno::Reference
< task::XInteractionRequest
> const & rRequest
,
94 bool bObtainErrorStringOnly
,
95 bool & bHasErrorString
,
96 OUString
& rErrorString
)
98 uno::Any
aAnyRequest(rRequest
->getRequest());
99 bHasErrorString
= false;
101 ucb::InteractiveIOException aIoException
;
102 if (aAnyRequest
>>= aIoException
)
104 uno::Sequence
< uno::Any
> aRequestArguments
;
105 ucb::InteractiveAugmentedIOException aAugmentedIoException
;
106 if (aAnyRequest
>>= aAugmentedIoException
)
107 aRequestArguments
= aAugmentedIoException
.Arguments
;
110 std::vector
< OUString
> aArguments
;
112 aErrorCode
[sal_Int32(ucb::IOErrorCode_WRONG_VERSION
) + 1][2]
113 = { { ERRCODE_IO_ABORT
, ERRCODE_UUI_IO_ABORT
}, // ABORT
114 { ERRCODE_IO_ACCESSDENIED
, ERRCODE_UUI_IO_ACCESSDENIED
},
116 { ERRCODE_IO_ALREADYEXISTS
,
117 ERRCODE_UUI_IO_ALREADYEXISTS
}, // ALREADY_EXISTING
118 { ERRCODE_IO_BADCRC
, ERRCODE_UUI_IO_BADCRC
}, // BAD_CRC
119 { ERRCODE_IO_CANTCREATE
, ERRCODE_UUI_IO_CANTCREATE
},
121 { ERRCODE_IO_CANTREAD
, ERRCODE_UUI_IO_CANTREAD
},
123 { ERRCODE_IO_CANTSEEK
, ERRCODE_UUI_IO_CANTSEEK
},
125 { ERRCODE_IO_CANTTELL
, ERRCODE_UUI_IO_CANTTELL
},
127 { ERRCODE_IO_CANTWRITE
, ERRCODE_UUI_IO_CANTWRITE
},
129 { ERRCODE_IO_CURRENTDIR
, ERRCODE_UUI_IO_CURRENTDIR
},
131 { ERRCODE_IO_DEVICENOTREADY
, ERRCODE_UUI_IO_NOTREADY
},
133 { ERRCODE_IO_NOTSAMEDEVICE
,
134 ERRCODE_UUI_IO_NOTSAMEDEVICE
}, // DIFFERENT_DEVICES
135 { ERRCODE_IO_GENERAL
, ERRCODE_UUI_IO_GENERAL
}, // GENERAL
136 { ERRCODE_IO_INVALIDACCESS
,
137 ERRCODE_UUI_IO_INVALIDACCESS
}, // INVALID_ACCESS
138 { ERRCODE_IO_INVALIDCHAR
, ERRCODE_UUI_IO_INVALIDCHAR
},
140 { ERRCODE_IO_INVALIDDEVICE
,
141 ERRCODE_UUI_IO_INVALIDDEVICE
}, // INVALID_DEVICE
142 { ERRCODE_IO_INVALIDLENGTH
,
143 ERRCODE_UUI_IO_INVALIDLENGTH
}, // INVALID_LENGTH
144 { ERRCODE_IO_INVALIDPARAMETER
,
145 ERRCODE_UUI_IO_INVALIDPARAMETER
}, // INVALID_PARAMETER
146 { ERRCODE_IO_ISWILDCARD
, ERRCODE_UUI_IO_ISWILDCARD
},
148 { ERRCODE_IO_LOCKVIOLATION
,
149 ERRCODE_UUI_IO_LOCKVIOLATION
}, // LOCKING_VIOLATION
150 { ERRCODE_IO_MISPLACEDCHAR
,
151 ERRCODE_UUI_IO_MISPLACEDCHAR
}, // MISPLACED_CHARACTER
152 { ERRCODE_IO_NAMETOOLONG
, ERRCODE_UUI_IO_NAMETOOLONG
},
154 { ERRCODE_IO_NOTEXISTS
, ERRCODE_UUI_IO_NOTEXISTS
},
156 { ERRCODE_IO_NOTEXISTSPATH
,
157 ERRCODE_UUI_IO_NOTEXISTSPATH
}, // NOT_EXISTING_PATH
158 { ERRCODE_IO_NOTSUPPORTED
, ERRCODE_UUI_IO_NOTSUPPORTED
},
160 { ERRCODE_IO_NOTADIRECTORY
,
161 ERRCODE_UUI_IO_NOTADIRECTORY
}, // NO_DIRECTORY
162 { ERRCODE_IO_NOTAFILE
, ERRCODE_UUI_IO_NOTAFILE
},
164 { ERRCODE_IO_OUTOFSPACE
, ERRCODE_UUI_IO_OUTOFSPACE
},
166 { ERRCODE_IO_TOOMANYOPENFILES
,
167 ERRCODE_UUI_IO_TOOMANYOPENFILES
},
168 // OUT_OF_FILE_HANDLES
169 { ERRCODE_IO_OUTOFMEMORY
, ERRCODE_UUI_IO_OUTOFMEMORY
},
171 { ERRCODE_IO_PENDING
, ERRCODE_UUI_IO_PENDING
}, // PENDING
172 { ERRCODE_IO_RECURSIVE
, ERRCODE_UUI_IO_RECURSIVE
},
174 { ERRCODE_IO_UNKNOWN
, ERRCODE_UUI_IO_UNKNOWN
}, // UNKNOWN
175 { ERRCODE_IO_WRITEPROTECTED
,
176 ERRCODE_UUI_IO_WRITEPROTECTED
}, // WRITE_PROTECTED
177 { ERRCODE_IO_WRONGFORMAT
, ERRCODE_UUI_IO_WRONGFORMAT
},
179 { ERRCODE_IO_WRONGVERSION
,
180 ERRCODE_UUI_IO_WRONGVERSION
} }; // WRONG_VERSION
181 switch (aIoException
.Code
)
183 case ucb::IOErrorCode_CANT_CREATE
:
186 if (getStringRequestArgument(aRequestArguments
, "Folder", &aArgFolder
))
189 if (getResourceNameRequestArgument(aRequestArguments
,
192 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE
;
193 aArguments
.reserve(2);
194 aArguments
.push_back(aArgUri
);
195 aArguments
.push_back(aArgFolder
);
199 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE_NONAME
;
200 aArguments
.push_back(aArgFolder
);
204 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][0];
208 case ucb::IOErrorCode_DEVICE_NOT_READY
:
211 if (getResourceNameRequestArgument(aRequestArguments
,
214 OUString aResourceType
;
215 getStringRequestArgument(aRequestArguments
, "ResourceType", &aResourceType
);
216 bool bRemovable
= false;
217 getBoolRequestArgument(aRequestArguments
, "Removable", &bRemovable
);
218 nErrorCode
= aResourceType
== "volume"
220 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
221 : ERRCODE_UUI_IO_NOTREADY_VOLUME
)
223 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
224 : ERRCODE_UUI_IO_NOTREADY
);
225 aArguments
.push_back(aArgUri
);
228 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][0];
232 case ucb::IOErrorCode_DIFFERENT_DEVICES
:
235 OUString aArgOtherVolume
;
236 if (getStringRequestArgument(aRequestArguments
, "Volume", &aArgVolume
)
237 && getStringRequestArgument(aRequestArguments
, "OtherVolume",
240 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][1];
241 aArguments
.reserve(2);
242 aArguments
.push_back(aArgVolume
);
243 aArguments
.push_back(aArgOtherVolume
);
246 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][0];
250 case ucb::IOErrorCode_NOT_EXISTING
:
253 if (getResourceNameRequestArgument(aRequestArguments
,
256 OUString aResourceType
;
257 getStringRequestArgument(aRequestArguments
, "ResourceType",
259 nErrorCode
= aResourceType
== "volume"
260 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
261 : (aResourceType
== "folder"
262 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
263 : ERRCODE_UUI_IO_NOTEXISTS
);
264 aArguments
.push_back(aArgUri
);
267 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][0];
274 if (getResourceNameRequestArgument(aRequestArguments
,
277 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][1];
278 aArguments
.push_back(aArgUri
);
281 nErrorCode
= aErrorCode
[static_cast<sal_Int32
>(aIoException
.Code
)][0];
286 handleErrorHandlerRequest(aIoException
.Classification
,
289 rRequest
->getContinuations(),
290 bObtainErrorStringOnly
,
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */