diff Lib/IMPL/DOM/Transform/PostToDOM.pm @ 113:7b14e0122b79

Updated PostToDOM transformation added selectSingleNode method to IMPL::DOM::Node Implemented FormWrapper in the Web::Application::ControllerUnit
author wizard
date Fri, 21 May 2010 02:38:11 +0400
parents 0ed8e2541b1c
children c8dfbbdd8005
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Transform/PostToDOM.pm	Tue May 18 17:59:31 2010 +0400
+++ b/Lib/IMPL/DOM/Transform/PostToDOM.pm	Fri May 21 02:38:11 2010 +0400
@@ -10,17 +10,22 @@
 BEGIN {
     public property documentClass => prop_get | owner_set;
     public property documentSchema => prop_get | owner_set;
+    public property prefix => prop_get | owner_set;
     private property _navi => prop_all;
+    public property Errors => prop_all | prop_list;
+    private property _schema => prop_all;
 }
 
 our %CTOR = (
     'IMPL::Transform' => sub {
-        HASH => \&TransfromPostData
+    	-plain => \&TransformPlain,
+        HASH => \&TransformContainer,
+        CGI => \&TransformCGI
     }
 );
 
 sub CTOR {
-	my ($this,$docClass,$docSchema) = @_;
+	my ($this,$docClass,$docSchema,$prefix) = @_;
 	$docClass ||= 'IMPL::DOM::Document';
 	
 	$this->_navi(
@@ -29,30 +34,60 @@
 			$docSchema
 		)
 	);
+	$this->_schema($docSchema);
+	$this->prefix($prefix) if $prefix;
 }
 
-sub TransformPostData {
+sub TransformContainer {
     my ($this,$data) = @_;
     
     my $navi = $this->_navi;
-    
-    my %
-    
+        
     while (my ($key,$value) = each %$data) {
-    	# TODO: review
-    	$navi->save;
-        my $node = $navi->Navigate(split /\//, $key);
-        $node->nodeValue($value);
-        $navi->resore;
+    	
+    	$navi->NavigateCreate($key);
+    	
+    	$this->Transform($value);
+    	
+    	$navi->Back();
     }
     
-    return $navi->Document;
+    return $navi->Current;
+}
+
+sub TransformPlain {
+	my ($this,$data) = @_;
+	
+	$this->_navi->Current->nodeValue( $this->_navi->inflateValue($data) );
 }
 
-sub 
-
-sub TransformErrors {
-	return $_[0]->_navi->BuildErrors;
+sub TransformCGI {
+	my ($this,$query) = @_;
+	
+	my $data={};
+	
+	my $prefix = $this->prefix;
+	$prefix = qr/$prefix/;
+	
+	foreach my $param (grep $_=~/$prefix/, $query->param()) {
+		my $value = $query->param($param);
+		
+		my @parts = split /\//,$param;
+		
+		my $node = $data;
+		while ( my $part = shift @parts ) {
+			if (@parts) {
+				$node = ($node->{$part} ||= {});
+			} else {			
+				$node->{$part} = $value;
+			}
+		}  
+	}
+	
+	my $doc = $this->Transform($data);
+	$this->Errors->Append( $this->_navi->BuildErrors);
+	$this->Errors->Append( $this->_schema->Validate($doc));
+	return $doc;
 }
 
 1;