if (bundles == null || bundles.length == 0)
{
return;
}
Bundle bundle = bundles[0];
Bitstream bitstream = bundle.getBitstreamByName("license_rdf");
String license_rdf = new String(copy(bitstream));
/* quickly fix xml by ripping out offensive parts */
license_rdf = license_rdf.replaceFirst("<license", "");
license_rdf = license_rdf.replaceFirst("</license>", "");
StringWriter result = new StringWriter();
try
{
templates.newTransformer().transform(
new StreamSource(new ByteArrayInputStream(license_rdf
.getBytes())), new StreamResult(result));
}
catch (TransformerException e)
{
throw new IllegalStateException(e.getMessage(), e);
}
StringBuffer buffer = result.getBuffer();
Bitstream newBitstream = bundle
.createBitstream(new ByteArrayInputStream(buffer.toString()
.getBytes()));
newBitstream.setName(bitstream.getName());
newBitstream.setDescription(bitstream.getDescription());
newBitstream.setFormat(bitstream.getFormat());
newBitstream.setSource(bitstream.getSource());
newBitstream.setUserFormatDescription(bitstream
.getUserFormatDescription());
newBitstream.update();
bundle.removeBitstream(bitstream);
bundle.update();
}