# HG changeset patch # User cin # Date 1390483594 -14400 # Node ID 2f16f13b000c128fc9b14d23ec7cbf9993cb3392 # Parent 99ac2e19c0cc057580647859bd4e643c7c33dadb DOM localization diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/DOM/Schema.pm --- a/Lib/IMPL/DOM/Schema.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/DOM/Schema.pm Thu Jan 23 17:26:34 2014 +0400 @@ -29,10 +29,10 @@ } ], props => [ - _TypesMap => PROP_RW | PROP_DIRECT, + _typesMap => PROP_RW | PROP_DIRECT, baseDir => PROP_RW | PROP_DIRECT, schemaName => PROP_RW | PROP_DIRECT, - BaseSchemas => PROP_RO | PROP_DIRECT, + baseSchemas => PROP_RO | PROP_LIST | PROP_DIRECT, stringMap => { get => '_getStringMap', direct => 1 @@ -44,7 +44,7 @@ #TODO rename and remove sub resolveType { - $_[0]->{$_TypesMap}->{$_[1]} or die IMPL::KeyNotFoundException->new($_[1]); + goto &ResolveType; } sub CTOR { @@ -55,7 +55,18 @@ # compat sub ResolveType { - goto &resolveType + my ($this,$typeName) = @_; + + my $type = $this->{$_typesMap}{$typeName}; + return $type if $type; + + foreach my $base ($this->baseSchemas) { + last if $type = $base->resolveType($typeName); + } + + die IMPL::KeyNotFoundException->new($typeName) + unless $type; + return $this->{$_typesMap}{$typeName} = $type; } sub Create { @@ -81,13 +92,13 @@ my ($this) = @_; return $this->{$stringMap} - if return $this->{$stringMap}; + if $this->{$stringMap}; my $map = StringMap->new(); if ($this->baseDir and $this->schemaName) { $map->paths( File::Spec->catdir($this->baseDir,'locale') ); - $map->name(schemaName); + $map->name( $this->schemaName ); } return $this->{$stringMap} = $map; @@ -100,7 +111,7 @@ $this->Include($_) foreach map $_->nodeProperty('source'), $this->selectNodes('Include'); # build types map - $this->{$_TypesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) }; + $this->{$_typesMap} = { map { $_->type, $_ } $this->selectNodes(sub { $_[0]->nodeName eq 'ComplexType' || $_[0]->nodeName eq 'SimpleType' } ) }; } sub Include { @@ -108,7 +119,7 @@ my $schema = $this->LoadSchema(File::Spec->catfile($this->baseDir, $file)); - $this->appendRange( $schema->childNodes ); + $this->baseSchemas->Append( $schema ); } sub LoadSchema { diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/DOM/Schema/Label.pm --- a/Lib/IMPL/DOM/Schema/Label.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/DOM/Schema/Label.pm Thu Jan 23 17:26:34 2014 +0400 @@ -27,6 +27,9 @@ unless $map; die ArgException->new('id' => 'A lable identifier is required') unless $id; + + $this->_map($map); + $this->_id($id); } our $AUTOLOAD; @@ -37,7 +40,9 @@ return if $method eq 'DESTROY'; - return $this->new($this->_map,$method); + warn $this->_id . ".$method"; + + return $this->new($this->_map,$this->_id . ".$method"); } sub ToString { diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/DOM/Schema/Node.pm --- a/Lib/IMPL/DOM/Schema/Node.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/DOM/Schema/Node.pm Thu Jan 23 17:26:34 2014 +0400 @@ -2,12 +2,11 @@ use strict; use warnings; -use parent qw(IMPL::DOM::Node); -use IMPL::Class::Property; -use IMPL::DOM::Property qw(_dom); - use IMPL::Const qw(:prop); use IMPL::declare { + require => { + Label => 'IMPL::DOM::Schema::Label' + }, base => [ 'IMPL::DOM::Node' => sub { my %args = @_; @@ -33,7 +32,7 @@ sub _getLabel { my ($this) = @_; - + $this->{$label} ||= Label->new($this->document->stringMap, $this->name ); } sub CTOR { diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/DOM/Schema/ValidationError.pm --- a/Lib/IMPL/DOM/Schema/ValidationError.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/DOM/Schema/ValidationError.pm Thu Jan 23 17:26:34 2014 +0400 @@ -31,7 +31,14 @@ } else { die new IMPL::InvalidArgumentException("A 'parent' or a 'node' parameter is required"); } - $this->{$message} = FormatMessage(delete $args{message}, \%args) if $args{message}; + + if(my $msg = $args{message}) { + if (my($msgId) = ( $msg =~ /^ID:([\w\.]+)$/ ) ) { + $this->{$message} = ($args{schema} || $args{source})->document->stringMap->GetString($msgId, \%args); + } else { + $this->{$message} = FormatMessage(delete $args{message}, \%args) if $args{message}; + } + } } sub toString { diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/Resources/Format.pm --- a/Lib/IMPL/Resources/Format.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/Resources/Format.pm Thu Jan 23 17:26:34 2014 +0400 @@ -35,7 +35,7 @@ sub _defaultResolver { my ($obj,$prop) = @_; - return ( eval { $obj->can($prop) } ? $obj->$prop() : undef ); + return eval { $obj->$prop() }; } 1; diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/Resources/StringLocaleMap.pm --- a/Lib/IMPL/Resources/StringLocaleMap.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/Resources/StringLocaleMap.pm Thu Jan 23 17:26:34 2014 +0400 @@ -129,7 +129,7 @@ chomp; $line ++ and next if /^\s*$/; - if (/^(\w+)\s*=\s*(.*)$/) { + if (/^([\w\.]+)\s*=\s*(.*)$/) { $map{$1} = $2; } else { die "Invalid resource format in $fname at $line"; diff -r 99ac2e19c0cc -r 2f16f13b000c Lib/IMPL/Web/View/Metadata/FormMeta.pm --- a/Lib/IMPL/Web/View/Metadata/FormMeta.pm Thu Jan 23 02:35:28 2014 +0400 +++ b/Lib/IMPL/Web/View/Metadata/FormMeta.pm Thu Jan 23 17:26:34 2014 +0400 @@ -49,7 +49,7 @@ } sub label { - shift->GetSchemaProperty('display'); + shift->GetSchemaProperty('label'); } sub inputType {