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"
36 using namespace com::sun::star
;
41 getStringRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
42 rtl::OUString
const & rKey
,
43 rtl::OUString
* pValue
)
46 for (sal_Int32 i
= 0; i
< rArguments
.getLength(); ++i
)
48 beans::PropertyValue aProperty
;
49 if ((rArguments
[i
] >>= aProperty
) && aProperty
.Name
== rKey
)
52 if (aProperty
.Value
>>= aValue
)
64 getBoolRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
65 rtl::OUString
const & rKey
,
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
)
87 getResourceNameRequestArgument(uno::Sequence
< uno::Any
> const & rArguments
,
88 rtl::OUString
* pValue
)
91 if (!getStringRequestArgument(rArguments
,
92 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
96 // Use the resource name only for file URLs, to avoid confusion:
97 //TODO! work with ucp locality concept instead of hardcoded "file"?
99 && pValue
->matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(
101 getStringRequestArgument(rArguments
,
102 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
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
;
130 std::vector
< rtl::OUString
> aArguments
;
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
},
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
},
141 { ERRCODE_IO_CANTREAD
, ERRCODE_UUI_IO_CANTREAD
},
143 { ERRCODE_IO_CANTSEEK
, ERRCODE_UUI_IO_CANTSEEK
},
145 { ERRCODE_IO_CANTTELL
, ERRCODE_UUI_IO_CANTTELL
},
147 { ERRCODE_IO_CANTWRITE
, ERRCODE_UUI_IO_CANTWRITE
},
149 { ERRCODE_IO_CURRENTDIR
, ERRCODE_UUI_IO_CURRENTDIR
},
151 { ERRCODE_IO_DEVICENOTREADY
, ERRCODE_UUI_IO_NOTREADY
},
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
},
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
},
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
},
174 { ERRCODE_IO_NOTEXISTS
, ERRCODE_UUI_IO_NOTEXISTS
},
176 { ERRCODE_IO_NOTEXISTSPATH
,
177 ERRCODE_UUI_IO_NOTEXISTSPATH
}, // NOT_EXISTING_PATH
178 { ERRCODE_IO_NOTSUPPORTED
, ERRCODE_UUI_IO_NOTSUPPORTED
},
180 { ERRCODE_IO_NOTADIRECTORY
,
181 ERRCODE_UUI_IO_NOTADIRECTORY
}, // NO_DIRECTORY
182 { ERRCODE_IO_NOTAFILE
, ERRCODE_UUI_IO_NOTAFILE
},
184 { ERRCODE_IO_OUTOFSPACE
, ERRCODE_UUI_IO_OUTOFSPACE
},
186 { ERRCODE_IO_TOOMANYOPENFILES
,
187 ERRCODE_UUI_IO_TOOMANYOPENFILES
},
188 // OUT_OF_FILE_HANDLES
189 { ERRCODE_IO_OUTOFMEMORY
, ERRCODE_UUI_IO_OUTOFMEMORY
},
191 { ERRCODE_IO_PENDING
, ERRCODE_UUI_IO_PENDING
}, // PENDING
192 { ERRCODE_IO_RECURSIVE
, ERRCODE_UUI_IO_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
},
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(
208 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
212 rtl::OUString aArgUri
;
213 if (getResourceNameRequestArgument(aRequestArguments
,
216 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE
;
217 aArguments
.reserve(2);
218 aArguments
.push_back(aArgUri
);
219 aArguments
.push_back(aArgFolder
);
223 nErrorCode
= ERRCODE_UUI_IO_CANTCREATE_NONAME
;
224 aArguments
.push_back(aArgFolder
);
228 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
232 case ucb::IOErrorCode_DEVICE_NOT_READY
:
234 rtl::OUString aArgUri
;
235 if (getResourceNameRequestArgument(aRequestArguments
,
238 rtl::OUString aResourceType
;
239 getStringRequestArgument(
241 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
244 bool bRemovable
= false;
245 getBoolRequestArgument(aRequestArguments
,
247 RTL_CONSTASCII_USTRINGPARAM(
251 = aResourceType
.equalsAsciiL(
252 RTL_CONSTASCII_STRINGPARAM("volume"))
254 ? ERRCODE_UUI_IO_NOTREADY_VOLUME_REMOVABLE
255 : ERRCODE_UUI_IO_NOTREADY_VOLUME
)
257 ? ERRCODE_UUI_IO_NOTREADY_REMOVABLE
258 : ERRCODE_UUI_IO_NOTREADY
);
259 aArguments
.push_back(aArgUri
);
262 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
266 case ucb::IOErrorCode_DIFFERENT_DEVICES
:
268 rtl::OUString aArgVolume
;
269 rtl::OUString aArgOtherVolume
;
270 if (getStringRequestArgument(
272 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
275 && getStringRequestArgument(
277 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
281 nErrorCode
= aErrorCode
[aIoException
.Code
][1];
282 aArguments
.reserve(2);
283 aArguments
.push_back(aArgVolume
);
284 aArguments
.push_back(aArgOtherVolume
);
287 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
291 case ucb::IOErrorCode_NOT_EXISTING
:
293 rtl::OUString aArgUri
;
294 if (getResourceNameRequestArgument(aRequestArguments
,
297 rtl::OUString aResourceType
;
298 getStringRequestArgument(
300 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
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
);
314 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
320 rtl::OUString aArgUri
;
321 if (getResourceNameRequestArgument(aRequestArguments
,
324 nErrorCode
= aErrorCode
[aIoException
.Code
][1];
325 aArguments
.push_back(aArgUri
);
328 nErrorCode
= aErrorCode
[aIoException
.Code
][0];
333 handleErrorHandlerRequest(aIoException
.Classification
,
336 rRequest
->getContinuations(),
337 bObtainErrorStringOnly
,