DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>registry_get('_dbpedia_path_'));
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/class');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/ontology');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data2');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data3');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/page');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/resource');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/statics');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/wikicompany/resource');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/sparql');


DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/',
	 ppath=>'http://wiki.dbpedia.org/',
	 is_dav=>0,
	 def_page=>''
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>rtrim (registry_get('_dbpedia_path_'), '/'),
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 vsp_user=>'dba'
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/class',
	 ppath=>'/',
	 is_dav=>0,
	 def_page=>'',
	 opts=>vector ('url_rewrite', 'dbp_rule_list_3')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/ontology',
	 ppath=>'/',
	 is_dav=>0,
	 def_page=>'',
	 opts=>vector ('url_rewrite', 'dbp_rule_list_owl')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data',
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 vsp_user=>'dba',
	 opts=>vector ('url_rewrite', 'pvsp_rule_list2')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data2',
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 vsp_user=>'dba',
	 opts=>vector ('url_rewrite', 'pvsp_rule_list7')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data3',
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 vsp_user=>'dba',
	 opts=>vector ('url_rewrite', 'pvsp_rule_data3')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/page',
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 opts=>vector ('url_rewrite', 'dbp_rule_list_7')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/resource',
	 ppath=>'/',
	 is_dav=>0,
	 def_page=>'',
	 opts=>vector ('url_rewrite', 'dbp_rule_list_2')
);


DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/statics',
	 ppath=>'/statics/',
	 is_dav=>0,
	 def_page=>'index.html'
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/wikicompany/resource',
	 ppath=>'/DAV/wikicompany/resource/',
	 is_dav=>1,
	 vsp_user=>'dba',
	 opts=>vector ('url_rewrite', 'dbp_wc_rule_list1')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/sparql',
	ppath=>'/!sparql/',
	is_dav=>1,
	def_page=>'',
	vsp_user=>'dba',
	opts=>vector ('noinherit', 'yes')
);



DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_wc_rule_list1', 1, vector ('dbp_wc_rule1', 'dbp_wc_rule2'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_wc_rule1', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description_white.vsp?res=%s', vector ('par_1'), NULL, NULL, 2, 0, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_wc_rule2', 1, '(/[^#]*)', vector ('par_1'), 1,
'/sparql?query=describe%%20%%3Chttp%%3A%%2F%%2Fdbpedia.openlinksw.com%s%%3E%%20from%%20%%3Chttp%%3A%%2F%%2Fdbpedia.openlinksw.com%%2Fwikicompany%%3E&format=%U',
vector ('par_1', '*accept*'), NULL, '(application/rdf.xml)|(text/rdf.n3)', 2, 303, '');

DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_2', 1, vector ('dbp_rule_14', 'dbp_rule_12'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_14', 1, '/resource/(.*)\x24', vector ('par_1'), 1,
    '/page/%s', vector ('par_1'), NULL, NULL, 2, 303, NULL);

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_12', 1, '/resource/(.*)\x24', vector ('par_1'), 1,
    '/data/__%s', vector ('par_1'), NULL, '(application/rdf.xml)|(text/rdf.n3)|(application/x-turtle)', 2, 303);

delete from DB.DBA.HTTP_VARIANT_MAP where VM_RULELIST = 'dbp_rule_list_2';
DB.DBA.HTTP_VARIANT_ADD ('dbp_rule_list_2', '__(.*)', '\x241.xml', 'application/rdf+xml', 0.95, location_hook=>null);
DB.DBA.HTTP_VARIANT_ADD ('dbp_rule_list_2', '__(.*)', '\x241.n3',  'text/rdf+n3', 0.80, location_hook=>null);
DB.DBA.HTTP_VARIANT_ADD ('dbp_rule_list_2', '__(.*)', '\x241.ttl',  'application/x-turtle', 0.70, location_hook=>null);


DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_3', 1, vector ('dbp_rule_6', 'dbp_rule_7', 'dbp_rule_18', 'dbp_rule_19'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_6', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description.vsp?res=%U', vector ('par_1'), NULL, NULL, 0, 0, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_7', 1, '/class/(.*)\x24', vector ('par_1'), 1,
'/data2/%s.rdf', vector ('par_1'), NULL, 'application/rdf.xml', 2, 303, 'Content-Type: application/rdf+xml');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_18', 1, '/class/(.*)\x24', vector ('par_1'), 1,
'/data2/%s.n3', vector ('par_1'), NULL, 'text/rdf.n3', 1, 303, 'Content-Type: text/rdf+n3');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_19', 1, '/class/(.*)\x24', vector ('par_1'), 1,
'/data2/%s.n3', vector ('par_1'), NULL, 'application/x-turtle', 2, 303, 'Content-Type: application/x-turtle');


DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_owl', 1, vector ('owl_rule_6', 'owl_rule_7', 'owl_rule_18', 'owl_rule_19'));
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_6', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description.vsp?res=%U', vector ('par_1'), NULL, NULL, 0, 0, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_7', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%s.rdf', vector ('par_1'), NULL, 'application/rdf.xml', 2, 303, 'Content-Type: application/rdf+xml');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_18', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%si.n3', vector ('par_1'), NULL, 'text/rdf.n3', 1, 303, 'Content-Type: text/rdf+n3');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_19', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%s.n3', vector ('par_1'), NULL, 'application/x-turtle', 2, 303, 'Content-Type: application/x-turtle');



DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_4', 1, vector ('dbp_rule_8', 'dbp_rule_9'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_8', 1, '/property/(.*)\x24', vector ('par_1'), 1,
'/page/property/%U', vector ('par_1'), NULL, NULL, 0, 303, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_9', 1, '/property/(.*)\x24', vector ('par_1'), 1,
'/data/property/%U.rdf', vector ('par_1'), NULL, 'application/rdf.xml', 0, 303, 'Content-Type: application/rdf+xml;qs=1');

DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_7', 1, vector ('dbp_rule_13'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'dbp_rule_13', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description.vsp?res=%U', vector ('par_1'), NULL, NULL, 0, 0, '');

DB.DBA.URLREWRITE_CREATE_RULELIST ( 'pvsp_rule_list2', 1, vector ('pvsp_data_rule2', 'pvsp_data_rule3', 'pvsp_data_rule4'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data_rule2', 1, '/data/(.*)\\.(xml)', vector ('par_1', 'f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fresource%%2F%U%%3E&format=rdf',
vector ('par_1'), NULL, NULL, 2, null, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data_rule3', 1, '/data/(.*)\\.(ttl)', vector ('par_1', 'f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fresource%%2F%U%%3E&format=n3',
vector ('par_1'), NULL, NULL, 2, null, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data_rule4', 1, '/data/(.*)\\.(n3|rdf)', vector ('par_1', 'f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fresource%%2F%U%%3E&format=%U',
vector ('par_1', 'f'), NULL, NULL, 2, null, '');

DB.DBA.URLREWRITE_CREATE_RULELIST ( 'pvsp_rule_list7', 1, vector ('pvsp_data_rule7'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data_rule7', 1, '/data2/(.*)\\.(n3|rdf)', vector ('par_1','f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fclass%%2F%U%%3E&format=%U',
vector ('par_1', 'f'), NULL, NULL, 2, null, '');

--DB.DBA.RDF_OBJ_FT_RULE_ADD ('http://dbpedia.org', null, 'http://dbpedia.org');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/ontology');

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/ontology',
	 ppath=>'/',
	 is_dav=>0,
	 def_page=>'',
	 opts=>vector ('url_rewrite', 'dbp_rule_list_owl')
);


DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_owl', 1, vector ('owl_rule_6', 'owl_rule_7', 'owl_rule_18', 'owl_rule_19'));
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_6', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description.vsp?res=%U', vector ('par_1'), NULL, NULL, 0, 0, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_7', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%s.rdf', vector ('par_1'), NULL, 'application/rdf.xml', 2, 303, 'Content-Type: application/rdf+xml');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_18', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%s.n3', vector ('par_1'), NULL, 'text/rdf.n3', 1, 303, 'Content-Type: text/rdf+n3');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'owl_rule_19', 1, '/ontology/(.*)\x24', vector ('par_1'), 1,
'/data3/%s.n3', vector ('par_1'), NULL, 'application/x-turtle', 2, 303, 'Content-Type: application/x-turtle');



DB.DBA.URLREWRITE_CREATE_RULELIST ( 'pvsp_rule_data3', 1, vector ('pvsp_data3_rule'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data3_rule', 1, '/data3/(.*)\\.(n3|rdf)', vector ('par_1', 'f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fontology%%2F%U%%3E&format=%U',
vector ('par_1', 'f'), NULL, NULL, 2, NULL, '');

DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/property');
DB.DBA.VHOST_REMOVE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data4');

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/property',
	 ppath=>'/',
	 is_dav=>0,
	 def_page=>'',
	 opts=>vector ('url_rewrite', 'dbp_rule_list_prop')
);

DB.DBA.VHOST_DEFINE ( lhost=>':80', vhost=>'dbpedia.org', lpath=>'/data4',
	 ppath=>registry_get('_dbpedia_path_'),
	 is_dav=>atoi (registry_get('_dbpedia_dav_')),
	 vsp_user=>'dba',
	 opts=>vector ('url_rewrite', 'pvsp_rule_data4')
);


DB.DBA.URLREWRITE_CREATE_RULELIST ( 'dbp_rule_list_prop', 1, vector ('prop_rule_6', 'prop_rule_7', 'prop_rule_18', 'prop_rule_19'));
DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'prop_rule_6', 1, '(/[^#]*)', vector ('par_1'), 1,
registry_get('_dbpedia_path_')||'description.vsp?res=%U', vector ('par_1'), NULL, NULL, 0, 0, '');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'prop_rule_7', 1, '/property/(.*)\x24', vector ('par_1'), 1,
'/data4/%s.rdf', vector ('par_1'), NULL, 'application/rdf.xml', 2, 303, 'Content-Type: application/rdf+xml');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'prop_rule_18', 1, '/property/(.*)\x24', vector ('par_1'), 1,
'/data4/%s.n3', vector ('par_1'), NULL, 'text/rdf.n3', 1, 303, 'Content-Type: text/rdf+n3');

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'prop_rule_19', 1, '/property/(.*)\x24', vector ('par_1'), 1,
'/data4/%s.n3', vector ('par_1'), NULL, 'application/x-turtle', 2, 303, 'Content-Type: application/x-turtle');



