Re: [Catalyst] XSD Validation of Forms

2009-08-13 Thread Alejandro Imass
Ok, this is what I do, so to spark some ideas. I can't disclose many
details because of legal issues but generally speaking
XXXLIB is a special module (can't disclose it's name) where all the
XML stuff is done. It uses LibXML as backend (gnome libxml2 via XS).
xxxapp is the app name
xxx_xsd is the XSD file

1) Figure out if the request is HTML or XML. Note XHTML is considered as HTML.

sub xxxmethod : Local {
  my ( $self, $c ) = @_;

  # figure out request type (html | xml)
  $c-forward('get_req_type');

  # xml lib object
  my $dx = xxxapp::Controller::Util::XXXLIB-new(
encoding = $c-stash-{encoding},
schema = $c-config-{root}.$c-config-{xxx_xsd},
  );

2) Process the request data. If it's XML is goes directly. If it's
HTML is goes through an HTML param to XML conversion. Perhaps by using
XFORMS and making XHTML mandatory I could have simplified the code
even more.

  # process request data
  my $req_data = undef;

  # these couple of methods validate xml using the xsd

  # xml request is processed directly by the xml parser
  if($c-stash-{xmlreq}) {
$req_data = $dx-process_omreq_xml($c-req-body,'xxxmethod');
  }
  # html request is converted into equivalent xml
  else{
# transforms params into a simple xml
$req_data = $dx-process_omreq_html($c-req-params,'xxxmethod');
  }

  # data did not pass check
  unless($req_data){
$c-stash-{error} = $dx-{error};
# code injection check
unless($dx-{inject}){
  $c-stash-{form_action} = $c-request-base.'xxxcont/xxxmethod';
  $c-detach('exception/omx/0');
}
else{
  $c-stash-{form_action} = '';
  $c-detach('exception/sys/1');
}
  }

3) From here on $req_data is a normalized hash... and that's it!

[snip]

} # end of controller method


sub get_req_type : Private {
  my ( $self, $c ) = @_;
  my $encoding = $c-req-content_encoding;
  # assume UTF-8 if not specified (application/x-www-form-urlencoded)
  $c-stash-{encoding} = $encoding ? $encoding : 'UTF-8';
  $c-stash-{xmlreq} = undef;
  my $ct = $c-req-content_type;
  # XML Request
  if($ct =~ m/text\/xml/i){
my $dx = cqridmp::Controller::Util::XXXLIB-new(encoding =
$c-stash-{encoding});
my $dom = $dx-slurp_file($c-req-body);
my $root = $dom-documentElement;
#XHTML is HTML
unless($root-nodeName =~ /.*html.*/i){
  $c-stash-{xmlreq} = 1;
}
  }
}



On Tue, Aug 11, 2009 at 8:36 PM, Chrishutchinson.ch...@gmail.com wrote:
 My comment was perhaps more oriented to using a common declarative
 validation idiom such as an xml schema because with this particular
 project, I found myself maintaining FormBuilder YAML files and XSDs.
 Then I decided to convert HTML to XML and use the common XSD for both.
 Since most decent XML parsers already perform the validation, and they
 are usually quite fast, I thought that perhaps something similar to
 the FormBuilder plug-in could be built that used an XML approach.


 I like the idea of a single 'base format' which can be used to drive
 the validation and the form layout too.

 Is your scheme a format which, when rendered as html, defines the form
 and, when parsed appropriately, provides the form validation too?

 As in:
 form
  input type=text id=abc format=integer /br /
  input type=submit /
 /form

 - Chris

 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] XSD Validation of Forms

2009-08-12 Thread John Napiorkowski




- Original Message 
 From: Chris hutchinson.ch...@gmail.com
 To: The elegant MVC web framework catalyst@lists.scsys.co.uk
 Sent: Tuesday, August 11, 2009 8:36:22 PM
 Subject: Re: [Catalyst] XSD Validation of Forms
 
  My comment was perhaps more oriented to using a common declarative
  validation idiom such as an xml schema because with this particular
  project, I found myself maintaining FormBuilder YAML files and XSDs.
  Then I decided to convert HTML to XML and use the common XSD for both.
  Since most decent XML parsers already perform the validation, and they
  are usually quite fast, I thought that perhaps something similar to
  the FormBuilder plug-in could be built that used an XML approach.
 
 
 I like the idea of a single 'base format' which can be used to drive
 the validation and the form layout too.

