[
https://issues.apache.org/jira/browse/SHINDIG-340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603171#action_12603171
]
Kevin Brown commented on SHINDIG-340:
-------------------------------------
Sorry for not being clear.
I think you can simplify your patch a lot by adding this ctor to MessageBundle
public MessageBundle(Element element) {
messages = extractMessages(element);
}
Modify the existing one as follows:
public MessageBundle(URI url, String xml) throws SpecParserException {
Element doc;
try {
doc = XmlUtil.parse(xml);
} catch (XmlException e) {
throw new SpecParserException("Malformed XML in file " + url.toString()
+ ": " + e.getMessage());
}
messages = extractMessages(doc);
}
}
and add this method (moving the functionality out of the existing ctor):
private Map<String, String> extractMessages(Element doc) {
NodeList nodes = doc.getElementsByTagName("msg");
Map<String, String> messages
= new HashMap<String, String>(nodes.getLength(), 1);
for (int i = 0, j = nodes.getLength(); i < j; ++i) {
Element msg = (Element)nodes.item(i);
String name = XmlUtil.getAttribute(msg, "name");
if (name == null) {
throw new SpecParserException(
"All message bundle entries must have a name attribute.");
}
messages.put(name, msg.getTextContent().trim());
}
return Collections.unmodifiableMap(messages);
}
This would allow LocaleSpec's ctor to simply do:
if (messages == null) {
this.messages = URI.create("");
this.messageBundle = new MessageBundle(element);
}
All told, it's about half as much code change as would be required in the
current patch.
Does that make sense?
I can go ahead and apply it with this modification if you'd like. The rest of
the patch looks great.
> Support msg elements as children of Locale elements
> ---------------------------------------------------
>
> Key: SHINDIG-340
> URL: https://issues.apache.org/jira/browse/SHINDIG-340
> Project: Shindig
> Issue Type: Sub-task
> Reporter: Kevin Brown
> Assignee: Kevin Brown
> Attachments: new-feature-SHINDIG-340.patch
>
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.