package Type::ProcHT; ###### 
# 	$Id: ProcHT.pm,v 1.1 2003/05/09 19:48:50 steve Exp $
#	This file is part of Combo and is licensed under the GPL.
#	Copyright 2001-2002 by the authors.  See README and LICENSE
#	for more details or see http://penguinsong.org/.

### Type::ProcHT is the Type for  HTML processed through AMP
#	

use Context;
use Combo;
use Site::Config;
use Site::Util;
use Type::Text;
use Type::Html;

BEGIN {
    use vars qw($VERSION @ISA);
    
    $VERSION=1.00;
    @ISA = qw(Type::Html Type::Text);
}



#############################################################################
###
### Information Functions:
###


### $t->canDetermineSize($cxt)
#	Returns true if the size if the content can be determined in advance.
#	Should return 0 if processing is done on the content.
#
sub canDetermineSize {
    my ($self, $cxt) = @_;
    return 0;
}



#############################################################################
###
### Processing Functions:
###

# Note:	We assume that by the time we get to a processing function, all error
#	and permission checking has already been done by the caller, so
#	that all the Type handler has to do is perform the operation.

# Note:	All processing functions take a (url)path as well as a Context.  In
#	some cases, the path of the resource to be retrieved, queried, or 
#	processed is different from that of the resource that was the subject
#	of the original request.  


### $s = $t->editForm($cxt, $realpath)
#	Returns the contents of a form suitable for editing the resource.  
#	Does _not_ include the <form...> tags because those need to be
#	computed by the caller.  Returns null if the object can't be edited.
sub editForm {
    my ($self, $cxt, $realpath) = @_;
    if ($cxt->getCGI->param('plain')) {
	return Type::Text::editForm(@_);
    }

    my $txt = entityEncode(getFile($self->getFilePath($cxt, $realpath)));

    # === get rows, cols from $cxt

    return ("<textarea name='text' rows='30' cols='72'>$txt</textarea>\n");
}


### $s = $t->preview($cxt, $realpath)
#	prints a preview, given the POST response to an edit form.
sub preview {
    my ($self, $cxt, $realpath) = @_;
}


### $s = $t->previewString($cxt, $realpath)
#	Returns a preview string, given the POST response to an edit form.
sub previewString {
    my ($self, $cxt, $realpath) = @_;
}


### $t->process($cxt, $text)
#	output the result of processing the content of the resource.
sub process {
    my ($self, $cxt, $realpath) = @_;

    # Really need to reverse-map $realPath
    my $path = $cxt->getPath;

    # Get a Process.  Note that we don't use $cxt->getProcessor
    #    because it's not guaranteed that $realPath is the same as the
    #    the path that was in the request (though that's the way to bet)
    my $p = new AMP::Process($cxt, $path, $realPath);

    $p->{'title'} = '';				# === needs to be done right.
    $p->processFile($self->getFilePath($cxt, $realpath));
    return '';
}


### $t->processText($cxt, $text)
#	output the result of processing $text as if it had been the
#	content of the resource; typically done for a preview.
sub processText {
    my ($self, $cxt, $text) = @_;
    print $text;				# === don't have the right hook
}



#############################################################################
###
### HTTP Request Handlers:
###


### $t->handleQuery($cxt, $realpath, $queryString)
#	Handle a (direct) GET request with a query string.
sub handleQuery {
    my ($self, $cxt, $realpath) = @_;
}

### $t->handlePOST($cxt, $realpath)
#
sub handlePOST {
    my ($self, $cxt, $realpath) = @_;
}

### $t->handlePUT($cxt, $realpath)
#	Handle a PUT request to the resource. 
sub handlePUT {
    my ($self, $cxt, $realpath) = @_;
}



#############################################################################
1;