I think the mozilla people did something with XUL... maybe we can leverage that 
stuff?

I've done a few firefox plugins and really thought the way it's internal 
templating worked
was quite elegant.  I'd love something similar for Catalyst.  The way overlays 
worked,
for example fit my brain a lot better than the way we generally use includes in 
TT.

 
 Is your scheme a format which, when rendered as html, defines the form
 and, when parsed appropriately, provides the form validation too?
 
 As in:
 

 

 
 
 
 - Chris
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/



  

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] XSD Validation of Forms

2009-08-11 Thread Alejandro Imass
Great input and insight, thanks!

My comment was perhaps more oriented to using a common declarative
validation idiom such as an xml schema because with this particular
project, I found myself maintaining FormBuilder YAML files and XSDs.
Then I decided to convert HTML to XML and use the common XSD for both.
Since most decent XML parsers already perform the validation, and they
are usually quite fast, I thought that perhaps something similar to
the FormBuilder plug-in could be built that used an XML approach.

I find your comments on JSON and model-to-DB very interesting but
don't agree with all of it. I think that sane RDBMS modeling is still
not going away for a while.

regarding REST take a look at this project I'm working on and that is
Catalyst-based:

http://www.p2ee.org

Cheers,
Alejandro Imass

On Mon, Aug 10, 2009 at 8:17 AM, John Napiorkowskijjn1...@yahoo.com wrote:


 --- On Thu, 8/6/09, Alejandro Imass alejandro.im...@gmail.com wrote:

 From: Alejandro Imass alejandro.im...@gmail.com
 Subject: [Catalyst] XSD Validation of Forms
 To: The elegant MVC web framework catalyst@lists.scsys.co.uk
 Date: Thursday, August 6, 2009, 12:15 PM
 I did something cool these days for a
 client and was thinking that
 perhaps might be a cool plugin for Catalyst.

 I created a B2B app for a client that has both HTML and XML
 API. So I
 decided to convert the HTML/XHTML requests to XML, the same
 XML format
 as the XML API and validate both with the same XSD.
 Laziness, of
 course, of having to maintain an HTML field validation
 scheme PLUS an
 XSD validation scheme using LibXML. Hope you're following
 me here...

 So, it occurred to me that perhaps XSD validations can be
 perhaps more
 useful and powerful than Formbuilder's declarative
 validation oin
 yaml.

 I did  an xforms based project a few years ago and enjoyed working with the 
 system but unfortunately true xforms support has lagged in all the browsers.  
 There are plugins but nothing native.  I think most people have settled on a 
 'best 80%' of features via ajax style libs.  submitting forms via json is a 
 somewhat similar approach, although not as clean as the xforms approach, but 
 at least it works.

 I do think the best approach is going to end up being similar to the way we 
 deploy and use DBIx::Class, where we generally first model in Perl and then 
 deploy to the target database engine.  In other words you model your user 
 interface expectations and then render the type you want.  I this this is 
 going to be more flexible than systems that validate the other way around.


 Does anyone here think this might be interesting? Maybe it
 already
 exists, but the whole thing came out so cool, that I
 thought it might
 be useful for the Catalyst / Perl world in general.

 Although Perl has pretty good XML support, with multiple parsers, both DOM 
 and SAX based, there doesn't seem to be strong excitement around it.  I don't 
 think most of the developers around here like XML based configuration files 
 (think they are too verbose) and you don't see a lot of love for XSLT or 
 similar.  Again, I think it's about pragmatism, where JSON approaches get you 
 most of the way for less effort.  Also the XML camps seem to be somewhat 
 offish to the Perl community.  Maybe it's just me but seems like all the 
 examples are Python or Java.  There's a certain amount of academia driving 
 XML, or big enterprises, and both groups tend to treat the Perl programming 
 language as something left over rather than something to be excited about.

 Axkit is a web development system that's totally XML driven, you might want 
 to take a look.  Also part of your interest might fit well with the various 
 REST projects going on.  I think if you're approach is that XML is the 
 transport rather than the framework you'd get more interest.


 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/





 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] XSD Validation of Forms

