1
|
#!/usr/bin/perl
|
2
|
|
3
|
# check that the correct number or parameters are issued
|
4
|
if (($#ARGV +1) != 3) {die "Usage: %./get_eml.pl <metacat_url> <login> <passwd>\n\n";}
|
5
|
|
6
|
($url, $username, $password) = @ARGV; #get the input file and output file names
|
7
|
|
8
|
|
9
|
use Metacat;
|
10
|
use XML::DOM;
|
11
|
|
12
|
my $metacat = Metacat->new();
|
13
|
|
14
|
|
15
|
if ($metacat) {
|
16
|
$metacat->set_options( metacatUrl => $url );
|
17
|
} else {
|
18
|
#print "Failed during metacat creation.";
|
19
|
$error = 1;
|
20
|
exit();
|
21
|
}
|
22
|
|
23
|
# Login to metacat
|
24
|
# //print "Logging in to metacat..........\n";
|
25
|
my $response1 = $metacat->login($username, $password);
|
26
|
if (! $response1) {
|
27
|
# //print $metacat->getMessage();
|
28
|
# //print "Failed during login: metacat.\n";
|
29
|
$error = 2;
|
30
|
} else {
|
31
|
# //print "Logged in.\n";
|
32
|
}
|
33
|
|
34
|
|
35
|
my $query = "<?xml version=\"1.0\" ?> <pathquery version=\"1.2\"> <querytitle>Untitled-Search-2</querytitle> <returndoctype>-//ecoinformatics.org//eml-dataset-2.0.0beta6//EN</returndoctype> <returndoctype>-//NCEAS//eml-dataset-2.0//EN</returndoctype> <returndoctype>eml://ecoinformatics.org/eml-2.0.0</returndoctype> <returnfield>dataset/title</returnfield> <returnfield>individualName/surName</returnfield> <returnfield>keyword</returnfield><returnfield>westBoundingCoordinate</returnfield><returnfield>eastBoundingCoordinate</returnfield><returnfield>northBoundingCoordinate</returnfield><returnfield>southBoundingCoordinate</returnfield><returnfield>westbc</returnfield><returnfield>eastbc</returnfield><returnfield>northbc</returnfield><returnfield>southbc</returnfield><querygroup operator=\"INTERSECT\"><querygroup operator=\"UNION\"><querygroup operator=\"UNION\"><queryterm searchmode=\"contains\" casesensitive=\"false\"><value>%25</value></queryterm></querygroup></querygroup></querygroup></pathquery>";
|
36
|
|
37
|
my $response = $metacat->squery($query);
|
38
|
|
39
|
my $mesg =$metacat->getMessage();
|
40
|
|
41
|
#print "\n\ngetting the message ... \n";
|
42
|
#print $mesg;
|
43
|
|
44
|
if($mesg eq ""){
|
45
|
# print ("Too much time is reply back from metacat...");
|
46
|
exit();
|
47
|
}
|
48
|
|
49
|
my $parser = new XML::DOM::Parser;
|
50
|
my $node;
|
51
|
my $name;
|
52
|
my $doc = $parser->parse($mesg);
|
53
|
my $nodes = $doc->getElementsByTagName("docid");
|
54
|
|
55
|
$numberNodes = $nodes->getLength;
|
56
|
|
57
|
|
58
|
for (my $loop_index =0; $loop_index < $numberNodes; $loop_index++)
|
59
|
{
|
60
|
$node = $nodes->item($loop_index);
|
61
|
$name = trimwhitespace($node->getFirstChild()->getNodeValue());
|
62
|
|
63
|
$node = $node->getParentNode();
|
64
|
my $tempnodes = $node->getElementsByTagName("param");
|
65
|
my $tempnumberNodes = $tempnodes->getLength;
|
66
|
|
67
|
my $title = "";
|
68
|
my $keyword = "";
|
69
|
my $cName = "";
|
70
|
my $eBC = "";
|
71
|
my $wBC = "";
|
72
|
my $nBC = "";
|
73
|
my $sBC = "";
|
74
|
|
75
|
for (my $loop =0; $loop < $tempnumberNodes; $loop++)
|
76
|
{
|
77
|
my $tempnode = $tempnodes->item($loop);
|
78
|
my $paramname = $tempnode->getAttributeNode("name")->getValue();
|
79
|
if($paramname eq "dataset/title"){
|
80
|
$title = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
81
|
}
|
82
|
if($paramname eq "keyword"){
|
83
|
$keyword = trimwhitespace($keyword.",".$tempnode->getFirstChild()->getNodeValue());
|
84
|
}
|
85
|
if($paramname eq "individualName/surName"){
|
86
|
$cName = trimwhitespace($cName.",".$tempnode->getFirstChild()->getNodeValue());
|
87
|
}
|
88
|
if($paramname eq "eastBoundingCoordinate"){
|
89
|
$eBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
90
|
}
|
91
|
if($paramname eq "eastbc"){
|
92
|
$eBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
93
|
}
|
94
|
if($paramname eq "westBoundingCoordinate"){
|
95
|
$wBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
96
|
}
|
97
|
if($paramname eq "westbc"){
|
98
|
$wBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
99
|
}
|
100
|
if($paramname eq "northBoundingCoordinate"){
|
101
|
$nBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
102
|
}
|
103
|
if($paramname eq "northbc"){
|
104
|
$nBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
105
|
}
|
106
|
if($paramname eq "southBoundingCoordinate"){
|
107
|
$sBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
108
|
}
|
109
|
if($paramname eq "southbc"){
|
110
|
$sBC = trimwhitespace($tempnode->getFirstChild()->getNodeValue());
|
111
|
}
|
112
|
}
|
113
|
|
114
|
if($keyword ne "" ){
|
115
|
$keyword = substr ($keyword, 1);
|
116
|
}
|
117
|
if($cName ne "" ){
|
118
|
$cName = substr ($cName, 1);
|
119
|
}
|
120
|
|
121
|
# print "$name, $title, ($cName), ($keyword), ($eBC,$wBC,$nBC,$sBC), $url?action=read&docid=$name&qformat=knb, \n";
|
122
|
# print trimwhitespace($eBC) + " \n";
|
123
|
if ($eBC ne "" && $nBC ne "" && $eBC ne "0" && $nBC ne "0") {
|
124
|
print "$name $wBC $eBC $sBC $nBC $url?action=read&docid=$name&qformat=knb \n";
|
125
|
}
|
126
|
}
|
127
|
|
128
|
|
129
|
# Remove whitespace from the start and end of the string
|
130
|
sub trimwhitespace($)
|
131
|
{
|
132
|
my $string = shift;
|
133
|
$string =~ s/^\s+//;
|
134
|
$string =~ s/\s+$//;
|
135
|
return $string;
|
136
|
}
|
137
|
#print $numberNodes;
|