Forum OpenACS Q&A: Response to Support for multibyte: .tcl ok .adp not

Posted by Gaizka Villate on
First of all, thanks for your answers about the system encoding you are using.

Now, let's try to solve this problem:

Henry, you're right when you say that you can call ns_adp_parse on files directly, that you must convert them to string before.

The problem is that, i don't know why, AOLserver seems to parse ns_adp_parse -string with the plain parser, and ns_adp_parse -file with the fancy parser.

Also, you forgot the ns_startcontent.

And the ecommerce module requires the fancy parser (it uses its own tags).

So i've come up with this piece of code. It works, but it is quite ugly.

Anyway, here is the code, and let's see if somebody smarter than me can tell if it is ok.

    set mimetype [ns_guesstype $fully_qualified_template_filename]
    set encoding [ns_encodingfortype $mimetype]
    set fd [open $fully_qualified_template_filename r]
    fconfigure $fd -encoding $encoding
    set template [read $fd]
    close $fd
        set http_header "HTTP/1.0 200 OK
MIME-Version: 1.0
Content-Type: $mimetype
Pragma: No-Cache
    if { $cache_p } {
        eval "uplevel { ns_write "$http_header[ns_startcontent -type $mimetype][ns_adp_eval -parser fancy {$template}]" }"
    } else {
        eval "uplevel { ns_return 200 $mimetype [ns_adp_eval -parser fancy {$template}] }"