comparison Lib/IMPL/DOM/Schema/Validator/Compare.pm @ 266:89179bb8c388

*corrected TTView to handle plain (and undefined) values *added URL generating methods to Application::Action *fixed the compare validatior for schemas
author cin
date Mon, 14 Jan 2013 03:10:06 +0400
parents b8c724f6de36
children 5aff94ba842f
comparison
equal deleted inserted replaced
265:6b6d4b2275a1 266:89179bb8c388
11 public property op => prop_all; 11 public property op => prop_all;
12 public property nodePath => prop_all; 12 public property nodePath => prop_all;
13 public property optional => prop_all; 13 public property optional => prop_all;
14 private property _pathTranslated => prop_all; 14 private property _pathTranslated => prop_all;
15 private property _targetNode => prop_all; 15 private property _targetNode => prop_all;
16 private property _sourceSchema => prop_all;
16 public property message => prop_all; 17 public property message => prop_all;
17 } 18 }
18 19
19 our %CTOR = ( 20 our %CTOR = (
20 'IMPL::DOM::Schema::Validator' => sub { 21 'IMPL::DOM::Schema::Validator' => sub {
66 my $query; 67 my $query;
67 my ($axis,$filter) = ( $chunk =~ /^(?:(\w+):)?(.*)$/); 68 my ($axis,$filter) = ( $chunk =~ /^(?:(\w+):)?(.*)$/);
68 69
69 if ($filter =~ /^\w+|\*$/ ) { 70 if ($filter =~ /^\w+|\*$/ ) {
70 $query = $filter eq '*' ? undef : $filter; 71 $query = $filter eq '*' ? undef : $filter;
71 } elsif ( $filter =~ /^(\w+|\*)\s*((?:\[\s*\w+\s*(?:=|!=|=~|!~|eq|ne|lt|gt|)\s*["'](?:[\\'"]|\\[\\"'])*["']\])+)$/) { 72 } elsif ( $filter =~ /^(\w+|\*)\s*((?:\[\s*\w+\s*(?:=|!=|=~|!~|eq|ne|lt|gt)\s*["'](?:[^\\'"]|\\[\\"'])*["']\])+)$/) {
72 my ($nodeName,$filterArgs) = ($1,$2); 73 my ($nodeName,$filterArgs) = ($1,$2);
74
73 75
74 my @parsedFilters = map { 76 my @parsedFilters = map {
75 my ($prop,$op,$value) = ($_ =~ /\s*(\w+)\s*(=|!=|=~|!~)\s*(["'](?:[\\'"]|\\[\\"'])*["'])/); 77 my ($prop,$op,$value) = ($_ =~ /\s*(\w+)\s*(=|!=|=~|!~|eq|ne|lt|gt)\s*(?:["']((?:[^\\'"]|\\[\\"'])*)["'])/);
78
76 $value =~ s/\\[\\'"]/$1/g; 79 $value =~ s/\\[\\'"]/$1/g;
77 { 80 {
78 prop => $prop, 81 prop => $prop,
79 op => $Ops{$op}, 82 op => $Ops{$op},
80 value => $value 83 value => $value
87 $node->nodeName eq $nodeName or return 0 if $nodeName ne '*'; 90 $node->nodeName eq $nodeName or return 0 if $nodeName ne '*';
88 $_->{op}->( 91 $_->{op}->(
89 _resovleProperty($node,$_->{prop}), 92 _resovleProperty($node,$_->{prop}),
90 FormatMessage($_->{value},{ 93 FormatMessage($_->{value},{
91 Schema => $this->parentNode, 94 Schema => $this->parentNode,
92 Node => $this->_targetNode 95 Node => $this->_targetNode,
96 schema => $this->parentNode,
97 node => $this->_targetNode,
98 source => $this->_sourceSchema
93 },\&_resovleProperty) 99 },\&_resovleProperty)
94 ) or return 0 foreach @parsedFilters; 100 ) or return 0 foreach @parsedFilters;
95 101 return 1;
96 }; 102 };
97 } else { 103 } else {
98 die new IMPL::Exception("Invalid query syntax",$path,$chunk); 104 die new IMPL::Exception("Invalid query syntax",$path,$chunk);
99 } 105 }
100 106
109 sub Validate { 115 sub Validate {
110 my ($this,$node,$ctx) = @_; 116 my ($this,$node,$ctx) = @_;
111 117
112 my @result; 118 my @result;
113 119
120 my $Source = $ctx && $ctx->{Source} || $this->parentNode;
121
122 $this->_sourceSchema($Source);
123
114 $this->_targetNode($node); 124 $this->_targetNode($node);
115 125
116 my $query = $this->_pathTranslated() || $this->_pathTranslated($this->TranslatePath($this->nodePath)); 126 my $query = $this->_pathTranslated() || $this->_pathTranslated($this->TranslatePath($this->nodePath));
117 127
118 my ($foreignNode) = $node->selectNodes(@$query); 128 my ($foreignNode) = $node->selectNodes(@$query);
119 129
120 my $Source = $ctx && $ctx->{Source} || $this->parentNode; 130
121 131
122 if ($foreignNode) { 132 if ($foreignNode) {
123 my $value = $this->nodeValue; 133 my $value = $this->nodeValue;
124 134
125 if ($value) { 135 if ($value) {
145 message => $this->message 155 message => $this->message
146 ); 156 );
147 } 157 }
148 158
149 $this->_targetNode(undef); 159 $this->_targetNode(undef);
160 $this->_sourceSchema(undef);
150 161
151 return @result; 162 return @result;
152 } 163 }
153 164
154 sub _resovleProperty { 165 sub _resovleProperty {