annotate Lib/IMPL/DOM/Schema/Property.pm @ 393:69a1f1508696

minor security refactoring
author cin
date Fri, 14 Feb 2014 16:41:12 +0400
parents 5aff94ba842f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
1 package IMPL::DOM::Schema::Property;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
2 use strict;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
3 use warnings;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
4
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
5 use IMPL::declare {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
6 require => {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
7 Label => 'IMPL::DOM::Schema::Label',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
8 DOMNode => 'IMPL::DOM::Node',
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
9 ValidationError => 'IMPL::DOM::Schema::ValidationError'
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
10 },
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
11 base => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
12 'IMPL::DOM::Schema::SimpleNode' => sub {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
13 my %args = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
14
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
15 $args{maxOccur} = 1;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
16 $args{minOccur} = delete $args{optional} ? 0 : 1;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
17 $args{nodeName} ||= 'Property';
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
18
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
19 return %args;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
20 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
21 ],
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
22 props => [
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
23 messageRequired => { get => 1, set => 1, dom => 1 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
24 ]
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
25 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
26
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
27 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
28 my ($this,%args) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
29
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
30 $this->messageRequired($args{messageRequired} || 'A property %schemaNode.name% is required in the %node.qname%');
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
33 sub Validate {
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
34 my ($this,$node,$ctx) = @_;
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
35
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
36 my $nodeValue = $node->nodeProperty($this->name);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
37
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
38 if (length $nodeValue) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
39 # we have a value so validate it
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
40
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
41 # buld a pseudo node for the property value
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
42 my $nodeProp = DOMNode->new(nodeName => '::property', nodeValue => $nodeValue);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
43
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
44 return $this->SUPER::Validate($nodeProp);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
45
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
46 } elsif($this->minOccur) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 165
diff changeset
47 # we don't have a value but it's a mandatory property
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
48 return ValidationError->new(
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
49 message => $this->_MakeLabel($this->messageRequired),
236
2904da230022 DOM refactoring
sergey
parents: 194
diff changeset
50 node => $node,
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
51 schemaNode => $this
103
c289ed9662ca Schema beta 2
wizard
parents: 101
diff changeset
52 );
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
53 }
104
196bf443b5e1 DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents: 103
diff changeset
54 return ();
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
55 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
56
389
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
57 sub _MakeLabel {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
58 my ($this,$label) = @_;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
59
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
60 if ($label =~ /^ID:(\w+)$/) {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
61 return Label->new($this->document->stringMap, $1);
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
62 } else {
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
63 return $label;
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
64 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
65 }
5aff94ba842f DOM Schema refactoring complete
cin
parents: 381
diff changeset
66
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 25
diff changeset
67 1;