File: dev.sql

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (276 lines) | stat: -rw-r--r-- 9,760 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
--  
--  $Id: dev.sql,v 1.6.2.1 2011/07/20 09:50:18 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  

-- This SQL is for developing purposes. 
-- It assumes that you have eighter symbolic link (on unix like system) or 
-- junction (on windows with ntfs systems) in you vsp root to binsrc/tutorial cvs dir
-- also to use the path /tutorial_dev which is a virtuoso directory without dev.vsp handler
-- you must run `./make_vad.sh dev` which will copy all files in vad_files ... the same way
-- they will be copied during vad compilation
set COMMAND_TEXT_ON_ERROR=off;

create procedure TUTORIAL_ROOT_DIR ()
{
     return http_root()||'/';
}
;

create procedure TUTORIAL_XSL_DIR ()
{
     return 'file://';
}
;

create procedure TUTORIAL_VDIR_DIR ()
{
   return '/';
}
;


DB.DBA.VHOST_REMOVE(lpath=>'/tutorial',del_vsps => 1);
DB.DBA.VHOST_DEFINE(
    lpath    => '/tutorial',
    ppath    => '/tutorial/dev.vsp',
    is_dav   => 0,
    vsp_user => 'dba',
    is_brws  => 0,
    opts     => vector('noinherit', 1)
)
;

DB.DBA.VHOST_REMOVE(lpath=>'/tutorial_dev',del_vsps => 1);
DB.DBA.VHOST_DEFINE(
    lpath    => '/tutorial_dev',
    ppath    => '/tutorial/vad_files/vsp/tutorial/',
    is_dav   => 0,
    vsp_user => 'dba',
    is_brws  => 1,
    def_page => 'index.vsp'
    --opts     => vector('noinherit', 1)
)
;

