root/main/trunk/greenstone2/runtime-src/src/oaiservr/dublincore.cpp @ 22739

Revision 22739, 5.4 KB (checked in by mdewsnip, 9 years ago)

Added copyright header to runtime-src/src/oaiserver/*.cpp and runtime-src/src/oaiserver/*.h.

  • Property svn:keywords set to Author Date Id Revision
Line 
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 *********************************************************************/
26
27
28#include "dublincore.h"
29#include "gsdltools.h"
30
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
53const text_t dublin_core::formatName() {
54  return "oai_dc";
55}
56
57const text_t dublin_core::formatPrefix() {
58  return "dc";
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
101bool dublin_core::output_custom_metadata(ostream &output, outconvertclass &outconvert, bool &headerDone, const text_t &collection, ResultDocInfo_t &docInfo) {
102  text_t value = get_metadata_value(docInfo, "gs.OAIResourceURL");
103  if (value.empty()) {
104    // try srclink_file
105    value = get_metadata_value(docInfo, "srclink_file");
106    if (value.empty()) {
107      // we have no file to link to, so link to the Greenstone version of the
108      // document
109      value = this->oaiConfigure->getBaseLibraryURL()+"?a=d&c="+collection+"&d="+docInfo.OID;
110    } else {
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);
115      }
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    } else {
122      value = "";
123    }
124      }
125    }
126  }
127  if (!value.empty()) {
128    if (!headerDone) {
129      this->output_metadata_header(output);
130      headerDone = true;
131    }
132    if (this->oaiConfigure->getOAIVersion() >= 200) {
133      output << outconvert << "        <dc:identifier>" << xml_safe(value) << "</dc:identifier>\n";
134    }
135    else {
136      output << outconvert << "        <identifier>"  << xml_safe(value) << "</identifier>\n";
137    }
138  }
139  return true;
140}
141
142bool dublin_core::output_formatdata(ostream &output)
143{
144  output << "    <metadataPrefix>oai_dc</metadataPrefix>" << endl;
145
146  if (this->oaiConfigure->getOAIVersion() <= 110) {
147    output << "    <schema>http://www.openarchives.org/OAI/1.1/dc.xsd</schema>" << endl
148       << "    <metadataNamespace>http://purl.org/dc/elements/1.1/</metadataNamespace>" << endl;
149  }
150  else {
151    output << "    <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>" << endl
152       << "    <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>"
153       << endl;
154  }
155  return true;
156}
157
Note: See TracBrowser for help on using the browser.