[12002] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * depositoraction.cpp --
|
---|
| 4 | * Copyright (C) 2000 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
| 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
| 9 | *
|
---|
| 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
| 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 | #include "gsdl_modules_cfg.h"
|
---|
| 27 | #ifdef GSDL_USE_DEPOSITOR_ACTION
|
---|
| 28 |
|
---|
| 29 | // note that the collectoraction relies on having direct access to a
|
---|
| 30 | // collections configuration file. this breaks the separation between
|
---|
| 31 | // receptionist and collection server and so is not suitable (at least
|
---|
| 32 | // in its current form) for use when collection servers are separate
|
---|
| 33 | // from the receptionist (e.g. when using the CORBA protocol).
|
---|
| 34 |
|
---|
| 35 | // following line required to get fstream.filedesc() on darwin (Mac OS X)
|
---|
| 36 | #define _STREAM_COMPAT 1
|
---|
| 37 | // required for utsname on solaris???
|
---|
| 38 | #define _XOPEN_SOURCE 1
|
---|
[19821] | 39 | // This was added for Solaris, but it makes things worse on Solaris for me...
|
---|
| 40 | // #define _XOPEN_SOURCE_EXTENDED 1
|
---|
[12002] | 41 |
|
---|
| 42 | #include "depositoraction.h"
|
---|
| 43 | #include "OIDtools.h"
|
---|
| 44 | #include "fileutil.h"
|
---|
| 45 | #include "cfgread.h"
|
---|
| 46 | #include "gsdltools.h"
|
---|
| 47 | #include "gsdltimes.h"
|
---|
| 48 | #include "argdb.h"
|
---|
| 49 | #include "cgiutils.h"
|
---|
[12008] | 50 |
|
---|
[12002] | 51 | #include <stdio.h>
|
---|
[12524] | 52 | //#include <strings.h> // seems to be needed for gcc 2.95, but not particularly happy it
|
---|
[12002] | 53 | #include <fcntl.h>
|
---|
| 54 | #include <time.h>
|
---|
| 55 |
|
---|
| 56 | #if !defined (__WIN32__)
|
---|
| 57 | #include <sys/utsname.h>
|
---|
| 58 | #include <unistd.h>
|
---|
| 59 | #endif
|
---|
| 60 |
|
---|
| 61 | #include <new>
|
---|
[12008] | 62 | //#include <string>
|
---|
[12002] | 63 | #include <vector>
|
---|
| 64 | #include <stdexcept>
|
---|
| 65 | #include <iostream>
|
---|
[12008] | 66 | //#include <cstdlib>
|
---|
[12002] | 67 |
|
---|
| 68 | depositoraction::depositoraction ()
|
---|
| 69 | : wizardaction()
|
---|
| 70 | {
|
---|
| 71 | macro_prefix = "di1"; //deposit item
|
---|
| 72 | lastpage = 0;
|
---|
| 73 |
|
---|
| 74 | cgiarginfo arg_ainfo;
|
---|
| 75 | arg_ainfo.shortname = "a";
|
---|
| 76 | arg_ainfo.longname = "action";
|
---|
| 77 | arg_ainfo.multiplechar = true;
|
---|
| 78 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 79 | arg_ainfo.argdefault = "depositor";
|
---|
| 80 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 81 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 82 |
|
---|
| 83 | arg_ainfo.shortname = "p";
|
---|
| 84 | arg_ainfo.longname = "page";
|
---|
| 85 | arg_ainfo.multiplechar = true;
|
---|
| 86 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 87 | arg_ainfo.argdefault = "select";
|
---|
| 88 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 89 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 90 |
|
---|
| 91 | //furthest page that has been visited
|
---|
| 92 | arg_ainfo.shortname = "di1lastpage";
|
---|
| 93 | arg_ainfo.longname = "depositor specific";
|
---|
| 94 | arg_ainfo.multiplechar = true;
|
---|
| 95 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 96 | arg_ainfo.argdefault = "0";
|
---|
| 97 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 98 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12516] | 99 |
|
---|
| 100 | // the fileupload info that cgiwrapper produces - we parse the fileupload_t
|
---|
| 101 | // and set di1userfile, di1userfilesize
|
---|
| 102 | arg_ainfo.shortname = "di1userfileinfo";
|
---|
| 103 | arg_ainfo.longname = "depositor specific";
|
---|
| 104 | arg_ainfo.fileupload = true;
|
---|
| 105 | arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 106 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 107 |
|
---|
[12516] | 108 | // essential: reset fileupload to default as we are not setting
|
---|
| 109 | // it for each arg
|
---|
| 110 | arg_ainfo.fileupload = false;
|
---|
| 111 |
|
---|
[12002] | 112 | //the name of the file to be added
|
---|
| 113 | arg_ainfo.shortname = "di1userfile";
|
---|
| 114 | arg_ainfo.longname = "depositor specific";
|
---|
| 115 | arg_ainfo.multiplechar = true;
|
---|
| 116 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 117 | arg_ainfo.argdefault = g_EmptyText;
|
---|
| 118 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 119 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 120 |
|
---|
| 121 | //the file size
|
---|
| 122 | arg_ainfo.shortname = "di1userfilesize";
|
---|
| 123 | arg_ainfo.longname = "depositor specific";
|
---|
| 124 | arg_ainfo.multiplechar = true;
|
---|
| 125 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 126 | arg_ainfo.argdefault = "0";
|
---|
| 127 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 128 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 129 |
|
---|
| 130 | //the file timestamp
|
---|
| 131 | arg_ainfo.shortname = "di1timestamp";
|
---|
| 132 | arg_ainfo.longname = "depositor specific";
|
---|
| 133 | arg_ainfo.multiplechar = true;
|
---|
| 134 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 135 | arg_ainfo.argdefault = "0";
|
---|
| 136 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 137 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 138 |
|
---|
| 139 | // temporary directory name for this collector
|
---|
| 140 | // session
|
---|
| 141 | arg_ainfo.shortname = "di1tmp";
|
---|
| 142 | arg_ainfo.longname = "depositor specific";
|
---|
| 143 | arg_ainfo.multiplechar = true;
|
---|
| 144 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 145 | arg_ainfo.argdefault = g_EmptyText;
|
---|
| 146 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 147 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 148 |
|
---|
[12516] | 149 | // arg_ainfo.shortname = "di1fullname";
|
---|
| 150 | // arg_ainfo.longname = "depositor specific";
|
---|
| 151 | // arg_ainfo.multiplechar = true;
|
---|
| 152 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 153 | // arg_ainfo.argdefault = g_EmptyText;
|
---|
| 154 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 155 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 156 |
|
---|
| 157 | arg_ainfo.shortname = "di1dirname";
|
---|
| 158 | arg_ainfo.longname = "depositor specific";
|
---|
| 159 | arg_ainfo.multiplechar = true;
|
---|
| 160 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
[12480] | 161 | arg_ainfo.argdefault = g_EmptyText;
|
---|
[12002] | 162 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 163 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 164 |
|
---|
| 165 | arg_ainfo.shortname = "di1contactemail";
|
---|
| 166 | arg_ainfo.longname = "depositor specific";
|
---|
| 167 | arg_ainfo.multiplechar = true;
|
---|
| 168 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 169 | arg_ainfo.argdefault = g_EmptyText;
|
---|
| 170 | arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 171 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 172 |
|
---|
[12516] | 173 | // arg_ainfo.shortname = "di1clone";
|
---|
| 174 | // arg_ainfo.longname = "depositor specific";
|
---|
| 175 | // arg_ainfo.multiplechar = false;
|
---|
| 176 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 177 | // arg_ainfo.argdefault = "0";
|
---|
| 178 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 179 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 180 |
|
---|
[12516] | 181 | // arg_ainfo.shortname = "di1clonecol";
|
---|
| 182 | // arg_ainfo.longname = "depositor specific";
|
---|
| 183 | // arg_ainfo.multiplechar = true;
|
---|
| 184 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 185 | // arg_ainfo.argdefault = g_EmptyText;
|
---|
| 186 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 187 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 188 |
|
---|
[12516] | 189 | // arg_ainfo.shortname = "cfgfile";
|
---|
| 190 | // arg_ainfo.longname = "configuration file contents";
|
---|
| 191 | // arg_ainfo.multiplechar = true;
|
---|
| 192 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 193 | // arg_ainfo.argdefault = g_EmptyText;
|
---|
| 194 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot;
|
---|
| 195 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 196 |
|
---|
[12516] | 197 | // // will be set if we arrived at the "configure collection" page
|
---|
| 198 | // // via the "changing an existing collection" page
|
---|
| 199 | // arg_ainfo.shortname = "di1econf";
|
---|
| 200 | // arg_ainfo.longname = "depositor specific";
|
---|
| 201 | // arg_ainfo.multiplechar = false;
|
---|
| 202 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 203 | // arg_ainfo.argdefault = "0";
|
---|
| 204 | // arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 205 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 206 |
|
---|
[12516] | 207 | // wizard uses this to see if we are working with an existing collection:
|
---|
| 208 | // set the default to 1
|
---|
[12002] | 209 | arg_ainfo.shortname = "di1esrce";
|
---|
| 210 | arg_ainfo.longname = "depositor specific";
|
---|
| 211 | arg_ainfo.multiplechar = false;
|
---|
| 212 | arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 213 | arg_ainfo.argdefault = "1";
|
---|
| 214 | arg_ainfo.savedarginfo = cgiarginfo::must;
|
---|
| 215 | argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
| 216 |
|
---|
[12516] | 217 | // arg_ainfo.shortname = "di1input";
|
---|
| 218 | // arg_ainfo.longname = "depositor specific";
|
---|
| 219 | // arg_ainfo.multiplechar = true;
|
---|
| 220 | // arg_ainfo.multiplevalue = true;
|
---|
| 221 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 222 | // arg_ainfo.argdefault = g_EmptyText;
|
---|
| 223 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 224 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 225 |
|
---|
[12516] | 226 | // //we don't need this in the depositor
|
---|
| 227 | // arg_ainfo.shortname = "di1inputtype";
|
---|
| 228 | // arg_ainfo.longname = "depositor specific";
|
---|
| 229 | // arg_ainfo.multiplechar = true;
|
---|
| 230 | // arg_ainfo.multiplevalue = true;
|
---|
| 231 | // arg_ainfo.defaultstatus = cgiarginfo::weak;
|
---|
| 232 | // arg_ainfo.argdefault = g_EmptyText;
|
---|
| 233 | // arg_ainfo.savedarginfo = cgiarginfo::mustnot; // saved on disk
|
---|
| 234 | // argsinfo.addarginfo (NULL, arg_ainfo);
|
---|
[12002] | 235 |
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | depositoraction::~depositoraction () {
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[12516] | 241 |
|
---|
[12002] | 242 | bool depositoraction::check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args, recptprotolistclass * protos, ostream &logout) {
|
---|
| 243 |
|
---|
| 244 | wizardaction::check_cgiargs(argsinfo,args,protos,logout);
|
---|
| 245 |
|
---|
| 246 | text_t ¤t_page = args["p"];
|
---|
| 247 |
|
---|
| 248 | // note that the "bildstatus" and "bildframe1" pages don't actually do anything
|
---|
| 249 | // functional so we don't need to worry about authenticating them (it's the
|
---|
| 250 | // underlying "bild" page that does the building (and creates the frameset))
|
---|
| 251 | // This helps us overcome a bit of a problem we have with multiple pages trying
|
---|
[19062] | 252 | // to read from the key.gdb database at the same time.
|
---|
[12002] | 253 |
|
---|
[12516] | 254 | //right now, anyone can do anything until it's time to build
|
---|
[20535] | 255 |
|
---|
| 256 | // Used to check current page was "select", now changed to "step1".
|
---|
| 257 | // (i.e. one page later). This is needed so users that belong to
|
---|
| 258 | // specific collection-edit groups (e.g. demo-collection-editor) are able
|
---|
| 259 | // to log in successfully.
|
---|
| 260 | //
|
---|
| 261 |
|
---|
| 262 | if (current_page == "step1") {
|
---|
[12002] | 263 | //authenticate the user if authentication is available
|
---|
| 264 | args["uan"] = 1;
|
---|
[20535] | 265 | args["ug"] = "all-collections-editor," + args["c"] + "-collection-editor";
|
---|
[12002] | 266 | }
|
---|
| 267 |
|
---|
| 268 |
|
---|
| 269 | //Check to see if a file was specified
|
---|
| 270 | //if so, upload it and set the di1userfile, di1userfilesize, and
|
---|
| 271 | //di1timestamp args.
|
---|
| 272 | //every time a new file is specified, a new timestamped folder is
|
---|
| 273 | //created.
|
---|
| 274 |
|
---|
| 275 | // This doesn't create a problem but is inefficient (wasted space)
|
---|
| 276 | // Consider recoding at some point in the future.
|
---|
| 277 |
|
---|
[12516] | 278 | fileupload_t *fileupload = args.getargfile("di1userfileinfo");
|
---|
[12794] | 279 |
|
---|
[12516] | 280 | if (fileupload != NULL) {
|
---|
[12794] | 281 |
|
---|
[12516] | 282 | if (!(*fileupload).tmp_name.empty() && file_exists((*fileupload).tmp_name)) {
|
---|
| 283 | // create the timestamp
|
---|
| 284 | time_t timestamp = time(NULL);
|
---|
| 285 | text_t timestamp_str(timestamp);
|
---|
[12794] | 286 |
|
---|
[12516] | 287 | args["di1timestamp"] = timestamp_str;
|
---|
[12002] | 288 |
|
---|
[12516] | 289 | // set filename and size from the fileupload struct
|
---|
| 290 | args["di1userfilesize"] = (*fileupload).size;
|
---|
| 291 | args["di1userfile"] = (*fileupload).name;
|
---|
| 292 | // copy the file into its temporary location
|
---|
| 293 | text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
|
---|
| 294 | bool tflag = mk_dir(tmpdir);
|
---|
| 295 | text_t tmpfile = filename_cat(tmpdir,(*fileupload).name);
|
---|
| 296 | if (!file_copy((*fileupload).tmp_name, tmpfile)) {
|
---|
| 297 | cerr << "Depositor error: cannot save uploaded fileto "<<tmpfile<<endl;
|
---|
| 298 | } else {
|
---|
| 299 | cerr << "Depositor: saved uploaded file to "<<tmpfile<<endl;
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | }
|
---|
| 303 |
|
---|
[12002] | 304 | if (current_page == "select") {
|
---|
| 305 |
|
---|
| 306 | //make sure the last page arg is re-set to zero
|
---|
| 307 | //since a new collection is being chosen
|
---|
| 308 | args["di1lastpage"] = "0";
|
---|
| 309 |
|
---|
[12019] | 310 | // assign (and create) a temporary directory This will create a new
|
---|
| 311 | // tbuild directory every time the user goes back to select a new
|
---|
| 312 | // collection. It causes no problems except wasted space. Should be
|
---|
| 313 | // addressed in the future
|
---|
[12002] | 314 | if (assign_tmpname (args, logout)==false) {
|
---|
| 315 | // there was an error creating the tmp dir
|
---|
| 316 | message="tmpfail";
|
---|
| 317 | return true; // true because we could still parse the arguments
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | // clean up any old builds left laying about in the tmp directory
|
---|
| 321 | // (note that it's possible this could take some time if there's a huge
|
---|
| 322 | // partially built collecton laying about so we'll make it an asynchronous
|
---|
| 323 | // system call)
|
---|
| 324 | gsdl_system ("perl -S cleantmp.pl", false, logout);
|
---|
| 325 |
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | if (current_page == "bildstatus" || current_page == "bildcancel") {
|
---|
| 329 | // if .final file exists then build has finished
|
---|
| 330 | text_t fbld = filename_cat (gsdlhome, "tmp", args[macro_prefix + "tmp"], args[macro_prefix + "dirname"] + ".bld.final");
|
---|
| 331 | if (file_exists (fbld)) {
|
---|
| 332 | char *fbldc = fbld.getcstr();
|
---|
| 333 | ifstream fbld_in (fbldc);
|
---|
| 334 | if (fbld_in) {
|
---|
| 335 | failcode = fbld_in.get();
|
---|
| 336 | fbld_in.close();
|
---|
| 337 | if (failcode == '0') {
|
---|
| 338 | // success - we need to create and configure a collection server for the
|
---|
| 339 | // newly built collection (for fastcgi and local library where
|
---|
| 340 | // initialization isn't going to be redone when the user clicks the
|
---|
| 341 | // "view your new collection" button
|
---|
| 342 | create_colserver (args[macro_prefix + "dirname"], logout);
|
---|
| 343 | current_page = "bilddone";
|
---|
| 344 | }
|
---|
| 345 | else current_page = "bildfail";
|
---|
| 346 | } else {
|
---|
| 347 | // assume build failed (we shouldn't get here though ... right?)
|
---|
| 348 | current_page = "bildfail";
|
---|
| 349 | }
|
---|
| 350 | delete []fbldc;
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | //is it a step page?
|
---|
| 355 | text_t::const_iterator here = current_page.begin();
|
---|
| 356 | text_t::const_iterator end = current_page.end();
|
---|
| 357 | text_t stepstring = substr(here,here+4);
|
---|
| 358 |
|
---|
| 359 | //if so, increment the step count
|
---|
| 360 | //this should not be going up more than one at a time.
|
---|
| 361 | if(stepstring == "step") {
|
---|
| 362 | text_t currpage_textt = substr(here+4,here+5);
|
---|
| 363 | int currpage = currpage_textt.getint();
|
---|
| 364 |
|
---|
| 365 | text_t lastpage_textt = args["di1lastpage"];
|
---|
| 366 | int lastpage = lastpage_textt.getint();
|
---|
| 367 | if (currpage > lastpage) {
|
---|
| 368 | lastpage++;
|
---|
| 369 | text_t lastpage_textt(lastpage);
|
---|
| 370 | args["di1lastpage"] = lastpage_textt;
|
---|
| 371 | }
|
---|
[16680] | 372 |
|
---|
| 373 | // create cached metadata values
|
---|
| 374 | text_t cached_metadata_values = "";
|
---|
| 375 | cgiargsclass::const_iterator args_here = args.begin();
|
---|
| 376 | cgiargsclass::const_iterator args_end = args.end();
|
---|
| 377 | while (args_here != args_end) {
|
---|
| 378 | text_t args_name = (*args_here).first;
|
---|
| 379 | int prefix_len = macro_prefix.size();
|
---|
| 380 | text_t args_prefix = substr(args_name.begin(),args_name.begin()+prefix_len+3);
|
---|
| 381 |
|
---|
| 382 | if (args_prefix == (macro_prefix+"md.")) {
|
---|
| 383 | text_t args_val = args[args_name];
|
---|
| 384 | text_t args_suffix = substr(args_name.begin()+prefix_len+3,args_name.end());
|
---|
| 385 |
|
---|
| 386 | text_tarray mdvalues;
|
---|
| 387 | splitchar (args_val.begin(), args_val.end(), ',', mdvalues);
|
---|
| 388 | int numvalues = mdvalues.size();
|
---|
| 389 |
|
---|
| 390 | for (int i = 0; i < numvalues; ++i) {
|
---|
| 391 | if (!mdvalues[i].empty()) {
|
---|
| 392 | decode_cgi_arg(mdvalues[i]);
|
---|
| 393 |
|
---|
| 394 | if (cached_metadata_values == "") {
|
---|
| 395 | cached_metadata_values = "var CachedMDValues = new Array(\\{";
|
---|
| 396 | } else {
|
---|
| 397 | cached_metadata_values += ",";
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | cached_metadata_values += "\"" + args_name + "\":\"" + args_val + "\"";
|
---|
| 401 | }
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | ++args_here;
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | if (cached_metadata_values != "") {
|
---|
| 408 | cached_metadata_values += "\\});";
|
---|
| 409 | args["cachedMDValues"] = cached_metadata_values;
|
---|
| 410 | }
|
---|
[12002] | 411 | }
|
---|
| 412 | return true;
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 |
|
---|
| 416 | void depositoraction::define_internal_macros (displayclass &disp, cgiargsclass &args,
|
---|
| 417 | recptprotolistclass *protos, ostream &logout) {
|
---|
| 418 |
|
---|
[12516] | 419 | // define_internal_macros sets some/all of the following macros (depending
|
---|
| 420 | // on cgiargs):
|
---|
[12002] | 421 | //
|
---|
[12516] | 422 | // _pagescriptextra_
|
---|
| 423 | // _header_
|
---|
| 424 | // _depositorbar_
|
---|
| 425 | // _textfailmsg_
|
---|
| 426 | // _di1userfile_
|
---|
| 427 | // _di1userfilesize_
|
---|
[12002] | 428 |
|
---|
| 429 | text_t &depositor_page = args["p"];
|
---|
[12524] | 430 |
|
---|
[12002] | 431 | // set _pagescriptextra_ macro to _cpagescriptextra_
|
---|
| 432 | disp.setmacro ("pagescriptextra", "depositor", "_" + depositor_page + "scriptextra_");
|
---|
| 433 |
|
---|
| 434 | if (depositor_page == "bildstatus" || depositor_page == "bilddone" ||
|
---|
[12576] | 435 | depositor_page == "bildfail" || depositor_page == "bildframe1" ||
|
---|
| 436 | depositor_page == "select") {
|
---|
[12002] | 437 | disp.setmacro ("header", "depositor", "_" + depositor_page + "header_");
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | if (depositor_page == "bildstatus") {
|
---|
| 441 | set_statusline (disp, args, logout);
|
---|
| 442 | }
|
---|
| 443 |
|
---|
| 444 | if (depositor_page == "select") {
|
---|
[12516] | 445 | set_fullnamemenu (disp, args, protos, logout);
|
---|
[12002] | 446 | }
|
---|
| 447 |
|
---|
| 448 | //how many pages in collection?
|
---|
| 449 | //we need a _depositorbar_ for each
|
---|
| 450 |
|
---|
| 451 | text_t numsteps_str;
|
---|
| 452 | disp.expandstring("depositor", "_numsteps_", numsteps_str);
|
---|
| 453 | int numsteps = numsteps_str.getint();
|
---|
| 454 |
|
---|
| 455 | //is the page a step page?
|
---|
| 456 |
|
---|
| 457 | text_t::const_iterator here = depositor_page.begin();
|
---|
| 458 | text_t::const_iterator end = depositor_page.end();
|
---|
| 459 | text_t stepstring = substr(here,here+4);
|
---|
| 460 |
|
---|
| 461 | if((stepstring) == "step" || (depositor_page == "depositonly") ) {
|
---|
[12516] | 462 | disp.setmacro("di1userfile","depositor",args["di1userfile"]);
|
---|
| 463 | disp.setmacro("di1userfilesize","depositor",args["di1userfilesize"]);
|
---|
[12002] | 464 | }
|
---|
| 465 |
|
---|
[12516] | 466 | //set up the depositor bar
|
---|
[12002] | 467 | text_t depositorbar = "<table class=wizardbar border=0 cellspacing=4 cellpadding=0><tr>\n";
|
---|
| 468 |
|
---|
[16680] | 469 | if(stepstring == "step") {
|
---|
| 470 | // check configured metadata elements
|
---|
| 471 | if (args["metadataconf"] == "var DepositorMDFields = new Array();" || args["metadataconf"] == "") {
|
---|
| 472 | text_t cfgfile_name = filename_cat (collecthome, args[macro_prefix + "dirname"], "etc", "collect.cfg");
|
---|
| 473 | text_t cfgfile_content;
|
---|
| 474 | text_t metadata_str;
|
---|
| 475 |
|
---|
| 476 | if (read_file (cfgfile_name, cfgfile_content)) {
|
---|
| 477 | text_t::const_iterator here = cfgfile_content.begin();
|
---|
| 478 | text_t::const_iterator end = cfgfile_content.end();
|
---|
| 479 | while (here != end) {
|
---|
| 480 | here = findchar (here, end, 'd');
|
---|
| 481 | if (here == end) break;
|
---|
| 482 | if ((here+17 < end) && (substr (here, here+17) == "depositormetadata")) {
|
---|
| 483 | here = findchar (here, end, '"');
|
---|
| 484 | if (here == end) break;
|
---|
| 485 | text_t enddelimit = "\"\n";
|
---|
| 486 | getdelimitstr (here+1, end, enddelimit, metadata_str);
|
---|
| 487 | args["metadataconf"] = "var DepositorMDFields = new Array("+metadata_str+");";
|
---|
| 488 | }
|
---|
| 489 | ++here;
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
[12516] | 492 |
|
---|
[16680] | 493 | if (metadata_str == "") {
|
---|
| 494 | args["metadataconf"] = "var DepositorMDFields = new Array({\"name\":\"dc.Title\",\"label\":\"Title\",\"tooltip\":\"dc.Title: A name given to the resource.\",\"type\":\"text\"}, {\"name\":\"dc.Creator\",\"label\":\"Creator\",\"tooltip\":\"dc.Creator: An entity primarily responsible for making the content of the resource.\",\"type\":\"text\"}, {\"name\":\"dc.Description\",\"label\":\"Description\",\"tooltip\":\"dc.Description: An account of the content of the resource.\",\"type\":\"textarea\"});";
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 |
|
---|
[12002] | 498 | here = depositor_page.begin();
|
---|
| 499 | text_t stepnums = substr(here+4,here+5);
|
---|
| 500 | int stepnum = stepnums.getint();
|
---|
| 501 |
|
---|
| 502 | text_t lastpage_textt = args["di1lastpage"];
|
---|
| 503 | int lastpage = lastpage_textt.getint();
|
---|
[12524] | 504 |
|
---|
[12002] | 505 | // again, begin with the select bar...
|
---|
| 506 | //the first button - selecting a collection
|
---|
| 507 | for(int i = 1; i <= numsteps; i++) {
|
---|
| 508 | text_t numstr(i);
|
---|
| 509 | if(i <= lastpage && i == stepnum) {
|
---|
| 510 | depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, false);
|
---|
| 511 | } else if (i <= lastpage) {
|
---|
| 512 | depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, true);
|
---|
| 513 | } else if((i == lastpage+1)){
|
---|
| 514 | depositorbar += get_button (args,depositor_page, "green", "step"+numstr, true);
|
---|
| 515 | } else {
|
---|
| 516 | depositorbar += get_button (args,depositor_page, "grey", "step"+numstr, false);
|
---|
| 517 | }
|
---|
| 518 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 519 |
|
---|
[16680] | 520 | }
|
---|
[12002] | 521 |
|
---|
| 522 | //the build and preview pages are always last
|
---|
| 523 | if(lastpage == numsteps) {
|
---|
| 524 | depositorbar += get_button (args,depositor_page, "green", "laststep", true);
|
---|
| 525 | } else {
|
---|
| 526 | depositorbar += get_button (args,depositor_page, "grey", "laststep", false);
|
---|
| 527 | }
|
---|
| 528 |
|
---|
| 529 | text_t laststep_textt;
|
---|
| 530 | disp.expandstring("depositor", "_laststep_", laststep_textt);
|
---|
| 531 | if(laststep_textt == "bild") {
|
---|
| 532 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 533 | depositorbar += get_button (args,depositor_page, "grey", "view", false);
|
---|
| 534 | }
|
---|
| 535 | depositorbar += "</tr><tr>";
|
---|
| 536 |
|
---|
[12524] | 537 | for(int j = 1; j <= 2*(stepnum-1); j++) {
|
---|
[12002] | 538 | depositorbar += "<td></td>";
|
---|
| 539 | }
|
---|
| 540 | depositorbar += "<td align=center>_icongreyuparrow_</td>\n";
|
---|
| 541 |
|
---|
| 542 | depositorbar += "</tr></table>\n";
|
---|
[16680] | 543 |
|
---|
| 544 | // set the javascript so that the metadata form can read the existing values
|
---|
| 545 | if (args["cachedMDValues"] != "") {
|
---|
| 546 | disp.setmacro("cachedmetadatavalues", "depositor", args["cachedMDValues"]);
|
---|
| 547 | }
|
---|
| 548 | if (args["metadataconf"] != "") {
|
---|
| 549 | disp.setmacro("metadataconf", "depositor", args["metadataconf"]);
|
---|
| 550 | }
|
---|
[12002] | 551 | }
|
---|
[12516] | 552 |
|
---|
[12019] | 553 | if ((depositor_page == "bildcancel") || (depositor_page == "bildfail")) {
|
---|
[12516] | 554 |
|
---|
[12002] | 555 | for(int i = 1; i <= numsteps; i++) {
|
---|
| 556 |
|
---|
| 557 | text_t numstr(i);
|
---|
| 558 | depositorbar += get_button (args,depositor_page, "yellow", "step"+numstr, true);
|
---|
| 559 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 560 |
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 | //the build and preview pages are always last
|
---|
| 564 | depositorbar += get_button (args,depositor_page, "green", "laststep", true);
|
---|
| 565 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 566 | depositorbar += get_button (args,depositor_page, "grey", "view", false);
|
---|
| 567 |
|
---|
| 568 | depositorbar += "</tr><tr>";
|
---|
| 569 |
|
---|
[12524] | 570 | for(int j = 1; j <= 2*numsteps; j++) {
|
---|
[12002] | 571 | depositorbar += "<td></td>";
|
---|
| 572 | }
|
---|
| 573 | depositorbar += "<td align=center>_icongreyuparrow_</td>\n";
|
---|
| 574 |
|
---|
| 575 | depositorbar += "</tr></table>\n";
|
---|
| 576 |
|
---|
| 577 | }
|
---|
| 578 |
|
---|
| 579 | if(depositor_page == "bilddone"){
|
---|
[12516] | 580 |
|
---|
[12002] | 581 | for(int i = 1; i <= numsteps; i++) {
|
---|
| 582 |
|
---|
| 583 | text_t numstr(i);
|
---|
| 584 | depositorbar += get_button (args, depositor_page, "grey", "step"+numstr, false);
|
---|
| 585 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 586 |
|
---|
| 587 | }
|
---|
| 588 |
|
---|
| 589 | //the build and preview pages are always last
|
---|
| 590 | depositorbar += get_button (args,depositor_page, "yellow", "laststep", false);
|
---|
| 591 | depositorbar += "<td>_icongreyarrow_</td>\n";
|
---|
| 592 | depositorbar += get_button (args,depositor_page, "green", "view", true);
|
---|
| 593 |
|
---|
| 594 | depositorbar += "</tr><tr>";
|
---|
| 595 |
|
---|
[12524] | 596 | for(int j = 1; j <= 2*numsteps; j++) {
|
---|
[12002] | 597 | depositorbar += "<td></td>";
|
---|
| 598 | }
|
---|
| 599 | depositorbar += "<td align=center>_icongreyuparrow_</td>\n";
|
---|
| 600 |
|
---|
| 601 | depositorbar += "</tr></table>\n";
|
---|
| 602 | }
|
---|
| 603 | disp.setmacro ("depositorbar", "depositor", depositorbar);
|
---|
[12019] | 604 |
|
---|
| 605 | if (depositor_page == "bildfail") {
|
---|
[12516] | 606 |
|
---|
[12019] | 607 | text_t textfailmsg = "_textfailmsg";
|
---|
| 608 | textfailmsg.push_back(failcode);
|
---|
| 609 | textfailmsg.push_back('_');
|
---|
| 610 | disp.setmacro("textfailmsg", "depositor", textfailmsg);
|
---|
| 611 |
|
---|
| 612 | text_t bldlog = filename_cat(gsdlhome, "tmp", args["di1tmp"], args["di1dirname"] + ".bld");
|
---|
[20593] | 613 | //text_t rawlog = file_tail (bldlog, 6, 0);
|
---|
| 614 | text_t rawlog;
|
---|
| 615 | read_file(bldlog, rawlog);
|
---|
[12019] | 616 | // we'll shove in some <br> tags where \n's occur
|
---|
| 617 | text_t faillog;
|
---|
| 618 | text_t::const_iterator here = rawlog.begin();
|
---|
| 619 | text_t::const_iterator end = rawlog.end();
|
---|
| 620 | while (here != end) {
|
---|
| 621 | if (*here == '\n') faillog += "<br>";
|
---|
| 622 | faillog.push_back (*here);
|
---|
| 623 | ++here;
|
---|
| 624 | }
|
---|
| 625 | disp.setmacro ("faillog", "depositor", dm_safe(faillog));
|
---|
| 626 | }
|
---|
[12516] | 627 | }
|
---|
[12019] | 628 |
|
---|
| 629 |
|
---|
[12002] | 630 | //basic framework
|
---|
| 631 | bool depositoraction::do_action (cgiargsclass &args, recptprotolistclass * /*protos*/,
|
---|
| 632 | browsermapclass * /*browsers*/, displayclass &disp,
|
---|
| 633 | outconvertclass &outconvert, ostream &textout,
|
---|
| 634 | ostream &logout) {
|
---|
| 635 | // make sure the depositor is enabled
|
---|
| 636 | if (disabled) {
|
---|
| 637 | textout << outconvert
|
---|
| 638 | << "<html>\n"
|
---|
| 639 | << "<head>\n"
|
---|
| 640 | << "<title>Depositor disabled</title>\n"
|
---|
| 641 | << "</head>\n"
|
---|
| 642 | << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
|
---|
| 643 | << "alink=\"#cc9900\" vlink=\"#666633\">\n"
|
---|
| 644 | << "<h2>Facility disabled</h2>\n"
|
---|
| 645 | << "Sorry, the Depositor end-user collecation update facility is currently disabled\n"
|
---|
| 646 | << "\n</body>\n"
|
---|
| 647 | << "</html>\n";
|
---|
| 648 | return true;
|
---|
| 649 | }
|
---|
| 650 |
|
---|
| 651 | text_t &depositor_page = args["p"];
|
---|
| 652 | text_t &collection = args["di1dirname"];
|
---|
| 653 |
|
---|
| 654 | // make sure we have perl (we won't bother with this check for the
|
---|
| 655 | // building status pages to avoid slowing things down unneccessarily)
|
---|
| 656 | if (depositor_page != "bildstatus" && depositor_page != "bildframe1" && !perl_ok(logout)) {
|
---|
| 657 | textout << outconvert
|
---|
| 658 | << "<html>\n"
|
---|
| 659 | << "<head>\n"
|
---|
| 660 | << "<title>Perl not found</title>\n"
|
---|
| 661 | << "</head>\n"
|
---|
| 662 | << "<body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#006666\" "
|
---|
| 663 | << "alink=\"#cc9900\" vlink=\"#666633\">\n"
|
---|
| 664 | << "<h2>Perl not found</h2>\n"
|
---|
| 665 | << "Greenstone could not detect perl on this system. It is therefore not\n"
|
---|
| 666 | << "possible to build a Greenstone collection, either from the Collector or the \n"
|
---|
| 667 | << "command-line tools, or to use the Collector for any other task.\n"
|
---|
| 668 | << "<p>Please refer to the Greenstone Installer's Guide for details on\n"
|
---|
| 669 | << "installing perl on your system.\n"
|
---|
| 670 | << "\n</body>\n"
|
---|
| 671 | << "</html>\n";
|
---|
| 672 | return true;
|
---|
| 673 |
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | text_t::const_iterator here = depositor_page.begin();
|
---|
| 677 | text_t::const_iterator end = depositor_page.end();
|
---|
| 678 | text_t stepstring = substr(here,here+4);
|
---|
| 679 |
|
---|
[12019] | 680 | if ((depositor_page == "select") || (stepstring == "step")) {
|
---|
[12002] | 681 | textout << outconvert << disp << ("_depositor:header_\n")
|
---|
| 682 | << ("_depositor:" + depositor_page + "content_\n")
|
---|
| 683 | << ("_depositor:footer_\n");
|
---|
| 684 |
|
---|
| 685 | }
|
---|
[12516] | 686 |
|
---|
[17240] | 687 | if ((depositor_page == "bild") || (depositor_page == "depositonly")) {
|
---|
[12002] | 688 |
|
---|
| 689 | text_t filename_textt = args["di1userfile"];
|
---|
| 690 | text_t timestamp_str = args["di1timestamp"];
|
---|
| 691 | //check to make sure a file was uploaded
|
---|
| 692 | //if more than one upload occurred, the last one is taken
|
---|
| 693 | if(filename_textt == "") {
|
---|
| 694 | textout << outconvert << disp << "<p> no file available</p>\n";
|
---|
| 695 | } else {
|
---|
| 696 |
|
---|
[16310] | 697 | text_t col_dirname = filename_cat(collecthome,args[macro_prefix+"dirname"]);
|
---|
[12002] | 698 | text_t import_dirname = filename_cat(col_dirname,"import");
|
---|
| 699 | if(!directory_exists(import_dirname)) {
|
---|
| 700 | bool flag = mk_dir(import_dirname);
|
---|
| 701 | if(!flag) {
|
---|
| 702 | cerr << "Error: unable to make directory " << import_dirname << endl;
|
---|
| 703 | return true;
|
---|
| 704 | }
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | text_t dirname = filename_cat(import_dirname,timestamp_str);
|
---|
| 708 | bool flag = mk_dir(dirname);
|
---|
| 709 | if(!flag) {
|
---|
| 710 | cerr << "Error: unable to make timestamp directory " << dirname << endl;
|
---|
| 711 | return true;
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | text_t filename_textt = args["di1userfile"];
|
---|
| 715 | text_t tmpdir = filename_cat(gsdlhome,"tmp",args["di1tmp"],timestamp_str);
|
---|
| 716 | text_t tmpfile = filename_cat(tmpdir,filename_textt);
|
---|
| 717 | text_t filename = filename_cat(dirname, filename_textt);
|
---|
| 718 | if(!file_copy(tmpfile, filename)) {
|
---|
| 719 | cerr << "Unable to copy " << tmpfile << " to " << filename << endl;
|
---|
| 720 | }
|
---|
[12516] | 721 |
|
---|
[12002] | 722 | //write the metadata file
|
---|
| 723 | write_metadata_file(args, filename_textt, timestamp_str);
|
---|
| 724 |
|
---|
| 725 | if(depositor_page == "bild"){
|
---|
| 726 |
|
---|
| 727 | //create a manifest file
|
---|
| 728 | write_manifest_file(args, filename_textt, timestamp_str);
|
---|
| 729 |
|
---|
| 730 | // do the work (download, import, build)
|
---|
| 731 | gsdl_build (args, logout);
|
---|
| 732 |
|
---|
| 733 | if (message.empty()) {
|
---|
| 734 | // bild page is a frameset so we don't want headers and stuff
|
---|
| 735 | textout << outconvert << disp << ("_depositor:bildcontent_\n");
|
---|
| 736 | }
|
---|
| 737 | }
|
---|
| 738 | }
|
---|
| 739 | }
|
---|
| 740 |
|
---|
[12019] | 741 | if (message.empty()) {
|
---|
[12002] | 742 |
|
---|
| 743 | if (depositor_page != "bild" && stepstring != "step" && depositor_page != "select") {
|
---|
| 744 | // output page ("bild" page was already output above)
|
---|
| 745 | textout << outconvert << disp << ("_depositor:header_\n")
|
---|
| 746 | << ("_depositor:" + depositor_page + "content_\n")
|
---|
| 747 | << ("_depositor:footer_\n");
|
---|
| 748 | }
|
---|
| 749 | } else {
|
---|
| 750 | // message was set somewhere (probably an error), output message page
|
---|
| 751 | textout << outconvert << disp << ("_depositor:header_\n")
|
---|
| 752 | << ("_depositor:" + message + "content_\n")
|
---|
| 753 | << ("_depositor:footer_\n");
|
---|
| 754 | message.clear();
|
---|
| 755 | }
|
---|
| 756 |
|
---|
| 757 | return true;
|
---|
| 758 |
|
---|
| 759 | }
|
---|
| 760 |
|
---|
| 761 |
|
---|
| 762 | //This function creates a metadata.xml file
|
---|
| 763 | void depositoraction::write_metadata_file(cgiargsclass &args, text_t filename_str, text_t& timestamp_str)
|
---|
| 764 | {
|
---|
| 765 |
|
---|
| 766 | //build metadata file
|
---|
| 767 | //the front
|
---|
| 768 | text_t metadata_file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
| 769 | metadata_file += "<!DOCTYPE DirectoryMetadata SYSTEM \"http://greenstone.org/dtd/DirectoryMetadata/1.0/DirectoryMetadata.dtd\">\n";
|
---|
| 770 | metadata_file += "<DirectoryMetadata>\n";
|
---|
| 771 | metadata_file += " <FileSet>\n";
|
---|
| 772 | metadata_file += " <FileName>";
|
---|
| 773 |
|
---|
[12019] | 774 | // Generate 'regular expression' save version of filename
|
---|
| 775 | // for now that means escaping any '.' characters
|
---|
| 776 | // consider generalising as function in gsdltools.h/cpp?
|
---|
[12002] | 777 |
|
---|
[12019] | 778 | text_t filename_re;
|
---|
| 779 | text_t::const_iterator here = filename_str.begin();
|
---|
| 780 | text_t::const_iterator end = filename_str.end();
|
---|
| 781 | while (here != end) {
|
---|
| 782 | if (*here == '.') {
|
---|
| 783 | filename_re.push_back('\\');
|
---|
| 784 | }
|
---|
| 785 |
|
---|
| 786 | filename_re.push_back(*here);
|
---|
| 787 | ++here;
|
---|
| 788 | }
|
---|
| 789 |
|
---|
| 790 | metadata_file += filename_re;
|
---|
| 791 |
|
---|
[12002] | 792 | metadata_file += "</FileName>\n";
|
---|
| 793 | metadata_file += " <Description>\n";
|
---|
| 794 |
|
---|
[16680] | 795 |
|
---|
[12002] | 796 | cgiargsclass::const_iterator args_here = args.begin();
|
---|
| 797 | cgiargsclass::const_iterator args_end = args.end();
|
---|
| 798 |
|
---|
| 799 | while (args_here != args_end) {
|
---|
| 800 | text_t args_name = (*args_here).first;
|
---|
| 801 |
|
---|
| 802 | int prefix_len = macro_prefix.size();
|
---|
| 803 |
|
---|
| 804 | text_t args_prefix = substr(args_name.begin(),args_name.begin()+prefix_len+3);
|
---|
| 805 |
|
---|
| 806 | if (args_prefix == (macro_prefix+"md.")) {
|
---|
| 807 | text_t args_val = args[args_name];
|
---|
| 808 |
|
---|
| 809 | text_t args_suffix = substr(args_name.begin()+prefix_len+3,args_name.end());
|
---|
| 810 |
|
---|
| 811 | text_tarray mdvalues;
|
---|
| 812 | splitchar (args_val.begin(), args_val.end(), ',', mdvalues);
|
---|
| 813 | int numvalues = mdvalues.size();
|
---|
| 814 |
|
---|
| 815 | for (int i = 0; i < numvalues; ++i) {
|
---|
| 816 | if (!mdvalues[i].empty()) {
|
---|
| 817 |
|
---|
| 818 | decode_cgi_arg(mdvalues[i]);
|
---|
| 819 |
|
---|
[16680] | 820 | metadata_file += " <Metadata mode=\"accumulate\" name=\"";
|
---|
[12002] | 821 | metadata_file += args_suffix;
|
---|
| 822 | metadata_file += "\">";
|
---|
| 823 | metadata_file += mdvalues[i];
|
---|
| 824 | metadata_file += "</Metadata>\n";
|
---|
| 825 |
|
---|
| 826 | }
|
---|
| 827 | }
|
---|
[16680] | 828 | }
|
---|
[12002] | 829 |
|
---|
| 830 | ++args_here;
|
---|
| 831 | }
|
---|
| 832 |
|
---|
| 833 | //the end of the file
|
---|
| 834 | metadata_file += " </Description>\n";
|
---|
| 835 | metadata_file += " </FileSet>\n";
|
---|
| 836 | metadata_file += "</DirectoryMetadata>\n";
|
---|
| 837 |
|
---|
| 838 | //create metadata.xml file
|
---|
[16310] | 839 | text_t metadata_path = filename_cat(collecthome, args[macro_prefix+"dirname"], "import", timestamp_str, "metadata.xml");
|
---|
[12002] | 840 | text_t my_path = filename_cat(gsdlhome,"tmp", "metadata.xml");
|
---|
| 841 |
|
---|
| 842 | ofstream metadata(metadata_path.getcstr());
|
---|
| 843 | ofstream my_tmp(my_path.getcstr());
|
---|
| 844 |
|
---|
| 845 | if(!metadata.is_open()) {
|
---|
| 846 | cerr << "Cannot open metadata.xml!" << endl;
|
---|
| 847 | } else {
|
---|
| 848 |
|
---|
| 849 | //write metadata.xml
|
---|
| 850 | metadata.write(metadata_file.getcstr(), metadata_file.size());
|
---|
| 851 | my_tmp.write(metadata_file.getcstr(), metadata_file.size());
|
---|
| 852 | }
|
---|
| 853 | }
|
---|
| 854 |
|
---|
| 855 | //This function creates a manifest.xml file
|
---|
| 856 | void depositoraction::write_manifest_file(cgiargsclass &args, text_t filename,
|
---|
| 857 | text_t& timestamp_str)
|
---|
| 858 | {
|
---|
| 859 |
|
---|
| 860 | //build manifest file
|
---|
| 861 |
|
---|
| 862 | //the front
|
---|
| 863 | text_t manifest_file = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
| 864 | manifest_file += "<Manifest>\n";
|
---|
[17248] | 865 | manifest_file += " <Import>\n";
|
---|
[12002] | 866 | manifest_file += " <Filename>\n";
|
---|
| 867 | manifest_file += " " + timestamp_str + "\n";
|
---|
| 868 | manifest_file += " </Filename>\n";
|
---|
| 869 |
|
---|
| 870 | //the end of the file
|
---|
[17248] | 871 | manifest_file += " </Import>\n";
|
---|
[12002] | 872 | manifest_file += "</Manifest>\n";
|
---|
| 873 |
|
---|
| 874 | //create manifest.xml file
|
---|
[16310] | 875 | text_t manifest_path = filename_cat(collecthome, args[macro_prefix+"dirname"], "manifest.xml");
|
---|
[12002] | 876 |
|
---|
| 877 | char* manifest_cstr = manifest_path.getcstr();
|
---|
| 878 |
|
---|
| 879 | ofstream manifest(manifest_cstr);
|
---|
| 880 |
|
---|
| 881 | if(!manifest.is_open()) {
|
---|
| 882 | cerr << "Cannot open" << manifest_cstr << endl;
|
---|
| 883 | } else {
|
---|
| 884 |
|
---|
| 885 | //write manifest.xml
|
---|
| 886 | char *manifest_file_cstr = manifest_file.getcstr();
|
---|
| 887 | manifest.write(manifest_file_cstr, manifest_file.size());
|
---|
| 888 | delete [] manifest_file_cstr;
|
---|
| 889 | }
|
---|
| 890 |
|
---|
| 891 | delete [] manifest_cstr;
|
---|
| 892 | }
|
---|
| 893 |
|
---|
| 894 |
|
---|
| 895 |
|
---|
| 896 | text_t depositoraction::get_button(cgiargsclass &args, const text_t &thispage,
|
---|
| 897 | const text_t &color,
|
---|
| 898 | const text_t &type, bool enabled)
|
---|
| 899 | {
|
---|
| 900 |
|
---|
| 901 | text_t::const_iterator here = type.begin();
|
---|
| 902 | text_t::const_iterator end = type.end();
|
---|
| 903 | text_t stepstring = substr(here,here+4);
|
---|
| 904 | if ((color != "green" && color != "grey" && color != "yellow") ||
|
---|
| 905 | (type != "select" && type != "laststep" && stepstring != "step" && type != "view"))
|
---|
| 906 | return g_EmptyText;
|
---|
| 907 |
|
---|
| 908 | text_t href = "_http"+type+"_";
|
---|
| 909 | text_t target = "";
|
---|
| 910 |
|
---|
| 911 | here = thispage.begin();
|
---|
| 912 | stepstring = substr(here,here+4);
|
---|
| 913 | if (thispage == "bildcancel" || thispage == "bildfail" || thispage == "select"|| stepstring == "step") {
|
---|
| 914 | // call the check submit macro instead of linking directly to the page
|
---|
| 915 |
|
---|
| 916 | if(type == "laststep") {
|
---|
| 917 | href="\"javascript:check_submit('_"+type+"_');\"";
|
---|
| 918 | } else {
|
---|
| 919 | href="\"javascript:check_submit('"+type+"');\"";
|
---|
| 920 | }
|
---|
| 921 |
|
---|
| 922 | } else if (type == "view") {
|
---|
[12476] | 923 | //target = " target=_top";
|
---|
| 924 | target = " target=_blank";
|
---|
[12002] | 925 | }
|
---|
| 926 |
|
---|
| 927 | text_t tdclass = "wizardbar"+color;
|
---|
| 928 | if (enabled) {
|
---|
| 929 | // link to the appropriate page
|
---|
| 930 | return "<td class="+tdclass+"><a href="+href+target+">_text"+type+"_</a></td>";
|
---|
| 931 | }
|
---|
| 932 | else {
|
---|
| 933 | // just display the text
|
---|
| 934 | return "<td class="+tdclass+">_text"+type+"_</td>";
|
---|
| 935 | }
|
---|
| 936 | }
|
---|
| 937 |
|
---|
| 938 |
|
---|
| 939 | #endif //GSDL_USE_DEPOSITOR_ACTION
|
---|