1 |
5020
|
costa
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2009 University of New Mexico and the
|
4 |
|
|
* Regents of the University of California
|
5 |
|
|
*
|
6 |
|
|
* '$Author: costa $'
|
7 |
|
|
* '$Date: 2009-07-27 17:47:44 -0400 (Mon, 27 Jul 2009) $'
|
8 |
|
|
* '$Revision: 4999 $'
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
*
|
24 |
|
|
* Additional Copyright 2006 OCLC, Online Computer Library Center
|
25 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
26 |
|
|
* you may not use this file except in compliance with the License.
|
27 |
|
|
* You may obtain a copy of the License at
|
28 |
|
|
*
|
29 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
30 |
|
|
*
|
31 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
32 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
33 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
34 |
|
|
* See the License for the specific language governing permissions and
|
35 |
|
|
* limitations under the License.
|
36 |
|
|
*/
|
37 |
|
|
|
38 |
|
|
package edu.ucsb.nceas.metacat.oaipmh.harvester;
|
39 |
|
|
|
40 |
|
|
import java.io.IOException;
|
41 |
|
|
import javax.xml.parsers.ParserConfigurationException;
|
42 |
|
|
import javax.xml.transform.TransformerException;
|
43 |
|
|
import org.xml.sax.SAXException;
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
/**
|
47 |
|
|
* This class represents an GetRecord response on either the server or on the
|
48 |
|
|
* client
|
49 |
|
|
*
|
50 |
|
|
* @author Duane Costa, University of New Mexico, LTER Network Office
|
51 |
|
|
* @author Jeffrey A. Young, OCLC Online Computer Library Center
|
52 |
|
|
*/
|
53 |
|
|
public class GetRecord extends HarvesterVerb {
|
54 |
|
|
|
55 |
|
|
/* Constructors */
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Mock object constructor (for unit testing purposes)
|
59 |
|
|
*/
|
60 |
|
|
public GetRecord() {
|
61 |
|
|
super();
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Client-side GetRecord verb constructor
|
67 |
|
|
*
|
68 |
|
|
* @param baseURL baseURL of the OAI-PMH provider to be queried
|
69 |
|
|
* @param identifier identifier of the record that we're getting
|
70 |
|
|
* @param metadataPrefix the metadata prefix, e.g. "oai_pmh"
|
71 |
|
|
*
|
72 |
|
|
* @exception MalformedURLException the baseURL is bad
|
73 |
|
|
* @exception SAXException the xml response is bad
|
74 |
|
|
* @exception IOException an I/O error occurred
|
75 |
|
|
*/
|
76 |
|
|
public GetRecord(String baseURL, String identifier, String metadataPrefix)
|
77 |
|
|
throws IOException, ParserConfigurationException, SAXException,
|
78 |
|
|
TransformerException
|
79 |
|
|
{
|
80 |
|
|
super(getRequestURL(baseURL, identifier, metadataPrefix));
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
/* Instance methods */
|
85 |
|
|
|
86 |
|
|
/**
|
87 |
|
|
* Get the oai:identifier from the oai:header
|
88 |
|
|
*
|
89 |
|
|
* @return the oai:identifier as a String
|
90 |
|
|
* @throws TransformerException
|
91 |
|
|
* @throws NoSuchFieldException
|
92 |
|
|
*/
|
93 |
|
|
public String getIdentifier()
|
94 |
|
|
throws TransformerException, NoSuchFieldException
|
95 |
|
|
{
|
96 |
|
|
if (SCHEMA_LOCATION_V2_0.equals(getSchemaLocation())) {
|
97 |
|
|
return getSingleString(
|
98 |
|
|
"/oai20:OAI-PMH/oai20:GetRecord/oai20:record/oai20:header/oai20:identifier"
|
99 |
|
|
);
|
100 |
|
|
}
|
101 |
|
|
else {
|
102 |
|
|
throw new NoSuchFieldException(getSchemaLocation());
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
/**
|
108 |
|
|
* Construct the query portion of the http request
|
109 |
|
|
*
|
110 |
|
|
* @param baseURL baseURL of the OAI-PMH provider to be queried
|
111 |
|
|
* @param identifier identifier of the record that we're getting
|
112 |
|
|
* @param metadataPrefix the metadata prefix, e.g. "oai_pmh"
|
113 |
|
|
* @return a String containing the query portion of the http request
|
114 |
|
|
*/
|
115 |
|
|
private static String getRequestURL(String baseURL,
|
116 |
|
|
String identifier,
|
117 |
|
|
String metadataPrefix) {
|
118 |
|
|
StringBuffer requestURL = new StringBuffer(baseURL);
|
119 |
|
|
requestURL.append("?verb=GetRecord");
|
120 |
|
|
requestURL.append("&identifier=").append(identifier);
|
121 |
|
|
requestURL.append("&metadataPrefix=").append(metadataPrefix);
|
122 |
|
|
return requestURL.toString();
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
}
|