Mercurial > pub > Impl
changeset 383:2f16f13b000c
DOM localization
author | cin |
---|---|
date | Thu, 23 Jan 2014 17:26:34 +0400 |
parents | 99ac2e19c0cc |
children | 4edd36025051 0d63f5273307 |
files | Lib/IMPL/DOM/Schema.pm Lib/IMPL/DOM/Schema/Label.pm Lib/IMPL/DOM/Schema/Node.pm Lib/IMPL/DOM/Schema/ValidationError.pm Lib/IMPL/Resources/Format.pm Lib/IMPL/Resources/StringLocaleMap.pm Lib/IMPL/Web/View/Metadata/FormMeta.pm |
diffstat | 7 files changed, 40 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- 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 {
--- 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 {
--- 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 {
--- 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 {
--- 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;
--- 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";