DB.DBA.URLREWRITE_CREATE_RULELIST ( 'pvsp_rule_data4', 1, vector ('pvsp_data4_rule'));

DB.DBA.URLREWRITE_CREATE_REGEX_RULE ( 'pvsp_data4_rule', 1, '/data4/(.*)\\.(n3|rdf)', vector ('par_1', 'f'), 1,
'/sparql?default-graph-uri=http%%3A%%2F%%2Fdbpedia.org&query=DESCRIBE+%%3Chttp%%3A%%2F%%2Fdbpedia.org%%2Fproperty%%2F%U%%3E&format=%U',
vector ('par_1', 'f'), NULL, NULL, 2, null, '');

DB.DBA.VHOST_REMOVE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/about');
DB.DBA.VHOST_DEFINE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/about',
	 ppath=>'/SOAP/Http/ext_http_proxy',
	 is_dav=>0,
	 soap_user=>'PROXY',
	 ses_vars=>0,
	 opts=>vector ('url_rewrite', 'ext_about_http_proxy_rule_list1'),
	 is_default_host=>0
);

DB.DBA.VHOST_REMOVE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/rdfdesc');
DB.DBA.VHOST_DEFINE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/rdfdesc',
	 ppath=>'/DAV/VAD/rdf_mappers/rdfdesc/',
	 is_dav=>1,
	 vsp_user=>'dba',
	 ses_vars=>0,
	 is_default_host=>0
);

DB.DBA.VHOST_REMOVE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/snorql');
DB.DBA.VHOST_DEFINE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/snorql',
	 ppath=>'/snorql/',
	 is_dav=>0,
	 def_page=>'index.html',
	 vsp_user=>'dba',
	 ses_vars=>0,
	 opts=>vector ('browse_sheet', 0),
	 is_default_host=>0
);

DB.DBA.VHOST_REMOVE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/sparql-auth');
DB.DBA.VHOST_DEFINE (
	 lhost=>':80',
	 vhost=>'dbpedia.org',
	 lpath=>'/sparql-auth',
	 ppath => '/!sparql/',
	 is_dav => 1,
	 vsp_user => 'dba',
	 opts => vector('noinherit', 1),
	 auth_fn=>'DB.DBA.HP_AUTH_SPARQL_USER',
	 realm=>'SPARQL',
	 sec=>'digest');

create procedure ensure_demo_user ()
{
    if (exists (select 1 from SYS_USERS where U_NAME = 'demo'))
	return;
	exec ('create user "demo"');
	DB.DBA.user_set_qualifier ('demo', 'Demo');
};

ensure_demo_user ();

drop procedure ensure_demo_user;

create procedure create_demo_home ()
{
  declare pwd any;
  pwd := (select pwd_magic_calc (U_NAME, U_PASSWORD, 1) from SYS_USERS where U_NAME = 'dav');
  DAV_COL_CREATE ('/DAV/home/', '110100100', http_dav_uid(), http_dav_uid() + 1, 'dav', pwd);
  DAV_COL_CREATE ('/DAV/home/demo/', '110100100', http_dav_uid(), http_dav_uid() + 1, 'dav', pwd);
  DAV_COL_CREATE ('/DAV/home/demo/dbpedia/', '110100100', http_dav_uid(), http_dav_uid() + 1, 'dav', pwd);
};

create_demo_home ();
drop procedure create_demo_home;

create procedure upload_isparql ()
{
  declare base varchar;
  declare pwd any;
  pwd := (select pwd_magic_calc (U_NAME, U_PASSWORD, 1) from SYS_USERS where U_NAME = 'dav');
  base := registry_get('_dbpedia_path_');
  if (base like '/DAV/%')
    {
      for select RES_FULL_PATH from WS..SYS_DAV_RES where RES_FULL_PATH like base||'%.isparql' do
	{
	  DAV_COPY (RES_FULL_PATH, '/DAV/home/demo/dbpedia/', 0, '111101101NN', 'dav', 'administrators', 'dav', pwd);
	}
    }
  else
    {
      declare arr any;
      arr := sys_dirlist (base);
      foreach (varchar f in arr) do
	{
	  if (f like '%.isparql')
	    DAV_RES_UPLOAD ('/DAV/home/demo/dbpedia/'||f, file_to_string (base||f), '', '110100100R', http_dav_uid(), http_dav_gid(), 'dav', pwd);
	}
    }
  -- the current trigger of isparql have bug
  update WS..SYS_DAV_RES set RES_PERMS = '110100100NN' where RES_FULL_PATH like '/DAV/home/demo/dbpedia/%';
}
;

upload_isparql ();
drop procedure upload_isparql;
