merged tag ooo/DEV300_m102
[LibreOffice.git] / uui / source / iahndl-ioexceptions.cxx
blobd21fe3e98f0b76bd75b537ff2073e919b60bf4f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include "com/sun/star/beans/PropertyValue.hpp"
29 #include "com/sun/star/task/XInteractionRequest.hpp"
30 #include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
32 #include "ids.hrc"
34 #include "iahndl.hxx"
36 using namespace com::sun::star;
38 namespace {
40 bool
41 getStringRequestArgument(uno::Sequence< uno::Any > const & rArguments,
42 rtl::OUString const & rKey,
43 rtl::OUString * pValue)
44 SAL_THROW(())
46 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
48 beans::PropertyValue aProperty;
49 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
51 rtl::OUString aValue;
52 if (aProperty.Value >>= aValue)
54 if (pValue)
55 *pValue = aValue;
56 return true;
60 return false;
63 bool
64 getBoolRequestArgument(uno::Sequence< uno::Any > const & rArguments,
65 rtl::OUString const & rKey,
66 bool * pValue)
67 SAL_THROW(())
69 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
71 beans::PropertyValue aProperty;
72 if ((rArguments[i] >>= aProperty) && aProperty.Name == rKey)
74 sal_Bool bValue = sal_Bool();
75 if (aProperty.Value >>= bValue)
77 if (pValue)
78 *pValue = bValue;
79 return true;
83 return false;
86 bool
87 getResourceNameRequestArgument(uno::Sequence< uno::Any > const & rArguments,
88 rtl::OUString * pValue)
89 SAL_THROW(())
91 if (!getStringRequestArgument(rArguments,
92 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
93 "Uri")),
94 pValue))
95 return false;
96 // Use the resource name only for file URLs, to avoid confusion:
97 //TODO! work with ucp locality concept instead of hardcoded "file"?
98 if (pValue
99 && pValue->matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(
100 "file:")))
101 getStringRequestArgument(rArguments,
102 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
103 "ResourceName")),
104 pValue);
105 return true;
108 } // namespace
110 bool
111 UUIInteractionHelper::handleInteractiveIOException(
112 uno::Reference< task::XInteractionRequest > const & rRequest,
113 bool bObtainErrorStringOnly,
114 bool & bHasErrorString,
115 rtl::OUString & rErrorString)
116 SAL_THROW((uno::RuntimeException))
118 uno::Any aAnyRequest(rRequest->getRequest());
119 bHasErrorString = false;
121 ucb::InteractiveIOException aIoException;
122 if (aAnyRequest >>= aIoException)
124 uno::Sequence< uno::Any > aRequestArguments;
125 ucb::InteractiveAugmentedIOException aAugmentedIoException;
126 if (aAnyRequest >>= aAugmentedIoException)
127 aRequestArguments = aAugmentedIoException.Arguments;
129 ErrCode nErrorCode;
130 std::vector< rtl::OUString > aArguments;
131 static ErrCode const
132 aErrorCode[ucb::IOErrorCode_WRONG_VERSION + 1][2]
133 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
134 { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED },
135 // ACCESS_DENIED
136 { ERRCODE_IO_ALREADYEXISTS,
137 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
138 { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC
139 { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE },
140 // CANT_CREATE
141 { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD },
142 // CANT_READ
143 { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK },
144 // CANT_SEEK
145 { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL },
146 // CANT_TELL
147 { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE },
148 // CANT_WRITE
149 { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR },
150 // CURRENT_DIRECTORY
151 { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY },
152 // DEVICE_NOT_READY
153 { ERRCODE_IO_NOTSAMEDEVICE,
154 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
155 { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL
156 { ERRCODE_IO_INVALIDACCESS,
157 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
158 { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR },
159 // INVALID_CHARACTER
160 { ERRCODE_IO_INVALIDDEVICE,
161 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
162 { ERRCODE_IO_INVALIDLENGTH,
163 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
164 { ERRCODE_IO_INVALIDPARAMETER,
165 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
166 { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD },
167 // IS_WILDCARD
168 { ERRCODE_IO_LOCKVIOLATION,
169 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
170 { ERRCODE_IO_MISPLACEDCHAR,
171 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
172 { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG },
173 // NAME_TOO_LONG
174 { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS },
175 // NOT_EXISTING
176 { ERRCODE_IO_NOTEXISTSPATH,
177 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
178 { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED },
179 // NOT_SUPPORTED
180 { ERRCODE_IO_NOTADIRECTORY,
181 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
182 { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE },
183 // NO_FILE
184 { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE },
185 // OUT_OF_DISK_SPACE
186 { ERRCODE_IO_TOOMANYOPENFILES,
187 ERRCODE_UUI_IO_TOOMANYOPENFILES },
188 // OUT_OF_FILE_HANDLES
189 { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY },
190 // OUT_OF_MEMORY
191 { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING
192 { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE },
193 // RECURSIVE
194 { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN
195 { ERRCODE_IO_WRITEPROTECTED,
196 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
197 { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT },
198 // WRONG_FORMAT
199 { ERRCODE_IO_WRONGVERSION,
200 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
201 switch (aIoException.Code)
203 case ucb::IOErrorCode_CANT_CREATE:
205 rtl::OUString aArgFolder;
206 if (getStringRequestArgument(
207 aRequestArguments,
208 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
209 "Folder")),
210 &aArgFolder))
212 rtl::OUString aArgUri;
213 if (getResourceNameRequestArgument(aRequestArguments,
214 &aArgUri))
216 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
217 aArguments.reserve(2);
218 aArguments.push_back(aArgUri);
219 aArguments.push_back(aArgFolder);
221 else
223 nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME;
224 aArguments.push_back(aArgFolder);
227 else
228 nErrorCode = aErrorCode[aIoException.Code][0];
229 break;
232 case ucb::IOErrorCode_DEVICE_NOT_READY:
234 rtl::OUString aArgUri;
235 if (getResourceNameRequestArgument(aRequestArguments,
236 &aArgUri))
238 rtl::OUString aResourceType;
239 getStringRequestArgument(
240 aRequestArguments,
241 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
242 "ResourceType")),
243 &aResourceType);
244 bool bRemovable = false;
245 getBoolRequestArgument(aRequestArguments,
246 rtl::OUString(
247 RTL_CONSTASCII_USTRINGPARAM(
248 "Removable")),
249 &bRemovable);
250 nErrorCode
251 = aResourceType.equalsAsciiL(
252 RTL_CONSTASCII_STRINGPARAM("volume"))
253 ? (bRemovable
254 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
255 : ERRCODE_UUI_IO_NOTREADY_VOLUME)
256 : (bRemovable
257 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
258 : ERRCODE_UUI_IO_NOTREADY);
259 aArguments.push_back(aArgUri);
261 else
262 nErrorCode = aErrorCode[aIoException.Code][0];
263 break;
266 case ucb::IOErrorCode_DIFFERENT_DEVICES:
268 rtl::OUString aArgVolume;
269 rtl::OUString aArgOtherVolume;
270 if (getStringRequestArgument(
271 aRequestArguments,
272 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
273 "Volume")),
274 &aArgVolume)
275 && getStringRequestArgument(
276 aRequestArguments,
277 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
278 "OtherVolume")),
279 &aArgOtherVolume))
281 nErrorCode = aErrorCode[aIoException.Code][1];
282 aArguments.reserve(2);
283 aArguments.push_back(aArgVolume);
284 aArguments.push_back(aArgOtherVolume);
286 else
287 nErrorCode = aErrorCode[aIoException.Code][0];
288 break;
291 case ucb::IOErrorCode_NOT_EXISTING:
293 rtl::OUString aArgUri;
294 if (getResourceNameRequestArgument(aRequestArguments,
295 &aArgUri))
297 rtl::OUString aResourceType;
298 getStringRequestArgument(
299 aRequestArguments,
300 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
301 "ResourceType")),
302 &aResourceType);
303 nErrorCode
304 = aResourceType.equalsAsciiL(
305 RTL_CONSTASCII_STRINGPARAM("volume"))
306 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
307 : (aResourceType.equalsAsciiL(
308 RTL_CONSTASCII_STRINGPARAM("folder"))
309 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
310 : ERRCODE_UUI_IO_NOTEXISTS);
311 aArguments.push_back(aArgUri);
313 else
314 nErrorCode = aErrorCode[aIoException.Code][0];
315 break;
318 default:
320 rtl::OUString aArgUri;
321 if (getResourceNameRequestArgument(aRequestArguments,
322 &aArgUri))
324 nErrorCode = aErrorCode[aIoException.Code][1];
325 aArguments.push_back(aArgUri);
327 else
328 nErrorCode = aErrorCode[aIoException.Code][0];
329 break;
333 handleErrorHandlerRequest(aIoException.Classification,
334 nErrorCode,
335 aArguments,
336 rRequest->getContinuations(),
337 bObtainErrorStringOnly,
338 bHasErrorString,
339 rErrorString);
340 return true;
342 return false;