1 16 package org.outerj.daisy.publisher.serverimpl.requestmodel; 17 18 import org.xml.sax.ContentHandler ; 19 import org.outerj.daisy.docdiff.DocDiffOutputHelper; 20 import org.outerj.daisy.docdiff.DiffGenerator; 21 import org.outerj.daisy.publisher.serverimpl.XmlDocDiffOutput; 22 import org.outerj.daisy.repository.Document; 23 import org.outerj.daisy.repository.Version; 24 import org.outerj.daisy.repository.Repository; 25 26 public class DiffRequest implements Request { 27 private final long otherDocumentId; 28 private final long otherBranchId; 29 private final long otherLanguageId; 30 private final long otherVersionId; 31 32 public DiffRequest(long otherDocumentId, long otherBranchId, long otherLanguageId, long otherVersionId) { 33 this.otherDocumentId = otherDocumentId; 34 this.otherBranchId = otherBranchId; 35 this.otherLanguageId = otherLanguageId; 36 this.otherVersionId = otherVersionId; 37 } 38 39 public void process(ContentHandler contentHandler, PublisherContext publisherContext) throws Exception { 40 Repository repository = publisherContext.getRepository(); 41 42 Document document1 = publisherContext.getDocument(); 43 Version version1 = publisherContext.getVersion(); 44 45 if (version1 == null) return; 47 48 long otherDocumentId = this.otherDocumentId == -1 ? publisherContext.getDocumentId() : this.otherDocumentId; 49 long otherBranchId = this.otherBranchId == -1 ? publisherContext.getBranchId() : this.otherBranchId; 50 long otherLanguageId = this.otherLanguageId == -1 ? publisherContext.getLanguageId() : this.otherLanguageId; 51 long otherVersionId = this.otherVersionId == -1 ? version1.getId() - 1 : this.otherVersionId; 52 if (otherVersionId < 1) 53 return; 54 55 Document document2 = repository.getDocument(otherDocumentId, otherBranchId, otherLanguageId, false); 56 Version version2 = document2.getVersion(otherVersionId); 57 58 if (this.otherVersionId == -1 && version1.getId() > version2.getId()) { 60 Document tmpDoc = document1; 61 Version tmpVersion = version1; 62 63 document1 = document2; 64 version1 = version2; 65 66 document2 = tmpDoc; 67 version2 = tmpVersion; 68 } 69 70 DocDiffOutputHelper diffOutputHelper = new DocDiffOutputHelper(document1, document2, version1, version2, repository, publisherContext.getLocale()); 71 DiffGenerator differ = new DiffGenerator(version1, version2, new XmlDocDiffOutput(contentHandler, diffOutputHelper)); 72 differ.generateDiff(); 73 } 74 } 75 | Popular Tags |