[
http://jira.nuxeo.org/browse/NXP-2066?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Stéfane Fermigier updated NXP-2066:
-----------------------------------
Fix Version/s: (was: 5.2 M2)
5.2 M3
> I18N implementation for the exceptions
> --------------------------------------
>
> Key: NXP-2066
> URL: http://jira.nuxeo.org/browse/NXP-2066
> Project: Nuxeo Enterprise Platform
> Issue Type: Improvement
> Components: Web UI
> Affects Versions: 5.1.3
> Reporter: Radu Darlea
> Assignee: Radu Darlea
> Fix For: 5.1.6, 5.2 M3
>
> Original Estimate: 1 day
> Remaining Estimate: 1 day
>
> The problem arose subsequent to some project specific requests. The idea is
> to have localized messages in the popups in the UI.
> Currently, there is no implementation for
> ClientException.getLocalizedMessage() and even if it is used in the UI
> controls, it falls to plain getMessage() method.
> The toughness of the problem is to pass the map of localized messages to the
> Exception in order to implement the getLocalizedMessage() method. I tried
> this using ThreadLocale, but I feel it is not a good solution, as
> ThreadLocale could be used for other purposes also (authentication?).
> So, the only way I see is to set the map of messages prior calling
> getLocalizedMessages() wherever appropriate.
> To add the code in ClientException:
> protected String id = null;
> protected List<Object> params = null;
> private Map<String, String> messages = null;
> @Override
> public String getLocalizedMessage() {
> if (messages == null || id == null) return getMessage();
> String text = messages.get(id);
> if (text == null) return getMessage();
> String ret = String.format(text, params) + huntCauses(getCause());
> return ret;
> }
> public void setId(String id) {
> this.id = id;
> }
> public void setParams(List<Object> params) {
> this.params = params;
> }
> public void setMessages(Map<String, String> messages) {
> this.messages = messages;
> }
> protected String huntCauses(Throwable e) {
> if (e == null) {
> return null;
> }
> String ret = ": ";
> if (e instanceof ClientException) {
> ((ClientException) e).setMessages(messages);
> return ret + e.getLocalizedMessage();
> }
> return ret + e.getLocalizedMessage() + huntCauses(e.getCause());
> }
> In order to use this feature, one should:
> i. set the id to the appropriate key in messages.properties prior throwing
> the exception (and also set parameters if required)
> The code would look like
> } catch (DocumentException e) {
> ClientException ce = new ClientException("Failed to move
> document: "
> + e.getMessage(), e);
> ce.setId("<message id here>");
> throw ce;
> }
> instead of
> } catch (DocumentException e) {
> throw new ClientException("Failed to move document: "
> + e.getMessage(), e);
> }
> ii. when the localized message is required, one should replace the current
> code
> catch (Throwable t) {
> return MOVE_ERROR + t.getLocalizedMessage();
> }
> with something like
> } catch (ClientException ce) {
> ce.setMessages(resourcesAccessor.getMessages());
> return MOVE_ERROR + ce.getLocalizedMessage();
> } catch (Throwable t) {
> return MOVE_ERROR + t.getLocalizedMessage();
> }
> I have the feeling that not only ClientException, but also CoreException and
> possible others have to be patched.
> Also, the code would suffer a quite big refactoring. Although it should be
> safe (if getLocalizedMessage() fails in its quest, just falls back to
> getMessage()), it won't be easy to convert all occurrences, but at least
> having the frame in place we'll have a chance to correct the messages on the
> fly.
> Other comments:
> "But I am not so sure that the UI messages (including the one displayed by JS
> or the browser plugin) should all be based on Exception management ... (I may
> be wrong)."
> Thierry
> "From a global point of view, I'm fine with error messages sent by the
> application when an error occur.
> I would prefer plan this when we will refactor the exception management
> infrastructure of the platform"
> Eric
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.nuxeo.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
ECM-tickets mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm-tickets