-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDC.pm
201 lines (157 loc) · 9.9 KB
/
DC.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package EPrints::Plugin::Export::DC;
# eprint needs magic documents field
# documents needs magic files field
use EPrints::Plugin::Export::TextFile;
@ISA = ( "EPrints::Plugin::Export::TextFile" );
use strict;
sub new
{
my( $class, %params ) = @_;
my $self = $class->SUPER::new( %params );
$self->{name} = "Dublin Core";
$self->{accept} = [ 'list/eprint', 'dataobj/eprint' ];
$self->{visible} = "all";
return $self;
}
sub output_dataobj
{
my( $plugin, $dataobj ) = @_;
my $data = $plugin->convert_dataobj( $dataobj );
my $r = "";
foreach( @{$data} )
{
next unless defined( $_->[1] );
my $v = $_->[1];
$v=~s/[\r\n]/ /g;
$r.=$_->[0].": $v\n";
}
$r.="\n";
return $r;
}
sub dataobj_to_html_header
{
my( $plugin, $dataobj ) = @_;
my $links = $plugin->{session}->make_doc_fragment;
$links->appendChild( $plugin->{session}->make_element(
"link",
rel => "schema.DC",
href => "http://purl.org/DC/elements/1.0/" ) );
$links->appendChild( $plugin->{session}->make_text( "\n" ));
my $dc = $plugin->convert_dataobj( $dataobj );
foreach( @{$dc} )
{
$links->appendChild( $plugin->{session}->make_element(
"meta",
name => "DC.".$_->[0],
content => $_->[1] ) );
$links->appendChild( $plugin->{session}->make_text( "\n" ));
}
return $links;
}
sub convert_dataobj
{
my( $plugin, $eprint ) = @_;
my @dcdata = ();
# push @dcdata, [ "title", $eprint->get_value( "title" ) ] if( $eprint->exists_and_set( "title" ) );
# foreach my $v (@{$eprint->value( "title" )})
# {
# push @dcdata, [ "title", $eprint->get_value("title")[0]->{name} ];
# }
foreach my $v ( @ {$eprint->value( "title" )})
{
push @dcdata, [ "title", $v->{name} ];
}
# grab the creators without the ID parts so if the site admin
# sets or unsets creators to having and ID part it will make
# no difference to this bit.
if( $eprint->exists_and_set( "creators_name" ) )
{
my $creators = $eprint->get_value( "creators_name" );
if( defined $creators )
{
foreach my $creator ( @{$creators} )
{
next if !defined $creator;
push @dcdata, [ "creator", EPrints::Utils::make_name_string( $creator ) ];
}
}
}
if( $eprint->exists_and_set( "subjects" ) )
{
my $subjectid;
foreach $subjectid ( @{$eprint->get_value( "subjects" )} )
{
my $subject = EPrints::DataObj::Subject->new( $plugin->{session}, $subjectid );
# avoid problems with bad subjects
next unless( defined $subject );
push @dcdata, [ "subject", EPrints::Utils::tree_to_utf8( $subject->render_description() ) ];
}
}
# push @dcdata, [ "description", $eprint->get_value( "abstract" ) ] if( $eprint->exists_and_set( "abstract" ) );
foreach my $v_a ( @ {$eprint->value( "abstract" )})
{
push @dcdata, [ "description", $v_a->{name} ];
}
# push @dcdata, [ "publisher", $eprint->get_value( "publisher" ) ] if( $eprint->exists_and_set( "publisher" ) );
foreach my $v_p ( @ {$eprint->value( "publisher" )})
{
push @dcdata, [ "publisher", $v_p->{name} ];
}
if( $eprint->exists_and_set( "editors_name" ) )
{
my $editors = $eprint->get_value( "editors_name" );
if( defined $editors )
{
foreach my $editor ( @{$editors} )
{
push @dcdata, [ "contributor", EPrints::Utils::make_name_string( $editor ) ];
}
}
}
## Date for discovery. For a month/day we don't have, assume 01.
if( $eprint->exists_and_set( "date" ) )
{
my $date = $eprint->get_value( "date" );
if( defined $date )
{
$date =~ s/(-0+)+$//;
push @dcdata, [ "date", $date ];
}
}
if( $eprint->exists_and_set( "type" ) )
{
push @dcdata, [ "type", EPrints::Utils::tree_to_utf8( $eprint->render_value( "type" ) ) ];
}
my $ref = "NonPeerReviewed";
if( $eprint->exists_and_set( "refereed" ) && $eprint->get_value( "refereed" ) eq "TRUE" )
{
$ref = "PeerReviewed";
}
push @dcdata, [ "type", $ref ];
my @documents = $eprint->get_all_documents();
my $mimetypes = $plugin->{session}->get_repository->get_conf( "oai", "mime_types" );
foreach( @documents )
{
my $format = $mimetypes->{$_->get_value("format")};
$format = $_->get_value("format") unless defined $format;
#$format = "application/octet-stream" unless defined $format;
push @dcdata, [ "format", $format ];
push @dcdata, [ "identifier", $_->get_url() ];
}
# Most commonly a DOI or journal link
if( $eprint->exists_and_set( "official_url" ) )
{
push @dcdata, [ "relation", $eprint->get_value( "official_url" ) ];
}
# The citation for this eprint
push @dcdata, [ "identifier",
EPrints::Utils::tree_to_utf8( $eprint->render_citation() ) ];
# The URL of the abstract page
push @dcdata, [ "relation", $eprint->get_url() ];
# dc.language not handled yet.
# dc.source not handled yet.
# dc.coverage not handled yet.
# dc.rights not handled yet.
return \@dcdata;
}
1;