
package provide xotcl::actiweb::htmlPlace 1.0

package require -exact xotcl::trace 1.0
package require -exact xotcl::actiweb::httpPlace 1.0
package require -exact xotcl::store::persistence 1.0
package require -exact xotcl::actiweb::agent 1.0
package require -exact xotcl::actiweb::pageTemplate 1.0

package require XOTcl 1

namespace eval ::xotcl::actiweb::htmlPlace {
    namespace import ::xotcl::*

    Class HtmlPlace -superclass Place -parameter {allowExit}

    HtmlPlace instproc init args {
	next
	#
	# just define a minimal object that can react 
	# with HTML decoration, if the called object
	# doesn't exist
	PageTemplateHtml create [self]::start.html

	my startingObj [self]::start.html
	if {[my exists allowExit]} {
	    set exitObj [WebObject create [self]::[my set allowExit]]
	    [Place getInstance] exportObjs $exitObj
	    $exitObj proc default {} {after 500 ::exit; return "Server terminates"}
	}
    }
    HtmlPlace instproc default {} {
	set place [string trimleft [self] :]
	set msg "<HTML><TITLE>Place $place</TITLE>
	<BODY><H2>Place $place</H2> Try one of the following links:<UL>"
	foreach o [my exportedObjs] {
	    set o [string trimleft $o :]
	    append msg "<LI><A HREF='[url encodeItem $o]'>$o</A></LI>"
	}
	append msg "</UL></BODY>\n"
    }

    namespace export HtmlPlace
}

namespace import ::xotcl::actiweb::htmlPlace::*
