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

Last change on this file since 32203 was 32203, checked in by kjdon, 6 years ago

custom code changed from outputting (for dc:identifier) gs.ResourceURL OR srclink OR link to outputting any and all that it finds of those three values.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
RevLine 
[22739]1/**********************************************************************
2 *
3 * dublincore.cpp --
4 *
5 * Copyright (C) 2004-2010 The New Zealand Digital Library Project
6 *
7 * A component of the Greenstone digital library software
8 * from the New Zealand Digital Library Project at the
9 * University of Waikato, New Zealand.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 *********************************************************************/
[8219]26
[22739]27
[8182]28#include "dublincore.h"
[21761]29#include "gsdltools.h"
[8182]30
[18895]31dublin_core::dublin_core() : metaformat() {
32 // These element names taken from the schema
33 // http://www.openarchives.org/OAI/2.0/oai_dc.xsd
34 elementSet.insert("contributor");
35 elementSet.insert("coverage");
36 elementSet.insert("creator");
37 elementSet.insert("date");
38 elementSet.insert("description");
39 elementSet.insert("format");
40 elementSet.insert("identifier");
41 elementSet.insert("language");
42 elementSet.insert("publisher");
43 elementSet.insert("relation");
44 elementSet.insert("rights");
45 elementSet.insert("source");
46 elementSet.insert("subject");
47 elementSet.insert("title");
48 elementSet.insert("type");
49
50
51}
52
[8182]53const text_t dublin_core::formatName() {
54 return "oai_dc";
55}
56
57const text_t dublin_core::formatPrefix() {
[8219]58 return "dc";
[8182]59}
60
61bool dublin_core::output_record(ostream &output, recptproto *protocol, const text_t &collection,
62 const text_t &record_OID)
63{
64 return metaformat::output_record(output, protocol, collection, record_OID);
65}
66
67void dublin_core::output_metadata_header(ostream &output)
68{
69 output << " <metadata>\n";
70
71 if (this->oaiConfigure->getOAIVersion() <= 110){
72 // output dublin core wrapper for OAI v1.1
73 output << " <dc xmlns=\"http://purl.org/dc/elements/1.1/\"\n"
74 << " xmlns:xsi=\"http://www.w3c.org/2001/XMLSchema-instance\"\n"
75 << " xsi:schemaLocation=\"http://purl.org/dc/elements/1.1/\n"
76 << " http://www.openarchives.org/OAI/1.1/dc.xsd\">\n";
77 }
78 else {
79 output << " <oai_dc:dc\n"
80 << " xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\"\n"
81 << " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n"
82 << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
83 << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/\n"
84 << " http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">\n";
85 }
86}
87
88void dublin_core::output_metadata_footer(ostream &output)
89{
90 if (this->oaiConfigure->getOAIVersion() <= 110) {
91 output << " </dc>" << endl;
92 }
93 else {
94 output << " </oai_dc:dc>" << endl;
95 }
96
97 output << " </metadata>" << endl;
98 output.flush();
99}
100
[32203]101// output dc:identifier for gs.OAIResourceURL, srclink, and link (whichever are defined)
[21761]102bool dublin_core::output_custom_metadata(ostream &output, outconvertclass &outconvert, bool &headerDone, const text_t &collection, ResultDocInfo_t &docInfo) {
[32203]103 text_tarray values;
[22214]104 text_t value = get_metadata_value(docInfo, "gs.OAIResourceURL");
[32203]105 if (!value.empty()) {
106 values.push_back(value);
[21761]107 }
[32203]108 // try srclinkFile (the metaname "srclink_file" is deprecated, use "srclinkFile")
109 value = get_metadata_value(docInfo, "srclinkFile");
[21761]110 if (!value.empty()) {
[32203]111 if (starts_with(value, "[")) {
112 // its a format statement type value eg [SourceFile], need to get the appropriate metadata
113 value = substr(findchar(value.begin(), value.end(), '[')+1,findchar(value.begin(), value.end(), ']') );
114 value = get_metadata_value(docInfo, value);
[21761]115 }
[32203]116
117 if (!value.empty()) {
118 text_t assocfilepath = get_metadata_value(docInfo, "assocfilepath");
119 if (!assocfilepath.empty()) {
120 value = this->oaiConfigure->getBaseDocRoot()+"/collect/"+collection+"/index/assoc/"+assocfilepath+"/"+value;
121 values.push_back(value);
122 } else {
123 value = "";
124 }
125 }
126 }
127 // now add link
128 value = this->oaiConfigure->getBaseLibraryURL()+"?a=d&c="+collection+"&d="+docInfo.OID;
129 values.push_back(value);
130
131 if (!headerDone) {
132 this->output_metadata_header(output);
133 headerDone = true;
134 }
135 for (int i=0; i<values.size(); i++) {
[21761]136 if (this->oaiConfigure->getOAIVersion() >= 200) {
[32203]137 output << outconvert << " <dc:identifier>" << xml_safe(values[i]) << "</dc:identifier>\n";
[21761]138 }
139 else {
[32203]140 output << outconvert << " <identifier>" << xml_safe(values[i]) << "</identifier>\n";
[21761]141 }
142 }
[32203]143
[21799]144 return true;
[21761]145}
146
[8182]147bool dublin_core::output_formatdata(ostream &output)
148{
149 output << " <metadataPrefix>oai_dc</metadataPrefix>" << endl;
150
151 if (this->oaiConfigure->getOAIVersion() <= 110) {
152 output << " <schema>http://www.openarchives.org/OAI/1.1/dc.xsd</schema>" << endl
153 << " <metadataNamespace>http://purl.org/dc/elements/1.1/</metadataNamespace>" << endl;
154 }
155 else {
156 output << " <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>" << endl
157 << " <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>"
158 << endl;
159 }
160 return true;
161}
162
Note: See TracBrowser for help on using the repository browser.