# HG changeset patch # User wizard # Date 1285199923 -14400 # Node ID 1e7f03414b65f726f89b0561bf463ac899f5a115 # Parent e36ffd8c29dbeb65a150c9c643421e54a1abc142 DOM: schema improvements DOM: saving to XML::Writer feature diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Document.pm --- a/Lib/IMPL/DOM/Document.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Document.pm Thu Sep 23 03:58:43 2010 +0400 @@ -31,6 +31,14 @@ ); } +sub save { + my ($this,$writer) = @_; + + $writer->xmlDecl(undef,'yes'); + $this->SUPER::save($writer); + $writer->end(); +} + { my $empty; sub Empty() { @@ -96,6 +104,19 @@ =end code +=item C< save($writer) > + +Сохраняет документ в виде XML узла и вызывает C<< $writer->end() >>. + +=over + +=item C<$writer> + +Объект с интерфейсом C который будет использован для записи +содержимого документа + +=back + =back =cut diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Node.pm --- a/Lib/IMPL/DOM/Node.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Node.pm Thu Sep 23 03:58:43 2010 +0400 @@ -317,7 +317,7 @@ } sub _getIsComplex { - $_[0]->childNodes->Count ? 1 : 0; + ($_[0]->{$childNodes} and $_[0]->{$childNodes}->Count) ? 1 : 0; } sub _updateDocRefs { @@ -392,6 +392,33 @@ return (keys %props,keys %{$this->{$_propertyMap}}); } +sub save { + my ($this,$writer) = @_; + + if ( not ( $this->isComplex or defined $this->{$nodeValue} ) ) { + $writer->emptyTag( + $this->{$nodeName}, + map { + $_, + $this->nodeProperty($_) + } grep defined $this->nodeProperty($_), $this->listProperties + ); + } else { + $writer->startTag( + $this->{$nodeName}, + map { + $_, + $this->nodeProperty($_) + } grep defined $this->nodeProperty($_), $this->listProperties + ); + $writer->characters($this->{$nodeValue}) if $this->{$nodeValue}; + + $_->save($writer) foreach $this->childNodes; + + $writer->endTag($this->{$nodeName}); + } +} + sub qname { $_[0]->{$nodeName}; } diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema.pm --- a/Lib/IMPL/DOM/Schema.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema.pm Thu Sep 23 03:58:43 2010 +0400 @@ -88,7 +88,8 @@ Navigator => new IMPL::DOM::Navigator::Builder( $class, $class->MetaSchema - ) + ), + SkipWhitespace => 1 ); $reader->ParseFile($file); diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/ComplexType.pm --- a/Lib/IMPL/DOM/Schema/ComplexType.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/ComplexType.pm Thu Sep 23 03:58:43 2010 +0400 @@ -5,10 +5,11 @@ use base qw(IMPL::DOM::Schema::ComplexNode); use IMPL::Class::Property; use IMPL::Class::Property::Direct; +use IMPL::DOM::Property qw(_dom); BEGIN { - public _direct property nativeType => prop_get; - public _direct property messageWrongType => prop_get; + public _dom _direct property nativeType => prop_get; + public _dom _direct property messageWrongType => prop_get; } our %CTOR = ( diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/Node.pm --- a/Lib/IMPL/DOM/Schema/Node.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/Node.pm Thu Sep 23 03:58:43 2010 +0400 @@ -8,13 +8,13 @@ use IMPL::Class::Property::Direct; BEGIN { - public _direct property minOccur => prop_all; - public _direct property maxOccur => prop_all; - public _direct property type => prop_all; - public _direct property name => prop_all; - public _direct property display => prop_all; - public _direct property display_no => prop_all; - public _direct property display_blame => prop_all; + public _dom _direct property minOccur => prop_all; + public _dom _direct property maxOccur => prop_all; + public _dom _direct property type => prop_all; + public _dom _direct property name => prop_all; + public _dom _direct property display => prop_all; + public _dom _direct property display_no => prop_all; + public _dom _direct property display_blame => prop_all; } our %CTOR = ( diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/NodeList.pm --- a/Lib/IMPL/DOM/Schema/NodeList.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/NodeList.pm Thu Sep 23 03:58:43 2010 +0400 @@ -4,6 +4,7 @@ use base qw(IMPL::DOM::Node); use IMPL::Class::Property; +use IMPL::DOM::Property qw(_dom); require IMPL::DOM::Schema::ValidationError; our %CTOR = ( @@ -11,8 +12,8 @@ ); BEGIN { - public property messageUnexpected => prop_all; - public property messageNodesRequired => prop_all; + public _dom property messageUnexpected => prop_all; + public _dom property messageNodesRequired => prop_all; } sub CTOR { diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/NodeSet.pm --- a/Lib/IMPL/DOM/Schema/NodeSet.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/NodeSet.pm Thu Sep 23 03:58:43 2010 +0400 @@ -4,15 +4,16 @@ use base qw(IMPL::DOM::Node); use IMPL::Class::Property; +use IMPL::DOM::Property qw(_dom); our %CTOR = ( 'IMPL::DOM::Node' => sub { nodeName => 'NodeSet' } ); BEGIN { - public property messageUnexpected => prop_all; - public property messageMax => prop_all; - public property messageMin => prop_all; + public _dom property messageUnexpected => prop_all; + public _dom property messageMax => prop_all; + public _dom property messageMin => prop_all; } sub CTOR { diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/Property.pm --- a/Lib/IMPL/DOM/Schema/Property.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/Property.pm Thu Sep 23 03:58:43 2010 +0400 @@ -6,11 +6,12 @@ require IMPL::DOM::Schema; require IMPL::DOM::Node; use IMPL::Class::Property; +use IMPL::DOM::Property qw(_dom); __PACKAGE__->PassThroughArgs; BEGIN { - public property messageRequired => prop_all; + public _dom property messageRequired => prop_all; } our %CTOR = ( diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/SimpleNode.pm --- a/Lib/IMPL/DOM/Schema/SimpleNode.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/SimpleNode.pm Thu Sep 23 03:58:43 2010 +0400 @@ -5,10 +5,11 @@ use base qw(IMPL::DOM::Schema::Node); use IMPL::Class::Property; use IMPL::Class::Property::Direct; +use IMPL::DOM::Property qw(_dom); BEGIN { - public _direct property inflator => prop_get; - public _direct property messageInflateError => prop_get; + public _dom _direct property inflator => prop_get; + public _dom _direct property messageInflateError => prop_get; } our %CTOR = ( @@ -23,8 +24,10 @@ sub CTOR { my ($this,%args) = @_; - $this->{$inflator} = $args{inflator} if $args{inflator}; - $this->{$messageInflateError} = $args{messageInflateError} || 'Failed to inflate nodeValue %Node.path%: %Error%'; + if ( $args{inflator} ) { + $this->{$inflator} = $args{inflator} ; + $this->{$messageInflateError} = exists $args{messageInflateError} ? $args{messageInflateError} : 'Failed to inflate nodeValue %Node.path%: %Error%'; + } } sub Validate { diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/SimpleType.pm --- a/Lib/IMPL/DOM/Schema/SimpleType.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/SimpleType.pm Thu Sep 23 03:58:43 2010 +0400 @@ -5,10 +5,11 @@ use base qw(IMPL::DOM::Schema::SimpleNode); use IMPL::Class::Property; use IMPL::Class::Property::Direct; +use IMPL::DOM::Property qw(_dom); BEGIN { - public _direct property nativeType => prop_get; - public _direct property messageWrongType => prop_get; + public _dom _direct property nativeType => prop_get; + public _dom _direct property messageWrongType => prop_get; } our %CTOR = ( diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Schema/SwitchNode.pm --- a/Lib/IMPL/DOM/Schema/SwitchNode.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Schema/SwitchNode.pm Thu Sep 23 03:58:43 2010 +0400 @@ -5,6 +5,7 @@ use base qw(IMPL::DOM::Schema::AnyNode); use IMPL::Class::Property; require IMPL::DOM::Schema::ValidationError; +use IMPL::DOM::Property qw(_dom); our %CTOR = ( 'IMPL::DOM::Schema::AnyNode' => sub { @@ -17,7 +18,7 @@ ); BEGIN { - public property messageNoMatch => prop_all; + public _dom property messageNoMatch => prop_all; } sub CTOR { diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/Transform/PostToDOM.pm --- a/Lib/IMPL/DOM/Transform/PostToDOM.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm Thu Sep 23 03:58:43 2010 +0400 @@ -75,7 +75,7 @@ my $prefix = $this->prefix; foreach my $param (grep index($_,$prefix) >= 0 , $query->param()) { - my $value = $query->param($param) or next; + defined (my $value = $query->param($param)) or next; my @parts = split /\//,$param; diff -r e36ffd8c29db -r 1e7f03414b65 Lib/IMPL/DOM/XMLReader.pm --- a/Lib/IMPL/DOM/XMLReader.pm Fri Aug 20 16:33:37 2010 +0400 +++ b/Lib/IMPL/DOM/XMLReader.pm Thu Sep 23 03:58:43 2010 +0400 @@ -14,6 +14,7 @@ BEGIN { public _direct property Navigator => prop_get | owner_set; + public _direct property SkipWhitespace => prop_get | owner_set; private _direct property _current => prop_all; private _direct property _text => prop_all; private _direct property _textHistory => prop_all; @@ -57,7 +58,7 @@ sub _OnEnd { my ($this,$element) = @_; - $this->{$_current}->nodeValue($this->Navigator->inflateValue( $this->{$_text} ) ) if length $this->{$_text}; + $this->{$_current}->nodeValue($this->Navigator->inflateValue( $this->{$_text} ) ) if length $this->{$_text} and (not $this->{$SkipWhitespace} or $this->{$_text} =~ /\S/); $this->{$_text} = pop @{$this->{$_textHistory}}; $this->{$_current} = $this->Navigator->Back; }