Browse Source

- added payloadmanifest.cpp

- added bagmetadata.cpp (needs more work)
master
parent
commit
65bd3a72fe
5 changed files with 151 additions and 6 deletions
  1. +2
    -2
      src/include/bag.hpp
  2. +29
    -4
      src/include/bagmetadata.hpp
  3. +78
    -0
      src/lib/bagmetadata.cpp
  4. +8
    -0
      src/lib/load_bag.cpp
  5. +34
    -0
      src/lib/payloadmanifest.cpp

+ 2
- 2
src/include/bag.hpp View File

@ -21,8 +21,8 @@ class Bag {
int bagit_version_minor;
string tag_file_character_encoding;
class Payload *payload_p;;
class Payloadmanifest *payloadmanifest_p; // TODO: list of manifests
class Tagmanifest *tagmanifest_p; // TODO: list of tag manifests, optional
class Payloadmanifest *payloadmanifest_p;
class Tagmanifest *tagmanifest_p;
class Bagmetadata *bagmetadata_p;
class Fetchfile *fetchfile_p;
class Othertags *othertags_p; //TODO: optional


+ 29
- 4
src/include/bagmetadata.hpp View File

@ -1,11 +1,36 @@
#ifndef LIBCBAG_BAGMETADATA
#define LIBCBAG_BAG_METADATA
#define LIBCBAG_BAGMETADATA
#include <string>
#include <map>
using namespace std;
class bagmetadata{
enum {
SourceOrganization,
OrganizationAddress,
ContactName,
ContactPhone,
ContactEmail,
ExternalDescription,
BaggingDate,
ExternalIdentifier,
BagSize,
PayloadOxum,
BagGroupIdentifier,
BagCount,
InternalSenderIdentifier,
InternalSenderDescription,
};
class Bagmetadata{
private:
map<string,string> metadata;
bool exist_bagmetadata_file;
public:
bagmetadata();
Bagmetadata( string basedir );
bool has_bagmetadata();
map<string,string> get_metadata();
};
#endif
// vim: set tabstop=4
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 78
- 0
src/lib/bagmetadata.cpp View File

@ -0,0 +1,78 @@
#include "bagmetadata.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <regex>
#include <tr1/regex>
#include <boost/filesystem.hpp>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
Bagmetadata::Bagmetadata( string basedir ) {
// test if file exists
string filename = basedir + "bag-info.txt";
fs::path p{ filename };
fs::file_status s = fs::status( p );
cout << "path "<< p.string() << endl;
cout << "is file: "<< fs::is_regular_file( s) << endl;
if (fs::is_regular_file( s)) {
this->exist_bagmetadata_file = true;
// map entries
// from spec: A metadata element MUST consist of a label, a colon, and a value,
// each separated by optional whitespace
// Long values may be continued
// onto the next line by inserting a newline (LF), a carriage return
// (CR), or carriage return plus newline (CRLF) and indenting the next
// line with linear white space (spaces or tabs)
ifstream file;
file.open( filename );
if (file.is_open()) {
string content(
(istreambuf_iterator<char>(file)),
istreambuf_iterator<char>()
);
file.close();
// parse content using regex based split
regex rgx_line("\\n(?=\\S)"); // entry should not start with whitespace
regex key_value_separator(":\\s*");
// DEBUG: string repl = "|";
// DEBUG: string content2 = regex_replace(content, rgx, "|");
// DEBUG: cout << "REPL:(" << content2 << ")" << endl;
sregex_token_iterator iter_line(content.begin(),
content.end(),
rgx_line,
-1);
sregex_token_iterator endline;
for ( ; iter_line != endline; ++iter_line) {
// DEBUG: std::cout << "ENTRY(" << *iter_line << ")" << endl;
string line = *iter_line;
sregex_token_iterator iter(line.begin(),
line.end(),
key_value_separator,
-1);
string key;
string value;
// TODO: add check for results!
key = *(iter);
value = (*++iter);
Bagmetadata::metadata[ key ] = value;
// DEBUG: cout << "KEY="<<key<<" value="<<value<<endl;
}
}
} else { // no file
this->exist_bagmetadata_file = false;
}
}
map <string,string> Bagmetadata::get_metadata() {
return this->metadata;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 8
- 0
src/lib/load_bag.cpp View File

@ -59,6 +59,13 @@ Bag::Bag( string dfname ) {
Bag::payloadmanifest_p = new Payloadmanifest(dfname);
// read in tagmanifest
Bag::tagmanifest_p = new Tagmanifest(dfname);
// read in baginfo
Bag::bagmetadata_p = new Bagmetadata(dfname);
map<string,string> md = Bag::bagmetadata_p->get_metadata();
map<string,string>::iterator m;
for (m=md.begin(); m!=md.end(); m++) {
cout << m->first << " = " << m->second <<endl;
}
list<string>::iterator i;
for (i=files.begin(); i!=files.end(); i++) {
@ -68,6 +75,7 @@ Bag::Bag( string dfname ) {
Bag::payloadmanifest_p->get_checksum_file_pairs( md5 );
Bag::tagmanifest_p->get_checksum_file_pairs( md5 );
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab


+ 34
- 0
src/lib/payloadmanifest.cpp View File

@ -0,0 +1,34 @@
#include "payloadmanifest.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
Payloadmanifest::Payloadmanifest( string basedir ) {
map<checksum_algorithms, string> possible_manifest_files;
possible_manifest_files[md5] = "manifest-md5.txt";
possible_manifest_files[sha1] = "manifest-sha1.txt";
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
// debug
cout << it->first << " => " << it->second << endl;
// test if file exists
string filename = basedir + it->second;
fs::path p{ filename };
fs::file_status s = fs::status( p );
cout << "path "<< p.string() << endl;
cout << "is file: "<< fs::is_regular_file( s) << endl;
if (fs::is_regular_file( s)) {
Payloadmanifest::manifest_algorithm_files[it->first] = filename;
}
}
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

Loading…
Cancel
Save