Asiri Rathnayake wrote:
On Wed, Nov 5, 2008 at 8:54 AM, Sergiu Dumitriu <[email protected]> wrote:
asiri (SVN) wrote:
Author: asiri Date: 2008-11-04 11:31:26 +0100 (Tue, 04 Nov 2008) New Revision: 13949 + private void filter(Node node) + { + if (node.hasAttributes()) { + try { + node.getAttributes().removeNamedItem("style"); + } catch (DOMException ex) { + // Not a problem. + } + }
I don't like this... try-catch code is costly, since creating an exception takes a lot of time and memory. Can't you check if the 'style' attribute exists instead?
Fixed with :
<code>
if (node.hasAttributes() && node.getAttributes().getNamedItem("style") != null) {
Isn't there a hasAttribute(attributeName) method? Just asking because this method exists in the DOM Level 2 Core specification. See http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-ElHasAttr
try { node.getAttributes().removeNamedItem("style"); } catch (DOMException ex) { // Should not occur. } }
</code>
And a catch block in general should indicate an exceptional execution, not a normal, expected case.
Agreed.
Thanks.
- Asiri
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs