diff --git a/src/main/java/se/kb/oai/ore/AggregatedResource.java b/src/main/java/se/kb/oai/ore/AggregatedResource.java
index 928e545..edd1908 100644
--- a/src/main/java/se/kb/oai/ore/AggregatedResource.java
+++ b/src/main/java/se/kb/oai/ore/AggregatedResource.java
@@ -31,6 +31,8 @@ import java.net.URISyntaxException;
*/
public class AggregatedResource extends AggregateBase {
+ private String mimetype;
+
/**
* Create an AggreagatedResource
with the specified id.
*
@@ -51,7 +53,24 @@ public class AggregatedResource extends AggregateBase {
public AggregatedResource(URI id) {
super(id);
}
-
+ /**
+ * Get the MIME type (if known) for this AggreagatedResource
.
+ *
+ * @return the MIME type, or null
if not known
+ */
+ public String getMimeType() {
+ return mimetype;
+ }
+
+ /**
+ * Set the MIME type for this AggreagatedResource
.
+ *
+ * @param mimetype the MIME type
+ */
+ public void setMimeType(String mimetype) {
+ this.mimetype = mimetype;
+ }
+
/**
* Get an InputStream
for the content held in this
* AggreagatedResource
.
diff --git a/src/main/java/se/kb/oai/ore/ResourceMapSerializer.java b/src/main/java/se/kb/oai/ore/ResourceMapSerializer.java
index fc01da5..41bc035 100644
--- a/src/main/java/se/kb/oai/ore/ResourceMapSerializer.java
+++ b/src/main/java/se/kb/oai/ore/ResourceMapSerializer.java
@@ -18,6 +18,7 @@ package se.kb.oai.ore;
import java.io.File;
import java.io.IOException;
+import java.io.OutputStream;
import org.dom4j.Element;
@@ -35,16 +36,26 @@ import org.dom4j.Element;
* @author Oskar Grenholm, National Library of Sweden
*/
public interface ResourceMapSerializer {
+
+ /**
+ * Serialize the resource map to an OutputStream
.
+ *
+ * @param map a resource map
+ * @param stream a stream to serialize to
+ *
+ * @throws IOException
+ */
+ public void serializeToStream(ResourceMap map, OutputStream stream) throws IOException;
/**
* Serialize the resource map to the given file.
*
- * @param file a file
* @param map a resource map
+ * @param file a file
*
* @throws IOException
*/
- public void serializeToFile(File file, ResourceMap map) throws IOException;
+ public void serializeToFile(ResourceMap map, File file) throws IOException;
/**
* Serialize the resource map and return it as a String
.
diff --git a/src/main/java/se/kb/oai/ore/impl/AtomConstants.java b/src/main/java/se/kb/oai/ore/impl/AtomConstants.java
index 8013bb7..ac1b15e 100644
--- a/src/main/java/se/kb/oai/ore/impl/AtomConstants.java
+++ b/src/main/java/se/kb/oai/ore/impl/AtomConstants.java
@@ -53,6 +53,7 @@ public class AtomConstants extends OREConstants {
public static final String LABEL = "label";
public static final String REL = "rel";
public static final String HREF = "href";
+ public static final String MIME_TYPE = "type";
public static final String ORE_TERMS_URL = "http://www.openarchives.org/ore/terms/";
public static final String ORE_TERMS_REM_URL = "http://www.openarchives.org/ore/terms/ResourceMap";
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 eb75376..9a89a6b 100644
--- a/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java
+++ b/src/main/java/se/kb/oai/ore/impl/AtomSerializer.java
@@ -117,6 +117,8 @@ public class AtomSerializer extends SerializerBase {
link = DocumentHelper.createElement(LINK);
link.addAttribute(REL, "alternate");
+ if (resource.getMimeType() != null)
+ link.addAttribute(MIME_TYPE, resource.getMimeType());
link.addAttribute(HREF, resource.getId().toString());
entry.add(link);
diff --git a/src/main/java/se/kb/oai/ore/impl/SerializerBase.java b/src/main/java/se/kb/oai/ore/impl/SerializerBase.java
index a6a6b76..5240610 100644
--- a/src/main/java/se/kb/oai/ore/impl/SerializerBase.java
+++ b/src/main/java/se/kb/oai/ore/impl/SerializerBase.java
@@ -19,6 +19,7 @@ package se.kb.oai.ore.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import org.dom4j.Element;
@@ -33,10 +34,14 @@ import se.kb.xml.XMLUtils;
*/
public abstract class SerializerBase implements ResourceMapSerializer {
- public void serializeToFile(File file, ResourceMap map) throws IOException {
- FileOutputStream out = new FileOutputStream(file);
- XMLUtils.writeXmlTo(serializeToXml(map), out);
- out.close();
+ public void serializeToStream(ResourceMap map, OutputStream stream) throws IOException {
+ XMLUtils.writeXmlTo(serializeToXml(map), stream);
+ }
+
+ public void serializeToFile(ResourceMap map, File file) throws IOException {
+ FileOutputStream stream = new FileOutputStream(file);
+ serializeToStream(map, stream);
+ stream.close();
}
public String serializeToString(ResourceMap map) throws IOException {
diff --git a/src/site/apt/examples.apt b/src/site/apt/examples.apt
index 91eaeb8..4daa3f7 100644
--- a/src/site/apt/examples.apt
+++ b/src/site/apt/examples.apt
@@ -27,8 +27,7 @@ Examples
+-----+
-String baseurl = "http://magasin.kb.se:8080/oaiprovider/";
-OaiPmhServer server = new OaiPmhServer(baseurl);
+OaiPmhServer server = new OaiPmhServer("http://magasin.kb.se:8080/oaiprovider/");
Record record = server.getRecord("oai:kb:1", "oai_dc");
+-----+
@@ -125,7 +124,7 @@ serializer.serializeToFile(new File("atom.xml"), map);
ResourceMap map = factory.getResourceMap("http://test.kb.se/atom.xml");
// Add one more AggregatedResource to the Aggregation.
-map.getAggregation.addResource(aResource);
+map.getAggregation().addResource(aResource);
// Set the modified date to now.
map.setModified(new Date());