You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2005/11/15 23:32:17 UTC

Validation of SVG elements

Hello,

     This question is related to the DOM Editor.  What I've noticed is
that if I put an invalid value for a particular attribute, the
JSVGCanvas returns an error when I try to render it.  Instead of
implementing validation for each and every possible attribute, is there
a way I can:

 

-          Take the changed node and "check" it against Batik.  (Like
whatever the JSVGCanvas does when it tries to render)

-          Revert to the original value if the check fails, otherwise
keep the new value.

 

I'd like to "trap" the error before I even attempt to render it and
simply revert the JTable data instead of a nasty pop-up (or a few) when
I submit invalid values to the element/node in question.

 

Michael Bishop


Re: Validation of SVG elements

Posted by th...@kodak.com.
Hi Michael,

"Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> wrote on 
11/15/2005 05:32:17 PM:

>      This question is related to the DOM Editor.  What I’ve noticed is 
that if
> I put an invalid value for a particular attribute, the JSVGCanvas 
returns an 
> error when I try to render it.  Instead of implementing validation for 
each 
> and every possible attribute, is there a way I can:
> 
> -          Take the changed node and “check” it against Batik.  (Like 
whatever
> the JSVGCanvas does when it tries to render)
> -          Revert to the original value if the check fails, otherwise 
keep the new value.

   The easiest way to do this would be to have a private 'GVTBuilder' 
clone the element (this is a little dicey as you don't really 
want to clone the whole tree, but for some elements like, 
patterns/gradients you need the whole tree, you might do a tree 
clone except for some 'known' elements like 'g', 'defs', 'svg'), 
make the change to the clone, and use the GVTBuilder with the clone 
to 'build' a graphics node. If this does not throw an error then 
you should be Ok to make the change to the real element.

   This is all "in theory" so there may be blockers that I don't
see just thinking about it.

> I’d like to “trap” the error before I even attempt to render it and 
simply 
> revert the JTable data instead of a nasty pop-up (or a few) when I 
submit 
> invalid values to the element/node in question.

   The other option would be to replace the UserAgent (the class that 
puts up the dialogs) for the Canvas so you can check if you are in the 
middle of updating an element from the DOMViewer and if so don't show
the error and roll back the element.  This could be a little simpler but 
I'd be a little nervous that there would be some ugliness in the display.