Project

General

Profile

1
/**
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 java.io.UnsupportedEncodingException;
42
import java.net.URLEncoder;
43
import javax.xml.parsers.ParserConfigurationException;
44
import javax.xml.transform.TransformerException;
45
import org.xml.sax.SAXException;
46

    
47

    
48
/**
49
 * This class represents an ListIdentifiers response on either the server or on
50
 * the client.
51
 * 
52
 * @author Duane Costa, University of New Mexico, LTER Network Office
53
 * @author Jeffrey A. Young, OCLC Online Computer Library Center
54
 */
55
public class ListIdentifiers extends HarvesterVerb {
56

    
57
  
58
/* Constructors */
59
  
60
  /**
61
   * Mock object constructor (for unit testing purposes)
62
   */
63
  public ListIdentifiers() {
64
    super();
65
  }
66

    
67

    
68
  /**
69
   * Client-side ListIdentifiers verb constructor
70
   * 
71
   * @param baseURL                baseURL of the OAI-PMH provider to be queried
72
   * @param from                   the from date, e.g. "2000-01-01"
73
   * @param until                  the until date. e.g. "2009-12-31"
74
   * @param metadataPrefix         the metadata prefix, e.g. "oai_pmh"
75
   * @param setSpec                the set specifier
76
   * 
77
   * @exception MalformedURLException  the baseURL is bad
78
   * @exception SAXException           the xml response is bad
79
   * @exception IOException            an I/O error occurred
80
   */
81
  public ListIdentifiers(String baseURL, String from, String until, 
82
                         String metadataPrefix, String setSpec) 
83
          throws IOException, ParserConfigurationException,
84
      SAXException, TransformerException {
85
    super(getRequestURL(baseURL, from, until, metadataPrefix, setSpec));
86
  }
87

    
88

    
89
  /**
90
   * Client-side ListIdentifiers verb constructor (resumptionToken version)
91
   * 
92
   * @param baseURL                baseURL of the OAI-PMH provider to be queried
93
   * @param resumptionToken        the resumptionToken string, as returned by
94
   *                               the provider server
95
   * @throws IOException
96
   * @throws ParserConfigurationException
97
   * @throws SAXException
98
   * @throws TransformerException
99
   */
100
  public ListIdentifiers(String baseURL, String resumptionToken)
101
      throws IOException, ParserConfigurationException, SAXException,
102
      TransformerException {
103
    super(getRequestURL(baseURL, resumptionToken));
104
  }
105

    
106
  
107
/* Class methods */
108

    
109
  /**
110
   * Construct the query portion of the http request (non-resumptionToken 
111
   * version)
112
   * @param baseURL                baseURL of the OAI-PMH provider to be queried
113
   * @param from                   the from date, e.g. "2000-01-01"
114
   * @param until                  the until date. e.g. "2009-12-31"
115
   * @param metadataPrefix         the metadata prefix, e.g. "oai_pmh"
116
   * @param setSpec                the set specifier
117
   * 
118
   * @return a String containing the query portion of the http request
119
   */
120
  private static String getRequestURL(String baseURL, String from,
121
                                      String until, String metadataPrefix,
122
                                      String setSpec)
123
  {
124
    StringBuffer stringBuffer = new StringBuffer(baseURL);
125
    stringBuffer.append("?verb=ListIdentifiers");
126
    
127
    if (from != null) stringBuffer.append("&from=").append(from);
128
    if (until != null) stringBuffer.append("&until=").append(until);
129
    if (setSpec != null) stringBuffer.append("&set=").append(setSpec);
130
    stringBuffer.append("&metadataPrefix=").append(metadataPrefix);
131
    
132
    String requestURL = stringBuffer.toString();
133
    return requestURL;
134
  }
135

    
136

    
137
  /**
138
   * Construct the query portion of the http request (resumptionToken version)
139
   * 
140
   * @param baseURL                baseURL of the OAI-PMH provider to be queried
141
   * @param resumptionToken        the resumptionToken string, as returned by
142
   *                               the provider server
143
   * @return a String containing the query portion of the http request
144
   */
145
  private static String getRequestURL(String baseURL, String resumptionToken) 
146
          throws UnsupportedEncodingException 
147
  {
148
    StringBuffer stringBuffer = new StringBuffer(baseURL);
149
    
150
    stringBuffer.append("?verb=ListIdentifiers");
151
    stringBuffer.append("&resumptionToken=");
152
    stringBuffer.append(URLEncoder.encode(resumptionToken, "UTF-8"));
153
    
154
    String requestURL = stringBuffer.toString();
155
    return requestURL;
156
  }
157
  
158
  
159
  /* Instance methods */
160

    
161
  /**
162
   * Get the oai:resumptionToken from the response
163
   * 
164
   * @return the oai:resumptionToken value
165
   * @throws TransformerException
166
   * @throws NoSuchFieldException
167
   */
168
  public String getResumptionToken() 
169
          throws TransformerException, NoSuchFieldException 
170
  {
171
    String schemaLocation = getSchemaLocation();
172
    String resumptionToken = "";
173
    
174
    if (SCHEMA_LOCATION_V2_0.equals(schemaLocation)) {
175
      resumptionToken = getSingleString(
176
                    "/oai20:OAI-PMH/oai20:ListIdentifiers/oai20:resumptionToken"
177
                                       );
178
    } 
179
    else {
180
      throw new NoSuchFieldException(getSchemaLocation());
181
    }
182
    
183
    return resumptionToken;
184
  }
185
 
186
}
(4-4/8)