Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / uui / source / iahndl-ioexceptions.cxx
blob33aaf2510a8f185467bf308c7201535534bcafb9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
24 #include "ids.hrc"
26 #include "iahndl.hxx"
28 using namespace com::sun::star;
30 namespace {
32 bool
33 getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
34 rtl::OUString const & rKey,
35 rtl::OUString * pValue)
36 SAL_THROW(())
38 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
40 beans::PropertyValue aProperty;
41 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
43 rtl::OUString aValue;
44 if (aProperty.Value >>= aValue)
46 if (pValue)
47 *pValue = aValue;
48 return true;
52 return false;
55 bool
56 getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments,
57 rtl::OUString const & rKey,
58 bool * pValue)
59 SAL_THROW(())
61 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
63 beans::PropertyValue aProperty;
64 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
66 sal_Bool bValue = sal_Bool();
67 if (aProperty.Value >>= bValue)
69 if (pValue)
70 *pValue = bValue;
71 return true;
75 return false;
78 bool
79 getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
80 rtl::OUString * pValue)
81 SAL_THROW(())
83 if (!getStringRequestArgument(rArguments,
84 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
85 "Uri")),
86 pValue))
87 return false;
88 // Use the resource name only for file URLs, to avoid confusion:
89 //TODO! work with ucp locality concept instead of hardcoded "file"?
90 if (pValue
91 && pValue->matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(
92 "file:")))
93 getStringRequestArgument(rArguments,
94 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
95 "ResourceName")),
96 pValue);
97 return true;
100 } // namespace
102 bool
103 UUIInteractionHelper::handleInteractiveIOException(
104 uno::Reference< task::XInteractionRequest > const & rRequest,
105 bool bObtainErrorStringOnly,
106 bool & bHasErrorString,
107 rtl::OUString & rErrorString)
108 SAL_THROW((uno::RuntimeException))
110 uno::Any aAnyRequest(rRequest->getRequest());
111 bHasErrorString = false;
113 ucb::InteractiveIOException aIoException;
114 if (aAnyRequest >>= aIoException)
116 uno::Sequence< uno::Any > aRequestArguments;
117 ucb::InteractiveAugmentedIOException aAugmentedIoException;
118 if (aAnyRequest >>= aAugmentedIoException)
119 aRequestArguments = aAugmentedIoException.Arguments;
121 ErrCode nErrorCode;
122 std::vector< rtl::OUString > aArguments;
123 static ErrCode const
124 aErrorCode[ucb::IOErrorCode_WRONG_VERSION + 1][2]
125 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
126 { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED },
127 // ACCESS_DENIED
128 { ERRCODE_IO_ALREADYEXISTS,
129 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
130 { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC
131 { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE },
132 // CANT_CREATE
133 { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD },
134 // CANT_READ
135 { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK },
136 // CANT_SEEK
137 { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL },
138 // CANT_TELL
139 { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE },
140 // CANT_WRITE
141 { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR },
142 // CURRENT_DIRECTORY
143 { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY },
144 // DEVICE_NOT_READY
145 { ERRCODE_IO_NOTSAMEDEVICE,
146 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
147 { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL
148 { ERRCODE_IO_INVALIDACCESS,
149 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
150 { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR },
151 // INVALID_CHARACTER
152 { ERRCODE_IO_INVALIDDEVICE,
153 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
154 { ERRCODE_IO_INVALIDLENGTH,
155 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
156 { ERRCODE_IO_INVALIDPARAMETER,
157 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
158 { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD },
159 // IS_WILDCARD
160 { ERRCODE_IO_LOCKVIOLATION,
161 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
162 { ERRCODE_IO_MISPLACEDCHAR,
163 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
164 { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG },
165 // NAME_TOO_LONG
166 { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS },
167 // NOT_EXISTING
168 { ERRCODE_IO_NOTEXISTSPATH,
169 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
170 { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED },
171 // NOT_SUPPORTED
172 { ERRCODE_IO_NOTADIRECTORY,
173 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
174 { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE },
175 // NO_FILE
176 { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE },
177 // OUT_OF_DISK_SPACE
178 { ERRCODE_IO_TOOMANYOPENFILES,
179 ERRCODE_UUI_IO_TOOMANYOPENFILES },
180 // OUT_OF_FILE_HANDLES
181 { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY },
182 // OUT_OF_MEMORY
183 { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING
184 { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE },
185 // RECURSIVE
186 { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN
187 { ERRCODE_IO_WRITEPROTECTED,
188 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
189 { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT },
190 // WRONG_FORMAT
191 { ERRCODE_IO_WRONGVERSION,
192 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
193 switch (aIoException.Code)
195 case ucb::IOErrorCode_CANT_CREATE:
197 rtl::OUString aArgFolder;
198 if (getStringRequestArgument(
199 aRequestArguments,
200 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
201 "Folder")),
202 &aArgFolder))
204 rtl::OUString aArgUri;
205 if (getResourceNameRequestArgument(aRequestArguments,
206 &aArgUri))
208 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
209 aArguments.reserve(2);
210 aArguments.push_back(aArgUri);
211 aArguments.push_back(aArgFolder);
213 else
215 nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME;
216 aArguments.push_back(aArgFolder);
219 else
220 nErrorCode = aErrorCode[aIoException.Code][0];
221 break;
224 case ucb::IOErrorCode_DEVICE_NOT_READY:
226 rtl::OUString aArgUri;
227 if (getResourceNameRequestArgument(aRequestArguments,
228 &aArgUri))
230 rtl::OUString aResourceType;
231 getStringRequestArgument(
232 aRequestArguments,
233 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
234 "ResourceType")),
235 &aResourceType);
236 bool bRemovable = false;
237 getBoolRequestArgument(aRequestArguments,
238 rtl::OUString(
239 RTL_CONSTASCII_USTRINGPARAM(
240 "Removable")),
241 &bRemovable);
242 nErrorCode = aResourceType == "volume"
243 ? (bRemovable
244 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
245 : ERRCODE_UUI_IO_NOTREADY_VOLUME)
246 : (bRemovable
247 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
248 : ERRCODE_UUI_IO_NOTREADY);
249 aArguments.push_back(aArgUri);
251 else
252 nErrorCode = aErrorCode[aIoException.Code][0];
253 break;
256 case ucb::IOErrorCode_DIFFERENT_DEVICES:
258 rtl::OUString aArgVolume;
259 rtl::OUString aArgOtherVolume;
260 if (getStringRequestArgument(
261 aRequestArguments,
262 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
263 "Volume")),
264 &aArgVolume)
265 && getStringRequestArgument(
266 aRequestArguments,
267 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
268 "OtherVolume")),
269 &aArgOtherVolume))
271 nErrorCode = aErrorCode[aIoException.Code][1];
272 aArguments.reserve(2);
273 aArguments.push_back(aArgVolume);
274 aArguments.push_back(aArgOtherVolume);
276 else
277 nErrorCode = aErrorCode[aIoException.Code][0];
278 break;
281 case ucb::IOErrorCode_NOT_EXISTING:
283 rtl::OUString aArgUri;
284 if (getResourceNameRequestArgument(aRequestArguments,
285 &aArgUri))
287 rtl::OUString aResourceType;
288 getStringRequestArgument(
289 aRequestArguments,
290 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
291 "ResourceType")),
292 &aResourceType);
293 nErrorCode = aResourceType == "volume"
294 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
295 : (aResourceType == "folder"
296 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
297 : ERRCODE_UUI_IO_NOTEXISTS);
298 aArguments.push_back(aArgUri);
300 else
301 nErrorCode = aErrorCode[aIoException.Code][0];
302 break;
305 default:
307 rtl::OUString aArgUri;
308 if (getResourceNameRequestArgument(aRequestArguments,
309 &aArgUri))
311 nErrorCode = aErrorCode[aIoException.Code][1];
312 aArguments.push_back(aArgUri);
314 else
315 nErrorCode = aErrorCode[aIoException.Code][0];
316 break;
320 handleErrorHandlerRequest(aIoException.Classification,
321 nErrorCode,
322 aArguments,
323 rRequest->getContinuations(),
324 bObtainErrorStringOnly,
325 bHasErrorString,
326 rErrorString);
327 return true;
329 return false;
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */