Exemple #1
0
  /**
   * listIdentifiers() auxiliar method.
   *
   * @param resumptionToken
   * @return
   */
  @SuppressWarnings("unchecked")
  private List<HeaderType> listIdentifiers(
      String resumptionToken, String from, String until, String set, String metadataPrefix)
      throws Exception {
    // TODO: handle status attribute
    identifiersResumptionToken = null;
    String url;
    if (resumptionToken == null) {
      url = baseUrl + "?verb=ListIdentifiers&metadataPrefix=" + metadataPrefix;
      if (from != null) {
        url += "&from=" + from;
      }
      if (until != null) {
        url += "&until=" + until;
      }
      if (set != null) {
        url += "&set=" + set;
      }
    } else {
      url = baseUrl + "?verb=ListIdentifiers&resumptionToken=" + resumptionToken;
    }
    OAIPMH oaipmh = oaipmhRequest(url);

    handleOaiErrors(oaipmh);

    ListIdentifiersType listIdentifiers = oaipmh.getListIdentifiers();

    // Resumption token
    if (listIdentifiers.getResumptionToken() != null
        && !"".equals(listIdentifiers.getResumptionToken().getValue())) {
      identifiersResumptionToken = listIdentifiers.getResumptionToken().getValue();
    }

    return listIdentifiers.getHeaders();
  }
Exemple #2
0
 private void handleOaiErrors(OAIPMH oaipmh) throws Exception {
   // Errors
   if (!oaipmh.getErrors().isEmpty()) {
     OAIPMHerrorType error = oaipmh.getErrors().get(0);
     throw new Exception("OAI harvester exception: " + error.getCode() + " - " + error.getValue());
   }
 }
Exemple #3
0
  /**
   * Returns an IdentifyType object containing information about the OAI respository.
   *
   * @return A IdentifyType object.
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public IdentifyType identify() throws Exception {

    String url = baseUrl + "?verb=Identify";
    OAIPMH oaipmh = oaipmhRequest(url);

    handleOaiErrors(oaipmh);

    return oaipmh.getIdentify();
  }
Exemple #4
0
  /**
   * Returns a Record object harvested by his identifier using 'oai_dc' as metadataPrefix
   *
   * @param identifier A OAI document identifier.
   * @return Record
   */
  @SuppressWarnings("unchecked")
  public RecordType getRecord(String identifier, String metadataPrefix) throws Exception {
    String url =
        baseUrl + "?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=" + metadataPrefix;
    OAIPMH oaipmh = oaipmhRequest(url);

    handleOaiErrors(oaipmh);

    return oaipmh.getGetRecord().getRecord();
  }
Exemple #5
0
  /**
   * Returns a List of MetadataFormatType from a given identifier.
   *
   * @param identifier valid OAI document identifier.
   * @return {@link java.util.List}
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  public List<MetadataFormatType> listMetadataFormats(String identifier) throws Exception {
    String url = baseUrl + "?verb=ListMetadataFormats";
    if (identifier != null) {
      url += "&identifier=" + identifier;
    }
    OAIPMH oaipmh = oaipmhRequest(url);

    handleOaiErrors(oaipmh);

    return oaipmh.getListMetadataFormats().getMetadataFormats();
  }
Exemple #6
0
  /**
   * Returns a List of SetType supported by the repository.
   *
   * @return {@link java.util.List}
   * @throws Exception
   */
  @SuppressWarnings("unchecked")
  private List<SetType> listSets(String resumptionToken) throws Exception {
    String url = baseUrl + "?verb=ListSets";
    if (resumptionToken != null) {
      url += "&resumptionToken=" + resumptionToken;
    }
    OAIPMH oaipmh = oaipmhRequest(url);

    handleOaiErrors(oaipmh);

    if (oaipmh.getListSets().getResumptionToken() != null
        && !"".equals(oaipmh.getListSets().getResumptionToken().getValue())) {
      setResumptionToken = oaipmh.getListSets().getResumptionToken().getValue();
    } else {
      setResumptionToken = null;
    }
    return oaipmh.getListSets().getSets();
  }