create procedure TUT_get_xml(in path varchar){
  declare _TUT_XML any;
  declare _ex_id, _ex_fspath, ex, _ex_xmlfile, _ex_optfile, _subsec_fspath varchar;
  declare xp_last_example, _subsec_options,_ex_optxml any;

  _TUT_XML := xml_tree_doc(xml_tree(file_to_string(http_root()|| path||'/'||'tutorial.xml')));
  xp_last_example := null;
  --string_to_file(http_root() ||path|| '/url_list.txt','',-2);
  foreach (any xp_example in xpath_eval('//example',_TUT_XML,0))do
  {
  	_ex_fspath := cast(xpath_eval('@fspath',xp_example) as varchar);
  	-- Exeption for bpeldemo
  	if (not(isnull(strstr(_ex_fspath,'bpeldemo/'))))
	  	_ex_id := replace(cast(xpath_eval('@id',xp_example) as varchar),'-','_');
  	else if (not(isnull(strstr(_ex_fspath,'hw-simulator'))))
	  	_ex_id := lower(cast(xpath_eval('@id',xp_example) as varchar));
  	else
	  	_ex_id := replace(lower(cast(xpath_eval('@id',xp_example) as varchar)),'-','_');

	  ex := '';
	  _ex_optxml := null;
	  _ex_optfile := path || '/' || _ex_fspath || '/options.xml';
    if (file_stat(http_root()||_ex_optfile))	  
      _ex_optxml := xml_tree_doc(xml_tree(file_to_string(http_root()|| _ex_optfile)));
	
  	if(isnull(xpath_eval('@wwwpath',xp_example)))
  	{
		 	if (_ex_optxml and lower(xpath_eval('string(/init/@is_vspx)',_ex_optxml)) = 'yes')
	       		ex := 'x';
  	  		XMLAddAttribute (xp_example,2,'wwwpath',concat(_ex_fspath ,'/', _ex_id , '.vsp',ex));
  	  	};

  	if(not(isnull(xp_last_example)))
  	{
  	  XMLAddAttribute (xp_example,2,'previd',xpath_eval('@id',xp_last_example));
  	  XMLAddAttribute (xp_last_example,2,'nextid',xpath_eval('@id',xp_example));
  	};
  	
		_ex_xmlfile := path || '/' || _ex_fspath || '/' || _ex_id || '.xml';
		if (file_stat(http_root()||_ex_xmlfile) = 0)
			signal('TUTNF','File not found:'||http_root()||_ex_xmlfile);
		XMLAddAttribute(xp_example,2,'date',date_rfc1123(stringdate (file_stat (http_root()||_ex_xmlfile))));
	  XMLAppendChildren(xp_example,xml_tree_doc(xml_tree(file_to_string(http_root()|| _ex_xmlfile))));
	  
	  _ex_optfile := path || '/' || _ex_fspath || '/options.xml';
    if (_ex_optxml)	  
      XMLAppendChildren(xp_example,_ex_optxml);
		xp_last_example := xp_example;
		
		--string_to_file(http_root() ||path|| '/url_list.txt',cast(xpath_eval('@wwwpath',xp_example) as varchar)|| '\n',-1);		
  };

  foreach (any xp_subsec in xpath_eval('//subsection',_TUT_XML,0))do
  {
  	_subsec_fspath := cast(xpath_eval('@fspath',xp_subsec) as varchar);
  	
  	--_subsec_xmlfile := _TUT_ROOT || '/' || _ex_fspath || '/' || replace(lower(_ex_id),'-','_') || '.xml';
  	if(not(isnull(xpath_eval('@ref',xp_subsec))))
  	  XMLAddAttribute  (xp_subsec,2,'ref',xpath_eval('@ref',xp_subsec));
  	if(isnull(xpath_eval('@wwwpath',xp_subsec)))
  	  XMLAddAttribute  (xp_subsec,2,'wwwpath',xpath_eval('@fspath',xp_subsec));
		_subsec_options :=  xml_tree_doc(xml_tree(file_to_string(http_root()||path || '/' || cast(xpath_eval('@fspath',xp_subsec) as varchar) || '/' || 'index.xml')));
		foreach (any _subsec_option in xpath_eval('/section/*',_subsec_options,0))do
		{
		  XMLAppendChildren(xp_subsec,_subsec_option);
		};

  };
  
  --string_to_file(http_root() ||path|| '/full_tutorial_xml.xml',serialize_to_UTF8_xml(_TUT_XML),-2);
  
  return _TUT_XML;
	
};

