try {
TripleIterator triples =
new FilteredTripleIterator(map, toAdd, true);
triples.toStream(out, RDFFormat.RDF_XML, false);
} catch (TrippiException e) {
throw new GeneralException(e.getMessage(), e);
}
dsxml = new XMLDatastreamProcessor(dsId);
Datastream newds = dsxml.getDatastream();
newds.DatastreamAltIDs = new String[0];
// formats for internal datastreams
if (dsId.equals("RELS-EXT")) {
newds.DSFormatURI = RELS_EXT1_0.uri;
} else {
if (dsId.equals("RELS-INT"))
newds.DSFormatURI = RELS_INT1_0.uri;
}
newds.DSMIME = "application/rdf+xml";
//newds.DSControlGrp = "X"; set by XMLDatastreamProcessor instead
newds.DSInfoType = null;
newds.DSState = "A";
newds.DSVersionable = false;
newds.DSVersionID = dsId + ".0";
newds.DSLabel = "Relationships";
newds.DSCreateDT = Server.getCurrentDate(m_context);
newds.DSLocation = null;
newds.DSLocationType = null;
newds.DSChecksumType = Datastream.getDefaultChecksumType();
dsxml.setXMLContent(out.toByteArray());
newds.DSSize = dsxml.getXMLContent().length;
ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
newds.DatastreamID,
newds);
addDatastream(newds, false);
} else { // (relsDatastream != null)
dsxml = new XMLDatastreamProcessor(relsDatastream);
FilteredTripleIterator newIter = null;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
TripleIterator iter =
TripleIteratorFactory.defaultInstance().fromStream(relsDatastream.getContentStream(),
RDFFormat.RDF_XML);
newIter = new FilteredTripleIterator(iter, toAdd, true);
newIter.toStream(out, RDFFormat.RDF_XML, false);
if (newIter.wasChangeMade()) {
XMLDatastreamProcessor newdsxml = dsxml.newVersion();
Datastream newds = newdsxml.getDatastream();
// TODO: only for XML Metadata datastream
newdsxml.setDSMDClass(dsxml.getDSMDClass());
newds.DatastreamID = relsDatastream.DatastreamID;
newds.DatastreamAltIDs = relsDatastream.DatastreamAltIDs;
newds.DSFormatURI = relsDatastream.DSFormatURI;
newds.DSMIME = relsDatastream.DSMIME;
// newds.DSControlGrp = "X"; set by XMLDatastreamProcessor
newds.DSInfoType = relsDatastream.DSInfoType;
newds.DSState = relsDatastream.DSState;
newds.DSVersionable = relsDatastream.DSVersionable;
newds.DSVersionID = newDatastreamID(dsId);
newds.DSLabel = relsDatastream.DSLabel;
newds.DSCreateDT = Server.getCurrentDate(m_context);
newds.DSLocation = null;
newds.DSLocationType = null;
newds.DSChecksumType = relsDatastream.DSChecksumType;
newdsxml.setXMLContent(out.toByteArray());
newds.DSSize = newdsxml.getXMLContent().length;
ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
newds.DatastreamID,
newds);
addDatastream(newds, newds.DSVersionable);
} else {
// relationship already exists
return false;
}
} catch (TrippiException e) {
throw new GeneralException(e.getMessage(), e);
} finally {
try {
if (newIter != null) {
newIter.close();
}
} catch (TrippiException e) {
throw new GeneralException(e.getMessage(), e);
}
}
}
return true;
}