source: main/trunk/greenstone2/runtime-src/src/oaiservr/dublincore.cpp@ 21799

Last change on this file since 21799 was 21799, checked in by kjdon, 12 years ago

output_custom_metadata needs a return value

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1
2#include "dublincore.h"
3#include "gsdltools.h"
4
5dublin_core::dublin_core() : metaformat() {
6 // These element names taken from the schema
7 // http://www.openarchives.org/OAI/2.0/oai_dc.xsd
8 elementSet.insert("contributor");
9 elementSet.insert("coverage");
10 elementSet.insert("creator");
11 elementSet.insert("date");
12 elementSet.insert("description");
13 elementSet.insert("format");
14 elementSet.insert("identifier");
15 elementSet.insert("language");
16 elementSet.insert("publisher");
17 elementSet.insert("relation");
18 elementSet.insert("rights");
19 elementSet.insert("source");
20 elementSet.insert("subject");
21 elementSet.insert("title");
22 elementSet.insert("type");
23
24
25}
26
27const text_t dublin_core::formatName() {
28 return "oai_dc";
29}
30
31const text_t dublin_core::formatPrefix() {
32 return "dc";
33}
34
35bool dublin_core::output_record(ostream &output, recptproto *protocol, const text_t &collection,
36 const text_t &record_OID)
37{
38 return metaformat::output_record(output, protocol, collection, record_OID);
39}
40
41void dublin_core::output_metadata_header(ostream &output)
42{
43 output << " <metadata>\n";
44
45 if (this->oaiConfigure->getOAIVersion() <= 110){
46 // output dublin core wrapper for OAI v1.1
47 output << " <dc xmlns=\"http://purl.org/dc/elements/1.1/\"\n"
48 << " xmlns:xsi=\"http://www.w3c.org/2001/XMLSchema-instance\"\n"
49 << " xsi:schemaLocation=\"http://purl.org/dc/elements/1.1/\n"
50 << " http://www.openarchives.org/OAI/1.1/dc.xsd\">\n";
51 }
52 else {
53 output << " <oai_dc:dc\n"
54 << " xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\"\n"
55 << " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
56 << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
57 << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n"
58 << " http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n";
59 }
60}
61
62void dublin_core::output_metadata_footer(ostream &output)
63{
64 if (this->oaiConfigure->getOAIVersion() <= 110) {
65 output << " </dc>" << endl;
66 }
67 else {
68 output << " </oai_dc:dc>" << endl;
69 }
70
71 output << " </metadata>" << endl;
72 output.flush();
73}
74
75bool dublin_core::output_custom_metadata(ostream &output, outconvertclass &outconvert, bool &headerDone, const text_t &collection, ResultDocInfo_t &docInfo) {
76 text_t value = get_metadata_value(docInfo, "srclink_file");
77 if (value.empty()) {
78 value = "gs doc"; // todo, situation where no source doc.
79 } else {
80 if (starts_with(value, "[")) {
81 // its a format statement type value eg [SourceFile], need to get the appropriate metadata
82 value = substr(findchar(value.begin(), value.end(), '[')+1,findchar(value.begin(), value.end(), ']') );
83 value = get_metadata_value(docInfo, value);
84 }
85 }
86 if (!value.empty()) {
87 text_t assocfilepath = get_metadata_value(docInfo, "assocfilepath");
88 if (!assocfilepath.empty()) {
89 value = this->oaiConfigure->getCollectionConfig("", "baseDocRoot")+"/collect/"+collection+"/index/assoc/"+assocfilepath+"/"+value;
90 } else {
91 value = "";
92 }
93
94 }
95 if (!value.empty()) {
96 if (!headerDone) {
97 this->output_metadata_header(output);
98 headerDone = true;
99 }
100 if (this->oaiConfigure->getOAIVersion() >= 200) {
101 output << outconvert << " <dc:identifier>" << xml_safe(value) << "</dc:identifier>\n";
102 }
103 else {
104 output << outconvert << " <identifier>" << xml_safe(value) << "</identifier>\n";
105 }
106 }
107 return true;
108}
109
110bool dublin_core::output_formatdata(ostream &output)
111{
112 output << " <metadataPrefix>oai_dc</metadataPrefix>" << endl;
113
114 if (this->oaiConfigure->getOAIVersion() <= 110) {
115 output << " <schema>http://www.openarchives.org/OAI/1.1/dc.xsd</schema>" << endl
116 << " <metadataNamespace>http://purl.org/dc/elements/1.1/</metadataNamespace>" << endl;
117 }
118 else {
119 output << " <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>" << endl
120 << " <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>"
121 << endl;
122 }
123 return true;
124}
125
Note: See TracBrowser for help on using the repository browser.