OAI4J has two dependencies on other Java libraries:

Both of these needs to be present on the classpath to successfully run OAI4J.


OAI-PMH examples

To create an OaiPmhServer object and use it to retrieve a Record:

OaiPmhServer server = new OaiPmhServer("");
Record record = server.getRecord("oai:kb:1", "oai_dc");

To get the metadata from the Record:

Element metadata = record.getMetadata();
// You can now use the org.dom4j.Element to handle the metadata as you see fit.

// OR you can get the metadata as a String instead.
String metadataString = record.getMetadataAsString();

To list ALL identifiers in the repository that has "oai_dc" metadata:

IdentifiersList list = server.listIdentifiers("oai_dc");
while (more) {
  for (Header header : list.asList()) {
  if (list.getResumptionToken() != null) 
    list = oai.listIdentifiers(list.getResumptionToken());                      
    more = false;

OAI-ORE examples

To create an AtomFactory and use it to create a new ResourceMap:

// AtomFactory implements ResourceMapFactory
AtomFactory factory = new AtomFactory();
ResourceMap map = factory.newResourceMap("");

To populate the ResourceMap with metadata:

map.setCreator("OAI4J Library");
map.setModified(new Date());

To populate the ResourceMap's Aggregation with an AggregatedResource:

Aggregation aggregation = map.getAggregation();
AggregatedResource resource = new AggregatedResource("");

// Add what kind of resource it is.
resource.addType(new Type(""));

// Add the author of the article.
resource.addMetadata(new Metadata(Namespace.DC, "creator", "Philip J. Fry"));

// Add the AggregatedResource to the Aggregation.

To create an AtomSerializer and use it to serialize the ResourceMap to a file:

// AtomSerializer implements ResourceMapSerializer
AtomSerializer serializer = new AtomSerializer();
serializer.serializeToFile(new File("atom.xml"), map);

To use an AtomFactory to parse an existing Atom feed and then modify it slightly:

ResourceMap map = factory.getResourceMap("");

// Add one more AggregatedResource to the Aggregation.

// Set the modified date to now.
map.setModified(new Date());