diff Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents d1676be8afcc
children
line wrap: on
line diff
--- a/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/Web/QueryHandler/PageFormat.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -18,117 +18,117 @@
 $Template::Plugin::URL::JOINT = '&';
 
 BEGIN {
-	public property templatesCharset => prop_all;
-	public property templatesBase => prop_all;
-	public property includes => prop_all | prop_list;
-	public property pathinfoPrefix => prop_all;
-	public property cache => prop_all;
-	public property preprocess => prop_all;
-	public property formatOutput => prop_all;
-	public property template => prop_all;
+    public property templatesCharset => prop_all;
+    public property templatesBase => prop_all;
+    public property includes => prop_all | prop_list;
+    public property pathinfoPrefix => prop_all;
+    public property cache => prop_all;
+    public property preprocess => prop_all;
+    public property formatOutput => prop_all;
+    public property template => prop_all;
 }
 
 sub CTOR {
-	my ($this) = @_;
-	
-	$this->templatesCharset('utf-8') unless $this->templatesCharset;
-	$this->cache(File::Spec->rel2abs($this->cache)) if $this->cache;
-	$this->templatesBase(File::Spec->rel2abs($this->templatesBase)) if $this->templatesBase;
+    my ($this) = @_;
+    
+    $this->templatesCharset('utf-8') unless $this->templatesCharset;
+    $this->cache(File::Spec->rel2abs($this->cache)) if $this->cache;
+    $this->templatesBase(File::Spec->rel2abs($this->templatesBase)) if $this->templatesBase;
 }
 
 sub Process {
-	my ($this,$action,$nextHandler) = @_;
-	
-	my $doc = new IMPL::Web::TT::Document(cache => $this->cache, preprocess => $this->preprocess);
-	
-	try {
+    my ($this,$action,$nextHandler) = @_;
+    
+    my $doc = new IMPL::Web::TT::Document(cache => $this->cache, preprocess => $this->preprocess);
+    
+    try {
 
-		$this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
-		
-		my ($requestUri) = split( /\?/, $ENV{REQUEST_URI} );
-		
-		my $pathInfo;
-		my @root = ('');
-		my @base;
-		
-		if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) {
-			# CGI with path info, for example
-			# /base/cgi-bin/myscript.cgi/path/info
-			# PATH_INFO will be /path/info
-			$pathInfo = $ENV{PATH_INFO};
-		} else {
-			# usual url, for exmaple
-			# /base/script.cgi will have PATH_INFO /base/script.cgi
-			# /base/ will have PATH_INFO /base/index.cgi (if index.cgi is a DirectoryIndex)
-			$pathInfo = $ENV{PATH_INFO};
-			
-			if (my $rx = $this->pathinfoPrefix) {
-				$requestUri =~ s/^($rx)//;
-				$pathInfo =~ s/^($rx)//;
-				push @root, grep $_, split /\//, $1 if $1;
-			}
-		}
-		
-		@base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri);
-		
-		local $ENV{PATH_INFO} = $pathInfo;
-		
-		my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
-		
-		my @pathContainer = @path;
-		pop @pathContainer;
-		
-		$doc->LoadFile (
-			($this->template || File::Spec->catfile($this->templatesBase,@path)),
-			$this->templatesCharset,
-			[$this->templatesBase, $this->includes],
-			{
-				result => scalar($nextHandler->()),
-				action => $action,
-				app => $action->application,
-		
-				absoluteUrl => sub { new URI(join ('/', @root, $_[0]) ) },
-				baseUrl => sub { new URI (join ('/', @root, @base, $_[0]) ) },
-				relativeUrl => sub { new URI(join ('/', @root, @base, @pathContainer,$_[0]) ) },
-		
-				user => IMPL::Security::Context->current->principal,
-				session => IMPL::Security::Context->current,
-		
-				to_json => \&to_json,
-				escape_string => sub { $_[0] =~ s/"/"/g; $_[0] },
-			}
-		);
-		
-		$action->response->contentType('text/html');
-		my $hOut = $action->response->streamBody;
-		if ($this->formatOutput == 1) {
-			my $tree = new HTML::TreeBuilder();
-			try {
-				$tree->parse_content($doc->Render());
-				print $hOut $tree->as_HTML('<>&',"    ",{});
-			} finally {
-				$tree->delete;
-			};
-		} elsif ($this->formatOutput() == 2 ) {
-			(my $data = $doc->Render()) =~ s/\s+/ /g;
-			print $hOut $data;
-		} else {
-			print $hOut $doc->Render();
-		}
-	} finally {
-		$doc->Dispose;
-	};
+        $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
+        
+        my ($requestUri) = split( /\?/, $ENV{REQUEST_URI} );
+        
+        my $pathInfo;
+        my @root = ('');
+        my @base;
+        
+        if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) {
+            # CGI with path info, for example
+            # /base/cgi-bin/myscript.cgi/path/info
+            # PATH_INFO will be /path/info
+            $pathInfo = $ENV{PATH_INFO};
+        } else {
+            # usual url, for exmaple
+            # /base/script.cgi will have PATH_INFO /base/script.cgi
+            # /base/ will have PATH_INFO /base/index.cgi (if index.cgi is a DirectoryIndex)
+            $pathInfo = $ENV{PATH_INFO};
+            
+            if (my $rx = $this->pathinfoPrefix) {
+                $requestUri =~ s/^($rx)//;
+                $pathInfo =~ s/^($rx)//;
+                push @root, grep $_, split /\//, $1 if $1;
+            }
+        }
+        
+        @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri);
+        
+        local $ENV{PATH_INFO} = $pathInfo;
+        
+        my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
+        
+        my @pathContainer = @path;
+        pop @pathContainer;
+        
+        $doc->LoadFile (
+            ($this->template || File::Spec->catfile($this->templatesBase,@path)),
+            $this->templatesCharset,
+            [$this->templatesBase, $this->includes],
+            {
+                result => scalar($nextHandler->()),
+                action => $action,
+                app => $action->application,
+        
+                absoluteUrl => sub { new URI(join ('/', @root, $_[0]) ) },
+                baseUrl => sub { new URI (join ('/', @root, @base, $_[0]) ) },
+                relativeUrl => sub { new URI(join ('/', @root, @base, @pathContainer,$_[0]) ) },
+        
+                user => IMPL::Security::Context->current->principal,
+                session => IMPL::Security::Context->current,
+        
+                to_json => \&to_json,
+                escape_string => sub { $_[0] =~ s/"/&quot;/g; $_[0] },
+            }
+        );
+        
+        $action->response->contentType('text/html');
+        my $hOut = $action->response->streamBody;
+        if ($this->formatOutput == 1) {
+            my $tree = new HTML::TreeBuilder();
+            try {
+                $tree->parse_content($doc->Render());
+                print $hOut $tree->as_HTML('<>&',"    ",{});
+            } finally {
+                $tree->delete;
+            };
+        } elsif ($this->formatOutput() == 2 ) {
+            (my $data = $doc->Render()) =~ s/\s+/ /g;
+            print $hOut $data;
+        } else {
+            print $hOut $doc->Render();
+        }
+    } finally {
+        $doc->Dispose;
+    };
 }
 
 sub URI::_query::new_params {
-	my ($this,$params) = @_;
-	
-	my $clone = $this->clone;
-	if (ref $params eq 'HASH' ) {
-		my %newParams = ($clone->query_form , %$params);
-		$clone->query_form(map { $_, ( Encode::is_utf8( $newParams{$_} ) ? Encode::encode('utf-8', $newParams{$_}) : $newParams{$_} ) } sort keys %newParams );
-	}
-	return $clone;
+    my ($this,$params) = @_;
+    
+    my $clone = $this->clone;
+    if (ref $params eq 'HASH' ) {
+        my %newParams = ($clone->query_form , %$params);
+        $clone->query_form(map { $_, ( Encode::is_utf8( $newParams{$_} ) ? Encode::encode('utf-8', $newParams{$_}) : $newParams{$_} ) } sort keys %newParams );
+    }
+    return $clone;
 }
 
 1;
@@ -148,9 +148,9 @@
 =begin code xml
 
 <handlersQuery type="IMPL::Object::List">
-	<item type="IMPL::Web::QueryHandler::PageFormat">
-		<charsetTemplates>utf-8</charsetTemplates>
-	</item>
+    <item type="IMPL::Web::QueryHandler::PageFormat">
+        <charsetTemplates>utf-8</charsetTemplates>
+    </item>
 </handlersQuery>
 
 =end code xml
@@ -161,7 +161,7 @@
 
 my $app = new IMPL::Web::Application();
 $app->handlersQuery->Add(
-	new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' );
+    new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' );
 );
 
 =end