XmldbURI diffUri = XmldbURI.createInternal(documentPath.toString() + '.' + revision);
vCollection.setTriggersEnabled(false);
StringWriter writer = new StringWriter();
SAXSerializer sax = (SAXSerializer) SerializerPool.getInstance().borrowObject(
SAXSerializer.class);
Properties outputProperties = new Properties();
outputProperties.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
outputProperties.setProperty(OutputKeys.INDENT, "no");
sax.setOutput(writer, outputProperties);
sax.startDocument();
sax.startElement(ELEMENT_VERSION, null);
writeProperties(sax, getVersionProperties(revision, documentPath, activeSubject));
if(event == REMOVE_DOCUMENT_EVENT) {
sax.startElement(ELEMENT_REMOVED, null);
sax.endElement(ELEMENT_REMOVED);
} else {
//Diff
if(document instanceof BinaryDocument) {
//create a copy of the last Binary revision
XmldbURI binUri = XmldbURI.create(diffUri.toString() + BINARY_SUFFIX);
broker.copyResource(transaction, document, vCollection, binUri);
//Create metadata about the last Binary Version
sax.startElement(ELEMENT_REPLACED_BINARY, null);
sax.attribute(ATTRIBUTE_REF, binUri.toString());
sax.endElement(ELEMENT_REPLACED_BINARY);
} else if(lastRev instanceof BinaryDocument) {
//create a copy of the last XML revision
XmldbURI xmlUri = XmldbURI.create(diffUri.toString() + XML_SUFFIX);
broker.copyResource(transaction, document, vCollection, xmlUri);
//Create metadata about the last Binary Version
sax.startElement(ELEMENT_REPLACED_XML, null);
sax.attribute(ATTRIBUTE_REF, xmlUri.toString());
sax.endElement(ELEMENT_REPLACED_BINARY);
} else {
//Diff the XML versions
Diff diff = new StandardDiff(broker);
diff.diff(lastRev, document);
diff.diff2XML(sax);
}
sax.endElement(ELEMENT_VERSION);
sax.endDocument();
String editscript = writer.toString();
if (removeLast) {
if(lastRev instanceof BinaryDocument) {
vCollection.removeBinaryResource(transaction, broker, lastRev.getFileURI());