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