diff --git a/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java b/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java
index 5e75edf..8e3c5b9 100644
--- a/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java
+++ b/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java
@@ -17,6 +17,7 @@
package se.kb.oai.ore.impl;
import java.util.List;
+import java.util.UUID;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
@@ -138,6 +139,6 @@ public class AtomSerializer extends SerializerBase {
}
protected String createAtomId() {
- return "urn:uid:" + (int) (Math.random() * 1000);
+ return "urn:uuid:" + UUID.randomUUID().toString();
}
}
diff --git a/src/main/java/se/kb/oai/pmh/IdentifiersList.java b/src/main/java/se/kb/oai/pmh/IdentifiersList.java
index f57cbdb..06b99d8 100644
--- a/src/main/java/se/kb/oai/pmh/IdentifiersList.java
+++ b/src/main/java/se/kb/oai/pmh/IdentifiersList.java
@@ -17,21 +17,19 @@
package se.kb.oai.pmh;
import java.util.LinkedList;
-import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
/**
* Class that represents the response from a ListIdentifiers
request.
- *
+ * You can use it to get a list of Headers
that holds identifiers.
+ *
* @author Oskar Grenholm, National Library of Sweden
*/
-public class IdentifiersList extends ResponseBase {
+public class IdentifiersList extends ListBase {
private static final String HEADER_XPATH = "oai:ListIdentifiers/oai:header";
-
- private List headers;
/**
* Creates an IdentifiersList
from the returned response.
@@ -42,42 +40,9 @@ public class IdentifiersList extends ResponseBase {
public IdentifiersList(Document document) throws ErrorResponseException {
super(document);
- this.headers = new LinkedList();
+ super.list = new LinkedList();
for(Node node : xpath.selectNodes(HEADER_XPATH)) {
- headers.add(new Header(node));
+ list.add(new Header(node));
}
}
-
- /**
- * Get the size of the list.
- *
- * @return the size
- */
- public int size() {
- return headers.size();
- }
-
- /**
- * Get the identifiers as a list of Headers
.
- *
- * @return a list of identifiers
- */
- public List asList() {
- return headers;
- }
-
- /**
- * Get the ResumptionToken
, if any, for this response.
- *
- * @return the ResumptionToken
, or null
- * if none available
- */
- public ResumptionToken getResumptionToken() {
- if (super.resumptionToken == null
- || super.resumptionToken.getId() == null
- || super.resumptionToken.getId().length() == 0)
- return null;
-
- return super.resumptionToken;
- }
}
diff --git a/src/main/java/se/kb/oai/pmh/MetadataFormatsList.java b/src/main/java/se/kb/oai/pmh/MetadataFormatsList.java
index 863f2e1..7532e90 100644
--- a/src/main/java/se/kb/oai/pmh/MetadataFormatsList.java
+++ b/src/main/java/se/kb/oai/pmh/MetadataFormatsList.java
@@ -17,23 +17,20 @@
package se.kb.oai.pmh;
import java.util.LinkedList;
-import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
/**
* This class represents the response from a ListMetadataFormats
request
- * to the OAI-PMH server.
+ * to the OAI-PMH server. You can use it to get a list of MetadataFormats
.
*
* @author Oskar Grenholm, National Library of Sweden
*/
-public class MetadataFormatsList extends ResponseBase {
+public class MetadataFormatsList extends ListBase {
private static final String METADATAFORMAT_XPATH = "oai:ListMetadataFormats/oai:metadataFormat";
- private List metadataFormats;
-
/**
* Creates a MetadataFormatsList
from the returned response.
*
@@ -43,27 +40,20 @@ public class MetadataFormatsList extends ResponseBase {
public MetadataFormatsList(Document document) throws ErrorResponseException {
super(document);
- this.metadataFormats = new LinkedList();
+ super.list = new LinkedList();
for(Node metadataFormat : xpath.selectNodes(METADATAFORMAT_XPATH)) {
- metadataFormats.add(new MetadataFormat(metadataFormat));
+ list.add(new MetadataFormat(metadataFormat));
}
}
/**
- * Get the size of the list.
- *
- * @return the size
+ * The response from a ListMetadataFormats
request will never
+ * have a resumption token, so this method will throw a NoSuchMethodError
+ * to prevent it from being used in that way.
*/
- public int size() {
- return metadataFormats.size();
+ @Override
+ public ResumptionToken getResumptionToken() {
+ throw new NoSuchMethodError("The response from the verb 'ListMetadataFormats' " +
+ "can't have a ResumptionToken!");
}
-
- /**
- * Get the metadata formats as a list of MetadataFormats
.
- *
- * @return a list of metadata formats
- */
- public List asList() {
- return metadataFormats;
- }
}
diff --git a/src/main/java/se/kb/oai/pmh/RecordsList.java b/src/main/java/se/kb/oai/pmh/RecordsList.java
index a11c80f..2cab881 100644
--- a/src/main/java/se/kb/oai/pmh/RecordsList.java
+++ b/src/main/java/se/kb/oai/pmh/RecordsList.java
@@ -17,22 +17,21 @@
package se.kb.oai.pmh;
import java.util.LinkedList;
-import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
/**
* Class that represents the response from a ListRecords
request.
+ * You can use it to get the list of Records
that made up the
+ * response.
*
* @author Oskar Grenholm, National Library of Sweden
*/
-public class RecordsList extends ResponseBase {
+public class RecordsList extends ListBase {
private static final String RECORD_XPATH = "oai:ListRecords/oai:record";
- private List records;
-
/**
* Creates a RecordsList
from the returned response.
*
@@ -42,42 +41,9 @@ public class RecordsList extends ResponseBase {
public RecordsList(Document document) throws ErrorResponseException {
super(document);
- this.records = new LinkedList();
+ super.list = new LinkedList();
for (Node record : xpath.selectNodes(RECORD_XPATH)) {
- records.add(new Record(document, record));
- }
- }
-
- /**
- * Get the size of the list.
- *
- * @return the size
- */
- public int size() {
- return records.size();
- }
-
- /**
- * Get the records as a list of Records
.
- *
- * @return a list of records
- */
- public List asList() {
- return records;
- }
-
- /**
- * Get the ResumptionToken
, if any, for this response.
- *
- * @return the ResumptionToken
, or null
- * if none available
- */
- public ResumptionToken getResumptionToken() {
- if (super.resumptionToken == null
- || super.resumptionToken.getId() == null
- || super.resumptionToken.getId().length() == 0)
- return null;
-
- return super.resumptionToken;
- }
+ list.add(new Record(document, record));
+ }
+ }
}
diff --git a/src/main/java/se/kb/oai/pmh/SetsList.java b/src/main/java/se/kb/oai/pmh/SetsList.java
index 27d644e..04b8d71 100644
--- a/src/main/java/se/kb/oai/pmh/SetsList.java
+++ b/src/main/java/se/kb/oai/pmh/SetsList.java
@@ -17,22 +17,20 @@
package se.kb.oai.pmh;
import java.util.LinkedList;
-import java.util.List;
import org.dom4j.Document;
import org.dom4j.Node;
/**
* Class that represents the response from a ListSets
request.
+ * You can use it to get a list of Sets
.
*
* @author Oskar Grenholm, National Library of Sweden
*/
-public class SetsList extends ResponseBase {
+public class SetsList extends ListBase {
private static final String SET_XPATH = "oai:ListSets/oai:set";
-
- private List sets;
-
+
/**
* Creates an SetsList
from the returned response.
*
@@ -42,42 +40,9 @@ public class SetsList extends ResponseBase {
public SetsList(Document document) throws ErrorResponseException {
super(document);
- this.sets = new LinkedList();
+ super.list = new LinkedList();
for (Node set : xpath.selectNodes(SET_XPATH)) {
- sets.add(new Set(set));
+ list.add(new Set(set));
}
}
-
- /**
- * Get the size of the list.
- *
- * @return the size
- */
- public int size() {
- return sets.size();
- }
-
- /**
- * Get the sets as a list of Sets
.
- *
- * @return a list of sets
- */
- public List asList() {
- return sets;
- }
-
- /**
- * Get the ResumptionToken
, if any, for this response.
- *
- * @return the ResumptionToken
, or null
- * if none available
- */
- public ResumptionToken getResumptionToken() {
- if (super.resumptionToken == null
- || super.resumptionToken.getId() == null
- || super.resumptionToken.getId().length() == 0)
- return null;
-
- return super.resumptionToken;
- }
}