create procedure TUT_generate_files(
	in path varchar,
	in _outmode varchar := 'sql'
){
  declare _TUT_XML,_stream, paths any;
  declare _file,xml_output varchar;
  declare _ins_sql varchar;
  declare xsl_mountpoint, _xsl_params any;
  
  _TUT_XML := TUT_get_xml(path);

  _stream := string_output();
  
  xml_output := '';
	
	if (_outmode = 'web'){
		http_rewrite();
		http('<pre>');
		http('Preparing for generating files.\n');
		http_flush(1);
	} else {
	  result_names('status');	
	  result('Preparing for generating files.');
	};
	paths := vector('/','/search.vsp','/rss.vsp','/opml.vsp','/ocs.vsp','/sioc.vsp');
  foreach (any tut_path in xpath_eval('//@wwwpath',_TUT_XML,0))do
  {
	  if (length(tut_path) > 5 and (
	      subseq(tut_path,length(tut_path) - 4,length(tut_path)) = '.vsp'  or
	  		subseq(tut_path,length(tut_path) - 5,length(tut_path)) = '.vspx')
	  		)
	  	paths := vector_concat(paths,vector('/'||cast(tut_path as varchar)));
	  else {
	  	paths := vector_concat(paths,vector('/'||cast(tut_path as varchar)||'/'));
	  	paths := vector_concat(paths,vector('/'||cast(tut_path as varchar)||'/rss.vsp'));
	  }
  };

  string_to_file(http_root() ||path|| '/fill_search.sql','',-2);
  foreach (any tut_example in xpath_eval('//example',_TUT_XML,0))do
  {
	  _ins_sql := 'INSERT SOFT DB.DBA.TUT_SEARCH (TS_PATH,TS_NAME,TS_TITLE) VALUES(''';
	  _ins_sql := _ins_sql || cast(xpath_eval('@wwwpath',tut_example) as varchar);
	  _ins_sql := _ins_sql || ''',''';
	  _ins_sql := _ins_sql || cast(xpath_eval('@id',tut_example) as varchar);
	  _ins_sql := _ins_sql || ''',''';
	  _ins_sql := _ins_sql || replace(cast(xpath_eval('refentry/refnamediv/refpurpose',tut_example) as varchar),'''','''''');
	  _ins_sql := _ins_sql || ''');\n';
	  
	  string_to_file(http_root() ||path|| '/fill_search.sql',_ins_sql,-1);
  };
  
	if (_outmode = 'web'){
		http('Start generating files.\n');
		http_flush(1);
	} else {
		result('Start generating files.');
	};

  foreach (varchar gen_path in paths)do
  {
    if (gen_path like '%/idp_s_1.vsp')
      goto _skip;
    
	  _file := 'index.vsp';
	  if (length(gen_path) > 5 and (
	      subseq(gen_path,length(gen_path) - 4,length(gen_path)) = '.vsp'  or
	  		subseq(gen_path,length(gen_path) - 5,length(gen_path)) = '.vspx')
	  		)
	  		_file := '';

	  xsl_mountpoint := regexp_replace(ltrim(gen_path,'/'),'[^/]*/','../',1,null);
	  if (length(xsl_mountpoint) > 5 and (
	      subseq(xsl_mountpoint,length(xsl_mountpoint) - 4,length(xsl_mountpoint)) = '.vsp'  or
	  		subseq(xsl_mountpoint,length(xsl_mountpoint) - 5,length(xsl_mountpoint)) = '.vspx')
	  		)
	  	xsl_mountpoint := regexp_replace(xsl_mountpoint,'[^/]*\$','');
	  xsl_mountpoint := trim(xsl_mountpoint,'/');
	  if (xsl_mountpoint = '')
	    xsl_mountpoint := '.';
	  _xsl_params := vector('mount_point',xsl_mountpoint);
	  if (trim(gen_path,'/') <> '')
	    _xsl_params := vector_concat(_xsl_params,vector('path',ltrim(gen_path,'/')));
	    
	  _xsl_params := vector_concat(_xsl_params,vector('now_rfc1123',date_rfc1123(now())));

	  _stream := string_output();
	  http_rewrite(_stream);
  	if (gen_path like '%/rss.vsp')
  		xml_output := '_rss_output';
  	else if (gen_path = '/opml.vsp')
  		xml_output := '_opml_output';
  	else if (gen_path = '/ocs.vsp')
  		xml_output := '_ocs_output';
  	else if (gen_path = '/sioc.vsp')
  		xml_output := '_sioc_output';
    else
      xml_output := '';
	  
	  http_value(xslt('file://'||path|| '/page'||xml_output||'.xsl',_TUT_XML,_xsl_params),null,_stream);
	  _stream := string_output_string(_stream);
	  if (xml_output <> '') {
	    _stream := replace(_stream,'dc:dc=""','');
            _stream := replace(_stream,'dcterms:dcterms=""','');
            _stream := replace(_stream,'foaf:foaf=""','');
	    _stream := replace(_stream,'ocs:ocs=""','');
	    _stream := replace(_stream,'rdf:rdf=""','');
	    _stream := replace(_stream,'content:content=""','');
	    _stream := replace(_stream,'sioc:sioc=""','');
	  };
	  string_to_file(http_root() ||path|| gen_path || _file,_stream,-2);
	  
		if (_outmode = 'web'){
		  http('Wrote ' || http_root() ||path|| gen_path || _file || '\n');
	  	http_flush (1);
	  } else {
	  	result('Wrote ' || http_root() ||path|| gen_path || _file);
	  }
	_skip:;  
  }
	if (_outmode = 'web'){
		http('Finished.\n');
		http_flush(1);
	} else {
		result('Finished.');
	};
};