Added functionality for getting/setting mimetypes for Aggregated Resources.

git-svn-id: https://oai4j-client.svn.sourceforge.net/svnroot/oai4j-client/trunk@14 201c9376-5148-0410-b534-98494c770f31
This commit is contained in:
bobcat_zed 2008-04-02 12:55:03 +00:00
parent ae23cb5e34
commit 2055261027
6 changed files with 47 additions and 10 deletions

View File

@ -31,6 +31,8 @@ import java.net.URISyntaxException;
*/ */
public class AggregatedResource extends AggregateBase { public class AggregatedResource extends AggregateBase {
private String mimetype;
/** /**
* Create an <code>AggreagatedResource</code> with the specified id. * Create an <code>AggreagatedResource</code> with the specified id.
* *
@ -51,7 +53,24 @@ public class AggregatedResource extends AggregateBase {
public AggregatedResource(URI id) { public AggregatedResource(URI id) {
super(id); super(id);
} }
/**
* Get the MIME type (if known) for this <code>AggreagatedResource</code>.
*
* @return the MIME type, or <code>null</code> if not known
*/
public String getMimeType() {
return mimetype;
}
/**
* Set the MIME type for this <code>AggreagatedResource</code>.
*
* @param mimetype the MIME type
*/
public void setMimeType(String mimetype) {
this.mimetype = mimetype;
}
/** /**
* Get an <code>InputStream</code> for the content held in this * Get an <code>InputStream</code> for the content held in this
* <code>AggreagatedResource</code>. * <code>AggreagatedResource</code>.

View File

@ -18,6 +18,7 @@ package se.kb.oai.ore;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import org.dom4j.Element; import org.dom4j.Element;
@ -35,16 +36,26 @@ import org.dom4j.Element;
* @author Oskar Grenholm, National Library of Sweden * @author Oskar Grenholm, National Library of Sweden
*/ */
public interface ResourceMapSerializer { public interface ResourceMapSerializer {
/**
* Serialize the resource map to an <code>OutputStream</code>.
*
* @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. * Serialize the resource map to the given file.
* *
* @param file a file
* @param map a resource map * @param map a resource map
* @param file a file
* *
* @throws IOException * @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 <code>String</code>. * Serialize the resource map and return it as a <code>String</code>.

View File

@ -53,6 +53,7 @@ public class AtomConstants extends OREConstants {
public static final String LABEL = "label"; public static final String LABEL = "label";
public static final String REL = "rel"; public static final String REL = "rel";
public static final String HREF = "href"; 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_URL = "http://www.openarchives.org/ore/terms/";
public static final String ORE_TERMS_REM_URL = "http://www.openarchives.org/ore/terms/ResourceMap"; public static final String ORE_TERMS_REM_URL = "http://www.openarchives.org/ore/terms/ResourceMap";

View File

@ -117,6 +117,8 @@ public class AtomSerializer extends SerializerBase {
link = DocumentHelper.createElement(LINK); link = DocumentHelper.createElement(LINK);
link.addAttribute(REL, "alternate"); link.addAttribute(REL, "alternate");
if (resource.getMimeType() != null)
link.addAttribute(MIME_TYPE, resource.getMimeType());
link.addAttribute(HREF, resource.getId().toString()); link.addAttribute(HREF, resource.getId().toString());
entry.add(link); entry.add(link);

View File

@ -19,6 +19,7 @@ package se.kb.oai.ore.impl;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import org.dom4j.Element; import org.dom4j.Element;
@ -33,10 +34,14 @@ import se.kb.xml.XMLUtils;
*/ */
public abstract class SerializerBase implements ResourceMapSerializer { public abstract class SerializerBase implements ResourceMapSerializer {
public void serializeToFile(File file, ResourceMap map) throws IOException { public void serializeToStream(ResourceMap map, OutputStream stream) throws IOException {
FileOutputStream out = new FileOutputStream(file); XMLUtils.writeXmlTo(serializeToXml(map), stream);
XMLUtils.writeXmlTo(serializeToXml(map), out); }
out.close();
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 { public String serializeToString(ResourceMap map) throws IOException {

View File

@ -27,8 +27,7 @@ Examples
+-----+ +-----+
String baseurl = "http://magasin.kb.se:8080/oaiprovider/"; OaiPmhServer server = new OaiPmhServer("http://magasin.kb.se:8080/oaiprovider/");
OaiPmhServer server = new OaiPmhServer(baseurl);
Record record = server.getRecord("oai:kb:1", "oai_dc"); 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"); ResourceMap map = factory.getResourceMap("http://test.kb.se/atom.xml");
// Add one more AggregatedResource to the Aggregation. // Add one more AggregatedResource to the Aggregation.
map.getAggregation.addResource(aResource); map.getAggregation().addResource(aResource);
// Set the modified date to now. // Set the modified date to now.
map.setModified(new Date()); map.setModified(new Date());