2009-08-11 Thread Chris
 My comment was perhaps more oriented to using a common declarative
 validation idiom such as an xml schema because with this particular
 project, I found myself maintaining FormBuilder YAML files and XSDs.
 Then I decided to convert HTML to XML and use the common XSD for both.
 Since most decent XML parsers already perform the validation, and they
 are usually quite fast, I thought that perhaps something similar to
 the FormBuilder plug-in could be built that used an XML approach.


I like the idea of a single 'base format' which can be used to drive
the validation and the form layout too.

Is your scheme a format which, when rendered as html, defines the form
and, when parsed appropriately, provides the form validation too?

As in:
form
 input type=text id=abc format=integer /br /
 input type=submit /
/form

- Chris

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] XSD Validation of Forms

2009-08-10 Thread John Napiorkowski


--- On Thu, 8/6/09, Alejandro Imass alejandro.im...@gmail.com wrote:

 From: Alejandro Imass alejandro.im...@gmail.com
 Subject: [Catalyst] XSD Validation of Forms
 To: The elegant MVC web framework catalyst@lists.scsys.co.uk
 Date: Thursday, August 6, 2009, 12:15 PM
 I did something cool these days for a
 client and was thinking that
 perhaps might be a cool plugin for Catalyst.
 
 I created a B2B app for a client that has both HTML and XML
 API. So I
 decided to convert the HTML/XHTML requests to XML, the same
 XML format
 as the XML API and validate both with the same XSD.
 Laziness, of
 course, of having to maintain an HTML field validation
 scheme PLUS an
 XSD validation scheme using LibXML. Hope you're following
 me here...
 
 So, it occurred to me that perhaps XSD validations can be
 perhaps more
 useful and powerful than Formbuilder's declarative
 validation oin
 yaml.

I did  an xforms based project a few years ago and enjoyed working with the 
system but unfortunately true xforms support has lagged in all the browsers.  
There are plugins but nothing native.  I think most people have settled on a 
'best 80%' of features via ajax style libs.  submitting forms via json is a 
somewhat similar approach, although not as clean as the xforms approach, but at 
least it works.

I do think the best approach is going to end up being similar to the way we 
deploy and use DBIx::Class, where we generally first model in Perl and then 
deploy to the target database engine.  In other words you model your user 
interface expectations and then render the type you want.  I this this is going 
to be more flexible than systems that validate the other way around.

 
 Does anyone here think this might be interesting? Maybe it
 already
 exists, but the whole thing came out so cool, that I
 thought it might
 be useful for the Catalyst / Perl world in general.

Although Perl has pretty good XML support, with multiple parsers, both DOM and 
SAX based, there doesn't seem to be strong excitement around it.  I don't think 
most of the developers around here like XML based configuration files (think 
they are too verbose) and you don't see a lot of love for XSLT or similar.  
Again, I think it's about pragmatism, where JSON approaches get you most of the 
way for less effort.  Also the XML camps seem to be somewhat offish to the Perl 
community.  Maybe it's just me but seems like all the examples are Python or 
Java.  There's a certain amount of academia driving XML, or big enterprises, 
and both groups tend to treat the Perl programming language as something left 
over rather than something to be excited about.

Axkit is a web development system that's totally XML driven, you might want to 
take a look.  Also part of your interest might fit well with the various REST 
projects going on.  I think if you're approach is that XML is the transport 
rather than the framework you'd get more interest.

 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/
 


  

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] XSD Validation of Forms

2009-08-06 Thread Alejandro Imass
I did something cool these days for a client and was thinking that
perhaps might be a cool plugin for Catalyst.

I created a B2B app for a client that has both HTML and XML API. So I
decided to convert the HTML/XHTML requests to XML, the same XML format
as the XML API and validate both with the same XSD. Laziness, of
course, of having to maintain an HTML field validation scheme PLUS an
XSD validation scheme using LibXML. Hope you're following me here...

So, it occurred to me that perhaps XSD validations can be perhaps more
useful and powerful than Formbuilder's declarative validation oin
yaml.

Does anyone here think this might be interesting? Maybe it already
exists, but the whole thing came out so cool, that I thought it might
be useful for the Catalyst / Perl world in general.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/