changeset 152:1e7f03414b65

DOM: schema improvements DOM: saving to XML::Writer feature
author wizard
date Thu, 23 Sep 2010 03:58:43 +0400
parents e36ffd8c29db
children 3765adf1803f
files Lib/IMPL/DOM/Document.pm Lib/IMPL/DOM/Node.pm Lib/IMPL/DOM/Schema.pm Lib/IMPL/DOM/Schema/ComplexType.pm Lib/IMPL/DOM/Schema/Node.pm Lib/IMPL/DOM/Schema/NodeList.pm Lib/IMPL/DOM/Schema/NodeSet.pm Lib/IMPL/DOM/Schema/Property.pm Lib/IMPL/DOM/Schema/SimpleNode.pm Lib/IMPL/DOM/Schema/SimpleType.pm Lib/IMPL/DOM/Schema/SwitchNode.pm Lib/IMPL/DOM/Transform/PostToDOM.pm Lib/IMPL/DOM/XMLReader.pm
diffstat 13 files changed, 85 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- 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<XML::Writer> который будет использован для записи
+содержимого документа
+
+=back
+
 =back
 
 =cut
--- 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};
 }
--- 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);
--- 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 = (
--- 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 = (
--- 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 {
--- 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 {
--- 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 = (
--- 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 {
--- 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 = (
--- 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 {
--- 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;
 		
--- 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;
 }