bump product version to 4.1.6.2
[LibreOffice.git] / uui / source / iahndl-ioexceptions.cxx
blobd969e25535924e1f1ad88289bc9254711d5c2be9
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 OUString const & rKey,
35 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 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 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 OUString * pValue)
81 SAL_THROW(())
83 if (!getStringRequestArgument(rArguments, "Uri", pValue))
84 return false;
85 // Use the resource name only for file URLs, to avoid confusion:
86 //TODO! work with ucp locality concept instead of hardcoded "file"?
87 if (pValue
88 && pValue->matchIgnoreAsciiCase("file:"))
89 getStringRequestArgument(rArguments, "ResourceName", pValue);
90 return true;
93 } // namespace
95 bool
96 UUIInteractionHelper::handleInteractiveIOException(
97 uno::Reference< task::XInteractionRequest > const & rRequest,
98 bool bObtainErrorStringOnly,
99 bool & bHasErrorString,
100 OUString & rErrorString)
101 SAL_THROW((uno::RuntimeException))
103 uno::Any aAnyRequest(rRequest->getRequest());
104 bHasErrorString = false;
106 ucb::InteractiveIOException aIoException;
107 if (aAnyRequest >>= aIoException)
109 uno::Sequence< uno::Any > aRequestArguments;
110 ucb::InteractiveAugmentedIOException aAugmentedIoException;
111 if (aAnyRequest >>= aAugmentedIoException)
112 aRequestArguments = aAugmentedIoException.Arguments;
114 ErrCode nErrorCode;
115 std::vector< OUString > aArguments;
116 static ErrCode const
117 aErrorCode[ucb::IOErrorCode_WRONG_VERSION + 1][2]
118 = { { ERRCODE_IO_ABORT, ERRCODE_UUI_IO_ABORT }, // ABORT
119 { ERRCODE_IO_ACCESSDENIED, ERRCODE_UUI_IO_ACCESSDENIED },
120 // ACCESS_DENIED
121 { ERRCODE_IO_ALREADYEXISTS,
122 ERRCODE_UUI_IO_ALREADYEXISTS }, // ALREADY_EXISTING
123 { ERRCODE_IO_BADCRC, ERRCODE_UUI_IO_BADCRC }, // BAD_CRC
124 { ERRCODE_IO_CANTCREATE, ERRCODE_UUI_IO_CANTCREATE },
125 // CANT_CREATE
126 { ERRCODE_IO_CANTREAD, ERRCODE_UUI_IO_CANTREAD },
127 // CANT_READ
128 { ERRCODE_IO_CANTSEEK, ERRCODE_UUI_IO_CANTSEEK },
129 // CANT_SEEK
130 { ERRCODE_IO_CANTTELL, ERRCODE_UUI_IO_CANTTELL },
131 // CANT_TELL
132 { ERRCODE_IO_CANTWRITE, ERRCODE_UUI_IO_CANTWRITE },
133 // CANT_WRITE
134 { ERRCODE_IO_CURRENTDIR, ERRCODE_UUI_IO_CURRENTDIR },
135 // CURRENT_DIRECTORY
136 { ERRCODE_IO_DEVICENOTREADY, ERRCODE_UUI_IO_NOTREADY },
137 // DEVICE_NOT_READY
138 { ERRCODE_IO_NOTSAMEDEVICE,
139 ERRCODE_UUI_IO_NOTSAMEDEVICE }, // DIFFERENT_DEVICES
140 { ERRCODE_IO_GENERAL, ERRCODE_UUI_IO_GENERAL }, // GENERAL
141 { ERRCODE_IO_INVALIDACCESS,
142 ERRCODE_UUI_IO_INVALIDACCESS }, // INVALID_ACCESS
143 { ERRCODE_IO_INVALIDCHAR, ERRCODE_UUI_IO_INVALIDCHAR },
144 // INVALID_CHARACTER
145 { ERRCODE_IO_INVALIDDEVICE,
146 ERRCODE_UUI_IO_INVALIDDEVICE }, // INVALID_DEVICE
147 { ERRCODE_IO_INVALIDLENGTH,
148 ERRCODE_UUI_IO_INVALIDLENGTH }, // INVALID_LENGTH
149 { ERRCODE_IO_INVALIDPARAMETER,
150 ERRCODE_UUI_IO_INVALIDPARAMETER }, // INVALID_PARAMETER
151 { ERRCODE_IO_ISWILDCARD, ERRCODE_UUI_IO_ISWILDCARD },
152 // IS_WILDCARD
153 { ERRCODE_IO_LOCKVIOLATION,
154 ERRCODE_UUI_IO_LOCKVIOLATION }, // LOCKING_VIOLATION
155 { ERRCODE_IO_MISPLACEDCHAR,
156 ERRCODE_UUI_IO_MISPLACEDCHAR }, // MISPLACED_CHARACTER
157 { ERRCODE_IO_NAMETOOLONG, ERRCODE_UUI_IO_NAMETOOLONG },
158 // NAME_TOO_LONG
159 { ERRCODE_IO_NOTEXISTS, ERRCODE_UUI_IO_NOTEXISTS },
160 // NOT_EXISTING
161 { ERRCODE_IO_NOTEXISTSPATH,
162 ERRCODE_UUI_IO_NOTEXISTSPATH }, // NOT_EXISTING_PATH
163 { ERRCODE_IO_NOTSUPPORTED, ERRCODE_UUI_IO_NOTSUPPORTED },
164 // NOT_SUPPORTED
165 { ERRCODE_IO_NOTADIRECTORY,
166 ERRCODE_UUI_IO_NOTADIRECTORY }, // NO_DIRECTORY
167 { ERRCODE_IO_NOTAFILE, ERRCODE_UUI_IO_NOTAFILE },
168 // NO_FILE
169 { ERRCODE_IO_OUTOFSPACE, ERRCODE_UUI_IO_OUTOFSPACE },
170 // OUT_OF_DISK_SPACE
171 { ERRCODE_IO_TOOMANYOPENFILES,
172 ERRCODE_UUI_IO_TOOMANYOPENFILES },
173 // OUT_OF_FILE_HANDLES
174 { ERRCODE_IO_OUTOFMEMORY, ERRCODE_UUI_IO_OUTOFMEMORY },
175 // OUT_OF_MEMORY
176 { ERRCODE_IO_PENDING, ERRCODE_UUI_IO_PENDING }, // PENDING
177 { ERRCODE_IO_RECURSIVE, ERRCODE_UUI_IO_RECURSIVE },
178 // RECURSIVE
179 { ERRCODE_IO_UNKNOWN, ERRCODE_UUI_IO_UNKNOWN }, // UNKNOWN
180 { ERRCODE_IO_WRITEPROTECTED,
181 ERRCODE_UUI_IO_WRITEPROTECTED }, // WRITE_PROTECTED
182 { ERRCODE_IO_WRONGFORMAT, ERRCODE_UUI_IO_WRONGFORMAT },
183 // WRONG_FORMAT
184 { ERRCODE_IO_WRONGVERSION,
185 ERRCODE_UUI_IO_WRONGVERSION } }; // WRONG_VERSION
186 switch (aIoException.Code)
188 case ucb::IOErrorCode_CANT_CREATE:
190 OUString aArgFolder;
191 if (getStringRequestArgument(aRequestArguments, "Folder", &aArgFolder))
193 OUString aArgUri;
194 if (getResourceNameRequestArgument(aRequestArguments,
195 &aArgUri))
197 nErrorCode = ERRCODE_UUI_IO_CANTCREATE;
198 aArguments.reserve(2);
199 aArguments.push_back(aArgUri);
200 aArguments.push_back(aArgFolder);
202 else
204 nErrorCode = ERRCODE_UUI_IO_CANTCREATE_NONAME;
205 aArguments.push_back(aArgFolder);
208 else
209 nErrorCode = aErrorCode[aIoException.Code][0];
210 break;
213 case ucb::IOErrorCode_DEVICE_NOT_READY:
215 OUString aArgUri;
216 if (getResourceNameRequestArgument(aRequestArguments,
217 &aArgUri))
219 OUString aResourceType;
220 getStringRequestArgument(aRequestArguments, "ResourceType", &aResourceType);
221 bool bRemovable = false;
222 getBoolRequestArgument(aRequestArguments, "Removable", &bRemovable);
223 nErrorCode = aResourceType == "volume"
224 ? (bRemovable
225 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
226 : ERRCODE_UUI_IO_NOTREADY_VOLUME)
227 : (bRemovable
228 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
229 : ERRCODE_UUI_IO_NOTREADY);
230 aArguments.push_back(aArgUri);
232 else
233 nErrorCode = aErrorCode[aIoException.Code][0];
234 break;
237 case ucb::IOErrorCode_DIFFERENT_DEVICES:
239 OUString aArgVolume;
240 OUString aArgOtherVolume;
241 if (getStringRequestArgument(aRequestArguments, "Volume", &aArgVolume)
242 && getStringRequestArgument(aRequestArguments, "OtherVolume",
243 &aArgOtherVolume))
245 nErrorCode = aErrorCode[aIoException.Code][1];
246 aArguments.reserve(2);
247 aArguments.push_back(aArgVolume);
248 aArguments.push_back(aArgOtherVolume);
250 else
251 nErrorCode = aErrorCode[aIoException.Code][0];
252 break;
255 case ucb::IOErrorCode_NOT_EXISTING:
257 OUString aArgUri;
258 if (getResourceNameRequestArgument(aRequestArguments,
259 &aArgUri))
261 OUString aResourceType;
262 getStringRequestArgument(aRequestArguments, "ResourceType",
263 &aResourceType);
264 nErrorCode = aResourceType == "volume"
265 ? ERRCODE_UUI_IO_NOTEXISTS_VOLUME
266 : (aResourceType == "folder"
267 ? ERRCODE_UUI_IO_NOTEXISTS_FOLDER
268 : ERRCODE_UUI_IO_NOTEXISTS);
269 aArguments.push_back(aArgUri);
271 else
272 nErrorCode = aErrorCode[aIoException.Code][0];
273 break;
276 default:
278 OUString aArgUri;
279 if (getResourceNameRequestArgument(aRequestArguments,
280 &aArgUri))
282 nErrorCode = aErrorCode[aIoException.Code][1];
283 aArguments.push_back(aArgUri);
285 else
286 nErrorCode = aErrorCode[aIoException.Code][0];
287 break;
291 handleErrorHandlerRequest(aIoException.Classification,
292 nErrorCode,
293 aArguments,
294 rRequest->getContinuations(),
295 bObtainErrorStringOnly,
296 bHasErrorString,
297 rErrorString);
298 return true;
300 return false;
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */