changeset 382:99ac2e19c0cc

Implemented a strings map for a DOM schema
author sergey
date Thu, 23 Jan 2014 02:35:28 +0400
parents ced5937ff21a
children 2f16f13b000c
files Lib/IMPL/DOM/Schema.pm Lib/IMPL/Resources/StringLocaleMap.pm _test/Test/DOM/Node.pm
diffstat 3 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Schema.pm	Wed Jan 22 16:56:10 2014 +0400
+++ b/Lib/IMPL/DOM/Schema.pm	Thu Jan 23 02:35:28 2014 +0400
@@ -80,9 +80,17 @@
 sub _getStringMap {
 	my ($this) = @_;
 	
-	
+	return $this->{$stringMap}
+		if return $this->{$stringMap};
+
+	my $map = StringMap->new();
+	if ($this->baseDir and $this->schemaName) {
+		
+		$map->paths( File::Spec->catdir($this->baseDir,'locale') );
+		$map->name(schemaName);
+	}
 	
-	File::Spec->catdir($this->baseDir,'locale');
+	return $this->{$stringMap} = $map;
 }
 
 sub Process {
--- a/Lib/IMPL/Resources/StringLocaleMap.pm	Wed Jan 22 16:56:10 2014 +0400
+++ b/Lib/IMPL/Resources/StringLocaleMap.pm	Thu Jan 23 02:35:28 2014 +0400
@@ -28,6 +28,10 @@
 		$this->_maps({ default => $data });
 	} elsif ( ref($data) eq 'HASH' ) {
 		$this->_maps({ default => StringMap->new($data,$parent)});
+	} else {
+		# в данном случае таблица строк по-умолчанию будет загружена
+		# из файла при необходимости
+		$this->_maps({});
 	}
 }
 
@@ -37,16 +41,17 @@
 	my $locale = Resources->currentLocale || 'default';
 	my $map;
 	
-	warn "id: $id,\t\tlocale: $locale";
+	#warn "id: $id,\t\tlocale: $locale";
 	
 	if(not $map = $this->_maps->{$locale}) {
-		$map = $this->LoadMap($locale,$this->_maps->{default});
+		my $default = $this->GetDefaultMap();
+		$map = $this->LoadMap($locale,$default);
 		if (is($map,StringMap)) {
 			#nop
 		} elsif (ref($map) eq 'HASH') {
-			$map = StringMap->new($map,$this->_maps->{default});
+			$map = StringMap->new($map,$default);
 		} elsif( not $map ) {
-			$map = $this->_maps->{default};
+			$map = $default;
 		} else {
 			die Exception->new("ResolveLocale returned unexpected data", $map);
 		}
@@ -57,6 +62,19 @@
 	return $map->GetString($id,$args);
 }
 
+sub GetDefaultMap {
+	my ($this) = @_;
+	
+	my $map = $this->_maps->{default};
+	return $map
+		if $map;
+	
+	$map = $this->LoadMap('default') || StringMap->new({});
+	$this->_maps->{default} = $map;
+	
+	return $map;
+}
+
 sub LoadMap {
 	my ($this,$locale,$default) = @_;
 	
--- a/_test/Test/DOM/Node.pm	Wed Jan 22 16:56:10 2014 +0400
+++ b/_test/Test/DOM/Node.pm	Thu Jan 23 02:35:28 2014 +0400
@@ -207,10 +207,11 @@
 test listNodePredefinedProps => sub {
     my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
     
+    # the order of properties is not defined
     my @props = $node->listProperties;
     my @expected = qw(name _private);
     
-    failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
+    failed "Got wrong list of props", @props unless cmparray([sort @props],[sort @expected]);
 };
 
 test listNodeAllProps => sub {
@@ -224,7 +225,7 @@
     my @props = $node->listProperties;
     my @expected = qw(name _private uuid); # systemName is not a DOM prop
     
-    failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
+    failed "Got wrong list of props", @props unless cmparray([sort @props],[sort @expected]);
 };
 
 test MemoryLeaks => sub {