:- ensure_loaded(common).
cvs_id('$Id: app_config.pl,v 1.5 2004/10/15 21:32:30 sandro Exp $').
/*
  Support for app_config/2 which is actually found elsewhere
  (sometimes "config_data.pl", but it depends on the context).
*/

:- ensure_loaded(mkdir).

app_config_file(Tag, Value) :-
	app_config(Tag, OriginalValue),
	OriginalValue \= '',
	(   app_config(sandbox, SandBox)
	->  atom_concat(SandBox, OriginalValue, V)
	;   V=OriginalValue
	),
	absolute_file_name(V, Value),
	make_parent_directories_if_missing(Value).

app_config_file_no_sandbox(Tag, Value) :-
	app_config(Tag, OriginalValue),
	OriginalValue \= '',
	V=OriginalValue,
	absolute_file_name(V, Value),
	make_parent_directories_if_missing(Value).

app_config_number(Tag, Number) :-
	app_config(Tag, Atom),
	atom_number(Atom, Number).


www_file(Part1, Part2, Result) :-
	% sometimes we really want out of the sandbox, thanks!
	(   app_config(www_override, WWW_Dir)
	->  true
	;   app_config(www_dir, WWW_Dir)
	),
	concat_atom([WWW_Dir, '/', Part1, Part2], Result).

configure_hostname :-
	retract(app_config(hostname, auto)),
	gethostname(Hostname),
	assert(app_config(hostname, Hostname)).
configure_hostname.

configure_site_uri :-
	retract(app_config(site_uri, auto)),
	app_config(hostname, Hostname),
	app_config(port, Port),
	concat_atom(['http://', Hostname, ':', Port, '/'], SiteURI),
	assert(app_config(site_uri, SiteURI)).
configure_site_uri.

configure_rdfpage :-
	app_config(site_uri, SiteURI),
	rdfpage_set_uri_prefix(_, SiteURI),
	app_config_file(cache_prefix, CachePrefix),
	rdfpage_set_storage_prefix(_, CachePrefix).

configure_self_uri :-
	app_config(site_uri, U),
	atom_concat(U, 'self#', T),
	rdf_register_ns(self,  T).    % will not be term_expanded, too late!

configure_about_this_run :-	
	rdfpage_gen_uri(AboutThisRun),
	print_message(informational, format('Run page: ~q', [AboutThisRun])),
	rdf_register_ns(aboutThisRun, AboutThisRun), % will not be expanded
	flag(aboutThisRun, _, AboutThisRun).
