boolean isLiteral,
String datatype) throws ServerException {
Triple toAdd =
createTriple(subject, relationship, object, isLiteral, datatype);
Datastream relsDatastream = GetDatastream(dsId, null);
XMLDatastreamProcessor dsxml = null;
if (relsDatastream == null) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Map<String, String> map = new HashMap<String, String>();
// namespaces for RELS-EXT
if (dsId.equals("RELS-EXT")) {
map.put(RELS_EXT.prefix, RELS_EXT.uri);
map.put(MODEL.prefix, MODEL.uri);
}
map.put(RDF.prefix, RDF.uri);
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;