Mercurial > pub > Impl
changeset 15:16795016e70b
Dom schema in progress
author | Sergey |
---|---|
date | Mon, 07 Sep 2009 17:30:55 +0400 |
parents | 65a7bb156fb7 |
children | 75d55f4ee263 |
files | Lib/IMPL/DOM/Document.pm Lib/IMPL/DOM/Navigator/Builder.pm Lib/IMPL/DOM/Schema.pm _test/Resources/form.schema _test/Resources/test.schema |
diffstat | 5 files changed, 165 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/DOM/Document.pm Mon Sep 07 17:30:55 2009 +0400 @@ -0,0 +1,29 @@ +package IMPL::DOM::Document; +use strict; +use warnings; + +use base qw(IMPL::DOM::Node); + +__PACKAGE__->PassThroughArgs; + +sub Create { + my ($this,$nodeName,$class,$refProps) = @_; + + $refProps ||= {}; + + return $class->new( + nodeName => $nodeName, + %$refProps + ); +} + +1; +__END__ + +=pod + +=head1 DESCRIPTION + + . + +=cut \ No newline at end of file
--- a/Lib/IMPL/DOM/Navigator/Builder.pm Fri Sep 04 16:38:15 2009 +0400 +++ b/Lib/IMPL/DOM/Navigator/Builder.pm Mon Sep 07 17:30:55 2009 +0400 @@ -11,7 +11,9 @@ public _direct property Document => prop_get | owner_set; } -__PACKAGE__->PassThroughArgs; +our %CTOR = ( + 'IMPL::DOM::Navigator' => sub { $_[0] } # IMPL::DOM::Navigator($domDocument) +); sub CTOR { my ($this,$domDocument,$schema) = @_; @@ -24,9 +26,9 @@ my ($this,$nodeName,%props) = @_; if ( my $nodeSchema = $this->{$_navigatorSchema}->Navigate(sub { $_[0]->nodeName eq $nodeName or $_[0]->isa('IMPL::DOM::Schema::AnyNode') }) ) { - my $class = $nodeSchema->type; + my $class = delete $props{type} || $nodeSchema->type || $nodeName; - my $node = $this->{$Document}->Create($nodeName, $class, \%props); + my $node = $this->{$Document}->Create(delete $props{nodeName} || $nodeName, $class, \%props); $this->Current()->appendNode($node); $this->Current($node); @@ -36,4 +38,65 @@ } } +sub Back { + my ($this) = @_; + + $this->{$_navigatorSchema}->Back; + return $this->SUPER::Back(); +} + 1; + +__END__ +=pod + +=head1 SYNOPSIS + +my $builder = new IMPL::DOM::Navigator::Builder(new MyApp::Document,$schema); +my $reader = new IMPL::DOM::XMLReader(Navigator => $builder); + +$reader->ParseFile("document.xml"); + +my @errors = $schema->Validate($builder->Document); + +=head1 DESCRIPTION + + DOM . + C<IMPL::DOM::XMLReader>. + +=head1 METHODS + +=over + +=item C<CTOR($domDocument,$schema)> + + , ( ) +. + +=item C<< $obj->NavigateCreate($nodeName) >> + + . + , . + + , + , + +=over + +=item C<type> , + +=item C<type> , , + . + +=item + +=back + + C<nodeName>. + +.. C<< <ComplexNode nodeName="Box" type="Container"> >> + C<< Container->new(nodeName => 'Box') >>. + +=back + +=cut \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/IMPL/DOM/Schema.pm Mon Sep 07 17:30:55 2009 +0400 @@ -0,0 +1,15 @@ +package IMPL::DOM::Schema; +use strict; +use warnings; + +use base qw(IMPL::DOM::Document); +use IMPL::Class::Property; +use IMPL::Class::Property::Direct; + +__PACKAGE__->PassThroughArgs; + +BEGIN { + private _direct property _TypesMap => prop_all; +} + +1;
--- a/_test/Resources/form.schema Fri Sep 04 16:38:15 2009 +0400 +++ b/_test/Resources/form.schema Mon Sep 07 17:30:55 2009 +0400 @@ -2,28 +2,57 @@ <schema> <Include src="forms.schema"/> <Form - dataObject="App::Data::User" + type="Form" dataPolicy="AddOrUpdate" - messageMin="Вы не заполнили %Node.formLabel.%" + dataType="App::Data::User" + messageMin="Вы не заполнили %Node.formLabel_blame%" > - <EditBox nodeName="Name" + <Name formLabel="Имя" - formLabel.blame="имя" - formLabel.no="имени" + formLabel_blame="имя" + formLabel_no="имени" + type="EditBox" /> - <EditBox nodeName="Nick" + <!-- Опциональный элемент --> + <Nick formLabel="Прозвище" - formLabel.no="прозвища" + formLabel_no="прозвища" minOccur="0" + type="EditBox" > <RegExp>\w{4,10}</RegExp> - </EditBox> - <ListBox nodeName="Role" - dataObject="App::Data::Role" + </Nick> + <Role + dataType="App::Data::Role" dataSource="roles" formLabel="Роль" - formLabel.blame="роль" + formLabel_blame="роль" + type="MultiSelect" + maxOccur="unbounded" /> + <Contacts + minOccur="0" + maxOccur="unbounded" + formLabel="Контакты" + dataType="App::Data::Contacts" + type="Container" + > + <NodeSet> + <EMail + type="EditBox" + minOccur="0" + formLabel="Эл. почта" + formLabel_no="эл. почты" + /> + <Phone + type="EditBox" + minOccur="0" + formLabel="Телефон" + formLabel_no="телефона" + /> + </NodeSet> + </Contacts> </Form> + </schema>
--- a/_test/Resources/test.schema Fri Sep 04 16:38:15 2009 +0400 +++ b/_test/Resources/test.schema Mon Sep 07 17:30:55 2009 +0400 @@ -4,6 +4,21 @@ <!-- Загрузка фрагмента схемы --> <Include src="basic.types.schema"/> + <!-- Определения типов --> + <SimpleType type="DateTime"> + <Regexp>\d{4}-\d{2}-\d{2}((T|\s)\d{2}\:\d{2}:\d{2})?</Regexp> + </SimpleType> + <ComplexType type="Person"> + <NodeSet> + <SimpleNode nodeName="FirstName"/> + <SimpleNode nodeName="LastName"/> + <ComplexNode maxOccur="unbounded" nodeName="Passport" type="Passport"> + <Node nodeName="DateExpire" type="DateTime"/> + <SimpleNode nodeName="Code"/> + </ComplexNode> + </NodeSet> + </ComplexType> + <!-- Содержимое возможные варианты для документов--> <ComplexNode nodeName="Form"> <NodeSet> @@ -23,7 +38,4 @@ </ComplexNode> </NodeSet> </ComplexNode> - <Type typeName="DateTime" deriveFrom="SimpleNode"> - <Regexp>\d{4}-\d{2}-\d{2}((T|\s)\d{2}\:\d{2}:\d{2})?</Regexp> - </Type> </schema> \ No newline at end of file