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"
37 using namespace com::sun::star
;
42 getStringRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
43 rtl::OUString
const & rKey
,
44 rtl::OUString
* pValue
)
47 for (sal_Int32 i
= 0; i
< rArguments
.getLength(); ++i
)
49 beans::PropertyValue aProperty
;
50 if ((rArguments
[i
] >>= aProperty
) && aProperty
.Name
== rKey
)
53 if (aProperty
.Value
>>= aValue
)
65 getBoolRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
66 rtl::OUString
const & rKey
,
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
)
88 getResourceNameRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
89 rtl::OUString
* pValue
)
92 if (!getStringRequestArgument(rArguments
,
93 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
97 // Use the resource name only for file URLs, to avoid confusion:
98 //TODO! work with ucp locality concept instead of hardcoded "file"?
100 && pValue
->matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(
102 getStringRequestArgument(rArguments
,
103 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
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
;
131 std::vector
< rtl::OUString
> aArguments
;
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
},
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
},
142 { ERRCODE_IO_CANTREAD
, ERRCODE_UUI_IO_CANTREAD
},
144 { ERRCODE_IO_CANTSEEK
, ERRCODE_UUI_IO_CANTSEEK
},
146 { ERRCODE_IO_CANTTELL
, ERRCODE_UUI_IO_CANTTELL
},
148 { ERRCODE_IO_CANTWRITE
, ERRCODE_UUI_IO_CANTWRITE
},
150 { ERRCODE_IO_CURRENTDIR
, ERRCODE_UUI_IO_CURRENTDIR
},
152 { ERRCODE_IO_DEVICENOTREADY
, ERRCODE_UUI_IO_NOTREADY
},
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
},
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
},
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
},
175 { ERRCODE_IO_NOTEXISTS
, ERRCODE_UUI_IO_NOTEXISTS
},
177 { ERRCODE_IO_NOTEXISTSPATH
,
178 ERRCODE_UUI_IO_NOTEXISTSPATH
}, // NOT_EXISTING_PATH
179 { ERRCODE_IO_NOTSUPPORTED
, ERRCODE_UUI_IO_NOTSUPPORTED
},
181 { ERRCODE_IO_NOTADIRECTORY
,
182 ERRCODE_UUI_IO_NOTADIRECTORY
}, // NO_DIRECTORY
183 { ERRCODE_IO_NOTAFILE
, ERRCODE_UUI_IO_NOTAFILE
},
185 { ERRCODE_IO_OUTOFSPACE
, ERRCODE_UUI_IO_OUTOFSPACE
},
187 { ERRCODE_IO_TOOMANYOPENFILES
,
188 ERRCODE_UUI_IO_TOOMANYOPENFILES
},
189 // OUT_OF_FILE_HANDLES
190 { ERRCODE_IO_OUTOFMEMORY
, ERRCODE_UUI_IO_OUTOFMEMORY
},
192 { ERRCODE_IO_PENDING
, ERRCODE_UUI_IO_PENDING
}, // PENDING
193 { ERRCODE_IO_RECURSIVE
, ERRCODE_UUI_IO_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
},
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(
209 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
213 rtl::OUString aArgUri
;
214 if (getResourceNameRequestArgument(aRequestArguments
,
217 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE
;
218 aArguments
.reserve(2);
219 aArguments
.push_back(aArgUri
);
220 aArguments
.push_back(aArgFolder
);
224 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE_NONAME
;
225 aArguments
.push_back(aArgFolder
);
229 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
233 case ucb::IOErrorCode_DEVICE_NOT_READY
:
235 rtl::OUString aArgUri
;
236 if (getResourceNameRequestArgument(aRequestArguments
,
239 rtl::OUString aResourceType
;
240 getStringRequestArgument(
242 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
245 bool bRemovable
= false;
246 getBoolRequestArgument(aRequestArguments
,
248 RTL_CONSTASCII_USTRINGPARAM(
251 nErrorCode
= aResourceType
== "volume"
253 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
254 : ERRCODE_UUI_IO_NOTREADY_VOLUME
)
256 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
257 : ERRCODE_UUI_IO_NOTREADY
);
258 aArguments
.push_back(aArgUri
);
261 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
265 case ucb::IOErrorCode_DIFFERENT_DEVICES
:
267 rtl::OUString aArgVolume
;
268 rtl::OUString aArgOtherVolume
;
269 if (getStringRequestArgument(
271 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
274 && getStringRequestArgument(
276 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
280 nErrorCode
= aErrorCode
[aIoException
.Code
][1];
281 aArguments
.reserve(2);
282 aArguments
.push_back(aArgVolume
);
283 aArguments
.push_back(aArgOtherVolume
);
286 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
290 case ucb::IOErrorCode_NOT_EXISTING
:
292 rtl::OUString aArgUri
;
293 if (getResourceNameRequestArgument(aRequestArguments
,
296 rtl::OUString aResourceType
;
297 getStringRequestArgument(
299 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
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
);
310 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
316 rtl::OUString aArgUri
;
317 if (getResourceNameRequestArgument(aRequestArguments
,
320 nErrorCode
= aErrorCode
[aIoException
.Code
][1];
321 aArguments
.push_back(aArgUri
);
324 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
329 handleErrorHandlerRequest(aIoException
.Classification
,
332 rRequest
->getContinuations(),
333 bObtainErrorStringOnly
,
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */